akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/abc085/tasks/abc085_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    enum class Type{
        A,B
    };
    ll N,H; cin>>N>>H;
    vector<pair<ll,Type>> abn;
    REP(i,N){
        ll a,b; cin>>a>>b;
        abn.emplace_back(a,Type::A);
        abn.emplace_back(b,Type::B);
    }
    sort(abn.begin(),abn.end(),[](const auto& a,const auto& b){ return a.first>b.first;});

    ll ans=0;
    ll pt=0;
    while(H>0){
        auto& atk=abn.at(pt);
        if (atk.second == Type::B) {
            H -= atk.first;
            ++ans;
            ++pt;
        } else {
            auto h = H+atk.first-1;
            ans += (h/atk.first);
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

//深さ優先
vector<int> seen;
vector<ll> h;

//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){
    seen[v] = 0; //v探索済み

    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }

    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}

bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }

    return false;
}

int main(){
    /*
    int n,m;
    cin>>n>>m;

    h.assign(n,0);
    rep(i,0,n) cin>>h[i];

    Graph G(n);
    rep(i,0,m){
        int a,b; cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    seen.assign(n,-1);

    rep(i,0,n){
        if(seen[i]==-1){
            dfs(G,i);
        }
    }

    int sum=accumulate(all(seen),0);

    cout<<sum<<endl;*/

    string s; cin>>s;
    int n=s.length();

    if(n%2==1){
        int n2=n-1;
        while(1){
            int st=n2/2;
            //cout<<s.substr(0,st)<<" "<<s.substr(st,st)<<endl;
            bool yes=true;
            for(int i=0;i<st;i++){
                if(s[i]!=s[st+i]){
                    yes=false;
                }
            }
            if(yes){
                cout<<n2<<endl;
                return 0;
            }
            n2-=2;
        }
    }else{
        int n2=n-2;
        while(1){
            int st=n2/2;
            //cout<<s.substr(0,st)<<" "<<s.substr(st,st)<<endl;//<<" "<<st<<" "<<n2;
            bool yes=true;
            for(int i=0;i<st;i++){
                if(s[i]!=s[st+i]){
                    yes=false;
                }
            }

            if(yes){
                cout<<n2<<endl;
                return 0;
            }
            n2-=2;
        }
    }

}

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>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i,m) cin >> a[i];
  
  int sum = 0;
  rep(i,m) {
      sum = sum + a[i];
  }
  
  int ans = 0;
  ans = n - sum;
  
  if (ans < 0) {
    cout << -1 << endl;
  }
  else {
    cout << ans << endl;
  }
  return 0;
  
}

Measured memory_bytes: 3576
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
 

//result = Math.pow(num1, num3)
//StringBuffer str = new StringBuffer(hoge1);
//String hoge2 = str.reverse().toString();
//map.containsKey(A)

//Map<String, Integer> map = new HashMap<String, Integer>(n);
/*for ( キーのデータ型 key : マップの名前.keySet() ) {
	データのデータ型 data = マップの名前.get( key );
	
	// keyやdataを使った処理;
}*/
//int i = Integer.parseInt(s);

//ArrayList<String> cc = new ArrayList<>(n);
//Collections.sort(list);
//Array.sort(list);
//Arrays.asList(c).contains("a")
//list.set(1,"walk");
public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String s;
	public static void main(String[] args) {
		s=sc.next();
		
		dfs(s.length()-1,s);
		long ans=0;
		for(String a:cc) {
			a=a+"+";
			String[] tmp=a.split("\\+");
			for(String i:tmp) {
				ans+=Long.parseLong(i);
			}
		}
		p(ans);
	}
	
	static int g=0;
	static int dfs(int i,String g) {
		StringBuilder str = new StringBuilder(g);
		if(i<=0) {
			cc.add(str.toString());
			return 0;
		}
		dfs(i-1,str.toString());
		dfs(i-1,str.insert(i,"+").toString());
		return 0;
		
	}
	static ArrayList<String> cc=new ArrayList<String>(100000);

	
	
	
}


Measured memory_bytes: 22740
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX 1000
int main(){
    int n=0,m=0,sn=0,sm=0; char g;int cnt=0;
    while(cin>>m>>g>>n){sn+=n;sm+=(m*n);cnt++;}
    cout<<sm<<endl;
    cout<<(int)(((double)sn/(double)cnt)+0.5)<<endl;
    return 0;
}

Measured memory_bytes: 3036
fun c89(args: Array<String>) {
    val people = args.drop(1)
    val peopleList = listOf(
            people.count { it.startsWith("M") },
            people.count { it.startsWith("A") },
            people.count { it.startsWith("R") },
            people.count { it.startsWith("C") },
            people.count { it.startsWith("H") })

    fun dfs(list: List<Int>, remain: Int): Long {
        if (remain == 0) {
            return 1L
        }
        val indexValueList = list
                .mapIndexed { index, i -> Pair(index, i) }
                .filter { it.second > 0 }
        if (indexValueList.isEmpty()) {
            return 0L
        }
        return indexValueList
                .map {
                    val (index, value) = it
                    val nextList = list.drop(index + 1)
                    value.toLong() * dfs(nextList, remain - 1)
                }
                .sum()
    }

    val ans = dfs(peopleList, 3)
    println(ans)
}

fun main(args: Array<String>) {
    c89(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

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

int A,B;

int main(){
	cin >> A >> B;

	int l8q = (A * 100) / 8;
	int l8r = (A * 100) % 8;
	int h8q = (A * 100 + 99) / 8;
	int h8r = (A * 100 + 99) % 8;

	int l8 = l8q + (l8r == 0 ? 0 : 1);
	int h8 = h8q;

	int l0q = (B * 100) / 10;
	int l0r = (B * 100) % 10;
	int h0q = (B * 100 + 99) / 10;
	int h0r = (B * 100 + 99) % 10;

	int l0 = l0q + (l0r == 0 ? 0 : 1);
	int h0 = h0q;

//	cout << l8 << " " << h8 << " " << l0 << " " << h0 << endl;

	int ll = max(l8,l0);
	int hh = min(h8,h0);
	if(hh < ll){
		cout << -1 << endl;
	}
	else{
		cout << ll << endl;
	}

	return 0;
}


Measured memory_bytes: 256
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var s string

func main() {
	sc.Split(bufio.ScanWords)
	s = nextStr()
	n := len(s) - 1
	sum := 0
	//組み合わせの数

	for i := 0; i < (1 << uint(n)); i++ {
		w := []rune{}
		for l := 0; l <= n; l++ {
			//1が出るまで、wに文字列をためていく
			w = append(w, rune(s[l]))
			//パターンiについて、l番目のしきりが有効であるとき
			if (i & (1 << uint(l))) > 0 {
				//ここまでの文字列を数字として足す
				sum += str2Int(string(w))
				//wを空にする
				w = []rune{}
			}
		}
		//残ったwを足す
		sum += str2Int(string(w))
		//fmt.Println(sum)
	}

	fmt.Println(sum)
}


Measured memory_bytes: 640
<?php
fscanf(STDIN, "%d", $k);
fscanf(STDIN, "%d %d", $a, $b);

for ($i = $a; $i <= $b; $i++) {
    if (($i % $k) === 0) {
        echo "OK\n";
        exit;
    }
}

echo "NG\n";


Measured memory_bytes: 16012
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

vector<ll> par(100000);
vector<ll> ran(100000);
void init(ll n){
  rep(i,n){
    par.at(i)=i;
    ran.at(i)=0;
  }
}
ll find(ll x){
  if(par.at(x)==x){
    return x;
  }else{
    return par.at(x)=find(par.at(x));
  }
}
void unite(ll x,ll y){
  x=find(x);
  y=find(y);
  if(x==y) return;
  if(ran.at(x)<ran.at(y)){
    par.at(x)=y;
  }else{
    par.at(y)=x;
    if(ran.at(x)==ran.at(y)) ran.at(x)++;
  }
}

int main(){
  ll N,M,ans=0;
  cin >> N >> M;
  init(N);
  rep(i,M){
    ll x,y,z;
    cin >> x >> y >> z;
    unite(x-1,y-1);
  }
  rep(i,N){
    if(i==par.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
  
        
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
typedef pair<double,double> P;

inline double dist(P p,P q){
  return ( (p.first-q.first)*(p.first-q.first) + (p.second-q.second)*(p.second-q.second));
}

int main(){
  int N;
  double sign[2] = {+1, -1};
  P p[310];
  while(scanf("%d",&N) != EOF){
    if(N == 0)break;
    REP(i,N)scanf("%lf %lf",&p[i].first,&p[i].second);
    int ans = 1;
    REP(i,N)REP(j,N)if(i!=j){
      double dst = dist(p[i],p[j]);
      if(dst > 4.0) continue;
      /*
       P v((p[j].first-p[i].first)/dst, (p[j].second-p[i].second)/dst);
       P m((p[j].first+p[i].first)/2.0, (p[j].second+p[i].second)/2.0);
       double lth = sqrt(1.0-(dst*dst)/4.0);
       REP(k,2){
       double cx = m.first + sign[k] * v.first * lth;
       double cy = m.second - sign[k] * v.second * lth;
       P center(cx,cy);
       int count = 0;
       REP(l,N){
       if(l == i || l == j || dist(center,p[l]) < 1.00001){
       count++;
       }
       if(N-l-1 + count < ans)break;
       }
       if(ans < count) ans = count;
       }
       */
      P dp((p[j].first-p[i].first)/2.0 , (p[j].second-p[i].second)/2.0);
      double d = sqrt(dist(P(0,0),dp));
      double t = sqrt(1.0-d*d)/d;
      P center(p[i].first + dp.first - t * dp.second, p[i].second + dp.second + t * dp.first);
      int count = 0;
      REP(k,N){
        if(dist(center,p[k]) < 0.00001 + 1)count++;
      }
      ans = max(ans,count);
    }
    printf("%d\n",ans);
  }
return 0;
}

Measured memory_bytes: 916
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <algorithm>
#include <sstream>
#include <set>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define INF (1<<30)
#define EPS 1e-6
using namespace std;
#define MAX_N 1005
int X1[MAX_N],X2[MAX_N],Y1[MAX_N],Y2[MAX_N];
int W,H;
int N;
typedef pair<int, int> P;
const int dx[] = {1,-1,0,0};
const int dy[] = {0,0,1,-1};
bool fld[6*MAX_N][6*MAX_N];
bool
init()
{
scanf("%d %d",&W,&H);
W *= 2 , H *= 2;
if (H == 0 && W == 0) {
return false;
}
scanf("%d",&N);
for (int i=0; i<N; ++i) {
scanf("%d %d %d %d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
X1[i] *= 2 , Y1[i] *= 2 , X2[i] *= 2 , Y2[i] *= 2;
}
return true;
}
int
compress(int *x1,int *x2,int w)
{
vector<int> xs;
for (int i=0; i<N; ++i) {
for (int d=-1; d<=1; ++d) {
int tx1 = x1[i] + d , tx2 = x2[i] + d;
if (0 <= tx1 && tx1 <= w) xs.push_back(tx1);
if (0 <= tx2 && tx2 <= w) xs.push_back(tx2);
}
}
sort(xs.begin(), xs.end());
xs.erase(unique(xs.begin(), xs.end()), xs.end());
for (int i=0; i<N; ++i) {
x1[i] = (int)distance(xs.begin(), find(xs.begin(), xs.end(), x1[i]));
x2[i] = (int)distance(xs.begin(), find(xs.begin(), xs.end(), x2[i]));
}
return (int)xs.size()-1;
}
void
solve()
{
memset(fld, false, sizeof(fld));
W = compress(X1, X2, W);
H = compress(Y1, Y2, H);
for (int i=0; i<N; ++i) {
for (int x = X1[i]; x <= X2[i]; ++x) {
for (int y = Y1[i]; y <= Y2[i]; ++y) {
fld[y][x] = true;
}
}
}
int ans = 0;
for (int x = 0; x <= W; ++x) {
for (int y = 0; y <= H; ++y) {
if (fld[y][x]) {
continue;
}
++ans;
queue<P> que;
que.push(P(x,y));
fld[y][x] = true;
while (!que.empty()) {
int sx = que.front().first , sy = que.front().second;
que.pop();
for (int i=0; i<4; ++i) {
int cx = sx + dx[i] , cy = sy + dy[i];
if (0 <= cx && cx <= W && 0 <= cy && cy <= H && !fld[cy][cx]) {
fld[cy][cx] = true;
que.push(P(cx,cy));
}
}
}
}
}
printf("%d\n",ans);
}
int
main()
{
while (init()) {
solve();
}
return 0;
}

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

long gcd(long x, long y){
  long r;
  if (x < y) swap(x, y);
  
  while(y > 0){
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

long CntPrime(long x){
  long cnt = 0;
  if (x < 2) {
    //cout << "CntPrimt(1)" << x << endl;
    return 0;
  }else if (x == 2) return 1;
  else if (x % 2 == 0)  {
    long y = 0;
    while (y == 0 && x != 1) {
      y = x % 2;
      x = x / 2;
    }
    if (y != 0) x = 2 * x + y;
    //cout << "CntPrimt(2)" << x << endl;
    cnt++;
    cnt += CntPrime(x);
    return cnt;
  } else {
    for (long i = 3; i <= x; i += 2){
      if (x % i == 0){
        long y = 0;
        while (y == 0 && x != 1) {
          y = x % i;
          x = x / i;
        }
        if (y != 0) x = x * i + y;
        //cout << "CntPrimt(" << i << ")" <<  x << endl;
        cnt++;
        cnt += CntPrime(x);
        return cnt;
      } else if(i * i > x){
        return 1;
      }
    }
  }
  //return cnt;
}

int main(){
  
  long A, B;
  cin >> A >> B;
  
  long num = gcd(A, B);
  //cout << num << endl;
  long cnt = CntPrime(num);
  
  cout << cnt + 1;
  
  return 0;
}



Measured memory_bytes: 256
import collections

N = int(input())
S = input()

CountRGB = collections.Counter(S)

ans = CountRGB["R"] * CountRGB["G"] * CountRGB["B"]

tmp = 0
for i in range(N-2):
    for j in range(i+1, N-1):

        if(2 * j - i > N - 1):
            break

        checker = []
        checker.append(S[i])
        checker.append(S[j])
        checker.append(S[2 * j - i])

        c = collections.Counter(checker)

        if(c["R"] == 1 and c["G"] == 1 and c["B"] == 1):
            tmp +=1

print(ans - tmp)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[100100];
int main(){
    int N;
    cin >> N;
    ll x;
    cin >> x;
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    ll ans = 0;
    for(int i = 0; i < N-1; i++){
        ll a = A[i];
        ll n = A[i+1];
        ll rem = a+n-x;
        if(rem > 0){
            ans += rem;
            n = max(0LL, n-rem);
            //tmp -= n;
            //if(n == 0LL){
            //    a -= tmp;
            //}
            A[i+1] = n;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#ifdef DBG_MACRO_NO_WARNING
#include <dbg.h>
#endif
#include <bits/stdc++.h>
#define all(c) c.begin(), c.end()
#define isz(c) (int)c.size()

using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

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

    if (s.back() == 's')
        cout << s << "es" << endl;
    else
        cout << s << "s" << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  bool L=false;
  long long K;
  cin>>S>>K;
  for(int X=0;X<K;X++){
    if(S.at(X)!='1'){
      cout<<S.at(X);
      L=true;
      break;
    }
  }
  if(L==false){
    cout<<1<<endl;
  }
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val,typename Number>
//use ll or int for gcd
Val gcd(Val a, Val b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//count vector and return pair (count,vector item)
template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->push_back(make_pair(count,A->at(i)));
        count = 1;
      }
    }else{
      R->push_back(make_pair(count,A->at(i)));
      count = 1;
    }
  }
}

//---------------------------------------------------------------

int main(){
  ll N;
  cin>>N;
  vector<string>M,A,R,C,H;
  llrep(i,N){
    string In;
    cin>>In;
    if(In.at(0)=='M')M.push_back(In);
    if(In.at(0)=='A')A.push_back(In);
    if(In.at(0)=='R')R.push_back(In);
    if(In.at(0)=='C')C.push_back(In);
    if(In.at(0)=='H')H.push_back(In);
  }
  ll m = M.size();
  ll a = A.size();
  ll r = R.size();
  ll c = C.size();
  ll h = H.size();

  ll ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h +
           m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;


cout<<ans<<endl;




}


Measured memory_bytes: 5748
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  long long n,a[100000]={},cnt=0,ans=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  sort(a,a+n);
  for(int i=0; i<n-1; i++) {
    cnt+=a[i];
    if(cnt*2>=a[i+1]) {
      ans++;
    }
    else {
      ans=0;
    }
  }
  cout << ans+1 << endl;
}


Measured memory_bytes: 1024
import java.util.*;
import java.util.stream.*;

public class Main {
  public static final long MOD = (long)1e9 + 7;

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    char[] S = in.nextLine().toCharArray();
    long[][] dp = new long[S.length + 1][13];
    dp[0][0] = 1;

    for (int i = 0; i < S.length; i++) {
      int c = S[i] == '?' ? -1 : S[i] - '0';
      for (int j = 0; j < 10; j++) {
        if (c != -1 && c != j) {
          continue;
        }
        for (int k = 0; k < 13; k++) {
          dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
        }
      }
      for (int k = 0; k < 13; k++) {
        dp[i + 1][k] %= MOD;
      }
    }
    System.out.println(dp[S.length][5]);
  }
}

Measured memory_bytes: 38844
import bisect

N, M = map(int, input().split())
S = input()

ok = True
cnt = 0
for c in S:
    if c == "1":
        cnt += 1
        if cnt == M:
            ok = False
            break
    else:
        cnt = 0

# 後ろから見て、各マスからもっとも近い右側の0の位置を格納(S[i]=0ならi)
ngo_pos = [0 for _ in range(N+1)]
most_neighbor_zero_pos = N
for i in range(N, -1, -1):
    if S[i] == "0":
        ngo_pos[i] = i
        most_neighbor_zero_pos = i
    else:
        ngo_pos[i] = most_neighbor_zero_pos

if not ok:
    print(-1)
else:
    ans = []
    pos = N
    while pos > 0:
        npos = ngo_pos[max(0, pos-M)]
        ans.append(pos-npos)
        pos = npos
    print(" ".join(map(str, ans[::-1])))


Measured memory_bytes: 15092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt(),b=s.nextInt();
        if(a==b) System.out.println("Draw");
        else if(a==1) System.out.println("Alice");
        else if(b==1) System.out.println("Bob");
        else if(a>b) System.out.println("Alice");
        else System.out.println("Bob");
    }

}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25332
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b,c=0;cin>>a;
  rep(i,a){
    cin>>b;
    if(b%2==1)c++;
  }
  if(c%2==0)cout<<"YES";
     else cout<<"NO";
     }

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
 
 
 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        long[] H = new long[N];
        long sum=0;
        for(int i=0;i<N;i++) {
        	H[i]=sc.nextLong();
        }
        
        Arrays.sort(H);
        
        for(int i=0;i<N-K;i++) {
        	sum=sum+H[i];
        }

        System.out.println(sum);
        		
    }
}

Measured memory_bytes: 88820
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

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

signed main(void)
{
    ll l, r;
    cin >> l >> r;
    ll ans = 2020;
    
    if (r-l > 2020) {
        mes(0);
        re0;
    }
    
    for(ll i = l; i < r; i++) {
        for (ll j = i+1; j <= r; j++) {
            ans = min(ans, (i*j)%2019);
        }
    }
    mes(ans);
    
    
    
    
    
    
}

Measured memory_bytes: 3576
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
  int a,b,d,r;
  double f;
  cin>>a>>b;
  d=a/b;
  r=a%b;
  f=(double)a/b;
  printf("%d %d %f\n",d,r,f);
}



Measured memory_bytes: 3144
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int mx[1<<18], n, a[1<<18];

void get_ans (int l, int r) {
	int b[(r-l)/2];
	if(l+1 == r) return;
	int mid = l+r >> 1;
	get_ans(l, mid);
	for(int i = mid; i < r; ++i)
		mx[i] = max(mx[i], a[i] + a[i - (r - mid)]);
	for(int i = mid; i < r; ++i)
		b[i-mid] = a[i], a[i] = max(a[i], a[i - (r - mid)]);
	get_ans(mid, r);
	for(int i = mid; i < r; ++i)
		a[i] = b[i-mid];
}

int main() {
	scanf("%d", &n);
	for(int i = 0; i < 1<<n; ++i) {
		scanf("%d", &a[i]);
	}
	get_ans(0, 1<<n);
	for(int i = 1; i < 1<<n; ++i) {
		mx[i] = max(mx[i], mx[i-1]);
		printf("%d\n", mx[i]);
	}
	return 0;
}


Measured memory_bytes: 6144
import numpy as np
N,D = map(int, input().split())
X_matrix = [list(map(int, input().split())) for _ in range(N)]
count=0
for i in range(N):
  for k in range(i+1,N):
      if np.sqrt(sum((np.array(X_matrix[i])-np.array(X_matrix[k]))**2)).is_integer():
        count+=1
print(count)

Measured memory_bytes: 12428
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		String flag = "No";
		for(int i=1;i<10;i++) {
			for(int j=1;j<10;j++) {
				if(i*j == N)flag = "Yes";
			}
		}
		
		System.out.println(flag);
		
		sc.close();
	}
}

Measured memory_bytes: 24020
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;
int main(){
    int n,m,c;
    cin >> n >> m >> c;
    vector<int> b(m);
    vector<vector<int>> a(n,vector<int>(m));
    for(int i=0; i<m; i++){
        cin >> b[i];
    }
    int sum=0;
    for(int i=0; i<n; i++){
        int ans=0;
        for(int j=0; j<m; j++){
            cin >> a[i][j];
            ans+=(a[i][j]*b[j]);
        }
        if(ans+c>0) sum++;
    }
    cout << sum << endl;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    for(int i=0; i<100; i++){
        /*T君の攻撃*/
        c = c - b;
        if(c <= 0){
            cout << "Yes" << endl;
            break;
        }
        /*A君の攻撃*/
        a = a - d; 
        if(a <= 0){
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3524
import math
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
n=I()
ls=sorted(LI(),reverse=True)
trans=0
for i in range(n-2):
    answer=0
    for j in range(i+1,n-1):
        l1=ls[i]
        l2=ls[j]
        l,r = j,n
#あえて左右一つ分ずつ広く取る
        while l+1 < r:
#この条件で探索の終点がうまく定められる
            mid = (l+r)//2
            if l1<l2+ls[mid]:
                l = mid
            else:
                r = mid
        ansij=l-j
        #print(ansij)
        answer+=ansij
    trans+=answer
print(trans)

Measured memory_bytes: 43100
"""
Match Matching
提出 #4299735 を参考に作成
"""


def solve():
    # 初期値の設定
    num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    N, M = map(int, input().split())
    A = [int(i) for i in input().split()]
    A.sort(reverse=True)
    # 丁度n本で作成できる最大桁数を格納する.
    # 初期値は -inf (丁度使い切ることは不可能) としておく
    dp = [-1 * float("inf")] * (N + 1)

    # 動的計画法で丁度n本のマッチを使うときに作れる最大桁数を計算する
    dp[0] = 0
    for n in range(1, N + 1):
        for a in A:
            if n - num[a] >= 0:
                # マッチがnum[a]本あるときにaが作れるなら,
                # n - num[a]本の時よりも1桁多く作れるはず.
                # これをすべてのAに対して行い、その中で最大となった桁数を求める.
                dp[n] = max(dp[n], dp[n - num[a]] + 1)
    # print('各本数丁度で作れる最大桁数')
    # print(dp)

    # 回答となる数値を算出
    ans = ''
    for i in range(dp[N]):  # dp[N]桁の数を上位の桁から決定していく
        for a in A:
            # num[a]本使って数を作ったとき,
            # N - num[a] 本で作れる桁数よりも N 本で作れる桁数のほうが1多い場合,
            # numを作っても最終的に作れる数の桁数は変わらない.
            # そのため dp[N] - 1 == dp[N - num[a]] を満たすような最大のAを作り,
            # 作成する数の上位桁に使用すればよい.
            # 同じ本数のマッチを使用する場合はより大きい数を採用する.
            # そのためAはあらかじめ降順にソートしておく.
            # 最初の条件で配列外アクセスを防ぐ
            if N - num[a] > -1 and dp[N] - 1 == dp[N - num[a]]:
                ans += str(a)
                N -= num[a]
                break
        # print('現在の残本数', N, '採用された数', a)

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3312
#include <stdio.h>

const long long mod = 998244353;
int N,K,H; long long C[4002][4002],G[1001][2002];

void add(long long &a, long long b)
{
	a = (a + b) % mod;
}

int main()
{
	scanf ("%d %d",&K,&N); H = K / 2;

	for (int i=0;i<=N+K;i++){
		C[i][0] = C[i][i] = 1;
		for (int j=1;j<i;j++) C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod;
	}

	G[0][0] = 1;
	for (int i=1;i<=H;i++){
		for (int j=1;j<=N;j++) G[i][j] = (G[i][j-1] + G[i-1][j-1] * 2) % mod;
		for (int j=0;j<=N;j++) add(G[i][j],G[i-1][j]);
	}

	for (int i=2;i<=K*2;i++){
		int c = 0, h = 0;
		for (int j=1;j<=K;j++){
			int k = i - j;
			if (1 <= k && k <= K){
				if (j < k) c++;
				else if (j == k) h++;
			}
		}

		long long res = 0;
		int g = K - 2 * c - h - 1;
		if (g < 0) add(res,G[c][N]);
		else for (int j=0;j<=N;j++) add(res,G[c][j]*C[N-j+g][g]);

		if (h){
			if (g < 0) add(res,G[c][N-1]);
			else for (int j=0;j<=N-1;j++) add(res,G[c][j]*C[N-1-j+g][g]);
		}

		printf ("%lld\n",res);
	}

	return 0;
}

Measured memory_bytes: 140928
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>

using ll = long long;

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

int main()
{
    
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    if ((a+b) > (c+d)) cout << "Left\n";
    else if ((a+b)==(c+d)) cout << "Balanced\n";
    else cout << "Right\n";
    
    
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vs= vector<string>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n,a=0,mx=0;
  cin >> n;
  string s;
  vector<string> tmp(2);
  map<string, int> mp;
  rep(i,0,n){
    cin >> s;
    mp[s]++;
    mx= max(mx, mp[s]);
  }
  for(auto i=mp.begin(); i!=mp.end(); i++){
    if(i->second==mx){
      cout << i->first << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 25216
import sys
def input(): return sys.stdin.readline().rstrip()
class UnionFind():
    def __init__(self, n):
        self.n=n
        self.parents=[-1]*n # 親(uf.find()で経路圧縮して根)の番号。根の場合は-(そのグループの要素数)
        self.member_color=[[0,0]for _ in range(n)] #.の数，#の数
        for i in range(n):
            if S[i//w][i%w]=="#": 
                self.member_color[i][1]=1
            else:
                self.member_color[i][0]=1
    def find(self,x):
        #グループの根を返す
        if self.parents[x]<0:return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        #要素x,yのグループを併合
        x,y=self.find(x),self.find(y)
        if x==y:return
        if self.parents[x]>self.parents[y]:#要素数の大きい方をxに
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x #要素数が大きい方に併合
        self.member_color[x][0]+=self.member_color[y][0]
        self.member_color[x][1]+=self.member_color[y][1] 
    def size(self,x):
        #xが属するグループの要素数
        return -self.parents[self.find(x)]
    def same(self,x,y):
        #xとyが同じグループ？
        return self.find(x)==self.find(y)
    def members(self,x):
        #xと同じグループに属する要素のリスト
        root=self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    def roots(self):
        #全ての根の要素のリスト
        return [i for i, x in enumerate(self.parents) if x<0]
    def group_count(self):
        #グループの数
        return len(self.roots())
    def all_group_members(self):
        #各ルート要素のグループに含まれる要素のリストの辞書
        return {r: self.members(r) for r in self.roots()}
    def all_group_members_list(self):
        #各ルート要素のグループに含まれる要素のリストのリスト
        #[[0, 2], [1, 3, 4, 5]]
        return list(self.all_group_members().values())
    def __str__(self):
        #各ルート要素のグループに含まれる要素のリストをprint()
        return '\n'.join('{}: {}'.format(r,self.members(r)) for r in self.roots())
def main():
    global w,S
    h,w=map(int,input().split())
    S=[input() for _ in range(h)]
    uf=UnionFind(h*w)
    for i in range(h):
        for j in range(w):
            ss=S[i][j]
            for row,col in ((1,0),(-1,0),(0,1),(0,-1)):
                if i+row>=0 and i+row<h and j+col>=0 and j+col<w and ss!=S[i+row][j+col]:
                    uf.unite((i+row)*w+j+col,i*w+j) 
    ans=0
    for r in uf.roots():
        ans+=uf.member_color[r][0]*uf.member_color[r][1]
    print(ans)
if __name__=='__main__':
    main()

Measured memory_bytes: 25128
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
using namespace std;
typedef pair< int , int > Pi;
#define INF (1 << 25)
#define fr first
#define sc second
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};
int main(){
  int n,a,b;
  while(cin >> n >> a >> b && n||a||b){
    int ans = 0;
    vector<bool> vc( n + 1 , false );
    vc[0] = true;
    rep(i,n+1){
      if(vc[i]){
        if( i + a <= n ) vc[i + a] = true;
        if( i + b <= n ) vc[i + b] = true;
      }else ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1316
//ada kartu bingo 3x3
//pada row ke i dari atas
//dan pada column ke j dari kiri
//berisikan Aij (angka kali)
//akan dipilih N, dari b1 hingga bN
//jika salah satu itu terpenuhi dari bingo sheet kita
//kita tandain
//tentukan jika kita bingo yaitu dengan cara menentukan apakah kita punya ada 3 yg berturut2 entah gmn itu arahnnya
//inputnya semua integer
//inputnya pake array3x3
//jika bingo Yes, jika tidak No

#include <stdio.h>
int main(){
	int card[3][3] = {0};
	for(int i = 0; i<3; i++)
	{
		for(int j=0; j<3; j++)
		{
			scanf("%d", &card[i][j]);		//minta input user buat bingo card
		}
	}

	//bingo card kosong buat nandain
	int pin[3][3] = {0};

	//bikin N, dan brp angka aja yg disebut biar dapet bingo apa ngga
	int N;
	scanf("%d", &N);		//banyak angka

	int pick; //input user
	//diulang biar dapet banyak N
	for(int k = 0; k<N; k++)
	{
		scanf("%d", &pick);

		for(int l = 0; l<3; l++)	//ceritanya dicocokin sama bingo card sebelah
		{
			for(int m = 0; m<3; m++)
			{
				if(card[l][m]==pick)	//kalo sama
				{
					pin[l][m]++;		//si pin ditandain
				}
			}
		}
	}



	//cek kebawah
	for(int i =0; i<3; i++)
	{
		if(pin[i][0]>=1)
		{
			if(pin[i][1]>=1)
			{
				if(pin[i][2]>=1)
				{
					puts("Yes");
					return 0;
				}
			}
		}
	}

	//cek vertikal
	for(int i =0; i<3; i++)
	{
		if(pin[0][i]>=1)
		{
			if(pin[1][i]>=1)
			{
				if(pin[2][i]>=1)
				{
					puts("Yes");
					return 0;
				}
			}
		}
	}

	//cek duagonal dari kiri
		if(pin[0][0]>=1)
		{
			if(pin[1][1]>=1)
			{
				if(pin[2][2]>=1)
				{
					puts("Yes");
					return 0;
				}
			}
		}

	//cek duagonal dari kanan
		if(pin[0][2]>=1)
		{
			if(pin[1][1]>=1)
			{
				if(pin[2][0]>=1)
				{
					puts("Yes");
					return 0;
				}
			}
		}

	puts("No");

	return 0;
}


Measured memory_bytes: 1592
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

//int dy[]={0, 0, 1, -1, 0};
//int dx[]={1, -1, 0, 0, 0};

int main(){
  int n, m;
  scanf("%d%d", &m, &n);
  vector<int> a(m);
  vector<P> b(n);
  REP(i, m) scanf("%d", &a[i]);
  VSORT(a);
  reverse(a.begin(), a.end());
  REP(i, n) scanf("%d%d", &b[i].first, &b[i].second);

  vector<vector<int> > dp(n+10, vector<int>(m+10, -INF));
  dp[0][0]=0;
  FOR(i, 1, n+1){
    REP(j, m+1){
      int tmp=max(j-b[i-1].first, 0);
      if(dp[i-1][tmp]==-INF) continue; 
      dp[i][j]=max(max(dp[i][j], dp[i-1][tmp]-b[i-1].second), dp[i-1][j]);
    }
  }
  
  int sum=0, ans=0;
  FOR(i, 1, m+1){
    sum+=a[i-1];
    ans=max(ans, dp[n][i]+sum);
  }

  printf("%d\n", ans);
}

Measured memory_bytes: 21064
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n, k;
int r, s, p;
string t;

LL ans = 0;

int main(){
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    REP(mo, k){
        int pre = -1;
        for(int i = mo;i < n;i += k){
            if(t[i] == 'r' && pre != 0)ans += p, pre = 0;
            else if(t[i] == 's' && pre != 1)ans += r, pre = 1;
            else if(t[i] == 'p' && pre != 2)ans += s, pre = 2;
            else pre = -1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long L;
int n,sz;
int ch[500005][2];
int dep[500005];
int ed[500005];
int a[100005];
char s[100005];
void insert(){
	int len=strlen(s+1);
	int x=0;
	for (int i=1;i<=len;i++){
		int t=s[i]-'0';
		if (!ch[x][t]){
			ch[x][t]=++sz;
			dep[ch[x][t]]=i;
		}
		x=ch[x][t];
	}
	ed[x]=1;
}
int work(){
	for (int i=0;i<=sz;i++)
		for (int j=0;j<2;j++)
			if (!ch[i][j]&&!ed[i])
				a[dep[i]+1]++;
}
int main(){
	scanf("%d%lld",&n,&L);
	for (int i=1;i<=n;i++){
		scanf("%s",s+1);
		insert();
	}
	long long sum2=0;
	work();
	for (int i=1;i<=100002;i++)
		if (a[i]&1){
			long long tmp=(L-i+1);
			sum2^=tmp&(-tmp);
		}
	puts(sum2?"Alice":"Bob");
}

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

//ライブラリ始まり (簡潔ver)

//定数
//円周率
const double pi = 3.1415926535897932384;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//ライブラリ終わり

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  string S;
  cin >> S;
  if (S.at(0) == 'R' && S.at(1) == 'R' && S.at(2) == 'R') {
    cout << 3 << endl;
  }
  else if (S.at(1) == 'R' && S.at(2) == 'R') {
    cout << 2 << endl;
  }
  else if (S.at(1) == 'R' && S.at(0) == 'R') {
    cout << 2 << endl;
  }
  else if (S.at(0) == 'S' && S.at(1) == 'S' && S.at(2) == 'S') {
    cout << 0 << endl;
  }
  else {
    cout << 1 << endl;
    }
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,D;
  cin>>N>>D;
  cout<<(N+2*D)/(2*D+1)<<endl;
  return 0;
}


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

#define lli long long int
#define pb push_back
#define in insert
#define pi pair<int, int>
#define pii pair<int, pi>
#define mp make_pair
#define fir first
#define sec second
#define MAXN 3001

signed main()
{
  int n , m ;
  cin >> n >> m ;
  vector <int> v (n) ;
  int sum = 0 ;
  for (int i = 0 ; i < n ; i++)
  {
    cin >> v[i];
    sum += v[i] ;
  }
  sort(v.begin(),v.end());
  double porc = 1.0/(4 * m);
  int selected = 0 ;
  int ans = 0 ;
  for(int i = n - 1 ; i >= 0 ; i--)
  {
    double at = (double)v[i] / sum ;
    if (at >= porc && selected < m)
    {
      selected++ ;
    }
  }
  (selected == m) ? cout << "Yes\n" : cout << "No\n";
  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++)
const int INF =1001001001;

bool visit[50];
bool graph[50][50];

void dfs(int v, int n){
   if(visit[v]) return;
   visit[v] = true;

   rep(i,n){
      if(graph[v][i] == false) continue;
      if(visit[i] == true) continue;
      dfs(i,n);
   }
}

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

   vector<int> a(m);
   vector<int> b(m);
   rep(i,m)
   {
      cin >> a[i] >> b[i];
      a[i]--; b[i]--;
      graph[a[i]][b[i]] = true;
      graph[b[i]][a[i]] = true;
   }
   int ans = 0;
   rep(i,m){
      //切り取る
      graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
      rep(j,n) visit[j] = false;

      //dfs
      dfs(0,n);
      
      bool bridge = false;
      //辿れない　＝　橋
      rep(j,n) if(visit[j] == false) bridge = true;
      if(bridge) {
         ++ans;
      }

      //元に戻す
      graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
   }

   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256