akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<string>
#define debug(x) cout << #x << " = " << x << endl
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N=100000;
bool isplndrm(int n)
{
	string s;

	s=to_string(n);
	n=s.size();
	if(n==1)
		return true;
	if(n==2)
	{
		if(s[0]==s[1])
		return true;
		return false;
	}
	if(n==3)
	{
		if(s[0]==s[2])
		return true;
		return false;
	}
	
	for(int i=0;i<=n/2;i++)
	{
		if(s[i]!=s[n-i-1])
		return false;
	}
	return true;
}
int a[N],n,m,c;
int main()
{
	cin>> n>>m;

	for(int i=n;i<=m;i++)
	{
		if(isplndrm(i))
		c++;
	}
	cout << c;
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
using namespace std;
const char* solve() {
    int N, M;
    cin >> N;
    unordered_map<int, int> D, T;
    for (int i = 0, d; i < N; i++) {
        cin >> d;
        D[d]++;
    }
    cin >> M;
    for (int i = 0, t; i < M; i++) {
        cin >> t;
        T[t]++;
    }
    for (const auto& p : T) if(D[p.first] < p.second) return "NO";
    return "YES";
}
int main() {
    cout << solve() << endl;
}


Measured memory_bytes: 16712
#include <bits/stdc++.h>
#define fst first
#define sec second
#define MAX_N (1 << 20)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rer(i, a, b) for(int i = a - 1; i >= b; i--)
#define sz(a) int(a.size())
using namespace std;

typedef vector<int> vi;
typedef long long int ll;
const ll linf = (1ll << 60);

int N;
char ans[1010][1010];

string three[3] = {
"aac",
"b.c",
"bdd"
};
string four[4] = {
"aacd",
"bbcd",
"efgg",
"efhh"
};
string five[5] = {
"abbcc",
"add.e",
"i..je",
"i..jf",
"hhggf"
};
string seven[7] = {
"aabbcc.",
"ggh...d",
"j.h...d",
"jii...e",
"...kkle",
"...n.lf",
"...nmmf",
};


int main() {
	cin >> N;
	rep(i, 0, N) {
		rep(j, 0, N) {
			ans[i][j] = '.';
		}
	}
	if(N == 2) cout << -1 << "\n";
	else {
		if(N == 7 || N == 11) {
			ans[0][0] = 'z';
			ans[0][1] = 'z';
			ans[0][2] = 'y';
			ans[0][3] = 'y';
			ans[0][4] = 'x';
			ans[0][5] = 'x';
			ans[1][6] = 'z';
			ans[2][6] = 'z';
			ans[3][6] = 'y';
			ans[4][6] = 'y';
			ans[5][6] = 'x';
			ans[6][6] = 'x';
			rep(i, 0, 3) {
				rep(j, 0, 3) {
					ans[i + 1][j] = three[i][j];
				}
			}
			rep(i, 0, 3) {
				rep(j, 0, 3) {
					ans[i + 4][j + 3] = three[i][j];
				}
			}
			if(N == 11) {
				rep(i, 0, 4) {
					rep(j, 0, 4) {
						ans[i + 7][j + 7] = four[i][j];
					}
				}
			}
		}
		else if(N % 3 == 0) {
			rep(k, 0, N / 3) {
				rep(i, 0, 3) {
					rep(j, 0, 3) {
						ans[k * 3 + i][k * 3 + j] = three[i][j];
					}
				}
			}
		}
		else {
			int a = -1, b = -1;
			for(int i = 0; i <= N; i++) {
				if(N - 4 * i >= 0 && (N - 4 * i) % 5 == 0) {
					a = i;
					b = (N - 4 * i) / 5;
				}
			}
			if(a != -1) {
				int at = 0;
				while(a--) {
					rep(i, 0, 4) {
						rep(j, 0, 4) {
							ans[at + i][at + j] = four[i][j];
						}
					}
					at += 4;
				}
				while(b--) {
					rep(i, 0, 5) {
						rep(j, 0, 5) {
							ans[at + i][at + j] = five[i][j];
						}
					}
					at += 5;
				}
			}
		}
		rep(i, 0, N) {
			rep(j, 0, N) {
				cout << ans[i][j];
			}
			cout << "\n";
		}
	}
}

Measured memory_bytes: 2176
// I.cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3030;
int n;
double prob[MAX_N], dp[MAX_N][MAX_N];
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lf", &prob[i]);
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= i; j++)
        {
            int x = j, y = i - j;
            if (x)
                dp[x][y] += dp[x - 1][y] * prob[i];
            if (y)
                dp[x][y] += dp[x][y - 1] * (1 - prob[i]);
        }
    double ans = 0;
    for (int i = 0; n - i > i; i++)
        ans += dp[n - i][i];
    printf("%.10lf", ans);
    return 0;
}

Measured memory_bytes: 71936
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f;
int n;
string s;
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='?') s[i]='D';
	}
	cout<<s<<endl;
}

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

using namespace std;

typedef long long ll;

struct Calc{
  ll p;
  string s;
  string::iterator it;

  Calc(ll p,string s) : p(p), s(s) {
    it = s.begin();
  }

  ll add(ll a,ll b){
    return (a + b) % p;
  }

  ll sub(ll a,ll b){
    return (a - b + p) % p;
  }

  ll mul(ll a,ll b){
    return (a * b) % p;
  }

  ll extgcd(ll a,ll b,ll &x,ll &y){
    ll d = a;
    if(b != 0LL){
      d = extgcd(b,a%b,y,x);
      y -= (a/b)*x;
    }else{
      x = 1LL;
      y = 0LL;
    }
    return d;
  }

  ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m + x % m) % m;
  }

  ll fact(){
    ll res = 0LL;
    if(*it == '('){
      ++it;
      res = exp();
      ++it;
    }else{
      while(isdigit(*it)){
        res *= 10LL;
        res += (*it-'0');
        ++it;
      }
    }
    return res;
  }

  ll term(){
    ll res = fact();
    while(*it == '*' || *it == '/'){
      if(*it == '*'){
        ++it;
        res = mul(res,fact());
      }else if(*it == '/'){
        ++it;
        ll x = fact();
        if(x == 0LL){ throw 0; }
        res = mul(res,mod_inverse(x,p));
      }
    }
    return res;
  }

  ll exp(){
    ll res = term();
    while(*it == '+' || *it == '-'){
      if(*it == '+'){
        ++it;
        res = add(res,term());
      }else if(*it == '-'){
        ++it;
        res = sub(res,term());
      }
    }
    return res;
  }
};

string compress(string s){
  string res;
  for(int i = 0 ; i < (int)s.size() ; i++){
    if(s[i] != ' '){ res += s[i]; }
  }
  return res;
}

int main(){
  ll p;
  string in;
  while(getline(cin,in),in != "0:"){
    string s;
    int i;
    in = compress(in);
    for(i = 0 ; i < (int)in.size() ; i++){
      if(in[i] == ':'){ break; }
      s += in[i];
    }
    stringstream ss(s);
    ss >> p;
    in = in.substr(i+1); 
    Calc c(p,in);
    try{
      ll res = c.exp();
      cout << in << " = " << res << " (mod " << p << ")" << endl;
    }catch(...){
      cout << "NG" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define INF 2e9

#define REP(i,n) for(int i = 0; i < n;++i)
#define REPA(i,a,n) for(int i = a; i < n; ++i)
#define ALL(a) a.begin, a.end()

using namespace std;

int main(void) {

	int A, B, count = 0, socket = 1;

	cin >> A >> B;

	if (B == 1) {
		cout << count << '\n';
		return 0;
	}

	socket = A;
	count++;

	while (B > socket) {
		count++;
		socket += A - 1;
	}

	cout << count << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    string s;
    cin>>s;
    int n=s.size() , ans = 0;
    for(int i = 0; i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
        ans++;
    }
	cout<<ans;

	return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>

int main(void) {
    int n, k;
    int x[100000];
    int min;

    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", &x[i]);

    min = 1000000000;
    for (int l = 0; l + k - 1 < n; l++) {
        int r = l + k - 1;
        if (x[l] == 0 && x[r] == 0) {
            min = 0;
        }
        else if (x[l] < 0 && x[r] <= 0) {
            if (-x[l] < min)
                min = -x[l];
        }
        else if (x[l] >= 0 && x[r] > 0) {
            if (x[r] < min)
                min = x[r];
        }
        else {
            int m = -x[l] + x[r] + (-x[l] < x[r]? -x[l]: x[r]);
            if (m < min)
                min = m;
        }
    }

    printf("%d\n", min);
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1920
#include <stdio.h>

int main() {
  long long  n,a,m,M,c,b,i;
  c = 0;
  m = 100000000;
  M =-100000000;
  scanf("%lld",&n);

  for(i=1; i<=n; i++){
    scanf("%lld",&a);
    if(a>M) {
      M = a;
    } 
    if(a < m){
      m = a;
    }
    c = c+a;
  }
    printf("%lld %lld %lld\n",m,M,c);

  return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>
#include<math.h>

int main(){
  int n,k,i,j,count;
  double sum=0;
  scanf("%d%d",&n,&k);
  int h[n];
  for(i=0;i<n;i++){
    j=i+1;
    count=0;
    while(j<k){
      j=j*2;
      count++;
    }
    h[i]=count;
  }
  double tmp=1.0/(double)n;
  double tmpp;
  for(i=0;i<n;i++){
    tmpp=(pow(0.5,(double)h[i]));
    sum+=(tmp*tmpp);
  }
    printf("%.12lf",sum);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 
 
int main() {
    int n,k; cin >> n >> k;
    vector<int> p(n); 
    rep(i,n){
        cin >> p[i];
        p[i]++;
    }
    vector<int> s(n+1);
    rep(i,n){
        s[i+1]=s[i]+p[i];
    }    
    int ans=0;
    for(int i=0; i+k<=n; i++) ans=max(ans,s[i+k]-s[i]);
    cout << fixed << setprecision(10) << (double)(ans)/2 << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll a, b;
  cin >> a >> b;
  if (a > b) cout << 2*a-1 << endl;
  else if (a == b) cout << 2*a << endl;
  else cout << 2*b-1 << endl;
}

Measured memory_bytes: 256
n, k = [int(i) for i in input().split()]
V = [int(i) for i in input().split()]

ans = 0

for m in range(min(n, k) + 1):
    for left in range(m + 1):
        right = m - left
        H = V[:left] + V[n - right:]
        H.sort()
        S = sum(H)
        remain = k - m
        for i in range(min(m, remain)):
            if H[i] > 0:
                break
            S -= H[i]
        
        ans = max(ans, S)

print(ans)

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

  string result = (a % 2 == 1 && b % 2 == 1) ? "Yes" : "No";

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  string S,T; cin>>S>>T;

  bool flag=false;
  for(int i=0;i<S.size();i++){
    if(S==T){
      flag=true; break;
    }
    S=S.back()+S.substr(0,S.size()-1);
  }
  if(flag){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const string NG = "invalid";

// ??°????????¢?????¨????????\??????
bool num(string s)
{
    bool ret = true;
    rep(i,s.size())if(s[i]<'0' || '9'<s[i]) ret = false;
    if(s[0]=='0') ret = (s=="0");
    return ret;
}

string MAX(string a, string b)
{
    if(a==NG) return b;
    int A = a.size(), B = b.size();
    if(A>B) return a;
    if(A<B) return b;
    return (a<b?b:a);
}

map<string,string> dp;
string E(string s)
{
    int S = s.size();
    if(S==0) return NG;
    if(dp.count(s)) return dp[s];

    string ret = NG;
    if(s[0]=='L' || s[0]=='R')
    {
        if(S<6) return NG;
        if(!(s[1]=='('||s[1]=='?')) return NG;
        if(!(s[S-1]==')'||s[S-1]=='?')) return NG;

        string y = s.substr(2,S-3);
        int Y = y.size();
        for(int i=1; i<Y-1; ++i)
        {
            if(y[i]=='?' || y[i]==',')
            {
                string l = E(y.substr(0,i));
                string r = E(y.substr(i+1));

                if(l!=NG && r!=NG)
                {
                    string x;
                    if(s[0]=='L') x=l;
                    if(s[0]=='R') x=r;
                    ret = MAX(ret,x);
                }
            }
        }
    }
    else if('0'<=s[0] && s[0]<='9')
    {
        rep(i,S)if(s[i]=='?') s[i]='9';
        return (num(s)?s:NG);
    }
    else if(s[0]=='?')
    {
        string candidate = "LR9";
        rep(i,3)
        {
            s[0] = candidate[i];
            string x = E(s);
            if(x!=NG) ret = MAX(ret,x);
        }
    }
    return dp[s]=ret;
}

int main()
{
    string s;
    cin >>s;
    cout << E(s) << endl;
    return 0;
}

Measured memory_bytes: 3424
#include<bits/stdc++.h>
using namespace std;
int a[1001],b[1001];
int main()
{
	int n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		for(int j=a[i];j<=b[i];j++)
		{
			sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
int main () {
    string S;
    cin >> S ;
    reverse(S.begin(),S.end());
    vector<int> a(2019);
    int tot = 0 ;
    int x = 1 ;
    int n = S.size();
    ll ans = 0; 
    rep(i,n){
        a[tot]++ ;
        tot += (S[i] - '0') * x ;
        tot %= 2019 ;
        ans += a[tot] ;
        x *= 10 ;
        x %= 2019 ;
    }
    cout << ans << endl ;
}

Measured memory_bytes: 3716
weat= input()
imput = 0
if weat == 'SSS':
  imput = 0
if weat == 'SSR' or weat == 'RSS' or weat == 'SRS' or weat == 'RSR':
  imput = 1
if weat == 'SRR' or weat == 'RRS':
  imput = 2
if weat == 'RRR':
  imput = 3

print(imput)

Measured memory_bytes: 9064
from collections import Counter

N,*A = map(int, open(0).read().split())
ac = Counter(A)
e = [x[0] for x in ac.items() if x[1] % 2 == 0]
if len(e) % 2 == 0:
    print(len(ac))
else:
    print(len(ac)-1)

Measured memory_bytes: 21608
function standardInput(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(text){console.log(text);}//standard output
//[no]param
//0:noConvert	1:singleNum	2:spaceList	3:newLineList	4:spaceNumList	5:newLineNumList
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  for(var i = 0; i < input[0].length; i++){
    var tmp = input[0].split("");
    var tmp2 = tmp[tmp.length - 1];
    tmp.pop();
    tmp.unshift(tmp2);
    input[0] = tmp.join("");
    if(input[0] == input[1]){
       myout("Yes");
      return;
       }
  }
  myout("No");
  
}

Main(standardInput());


Measured memory_bytes: 7372
fun main(args: Array<String>) {
    val (n, _) = readLine()!!.split(" ").map { it.toInt() }
    val p = readLine()!!.split(" ").map { it.toInt() }
    val sum = p.sum()
    val ans = sum / (n+1) + if(sum % (n+1) == 0) 0 else 1
    println(ans)
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

string str;
const string invalid="";
string number_memo[51][51],expr_memo[51][51];

string number(const int begin,const int end){
    string& res=number_memo[begin][end];
    if(res!="undefined") return res;

    if(str[begin]=='0'){
        if(end-begin==1) return res="0";
        else return res=invalid;
    }
    res=invalid;
    int pos=begin;
    while(pos!=end and (isdigit(str[pos]) or str[pos]=='?')){
        res+=str[pos]=='?'?'9':str[pos];
        ++pos;
    }
    if(pos!=end) res=invalid;
    return res;
}

string expr(const int begin,const int end){
    string& res=expr_memo[begin][end];
    if(res!="undefined") return res;

    res=number(begin,end);
    if(end-begin<6) return res;
    const char initial=str[begin];
    if((initial!='?' and initial!='L' and initial!='R') or (str[begin+1]!='?' and str[begin+1]!='(') or (str[end-1]!='?' and str[end-1]!=')')) return res;
    rep(i,begin+3,end-2){
        if(str[i]!='?' and str[i]!=',') continue;
        const string tmp1=expr(begin+2,i),tmp2=expr(i+1,end-1);
        if(tmp1==invalid or tmp2==invalid) continue;
        if(initial=='L'){
            if(tmp1.size()>res.size()) res=tmp1;
            else if(tmp1.size()==res.size()) res=max(res,tmp1);
        }
        if(initial=='R'){
            if(tmp2.size()>res.size()) res=tmp2;
            else if(tmp2.size()==res.size()) res=max(res,tmp2);
        }
        if(initial=='?'){
            if(tmp1.size()>res.size()) res=tmp1;
            else if(tmp1.size()==res.size()) res=max(res,tmp1);
            if(tmp2.size()>res.size()) res=tmp2;
            else if(tmp2.size()==res.size()) res=max(res,tmp2);
        }
    }
    return res;
}

void solve(){
    fill_n((string*)number_memo,51*51,"undefined");
    fill_n((string*)expr_memo,51*51,"undefined");
    cin >> str;
    const string ans=expr(0,str.size());
    if(ans==invalid) cout << "invalid" << endl;
    else cout << ans << endl;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

Measured memory_bytes: 3528
import math

a,b,c,d=map(int, input().split())

lcm=c*d//math.gcd(c,d)

ac=a//c
ad=a//d
acd=a//lcm
bc=b//c
bd=b//d
bcd=b//lcm

A=a-ac-ad+acd
B=b-bc-bd+bcd

if a%c==0 or a%d==0:
  print(B-A)
else:
  print(B-A+1)

Measured memory_bytes: 9128
def sieve(n):
    a = range(n)
    a[:2] = None, None
    for i in range(2, n):
        if i ** 2 >= n: break
        if not a[i]: continue
        for i in range(i ** 2, n, i):
            a[i] = None
    return [v for v in a if v]

def partialsum(a):
    b = [0] + a
    for i in range(len(a)):
        b[i + 1] += b[i]
    return b

a = partialsum(sieve(200000))
while True:
    n = int(raw_input())
    if n == 0: break
    print a[n]

Measured memory_bytes: 20048
from collections import defaultdict
N = int( input())
S = list( map( int, input().split()))

ans = 0
for c in range(1,N):
    now = 0
    for t in range(c ,N, c):
        if ((N-1-t)%c == 0 and N-1-t <= t) or N-1-t - c <=0:
            break
        now += S[t] + S[N-1-t]
        if now > ans:
            ans = now
print(ans)


Measured memory_bytes: 14588
var
 a,b,i,s:longint;
 st:string;
 p:boolean;
begin
 readln(a,b);
 read(st);
 if st[a+1]<>'-' then begin writeln('No');halt;end;
 for i:=1 to a+b+1 do 
  if (i<>a+1) and (st[i] in ['0'..'9']) then inc(s);
 if s<>a+b then writeln('No') else writeln('Yes');
end. 

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

int main(){
    string s;
    cin>>s;
    int count = 0;
    int n = s.size();
    for (int i = 0; i < n/2; i++){
        if (s[i] != s[n-i-1]) count++;
    }
    cout<<count;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<ll,pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main(){
    string s;
    cin >> s;
    int sum = 0;
    rep(i, s.size()) sum += (s[i]-'0');
    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
}   

Measured memory_bytes: 3744
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

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

int main() {
    int w, h, c, g;
    cin >> w >> h >> c;
    g = gcd(w, h);
    cout << (w / g) * (h / g) * c << endl; 

    return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

ll gcd(ll a, ll b) {
    if(a < b) gcd(b, a);
    ll r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

ll lcm(ll a, ll b) {
    return a*gcd(a,b) * b;
}

int main() {
   

    unsigned long long a,b,c,d;
    cin >> a >> b >> c >> d;
    ll cDiv = b/c - (a-1)/c;
    ll dDiv = b/d - (a-1)/d;
    ll cd = c*d/gcd(c,d);
    ll cdDiv = b/cd - (a-1)/cd;
    cout << (b-a+1) - cDiv - dDiv + cdDiv << endl;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	cin >> n;
	cout << n/500*1000+n%500/5*5 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;

    if((a==1 && b==2)||(b==1 && a==2)){cout<<"3"<<endl;}
    else if((a==1 && b==3)||(a==3 && b==1)){cout<<"2"<<endl;}
    else if((a==2 && b==3)||(a==3 && b==2)){cout<<"1"<<endl;}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fori(i,n) for(int i =0;i<n;i++)
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
#define mp make_pair
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(15);
 
 
int mod = 1e9+7;
 
int pow(int a, int b) {
    int ans = 1;
    a %= mod;
    while(b) {
        if(b%2) {
            ans *= a;
            ans %= mod;
        }
        b /= 2;
        a *= a;
        a %= mod;
    }
    return ans;
}

int inv(int a) {
    return pow(a,mod-2);
}

int mul (int a,int b) {
    return ((a%mod)*(b%mod))% mod;
}

struct cmp {
    bool operator() (pair<int,int> a, pair<int,int> b) const {
        int x = a.F;
        int y = b.F;
        return x>=y;
    }
};


int32_t main() {
    FAST;
    int t;
    // cin>>t;
    t = 1;
    while(t--) {
        int x,y;
        cin>>x>>y;
        bool f = 0;
        fori(i,x+1) {
            if(i*2 + (x-i)*4 == y) f = 1;
        }
        cout<<(f ? "Yes" : "No");
    }
    
    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		
		if((x < 0) || (y < 0)) {
			System.out.println("No");
		} else {
			if((W >= (x + r)) && (H >= (y + r))) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}

}



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

vector<bool> visited, exhausted;
stack<int> cycle;
int closing_point;

void DFS(const vector<vector<int>> &graph, int v, int previous_v){
    visited[v] = true;
    cycle.push(v);

    for(auto next_v : graph[v]){
        if(next_v == previous_v) continue;

        if(exhausted[next_v] == false){
            if(visited[next_v] == true)  closing_point = next_v;
            if(visited[next_v] == false) DFS(graph, next_v, v);

            if(closing_point != -1) return;
        }
    }

    // if
    // 1. no next_v (dead-end) or
    // 2. all next_v lead to dead-end
    cycle.pop();
    exhausted[v] = true;
}

int main(){
    int V, E;
    cin >> V >> E;

    vector<vector<int>> graph(V);
    for(int i=0; i<E; i++){
        int s, t;
        cin >> s >> t;
        s -= 1;
        t -= 1;
        graph[s].push_back(t);
        // graph[t].push_back(s);
    }

    for(int i=0; i<V; i++){
        visited.assign(V, false);
        exhausted.assign(V, false);
        while(cycle.empty() == false){
            cycle.pop();
        }
        closing_point = -1;
        DFS(graph, i, -1);

        vector<int> prov_ans;
        while(cycle.empty() == false){
            int t = cycle.top(); cycle.pop();
            prov_ans.push_back(t);
            if(t == closing_point) break;
        }

        int nvc = prov_ans.size();// number of vertices in the cycle
        if(nvc != 0){
            reverse(prov_ans.begin(),prov_ans.end());
            map<int, int> vc;
            for(int j=0; j<nvc; j++){
                vc[prov_ans[j]] = j;
            }

            bool flag = false;
            int start = 0, end = nvc-1;
            for(int j=1; j<nvc; j++){
                for(auto adjacent_v : graph[prov_ans[j]]){
                    // since directed
                    if(j <  nvc - 1 && adjacent_v == prov_ans[j+1]) continue;
                    if(j == nvc - 1 && adjacent_v == prov_ans[0])   continue;

                    if(vc.count(adjacent_v)){
                        //cout << prov_ans[j] << " -- " << adjacent_v << endl;
                        flag = true;
                        end = j;
                        start = max(start, vc[adjacent_v]);
                    }
                }
                if(flag == true){
                    cout << end - start + 1 << endl;
                    for(int k=start; k<=end; k++){
                        cout << prov_ans[k] + 1 << endl;
                    }
                    return 0;
                }
            }
            cout << end - start + 1 << endl;
            for(int k=start; k<=end; k++){
                cout << prov_ans[k] + 1 << endl;
            }
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int k = sc.nextInt();
		int t = sc.nextInt();
		
		int max = 0;
		int[] a = new int[t];
		for (int i = 0; i < t; i++) {
			a[i] = sc.nextInt();
			max = max(max, a[i]);
		}
		
		int ans = max(0, max * 2 - (k + 1));
		
		out.println(ans);
		out.flush();
	}
	
	static int max(int a, int b) {
		return a < b ? b : a;
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
}


Measured memory_bytes: 8276
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
//1-indexed
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT():n(-1){}
	BIT(int n_,T a):n(n_),bit(n_+1,a){}

	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
};
vector<int>G[1<<17];
int n;
int f[1<<17],l[1<<17];
int dfs(int u,int cnt)
{
	f[u]=cnt++;
	for(int i=0;i<G[u].size();i++)cnt=dfs(G[u][i],cnt);
	l[u]=cnt++;
	return cnt;
}
main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int k;scanf("%d",&k);
		for(int j=0;j<k;j++)
		{
			int x;scanf("%d",&x);
			G[i].push_back(x);
		}
	}
	BIT<int>a(dfs(0,1),0);
	int c,x,y,q;scanf("%d",&q);
	for(;q--;)
	{
		scanf("%d",&c);
		if(!c)
		{
			scanf("%d%d",&x,&y);
			a.add(f[x],y);
			a.add(l[x],-y);
		}
		else
		{
			scanf("%d",&x);
			printf("%d\n",a.sum(l[x]-1));
		}
	}
}



Measured memory_bytes: 15236
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define NFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); --i)
#define endl "\n"
#define mp make_pair
#define X first
#define Y second
#define inf 1e9
#define mod 1000000007
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()
#define sz(x) int(x.size())
// #define lli int
typedef long long int lli;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<lli,lli> pll;
typedef vector<lli> vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef complex <long double> complex_t;
const long double PI = acos((long double)-1.0);

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

int main() {
    ll b, e;
    cin >> b >> e;
    ll mul = e/b;
    ll powerLimit = 1;
    while ((1LL<<powerLimit) <= mul) {
        // pr((1LL<<powerLimit));
        powerLimit++;
    }
    cout << powerLimit << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair
#ifndef ONLINE_JUDGE 
#include "/home/asif/Codes/Library/debug.h"
#endif
/*--------------------------------------------------------------------*/

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);

double getC(double A, double B, double ang){
  ang = min(ang, 2 * pi - ang);
  ang = abs(ang);
  return sqrt( A * A + B * B - 2 * A * B * cos(ang));
}

int main() {

  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double angA = (pi / 30) * m;
  double angB = (pi / 6) * (h + (double(m) / 60.0) );
  printf("%.20lf\n", getC(a, b, abs(angA - angB)));

  return 0;
}

Measured memory_bytes: 4136
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  long long n,mi,ma,sum=0LL;
  cin>>n;
  vector<long long> a(n,0);
  rep(i,n){
    cin>>a[i];
    if(i==0){
      ma=a[i];
      mi=a[i];
    }
    sum+=a[i];
    ma=max(ma,a[i]);
    mi=min(mi,a[i]);
  }
  cout<<mi<<" "<<ma<<" "<<sum<<endl;
}

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

int main(){
  int k,x;
  cin >> k >> x;
  int n = 2000001;
  for(int i = max(x-k+1,-1000000);i<=min(x+k-1,1000000);i++){
    cout << i << " ";
  }
  cout << endl;
}



Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


char S[300010];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N;
	scanf("%d ", &N);

	fread(S, 1, N * 3, stdin);

	const int mod = 998244353;
	ll kotae = 1;
	char k = 0;
	int r = 0, g = 0, b = 0;
	int rg = 0, gb = 0, br = 0;
	char mae = 0;
	rep(i, 3 * N) {
		if (S[i] == 'R') {
			if (gb) kotae = kotae * gb-- % mod;
			else if (g) kotae = kotae * g-- % mod, rg++;
			else if (b) kotae = kotae * b-- % mod, br++;
			else r++;
		}
		else if (S[i] == 'G') {
			if (br) kotae = kotae * br-- % mod;
			else if (b) kotae = kotae * b-- % mod, gb++;
			else if (r) kotae = kotae * r-- % mod, rg++;
			else g++;
		}
		else {
			if (rg) kotae = kotae * rg-- % mod;
			else if (r) kotae = kotae * r-- % mod, br++;
			else if (g) kotae = kotae * g-- % mod, gb++;
			else b++;
		}
	}
	rep1(i, N) kotae = kotae * i % mod;

	printf("%lld\n", kotae);


	Would you please return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#define vi vector<int>
using namespace std;
int main(){vi v(4,0);vi v2(2,0);while(cin>>v[0]>>v[1]>>v[2]>>v[3]>>v2[0]>>v2[1]){sort(v.begin(),v.end());int ans=0;for(int i=1;i<=3;i++)ans+=v[4-i];cout<<ans+max(v2[0],v2[1])<<endl;}}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>

using namespace std;

using ull = unsigned long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vull = vector<ull>;
using vpii = vector<pii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    string S;
    cin >>S;
    cout <<(700+((S[0]=='o')+(S[1]=='o')+(S[2]=='o'))*100);

    return 0;
}

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

using ll = long long;

using namespace std;

int main() {
    string n;
    cin >> n;
    int ans = 0;
    for (auto c:n) {
        ans += c - '0';
        ans %= 9;
    }
    cout << (ans == 0 ? "Yes" : "No") << '\n';
    return 0;
}

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

using namespace std;
typedef long long LL;
int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
const int N = 200001;
int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
char getc() {
	char ch = getchar();
	while(ch < 'A' || ch > 'Z') ch = getchar();
	return ch;
}
void put(int x) {
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

struct node {char c1, c2;} g[N];
char ss[N]; int n, q;

bool checkl(int mid) {
	int id = mid; char cc = ss[mid];
	for(int i = 1; i <= q; i++) {
		if(g[i].c1 == cc) {
			if(g[i].c2 == 'L') id--;
			else id++;
			if(id <= 0) return 1;
			if(id > n) return 0;
			cc = ss[id];
		}
	} return 0;
}

bool checkr(int mid) {
	int id = mid; char cc = ss[mid];
	for(int i = 1; i <= q; i++) {
		if(g[i].c1 == cc) {
			if(g[i].c2 == 'L') id--;
			else id++;
			if(id > n) return 1;
			if(id <= 0) return 0;
			cc = ss[id];
		}
	} return 0;
}

int main() {
	n = read(), q = read();
	scanf("%s", ss + 1);
	for(int i = 1; i <= q; i++) g[i].c1 = getc(), g[i].c2 = getc();
	int l = 1, r = n, h1 = 0;
	while(l <= r) {
		int mid = (l + r) / 2;
		if(checkl(mid)) l = mid + 1, h1 = mid;
		else r = mid - 1;
	} l = 1, r = n; int h2 = n + 1;
	while(l <= r) {
		int mid = (l + r) / 2;
		if(checkr(mid)) r = mid - 1, h2 = mid;
		else l = mid + 1;
	} h1++, h2--;
	if(h1 > h2) puts("0");
	else put(h2 - h1 + 1), puts("");
	return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

const int mod = 1e9+7;
#define ll long long int
const double epsilon = 1e-7;

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}

int main(void){
    ll h, w;
    scanf("%lld %lld", &h, &w);
    if(h%3 == 0 || w%3 == 0){
        printf("0\n");
        return 0;
    }
    if(h == 2 || w == 2){
        printf("1\n");
        return 0;
    }
    ll ans = mi(h, w);
    if(h%2 == 0){
        ans = mi(ans, (w*h-w/3*h)/2 - w/3*h);
        ans = mi(ans, -(w*h-(w/3+1)*h)/2 + (w/3+1)*h);
    }else{
        ans = mi(ans, (w-w/3)*(h/2+1) - mi(w/3*h, (w-w/3)*(h/2)));
        ans = mi(ans, 0-(w-w/3-1)*(h/2) - mi(-(w/3+1)*h, -(w-w/3-1)*(h/2+1)));
    }
    if(w%2 == 0){
        ans = mi(ans, (w*h-h/3*w)/2 - h/3*w);
        ans = mi(ans, -(w*h-(h/3+1)*w)/2 + (h/3+1)*w);
    }else{
        ans = mi(ans, (h-h/3)*(w/2+1) - mi(h/3*w, (h-h/3)*(w/2)));
        ans = mi(ans, 0-(h-h/3-1)*(w/2) - mi(-(h/3+1)*w, -(h-h/3-1)*(w/2+1)));
    }
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

int main()
{
    int n, a, b, c, d;

    cin>>n;
    d=n%10;
    n/=10;
    c=n%10;
    n/=10;
    b=n%10;
    n/=10;
    a=n%10;
    n/=10;

    if(a+b+c+d==7)
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
    else if(a+b+c-d==7)
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
    else if(a+b-c+d==7)
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
    else if(a+b-c-d==7)
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
    else if(a-b+c+d==7)
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
    else if(a-b+c-d==7)
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
    else if(a-b-c+d==7)
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
    else if(a-b-c-d==7)
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll q,n,a[200],b[61];
string s;
ll ins(ll x){
    for(ll i=60;i>=0;i--){
        if(((x>>i)&1)==1){
            if(b[i]==0){b[i]=x;return 1;}
            x^=b[i];
        }
    }
    return 0;
}
int main(void){
    cin>>q;
    while(q--){
        ll ok=0;
        cin>>n;
        for(int i=0;i<n;i++)cin>>a[i];
        cin>>s;
        for(int i=0;i<=60;i++)b[i]=0;
        for(int i=n-1;i>=0;i--){
            if(ins(a[i])==1&&s[i]=='1'){cout<<1<<endl;ok=1;break;}
        }
        if(ok==0)cout<<0<<endl;
    }
}


Measured memory_bytes: 3640
#include <iostream>
#define N_MIN 1
#define N_MAX 100
#define A_MIN 0
#define A_MAX 100
using namespace std;

int bubbleSort(int *A, int n, int num) {
    bool flag = true;
    while (flag) {
        flag = false;
        for (int i = n - 1; i >= 1; i--) {
            if (A[i] < A[i-1]) {
                swap(A[i], A[i-1]);
                num += 1;
                flag = true;
            }
        }
    }
    return num;
}

int main() {
    // input
    int n;
    cin >> n;

    int A[N_MAX];
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }

    // solve
    int num = 0;
    num = bubbleSort(A, n, num);

    // output
    for (int i = 0; i < n; i++) {
        cout << A[i];
        if (i == n - 1) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
    cout << num << endl;
}


Measured memory_bytes: 3072
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        double r = Double.parseDouble(br.readLine());
        System.out.printf("%.6f %.6f\n",r*r*Math.PI,2*r*Math.PI);
        
    }
}

Measured memory_bytes: 24780
# 入力
n, m, x = map(int, input().split())
a = list(map(int, input().split()))


goto_goal_0 = 0 # 0までのコスト
goto_goal_n = 0 # nまでのコスト

# x から 0 へ向かうコストを計算
for i in range(x - 1, 0, -1):   # x-1 番目から順番にデクリメントしながらforループ
    if i in a:
        goto_goal_0 += 1
        # print("0 is {}".format(goto_goal_0))

# x から n へ向かうコストを計算
for i in range(x, n + 1):   # x 番目から順番にインクリメントしながらforループ
    if i in a:
        goto_goal_n += 1
        # print("n is {}".format(goto_goal_n))

if goto_goal_0 < goto_goal_n:
    print(goto_goal_0)
else:
    print(goto_goal_n)

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

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)


using namespace std;
ll INF = LONG_LONG_MAX;
ll mod = 1000000000 + 7;

template <typename T, typename L>
void read(vector<T> & _data, L & _size, bool _shift) {
    _data.resize(_size + (ll)_shift);
    for (ll i = (ll)_shift; i < _size + (ll)_shift; i++)
        cin >> _data[i];
}

template <typename T, typename L>
void read(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) {
    _data.resize(_rows + (ll)_shiftRows);
    for (ll i = 0; i < _rows + (ll)_shiftRows; i++)
        _data[i].resize(_cols + (ll)_shiftCols);
    for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++)
        for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++)
            cin >> _data[i][j];
}

template <typename T>
void write(vector<T> & _data, bool _shift) {
    for (ll i = (ll)_shift; i < _data.size(); i++)
        cout << _data[i] << " ";
    cout << endl;
}


//TODO: SOLUTION


void solve() {
    ll n, k, q;
    cin >> n >> k >> q;
    vll a; read(a, n, 0);
    ll ans = INF/2;

    for (auto x : a) {
        vvll split;
        int i = 0;
        while (i < n) {
            while (i < n && a[i] < x)
                i++;
            if (i >= n)
                break;

            split.push_back({});
            while (i < n && a[i] >= x) {
                split[split.size() - 1].push_back(a[i]);
                i++;
            }
        }

        vll all;

        for (auto v : split) {
            sort(v.begin(), v.end());
            int j = 0;
            while (j < (int)v.size() - k + 1) { // v.size() is unsigned integer
                all.push_back(v[j]);
                j++;
            }
        }

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

        if ((ll)all.size() >= q)
            ans = min(ans, all[q - 1] - x);
    }

    cout << ans << endl;
}


int main() {

    // TODO: Set value of this variable manually
    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3788