akhauriyash/Code-Regression huggingface dataset:
N = int(input())
NR = int(N**0.5)
count = 0
if int(N/2)-N/2 == 0:
    for i in range(1,int(N/2)):
        if int(N/i)-N/i == 0:
            count += int(N/i)-1
        else:
            count += int(N/i)
else:
    for i in range(1,int(N/2)+1):
        if int(N/i)-N/i == 0:
            count += int(N/i)-1
        else:
            count += int(N/i)

count += int(N/2)
print(count)


Measured memory_bytes: 9436
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int n,mod;
  cin >> n >> mod;

  vector<Int> X(n);
  cin>>X;
  sort(X.begin(),X.end());
  map<Int,Int> cnt;
  for(Int x:X) cnt[x]++;
  
  map<Int,Int> eq;
  for(auto p:cnt) eq[p.first%mod] += p.second / 2;

  map<Int,Int> eqmod;
  for(Int x:X) eqmod[x%mod]++;

  Int ans = 0;
  ans += eqmod[0] / 2;
  for(Int i = 1;i < mod;i++){
    if(i > mod - i) continue;
    
    if(i == mod - i){
      ans += eqmod[i] / 2;
      continue;
    }

    Int a = 0;
    if(eqmod[i] < eqmod[mod - i]) a = min(abs(eqmod[mod-i]-eqmod[i])/2, eq[mod-i]);
    if(eqmod[i] > eqmod[mod - i]) a = min(abs(eqmod[mod-i]-eqmod[i])/2, eq[i]);
    ans += min(eqmod[i], eqmod[mod-i]) + a;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 19840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >>x;
  int kazu=x/100;
  int amari=x%100;
  for(int i=0;i<=kazu;i++){
    for(int j=0;j<=kazu;j++){
      for(int k=0;k<=kazu;k++){
        for(int m=0;m<=kazu;m++){
          for(int n=0;n<=kazu;n++){
            if(i+j*2+k*3+m*4+n*5==amari&&i+j+k+m+n<=kazu){
              cout<<1<<endl;
              return 0;
            }
            if(i+j+k+m+n>kazu)break;
          }
        }
      }
    }
  }
  cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
const int inf = 1000000000; // 10^9

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int L = inf, R = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		L = min(L, a[i]);
		R = max(R, a[i]);
	}

	int totalStamina = inf;
	for (int i = L; i <= R; i++) {
		int sum = 0;
		for (int j = 0; j < n; j++) sum += pow(a[j] - i, 2);
		totalStamina = min(totalStamina, sum);
	}
	cout << totalStamina;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char str[105];
int v[30];
int main(){
  scanf("%s",str);
  for (int i=0; str[i]; ++i){
    v[str[i]-'a']++;
  }
  int flag=0;
  for (int i=0; i<26; ++i){
    if (v[i]&1)flag=1;
    if (flag)break;
  }
  if (flag)printf("No\n");
  else printf("Yes\n");
}

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

typedef long long ll;

const int MOD = 1000000007;

int main(){
    int N;
    string S;
    int t[26] = {0};
    cin >> N;
    cin >> S;

    for(int i=0; i<N; i++){
        t[S[i] - 'a'] += 1; 
    }

    ll ans = 1;
    for(int i=0; i<26; i++){
        ans *= t[i] + 1;
        ans = ans % MOD;
    }

    ans = (ans-1) % MOD;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;

  int ans = 2 * n;
  for(int i = 0; i < n; i++){
    bool match = true;
    for(int j = 0; i + j < n; j++){
      if(s[i + j] != t[j]){
        match = false;
        break;
      }
    }
    if(match) ans = min(ans, 2 * n - (n - i));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;

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

	while(true){
	ipot=s.nextLine();
		
		if("0 0".equals(ipot)){
		break;
		}
		
		System.out.println(cop(ipot));
	
	}
	}
	private static String cop(String ipot){
	String space=" ";
	String nums[]=ipot.split(space);
		
		Long x= Long.parseLong(nums[0]);
		Long y= Long.parseLong(nums[1]);
		
		if(x>y){
		
		return (y+space+x);
		
		}
		return (x+space+y);
	}
	
	
}


Measured memory_bytes: 35140
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e3 + 5;
LL a[maxn],b[maxn][maxn];

int sleep() {
	int j=0;
	for(int i=1; i<2000001; i++) j++;
	return j;
}

int main() {
	int n;
	LL x,sum = 1LL << 60LL;
	cin >> n >> x;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) {
		b[i][0] = a[i];
		for(int k = 1; k <= n - 1; k++) {
			int pos = i - k;
			if(pos <= 0) pos = n - abs(pos);
			b[i][k] = min(b[i][k - 1],a[pos]);
		}
	}
	for(int k = 0; k <= n - 1; k++) {
		LL ans = 0;
		for(int i = 1; i <= n; i++) {
			ans += b[i][k];
		}
		sum = min(sum,ans + x * k);
	}
	printf("%lld",sum);
	sleep();
	return 0;
}

Measured memory_bytes: 31616
N,K = map(int,input().split())
S= input()
i,j = 0,0
onenumber = [0] * (K+1)
zeronumber = [0] * K
test, answer = 0,0
infront = ''

for x in S:
    if x == '0':
        if infront == '1':
            test += onenumber[j]
            answer = max(answer,test)
            if j == K:
                j = -1
            j += 1
            if i == K:
                i = 0
            test -= onenumber[j]
            test -= zeronumber[i]
            onenumber[j],zeronumber[i] = 0, 0
        zeronumber[i] += 1
        infront = '0'
    if x == '1':
        if infront == '0':
            test += zeronumber[i]
            i += 1
        onenumber[j] += 1
        infront = '1'

if S[-1] == '0':
    test += zeronumber[i]
else:
    test += onenumber[j]
answer = max(answer,test)
print(answer)


Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define md 1000000007
int main()
{
    int m; cin >> m;
     char a[100],b[100],c[100]; cin >> a >> b; ll d = strlen(a);
    for(ll i =0; i < d ;i++)

    {
        //c[i] = a[i] + b[i];
        printf("%c%c",a[i],b[i]);
    }


}


Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def calc(x: Int): Int = if (x == 1) (1) else (calc(x / 2) * 2)

  def solve(sc: => Scanner): Unit = {
    val A = Array.fill[Int](12)(sc.nextInt).sorted
    if (A(0) == A(1) && A(1) == A(2) && A(2) == A(3)
      && A(4) == A(5) && A(5) == A(6) && A(6) == A(7)
      && A(8) == A(9) && A(9) == A(10) && A(10) == A(11))
      (println("yes")) else (println("no"))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 45212
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
#include <cassert>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int T, H, W, N;
char m[22][32], q[110];
const char dir[] = { 'U', 'R', 'D', 'L' };
const char dir_c[] = { '^', '>', 'v', '<' };
const int di[] = { -1, 0, 1, 0 };
const int dj[] = { 0, 1, 0, -1 };

bool is_tank(char c) { return c == '<' || c == '>' || c == '^' || c == 'v' ; }

int get_dir(char c) {
  int ret = -1;
  rep(i,4) if (c == dir[i]) ret = i;
  return ret;
}
char get_dir_c(char c) {
  char ret = -1;
  rep(i,4) if (c == dir[i]) ret = dir_c[i];
  return ret;
}

void do_shoot(int dir, int ci, int cj) {
  while (0 <= ci && ci < H && 0 <= cj && cj < W) {
    bool flag = false;
    switch (m[ci][cj]) {
      case '-':
      case '.': break;
      case '#': flag = true; break;
      case '*': m[ci][cj] = '.'; flag = true; break;
    }
    if (flag) break;
    ci += di[dir];
    cj += dj[dir];
  }
}

void f() {
  int dir = -1, ci = -1, cj = -1;
  rep(i,H) rep(j,W) if(is_tank(m[i][j])) {
    switch (m[i][j]) {
      case '^': dir = 0; break;
      case '>': dir = 1; break;
      case 'v': dir = 2; break;
      case '<': dir = 3; break;
    }
    ci = i, cj = j;
    break;
  }
  rep(i,N) {
    if (q[i] == 'S') {
      do_shoot(dir, ci, cj);
    } else {
      dir = get_dir(q[i]);
      int ti = ci + di[dir], tj = cj + dj[dir];
      if (0 <= ti && ti < H && 0 <= tj && tj <= W && (m[ti][tj] == '.')) {
        m[ci][cj] = '.';
        m[ti][tj] = get_dir_c(q[i]);
        ci = ti, cj = tj;
      } else {
        m[ci][cj] = get_dir_c(q[i]);
      }
    }
  }
  rep(i,H) printf("%s\n", m[i]);
}

int main() {
  scanf("%d", &T);
  rep(loop,T) {
    if (loop) puts("");
    scanf("%d%d", &H, &W);
    rep(i,H) scanf("%s", m[i]);
    scanf("%d", &N);
    scanf("%s", q);
    f();
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long 
#define ld long double
//=======================================================================================================
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
//=================================================================
#define vi vector<int>
#define vll vector<ll>
#define vvi vector< vector<int> >
#define vvll vector< vector<ll> >
#define vs vector<string>
#define si set<int>
#define sll set<ll>
#define ss set<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define pb push_back
#define fxsp(a) fixed<<setprecision(a)
//=============================================================
#define rFor(i,a,b) for(int i=a;i>b;i--)
#define For(i,a,b) for(int i=a;i<b;i++)
//=============================================================
void inout_fast(){
    //input output file && fast input
    ios::sync_with_stdio(0); 
    cin.tie(0);

    //freopen("input.txt","r",stdin);

      
}
//=====================================================================================================

int main(){
    inout_fast();
 //start coding :):):)  


    ll a;
    cin>>a;
    ll sum=0;

    for(ll i=1;i<=a;i++){
        for(ll j=1;j<=a;j++){
            for(ll k=1;k<=a;k++){
                sum+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<sum<<endl;
    
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

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

    int cnta=0,cntb=0,cntc=0;

    rep(i,n){
        int p;
        cin>>p;
        if(p<=a){
            cnta++;
        }
        else if (p<=b) {
           cntb++;
        }
        else {
            cntc++;
        }
    }
    int ans=min({cnta,cntb,cntc});
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int n,x=0,y=0,w=0,z=0;
 cin>>n;
 for (int i = 0; i < n; i++) {
   string a;
   cin>>a;
   if(a=="AC"){
     x++;
   }
   else if(a=="WA"){
     y++;
   }
   else if(a=="TLE"){
     w++;
   }
   else{
     z++;
   }
 }
   cout<<"AC x "<<x<<endl;
   cout<<"WA x "<<y<<endl;
   cout<<"TLE x "<<w<<endl;
   cout<<"RE x "<<z<<endl;
}

Measured memory_bytes: 3628
def main():
    _ = int(input())
    a = list(map(int, input().split()))
    odds = []
    for i in a:
        if i % 2 == 0:
            odds.append(i)

    for i in odds:
        if i % 3 != 0 and i % 5 != 0:
            print("DENIED")
            return

    print("APPROVED")


def main1():
    _ = int(input())
    a = list(map(int, input().split()))
    odds = list(filter(lambda x: x % 2 == 0, a))
    denied = list(filter(lambda x: x % 3 != 0 and x % 5 != 0, odds))
    if denied:
        print("DENIED")
    else:
        print("APPROVED")


if __name__ == "__main__":
    main1()


Measured memory_bytes: 38384
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

string s;
int cnt[20000];
set<int> st;

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

   cin >> s;
   for(auto t:s){
      cnt[t]++;
      st.insert(t);
   }

   if(st.size()==2){
      for(auto t:st){
         if(cnt[t]==2)continue;
         else {
            cout << "No" << endl;
            return 0;
         }
      }
      cout << "Yes" << endl;
      return 0;
   }
   cout << "No" << endl;


return 0;
}
///....


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <iostream>
#include <functional>
#include <map>
using namespace std;



int main()
{
	int w, h, n;
	cin >> w >> h >> n;
	int lmin = 0, umax = h, lmax = w, umin = 0;
	int x, y, a;
	for (int i = 0; i < n; i++)
	{
		cin >> x >> y >> a;
		if (a == 1)
		{
			if (x>lmin)
				lmin = x;
		}
		if (a == 2)
		{
			if (x < lmax)
				lmax=x;
		}
		if (a == 3)
		{
			if (y>umin)
				umin = y;
		}
		if (a == 4)
		{
			if (y < umax)
				umax = y;
		}
	}
	if (lmax>lmin &&umax>umin)
	{
		cout << (lmax - lmin)*(umax - umin) << endl;
	}
	else
	{
		cout << "0" << endl;
	}



	return 0;
}


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

using namespace std;

typedef long long ll;

const int N = 300005;
int l[N], r[N], n;
char s[N];

int main()
{
    cin>>n;
    scanf("%s", s+1);
    for (int i = 1; i <= n; i++)
        {
        if (s[i] == 'W') l[i+1] = l[i] + 1;
        else l[i+1] = l[i];
        }
    for (int i = n; i >= 1; i--)
        {
        if (s[i] == 'E') r[i-1] = r[i] + 1;
        else r[i-1] = r[i];
        }
    int ans = 1e9;
    for (int i = 1; i <= n; i++)
        {
        //printf("%d %d\n", l[i], r[i]);
        ans = min(ans, l[i] + r[i]);
        }
    cout << ans;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define int long long
using namespace std;

vector<pair<int,int>> find(vector<int> v){
    v.push_back(0);
    int num=0;
    vector<pair<int, int>> ans;
    for(int i=0; i<v.size()-1; i++){
        num++;
        if(v.at(i)!=v.at(i+1)){
            ans.push_back(make_pair(num, v.at(i)));
            num=0;
        }
    }
    sort(ans.begin(),ans.end(),greater<pair<int, int>>());
    return ans;
}

signed main(){
    int n; cin>>n;
    vector<int> a(n/2),b(n/2);
    for(int i=0; i<n; i++){
        if(i%2==0) cin>>a.at(i/2);
        else cin>>b.at((i-1)/2);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    vector<pair<int, int>> A=find(a),B=find(b);
    int ans=0;
    if(A.front().second==B.front().second){
        if(A.size()==1 and B.size()==1){
            ans=a.size();
        }else if(A.size()==1){
            ans=b.size()-B.at(1).first;
        }else if(B.size()==1){
            ans=a.size()-A.at(1).first;
        }else{
            ans=(a.size()-A.front().first+b.size()-B.at(1).first<a.size()-A.at(1).first+b.size()-B.front().first?
                 a.size()-A.front().first+b.size()-B.at(1).first:a.size()-A.at(1).first+b.size()-B.front().first);
        }
    }else{
        ans=a.size()-A.front().first+b.size()-B.front().first;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4204
package main

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

var scan *bufio.Scanner
var writer io.Writer

func init() {
	scan = bufio.NewScanner(os.Stdin)
	writer = os.Stdout
	scan.Split(bufio.ScanWords)
}

func main() {
	solve()
}

func solve() {
	a, b := nextInt(), nextInt()
	aa := a - 1
	bb := b - 1
	res := bb / aa
	if bb%aa != 0 {
		res++
	}
	fmt.Fprint(writer, res)
}

func nextWord() string {
	scan.Scan()
	str := scan.Text()
	return str
}

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
    ll n, k;
    cin >> n >> k;
    ll h[n];
    rp(i, 0, n) cin >> h[i];
    ll sum = 0;

    sort(h, h + n);
    if (k >= n)
    {
        cout << 0 << endl;
    }
    else
    {
        rp(i, 0, n - k)
        {
            sum += h[i];
        }
        cout << sum << endl;
    }
}

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

int main()
{
    int n, k;
    cin >> n >> k;

    string s;
    cin >> s;
    vector<char> s_lr;

    int i = 0;
    while (i < s.size())
    {
        char now = s[i];
        s_lr.push_back(now);
        for (i; i < s.size() and s[i] == now; i++){}
    }

    i = min(2 * k, (int)s_lr.size() - 1);
    int ans = n;
    if (s_lr[i] == 'L')
    {
        i++;
        --ans;
    }
    
    ans -= (max(0, (int)s_lr.size() - i) / 2) * 2;
    if (s_lr.back() == 'R')
        ans--;

    // rep(i, 0, s_lr.size())
    //     cout << s_lr[i] << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, m: usize,
        s: chars,
    }
    const INF: i64 = 1 << 50;
    let mut dp = vec![INF; n + 1];
    dp[n] = 0;
    let mut st = vec![None; n + 1];
    st[0] = Some((n, n));
    let mut pos = 0;
    for i in (0..n).rev() {
        if s[i] == '1' { continue; }
        if pos == 0 { pos += 1; }
        while let Some((lo, _hi)) = st[pos - 1] {
            if lo <= i + m {
                break;
            }
            pos += 1;
        }
        if st[pos - 1].is_none() {
            puts!("-1\n");
            return;
        }
        let (x, y) = st[pos].unwrap_or((i, i));
        st[pos] = Some((min(x, i), y));
    }
    for i in (1..pos + 1).rev() {
        puts!("{} ", st[i - 1].unwrap().0 - st[i].unwrap().0);
    }
    puts!("\n");
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 12796
# -*- coding: utf-8 -*-

'''
7
abcdbbd
6
2 3 6
1 5 z
2 1 1
1 4 a
1 7 d
2 1 7
'''

# from helper import elapsed_time
from bisect import bisect_left, insort_left


N = int(input())
s = list(input())
Q = int(input())

# a-zまでの26文字に対して、s文字列の各文字に該当するindexを格納しておく
d = {i: [] for i in range(26)}
for i, c in enumerate(s):
    d[ord(c) - ord("a")].append(i)


# @elapsed_time
def convert(d: dict, s: list, q1: int, q2: str):
    if s[q1] == q2:
        return d, s

    didx_before = ord(s[q1]) - ord("a")
    didx_after = ord(q2) - ord("a")

    idx = bisect_left(d[didx_before], q1)
    d[didx_before].pop(idx)
    s[q1] = q2
    insort_left(d[didx_after], q1)

    return d, s


# @elapsed_time
def calc(d: dict, q1: int, q2: int):
    ans = 0
    for i in range(26):
        idx = bisect_left(d[i], q1)
        if d[i] and q1 <= d[i][-1] and d[i][idx] < q2 + 1:
            ans += 1

    return ans


for _ in range(Q):
    q, q1, q2 = input().split()
    q = int(q)
    if q == 1:
        d, s = convert(d, s, int(q1) - 1, q2)
    if q == 2:
        print(calc(d, int(q1) - 1, int(q2) - 1))


Measured memory_bytes: 28808
N = int(input())
dict = []
for i in range(N):
    line = input().split()
    S = line[0]
    P = int(line[1])
    dict.append({"id": i+1, "S":S, "P":P})

dict = sorted(dict, key=lambda x:(x["S"],-x["P"]))

for d in dict:
    print(d["id"])

Measured memory_bytes: 3064
abcd = list(input())

for bit in range(1 << 3):
    answer = 0
    op = ["-", "-", "-"]
    for i in range(3):
        if (bit >> i) & 1:
            op[i] = "+"
    if eval(abcd[0] + op[0] + abcd[1] + op[1] + abcd[2] + op[2] + abcd[3]) == 7:
        answer = abcd[0] + op[0] + abcd[1] + op[1] + abcd[2] + op[2] + abcd[3] + "=7"
        break
print(answer)


Measured memory_bytes: 9008
#include<bits/stdc++.h>
#define N 305
#define pd(x) push_back(x)
using namespace std;
int n,m;
int a[N][N];
int vis[N];
vector<int>v[N];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            scanf("%d",&a[i][j]);
        }
        v[a[i][1]].pd(i);
    }
    int ans=10000;
    for(int i=1;i<=m;i++)
    {
        int now=0,id;
        for(int j=1;j<=m;j++)
        {
            if(!vis[j]&&v[j].size()>now)now=v[j].size(),id=j;
        }
        ans=min(ans,now);
        vis[id]=1;
        for(int j=0;j<v[id].size();j++)
        {
            int tmp=v[id][j];
            for(int k=1;k<=m;k++)
            {
                if(!vis[a[tmp][k]])
                {
                    v[a[tmp][k]].pd(tmp);
                    break;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1280
<?php
$n = intval(fgets(STDIN));
$a = explode(" ", trim(fgets(STDIN)));

$min = 10**10;
$s = 0;
for($i = 0; $i < $n; $i++){
  $s+=$a[$i];
  $diff = abs(array_sum($a)-$s*2);
  $min = min($diff, $min);
}
echo $min;

Measured memory_bytes: 4728
#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;
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
#define f first
#define s second
#define CS ios_base::sync_with_stdio(0);cin.tie(0);
#define PI acos(-1)
typedef long long ll;
typedef long double ld;
const int mod = ( int ) 1e9 + 7;
const int mod2 = ( int ) 1e9 + 9;
const ll inf = 1e18 + 100;
const int INF = 2000000000;
const int N = 1e6 + 100;
const long double EPS = 1e-9;
typedef complex < double > pt;



int main()
{
	CS;

	int h, w, d;
	cin >> h >> w >> d;
	for(int i = 0; i < h; i++)
	{
		int x = 550 - i;
		for( int j = i ; j < w + i ; j++, x++ )
		{
			if((x / d) % 2 == 0 && (j / d) % 2 == 0 )
				cout << 'Y';
			else if((x / d) % 2 == 1 && (j / d) % 2 == 0 )
				cout << 'G';
			else if((x / d) % 2 == 0 && (j / d) % 2 == 1 )
				cout << 'R';
			else if((x / d) % 2 == 1 && (j / d) % 2 == 1 )
				cout << 'B';
			if( j == w + i - 1 )
				cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 512
/*
 * Author : Sadi
 * Tue 14/07/2020
 * 14:03:50.98
 */
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

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

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n;
    cin >> n;
    string str;
    cin >> str;
    int ans = 0;
    for(int i = 0; i < n - 1; ++i) {
        if(str[i] != str[i + 1]) {
            ans++;
        }
    }
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 3748
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val hs = (0 until n).map { readLine()!!.toLong() }.sorted()
    println((0..(n - k)).map { hs[it + k - 1] - hs[it] }.min())
}

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

#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define fi first
#define se second
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef long double ld;
typedef string st;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
const ll MOD = 1e9 + 7 ;
const ll INF=1e14;
ll mpow(ll a,ll b,ll p=MOD){a=a%p;ll res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const ll N=800005;
ll dp[3002][3002];
pii pa[3002][3002];
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  st a,b;
  cin>>a>>b;
  ll n=(ll)a.length();
  ll m=(ll)b.length();
  forn(i,a.length()+1)
  {
    forn(j,b.length()+1)
    {
      pa[i][j]={-1,-1};
      if(i==0||j==0) dp[i][j]=0;
      else{
        if(a[i-1]==b[j-1])
        {
          dp[i][j]=dp[i-1][j-1]+1;
          pa[i][j]={i-1,j-1};
        }
        else{
          if(dp[i-1][j]>=dp[i][j-1])
          {
            dp[i][j]=dp[i-1][j];
            pa[i][j]=pa[i-1][j];
          }
          else {
           dp[i][j]=dp[i][j-1];
           pa[i][j]=pa[i][j-1]; 
          }
        }
      }
    }
  }
  st ans="";
  pii p=pa[n][m];
  while(p.fi!=-1)
  {
    //cout<<p.fi<<" "<<p.se<<'\n';
   ans+=a[p.fi];
   p=pa[p.fi][p.se];
  }
  reverse(all(ans));
  cout<<ans;
}
//nothing is impossible

Measured memory_bytes: 211456
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int[] A = new int[N], B = new int[N], C = new int[N];
		int ans = 0;
		for(int i = 0;i < N;i++) {
			A[i] = scn.nextInt();
		}
		for(int i = 0;i < N;i++) {
			B[i] = scn.nextInt();
			ans += B[i];
		}
		for(int i = 0;i < N-1;i++) {
			C[i] = scn.nextInt();
		}
		int b = -2;
		int n = A[0];
		for(int i = 0;i < N-1;i++) {
			b = n;
			n = A[i+1];
			if(n-b==1) {
				ans += C[b-1];
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 23252
import Control.Monad (forM_,replicateM)
import Control.Monad.ST (ST,runST)
import qualified Data.Array.ST as STArr

type Block = (Int,Int)

main = do
    [a,b] <- getLine >>= return . map read . words
    if all (==0) [a,b] then return () else do
        n <- readLn
        blocks <- replicateM n (getLine >>= return . block . map read. words)
        print $ countRoute a b blocks
        main

    where
    block [x,y] = (x,y)

countRoute :: Int -> Int -> [Block] -> Int
countRoute a b blocks = runST $ do
    counts <- STArr.newArray ((0,0),(a,b)) 0
        :: ST s (STArr.STUArray s (Int,Int) Int)

    STArr.writeArray counts (1,1) 1
    forM_ [(i,j)|i<-[1..a] ,j<-[1..b], (i,j) /= (1,1) && not ((i,j) `elem` blocks)]
        (updateCount counts)

    STArr.readArray counts (a,b)

    where
    updateCount counts (i,j) = do
        c1 <- STArr.readArray counts (i-1,j)
        c2 <- STArr.readArray counts (i,j-1)
        STArr.writeArray counts (i,j) (c1+c2)

Measured memory_bytes: 4156
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int main(){
	string s,r,temp,temp1,temp2,temp3;
	cin>>s;
	r=s;
	ll a=(s.length()-1)/2;
	ll z=(s.length()+3)/2;
	temp=s.substr(0,a);
	temp1=temp;
	temp2=s.substr(z-1,(s.length()-z)+1);
	temp3=temp2;
	reverse(temp1.begin(),temp1.end());
	reverse(temp3.begin(),temp3.end());
	reverse(r.begin(),r.end());
	if(temp==temp1&&temp2==temp3&&r==s){
		cout<<"Yes"<<endl;
	}
	else
		cout<<"No"<<endl;

}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;

int main(){
  vector<int> a(5);
  int k;
  REP(i, 5){
    cin >> a[i];
  }
  cin >> k;
  if(a[4] - a[0] <= k){
    cout << "Yay!" << endl;
  }
  else{
    cout << ":(" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;

int main() {
	ull A,B,C;
	cin >> A >> B >> C;

	ull ans = 0;
	if (B >= C || A + B >= C) {
		// 解毒が十分にあればたべられる。
		ans = B + C;
	} else {
		// 解毒が足りない場合、
		ans += B * 2;
		B = 0;
//		C = C - B;
		ans += A + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        System.out.println(n%x==0?n/x*t:(n/x+1)*t);
    }
}

Measured memory_bytes: 35660
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
inline int getint(){
  char c; int res = 0;
  for(c = getchar();c < '0' || c > '9';c = getchar());
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res;
}

int main(){
  int n = getint(), m = getint(), h = getint(), w = getint();
  printf("%d\n",(n - h) * (m - w));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(),T = in();
    vector<int> st(N);
    REP(i,N)st[i] = in();
    int cut = 0;
    REP(i,N-1){
        cut += max(0,st[i+1] - st[i] - T);
    }
    int answer = st[N-1]-cut+T;
    cout << answer << "\n";
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll u(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll d(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll z(ll a){
  if(a<0)return -a;
  return a;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
ll nCr(int n,int k){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
char c[4];
void itos(int a){
  FOR(3){
    c[i]='0'+a%10;
    a/=10;
  }
}
int main(void){
  int n,ans=0;
  scanf("%d",&n);
  char s[n+1];
  scanf("%s",s);
  FOR(1000){
    itos(i);
    int cnt=0;
    FORJ(n)if(s[j]==c[cnt])cnt++;
    if(cnt==3)ans++;
  }
  PRN(ans);
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
ans = 'x'*n
print(ans)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair

using namespace std;

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	
	double x,y;cin>>x>>y;
	cout<<x+y/2.0<<endl;
}

Measured memory_bytes: 256
def kaibun(str):
    if str != str[::-1]:
        return False
    str2 = str[:(n-1)//2]
    if str2 != str2[::-1]:
        return False
    str3 = str[(n+3)//2-1:]
    if str3 != str3[::-1]:
        return False
    return True

str = input()
n = len(str)
print('Yes' if kaibun(str) else 'No')

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main(){
    string S;
	cin >> S;
    int s[4];
    for(int i = 0; i < 4; i++){
        s[i] = S[i]-'0';
    }

	int ans = 0;
    int sum;
    int a;
	for(int bit = 0; bit < (1<<4); bit++){
	    sum = s[0];
		a = s[1];
		for(int i = 1; i < 4; i++){
			if(bit & (1<<i)){
				sum += a;
				a = s[i+1];
			}else{
				sum -= a;
				a = s[i+1];
			}
		}

        ans = sum;
        if(ans == 7){
            cout << s[0];
            for(int i = 1; i < 4; i++){
                if(bit & (1 << i)){
                    cout << "+" << s[i];
                }else{
                    cout << "-" << s[i];
                }
            }
            cout << "=" << ans << endl;

            break;
        }
	}


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
int n,m,q;
std::vector<int> val(11),A(10);
std::vector<int> a(50),b(50),c(50),d(50);
int ans = 0;

void dfs(std::vector<int> &enu, int h){
    if(h == n){
        int cnt = 0;
        for(int k = 0;k < q;k++){
            if(enu.at(b.at(k)) - enu.at(a.at(k)) == c.at(k)){
                cnt += d.at(k);
            }
            ans = std::max(ans,cnt);
        }
        return;
    }
    for(int i = enu.at(h);i <= m;i++){
        val.at(h+1) = i;
        dfs(enu,h+1);
    }
    return;
}

int main(){
    std::cin >> n >> m >> q;
    for(int i = 0;i < q;i++){
        std::cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
        a.at(i)--;
        b.at(i)--;
    }
    for(int j = 1;j <= m;j++){
        val.at(0) = j;
        dfs(val,0);
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
typedef double db;
const int maxn = 45000 + 5;
const int mod = 1e9 + 7;

int main(){
    ll k, a, b;
    cin >> k >> a >> b;
    ll cnt = 1, sum = 0;
    if(a + 1 >= b || k <= a){
        cnt += k;
    }
    else{
        k -= a;
        cnt = 0;
        sum++;
        if(k){
            if(k & 1){
                ll p = (k + 1) / 2;
                cnt = p * b;
                cnt -= (p - 1) * a;
            }
            else{
                ll p = k / 2;
                cnt = p * b + 1;
                cnt -= (p - 1) * a;
            }
        }

    }
    printf("%lld\n", cnt);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define err(A) cout << #A << " = " << (A) << endl
using namespace std;
const int N=2003,mod=1e9+7;
ll dp[N][N];
ll a[N],b[N];
int32_t main(){

    ll n,m;
    cin >> n >> m;
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    for (int i=0;i<m;i++){
        cin >> b[i];
    }

    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            dp[i][j]=dp[i-1][j]+dp[i][j-1];
            dp[i][j]-=dp[i-1][j-1];
            dp[i][j]+=mod;
            dp[i][j]%=mod;
            if (a[i-1]==b[j-1]){
                dp[i][j]+=dp[i-1][j-1]+1;
                dp[i][j]%=mod;
            }
        }
    }
    cout << dp[n][m]+1;
}


Measured memory_bytes: 31616
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;


int main(){
  int j,k;
  char s[1001],t[1001];
  int dis[1001][1001];
  cin>>s>>t;
  int m=strlen(s);
  int n=strlen(t);
  //cout<<m<<n<<endl;
  for(j=1;j<=m;j++){
    dis[j][0]=j;
  }
  for(j=1;j<=n;j++){
    dis[0][j]=j;
  }
  for(j=1;j<=m;j++){
    for(k=1;k<=n;k++){
      dis[j][k]=min(dis[j-1][k]+1,min(dis[j][k-1]+1, (s[j-1]==t[k-1] ? dis[j-1][k-1] : dis[j-1][k-1] + 1 )));
    }
  }
  cout<<dis[m][n]<<endl;
  return 0;
}

Measured memory_bytes: 5056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
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() {
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = n;
  rep(i, n - 1) {
    if(s[i] == s[i + 1]) continue;
    ll now = max(i + 1, n - i - 1);
    ans = min(ans, now);
  }
  cout << ans << endl;
}

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

int main(){
  int n,z,x,y; 
  string s;
  cin >> x>>y ;
  vector<int> a(n);
  vector<int> sum(n);
  z=0;
   if(x==y){for(int i=0;i<x;i++){cout<<x;}}
else{if(x>y){for(int i=0;i<x;i++){cout<<y;}}
    if(y>x){for(int i=0;i<y;i++){cout<<x;}}  

          }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
e = [[] for _ in range(N + 1)]
for _ in range(M):
  x, y = map(int, input().split())
  e[x].append(y)

dp = [0] * (N + 1)
for x in range(N, 0, -1):
  for y in e[x]:
    dp[x] += (dp[y] + 1) / len(e[x])
#print(dp)
table = [0] * (N + 1)
table[1] = 1
for x in range(1, N + 1):
  for y in e[x]:
    table[y] += table[x] / len(e[x])
res = 0
for x in range(1, N + 1):
  for y in e[x]:
    if len(e[x]) == 1: break
    u = dp[x] * table[x]
    v = (dp[x] - (dp[y] + 1) / len(e[x])) * len(e[x]) / (len(e[x]) - 1) * table[x]
    res = max(res, u - v)
print(dp[1] - res)

Measured memory_bytes: 51804
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mod 1000000007
#define mod1 1000000009
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
// #define mp make_pair
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define int ll
vector<ll> ft(1, 1LL);
/*======================================================================*/
set<pair<int, int> > st;
pair<int, int> hs(string &s){
    int f = 0, f2 = 0, p = 1337, pro = 1, pro1 = 1;
    for(auto i : s){
        f = (f+i*pro)%mod;
        f2 = (f2+i*pro1)%mod1;
        pro = (pro*p)%mod;
        pro1 = (pro1*p)%mod1;
    }
    return {f, f2};
}
void solve(){
    int n;
    cin >> n;
    string s;
    rep(i, 0, n){cin >> s;
    st.insert(hs(s));}
    cout << st.size();
}
signed main() {
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

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

int main(){
    unsigned long long a,b,x;
    cin >> a >> b >> x;
    // unsigned long long count = 0;

    // cout << ULLONG_MAX << endl;

    // for(unsigned long long i = a;i <= b;i++){
    //     if(i % x == 0) count++;
    // }
    if(a == 0) cout << (b / x) + 1 ;
    else cout << (b / x) - ((a - 1) / x) << endl;
}

Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._
  val Array(n, k) = readLine.trim.split(' ').map(_.toLong)
  val numbers = 0 +: readLine.trim.split(' ').map(_.toInt)//numbers(i) == [0, i)の排他的論理和
  for (i ← numbers.indices.tail) numbers(i) ^= numbers(i - 1)
  var rest = k
  var result = 0
  val maxDigit = 20
  val count = Array.tabulate(1 << maxDigit){_ ⇒ 0}
  for (topDigit ← 1 to maxDigit){
    val next = result * 2 + 1
    var sum = 0L
    for (num ← numbers){
      count(num >> (maxDigit - topDigit)) += 1
      sum += count((num >> (maxDigit - topDigit)) ^ next)
    }
    if (sum >= rest){
      result = result * 2 + 1
    }else {
      result = result * 2
      rest -= sum
    }
    (0 until (1 << topDigit)).foreach(i ⇒ count(i) = 0)
  }
  println(result)
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 100740
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = []
X = []
for i in range(M):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)

for i in range(M):
    time = sum(T) - T[P[i] - 1] + X[i]
    print(time)


Measured memory_bytes: 9104
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
M = [[0 for i in range(W)] for j in range(H)]
p = [0, 0]
x = 0
for i in range(N):
  for j in range(A[i]):
    M[p[0]][p[1]] = i+1
    x += 1
    if x % W == 0:
      p[0] += 1
    else:
      if (x // W) % 2 == 0:
        p[1] += 1
      else:
        p[1] -= 1
for i in range(H):
  for j in range(W-1):
    print(M[i][j], end = ' ')
  print(M[i][W-1])

Measured memory_bytes: 3920