akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    string S; cin >> S;
    int cnt = 1;
    int last = 0;
    for (int i = 1; i < S.size(); i++) {
        if (i - last == 2) {
            cnt++;
            last = i;
        } else if (S[i] != S[last]) {
            cnt++;
            last = i;
        } else if (i + 1 < S.size()) {
            cnt++;
            last = i;
            i++;
        }
    }
    cout << cnt << '\n';
    return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;

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

    sort(H, H+N, greater<>());

    for (int i = 0; i < K && i < N; i++) {
        H[i] = 0;
    }

    long sum = 0;
    for (int h: H) {
        sum += h;
    }

    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 1152
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=1
k=0
if a[-1]==0:
    print(0)
    exit()
else:
    while k<n:
        if len(str(ans))<19:
            ans*=a[k]
            k+=1
        else:
            print(-1)
            exit()
if len(str(ans))<19 or ans==10**18:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 21792
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

int main() {
  int n,x;
  scanf("%d %d", &n, &x);
  int A[n];
  for (int i=0; i<n; i++) {
    scanf("%d", &A[i]);
  }
  sort(A, A + n);
  int count=0;
  for (int i = 0; i < n-1; i++) {
    if (x>=A[i]) {
      x -= A[i];
      count++;
    }
  }
  if (x==A[n-1]) {
    x -= A[n-1];
    count++;
  }
  printf("%d\n", count);

  return 0;
}


Measured memory_bytes: 128
let () =
  let as_ =
    Array.init 3 @@ fun _ ->
      Array.init 3 @@ fun _ ->
        Scanf.scanf "%d " @@ fun a -> a in
  let mark = Array.make_matrix 3 3 false in
  Scanf.scanf "%d\n" @@ fun n ->
    for i = 0 to n - 1 do
      Scanf.scanf "%d\n" @@ fun b ->
        for i = 0 to 2 do
          for j = 0 to 2 do
            if as_.(i).(j) = b then
              mark.(i).(j) <- true
          done
        done
    done;
    print_endline @@
    if
      mark.(0) = [| true; true; true |] ||
      mark.(1) = [| true; true; true |] ||
      mark.(2) = [| true; true; true |] ||
      Array.init 3 (fun i -> mark.(i).(0)) = [| true; true; true |] ||
      Array.init 3 (fun i -> mark.(i).(1)) = [| true; true; true |] ||
      Array.init 3 (fun i -> mark.(i).(2)) = [| true; true; true |] ||
      Array.init 3 (fun i -> mark.(i).(i)) = [| true; true; true |] ||
      Array.init 3 (fun i -> mark.(2 - i).(i)) = [| true; true; true |]
    then "Yes"
    else "No"

Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
int main() {
    // your code goes here
    int n;
    while(cin >> n && n!=0){
        n=1000-n;
        int sum=0;
        int coin[]={500,100,50,10,5,1};
        for(int i=0;i<6;i++)
            while(n>=coin[i]){
                sum++;
                n-=coin[i];
            }
    cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

int N;
int table[20];
int reserv[210];

void dfs(int task, int pos, int &res){
  // cout << task << " "<< pos << " " << res << endl;
  if(pos + N >= res) return ;
  if(task == 10){
    res = min(pos + N, res);
    return;
  }
  
  for(int npos = pos; npos <= pos + N; npos++){
    bool ok = true;
    REP(j, N)if(reserv[npos + j] & table[j]){
      ok = false;
      break;
    }
    if(ok){
      REP(j, N) reserv[npos + j] |= table[j];
      dfs(task + 1, npos, res);
      REP(j, N) reserv[npos + j] ^= table[j];
    }
  }
}

int main(){
  while(cin >> N, N){
    string str;
    memset(table, 0, sizeof(table));
    memset(reserv, 0, sizeof(reserv));
    
    REP(i, 5){
      cin >> str;
      REP(j, N) if(str[j] == 'X') table[j] |= (1 << i);
    }
    REP(i, N) reserv[i] = table[i];
    int res = INF;
    dfs(1, 0, res);
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t;
  cin >> s;
  int x;
  int size = s.size()-2;
  vector<int> list(size);
  for(int i=0; i<size; i++) {
    t = s.substr(i,3);
    x = atoi(t.c_str());
    x = abs(753-x);
    list.at(i) = x;
  }
  sort(list.begin(),list.end());
  cout << list.at(0) << endl;
}

Measured memory_bytes: 3584
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        String s = sc.next();
        sc.close();

        s += '1';
        int cnt = 0;
        int idx = 0;
        while(idx < N){
            cnt++;
            while(s.charAt(idx) == s.charAt(idx+1)){
                idx++;
            }
            idx++;
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 28052
#include <cmath>
#include <iostream>
#include <utility>
#include <iomanip>
#include <string>

void print(const std::pair<double, double>& p)
{
    std::cout 
        << p.first
        << " "
        << p.second << std::endl;
    return;
}

void create_koch(
    const std::pair<double, double>& l,
    const std::pair<double, double>& r,
    const int depth)
{
    if (depth == 0) {
        print(l);
        return;
    }
    const auto p0 = std::make_pair(
        (l.first * 2 + r.first) / 3.0,
        (l.second * 2 + r.second) / 3.0);
    const auto p2 = std::make_pair(
        (l.first + r.first * 2) / 3.0,
        (l.second + r.second * 2) / 3.0);
    const auto p0top2 = std::make_pair(
        p2.first - p0.first,
        p2.second - p0.second);
    const double a[2][2]
        = { { 0.5, -std::sqrt(3) * 0.5} ,
        { std::sqrt(3) * 0.5, 0.5 } };
    const auto p1 = std::make_pair(
        p0.first + a[0][0] * p0top2.first + a[0][1] * p0top2.second,
        p0.second + a[1][0] * p0top2.first + a[1][1] * p0top2.second);
    create_koch(l, p0, depth - 1);
    create_koch(p0, p1, depth - 1);
    create_koch(p1, p2, depth - 1);
    create_koch(p2, r, depth - 1);

    return;
}

int main()
{
    int n;
    {
        std::string buf;
        std::getline(std::cin, buf);
        n = std::stoi(buf);
    }
    const auto l = std::make_pair(0, 0);
    const auto r = std::make_pair(100, 0);
    create_koch(l, r, n);
    print(r);
    return 0;
}

Measured memory_bytes: 3268
#include <cmath>
#include <vector>
#include <iostream>
#include <limits>
#include <iostream>
#include <vector>
#include <cassert>
#include <complex>
#include <cstdio>
#include <set>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <queue>
#include <bitset>
#include <ctime>
#include <unordered_map>
#include <numeric>
#include <climits>

using namespace std;
typedef long long Long;
typedef long double Double;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef pair<Long,Long> PLL;

int read(int &x) { return scanf("%d", &x); }
int read(int &x, int &y) { return scanf("%d%d", &x, &y); }
int read(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
int read(Long &x) { return scanf("%lld", &x); }
char buff[1000010];
int read(string &s) { int r = scanf("%s", buff); s = buff; return r; }

#define dlog2(n) (31-__builtin_clz(n))



int main() {

	int A, B;
	read(A, B);
	cout << max(A + B, max(A - B, A * B)) << endl;

	return 0;
}

/*
3 -> 2 -> 1
3 -> 1 -> 1
2 -> 1 -> 1
1 -> 2 -> 1
1 -> 1 -> 1



*/

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

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];

int main(){
    ll a, N, ans=0;
    cin >> N;
    vector<ll> A;
    for (int i = 0; i < N; i++){
        cin >> a;
        A.push_back(a);
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < N-1; i++){
        if(A[i] == A[i+1])ans = 1;
    }
    if(ans == 1) cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 2420
#include <iostream>

using namespace std;

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

	int a = A + B;
	int b = A - B;
	int c = A * B;

	int result;
	if (a < b) {
		result = b;
	} else {
		result = a;
	}

	if (result < c) {
		result = c;
	}
	cout << result << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	double n,tmp,sum=0;
	while(scanf("%lf",&n)!=EOF)
	{
		sum=0;
		tmp = n;
		for(int i=1;i<=10;i++)
		{
			if(i==1)
			{
			}
			else if(i%2==0)
			{
				tmp *=2;
			}
			else
			{
				tmp /=3;
			}
			sum += tmp;
		}
		printf("%.8f\n",sum);
	}
	return 0;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod>
struct modulo {
	int w;
	operator int&() { return w; }
	
	modulo() {}
	modulo(int w, bool f = 0) { this->w = w; if (f) fix(); }
	void inline fix() { w %= mod; if (w < 0) w += mod; }
	modulo inline fix(int w) const { w %= mod; if (w < 0) w += mod; return w; }
	
	modulo& operator += (modulo b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	modulo& operator -= (modulo b) { if ((w -= b.w) < 0) w += mod; return *this; }
	modulo& operator *= (modulo b) { w = (num) w * b.w % mod; return *this; }
	modulo& operator /= (modulo b) { w = (num) w * b.inv() % mod; return *this; }
	modulo inline operator + (modulo b) { modulo r = *this; r += b; return r; }
	modulo inline operator - (modulo b) { modulo r = *this; r -= b; return r; }
	modulo inline operator * (modulo b) { modulo r = *this; r *= b; return r; }
	modulo inline operator / (modulo b) { modulo r = *this; r /= b; return r; }
	
	modulo inline inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return fix(u);
	}
	
	modulo inline pow(int p) const {
		if (!w)  return 0;
		modulo a = *this, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
const int mod = int(1e9 + 7);
typedef modulo<mod> rem;

const int nsz = int(5e3);
int n, k, a[nsz + 5];
rem dp[nsz + 5][nsz + 5], ans;
vector<int> r;

struct union_find {
	int pr[nsz + 5], siz[nsz + 5];
	
	union_find() {
		cont (u, nsz) pr[u] = u, siz[u] = 1;
	}
	
	int inline operator [] (int id) { return qry(id); }
	
	int qry(int u) { return pr[u] == u ? u : pr[u] = qry(pr[u]); }
	
	bool inline link(int u, int v) {
		int pu = qry(u), pv = qry(v);
		if (pu == pv) return 0;
		pr[pv] = pu;
		siz[pu] += siz[pv];
		return 1;
	}
};
union_find uf;

int main() {
	scanf("%d", &n);
	cont (i, n) {
		scanf("%d", &a[i]);
		if (a[i] != -1) uf.link(a[i], i);
	}
	cont (u, n) {
		if (uf[u] != u) continue;
		if (a[u] == -1) r.push_back(u);
	}
	k = int(r.size());
	
	cont (u, n) {
		if (uf[u] != u || a[u] == -1) continue;
		ans += rem(n - 1).pow(k);
	}
	
	dp[0][0] = 1;
	loop (i, k) {
		int u = r[i];
		circ (j, 0, i) {
			dp[i + 1][j] += dp[i][j];
			dp[i + 1][j + 1] += dp[i][j] * (j ? rem(j) : rem(1)) * rem(uf.siz[u]);
		}
	}
	
	cont (j, k) {
		ans += dp[k][j] * rem(n - 1).pow(k - j);
	}
	cont (u, n) {
		if (uf[u] != u || a[u] != -1) continue;
		ans -= rem(n - 1).pow(k - 1);
	}
	
	ans = rem(n) * rem(n - 1).pow(k) - ans;
	printf("%d\n", ans);
}

Measured memory_bytes: 70648
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long int

ll x,a,b;

void keisan(){
    for(a=0;a<=151;a++){
    for(b=-200;b<=150;b++){
      ll tmpa,tmpb,sa;
      tmpa = a*a*a*a*a;
      tmpb = b*b*b*b*b;
      sa = tmpa-tmpb;
      
      if(sa==x){
	printf("%lld %lld\n",a,b);
	return ;}}
    }
    return;
}

int main(){
  scanf("%lld",&x);
  keisan();


  //printf("%lld %lld\n",a,b);
  
  return 0;
}


Measured memory_bytes: 1732
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a,b,c;
		int hoz;
		a = sc.nextInt(); //4
		b = sc.nextInt(); //3
		c = sc.nextInt(); //1
		if(a>b){
			hoz = a;
			a = b; 
			b = hoz; 
			if(b>c){
				hoz = b;
				b = c; 
				c = hoz; 
				if(a>b){
					hoz = a;
					a = b;
					b = hoz;
				}
			}
		}else if(b>c){
			hoz = b;
			b = c;
			c = hoz;
			if(a>b){
				hoz = a;
				a = b;
				b = hoz;
			}
		}
		System.out.println(a+" "+b+" "+c);
	}
}

Measured memory_bytes: 17160
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n,h,w;
    cin >> n >> h >> w;
    vi a(n), b(n);
    rep(i,n) cin >> a.at(i) >> b.at(i);
    ll res = 0;
    rep(i,n){
        if(a.at(i)>=h && b.at(i)>=w) res++;
    }
    cout << res << endl;
}

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

using namespace std;

int main(void){
  vector<int>num,ans;
  int n,p,prime[1000001];

  for(int i=0;i<1000001;i++)prime[i]=0;
  prime[0]=prime[1]=1;

  for(int i=2;i*i<1000001;i++){
    if(prime[i]==0){
      for(int j=2*i;j<1000001;j+=i){
	prime[j]=1;
      }
    }
  }


  while(cin >> n >> p){
    if(n<0 && p<0)break;
    num.clear();
    ans.clear();

    for(int i=n+1;i<n+p+1000;i++)
      if(prime[i]==0)num.push_back(i);

    for(int i=0;i<num.size();i++){
      for(int j=i;j<num.size();j++){
	ans.push_back(num[i]+num[j]);
      }
    }
    sort(ans.begin(),ans.end());

    cout << ans[p-1] << endl;
  }

  return 0;
}

Measured memory_bytes: 5256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <numeric>
#include <cmath>
#include <set>
#include <utility>
 
using namespace std;
 
int main(){
    int n,m;
    vector<int> v;
    set<int> s;
    scanf("%d %d",&n,&m);
    bool f = false;
    for (int i = 0; i < m; i++){
        int x,y;
        scanf("%d %d",&x,&y);
        if(y == n){
            f = true;
        }
        if(x == 1){v.push_back(y);}
        if(y == n){s.insert(x);}
        
    }
    if(f == false){
        printf("IMPOSSIBLE");
        exit(0);
    }
 
    for(int i = 0;i < v.size(); i++){
        decltype(s)::iterator it = s.find(v[i]);
        if (it != s.end()) {
            printf("POSSIBLE");
            exit(0);
        }
    }
    printf("IMPOSSIBLE");
}

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

using namespace std;

int f(int x) {
	if (x & 1) {
		return 3 * x + 1;
	} else {
		return x / 2;
	}
}

int main() {
	int s;
	cin >> s;
	vector <int> ans;
	ans.push_back(s);
	int i = 1;
	while (true) {
		int ns = f(ans.back());
		i++;
		if (find(ans.begin(), ans.end(), ns) != ans.end()) {
			cout << i;
			return 0;
		}
		ans.push_back(ns);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<" = "<<x<<endl;
typedef long long int ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int arr[n];
    int arr2[n];
    int arr3[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        cin>>arr2[i];
        cin>>arr3[i];

    }
    int ans[n];
    int ans2[n];
    int ans3[n];
    ans[0]=arr[0];
    ans2[0]=arr2[0];
    ans3[0]=arr3[0];
    for(int i=1;i<n;i++){
        ans[i]=arr[i]+max(ans2[i-1],ans3[i-1]);
        ans2[i]=arr2[i]+max(ans3[i-1],ans[i-1]);
        ans3[i]=arr3[i]+max(ans2[i-1],ans[i-1]);
    }
    int res=max({ans[n-1],ans2[n-1],ans3[n-1]});
    cout<<res<<"\n";
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, r;
	while (cin >>r>>n, r) {
		map<int, int> v;

		REP(i, n) {
			int a, b, c;
			cin >> a >> b >> c;
			
			FOR(j, a, b)v[j] = max(v[j], c);
		}
		FOR(i, -20, -r)v[i] = INF;
		FOR(i, r, 20)v[i] = INF;
		if (n==0) {
			cout << 0 << endl;
		}
		
		else {
			double u = 21, l = -1;
			while (u - l > EPS) {
				int flag = 1;
				double mid = (u + l) / 2;
				FOR(i, -20, 20) {
					int d = i;
					if (i < 0)d++;
					if (abs(i) > r)continue;
					double c = sqrt(r*r - d*d);
					if (c + mid > v[i]+r)flag = 0;
				}
				if (flag)l = mid;
				else u = mid;
			}
			cout << fixed << setprecision(4) << l << endl;
		}
	}
}

Measured memory_bytes: 3296
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{ 
 
 
    static long mod=1000000007;
    static int dx[]={1,-1,0,0};
    static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1};
    // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); 
    //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
        // ArrayList<Integer> lis = new ArrayList<Integer>();
    // ArrayList<Integer> map[]=new ArrayList[26];
    static HashMap<Integer,Long> map = new HashMap<Integer,Long>();

    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // long n=sc.nextLong();
        // char c[][] = new char[h][w];
        // long a[] = new long [n];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {a[i]=sc.nextInt();}
        int n=sc.nextInt();
        int k=sc.nextInt();
        long ans=0;
        if(k>0)for (int i=k+1,t=1; i<=n ;i++,t++ ) {
            ans+=(long)t*(n/i);
            if(n%i>=k)ans+=(n%i)-k+1;
            // db(i,(long)t*(n/i)+max((t-n%i-k),0));
        }
        else ans=(long)n*n;

        
        out.println(ans);
        out.flush();
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
     
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class XY {
    int x,y,d;
    XY(int x, int y, int d) {
        this.x=x;
        this.y=y;
        this.d=d;
    } 
}
 
class P implements Comparable<P>{
    int x,y;
    P(int x, int y) {
        this.x=x;
        this.y=y;
    } 
      
    public int compareTo(P p){
        return -x + p.x;//des
    } 
}
 
class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 21328
import scala.io.StdIn._
import scala.collection._

object Main {

  class Sieve(val n: Int){
    private[this] val top = (n - 3) / 2 + 1
    private[this] val sqrtLimit = (Math.sqrt(n).toInt - 3) / 2

    private[this] val cmpsts = new Array[Int]((top >>> 5) + 1)
    def isPrime(ci: Int): Boolean = (cmpsts(ci >>> 5) & (1 << (ci & 31))) == 0
    def notPrime(ci: Int): Unit = cmpsts(ci >>> 5) |= 1 << (ci & 31)

    def next(i: Int): Int = if((i > top) || isPrime(i)) 2 * i + 3 else next(i + 1)

    def exec: Iterator[Int] = {
/*
      for{
        i <- 0 to sqrtLimit
        if isPrime(i)
        j <- Range(((2 * i + 3)*(2 * i + 3)-3)/2, top, (2 * i + 3))
      } notPrime(j)
      */
      /*
      (0 to sqrtLimit).map{ i =>
        val p = 2 * i + 3
        if(isPrime(i))Range((p*p-3)/2, top, p).map{notPrime}
      }
      */

      (0 to sqrtLimit).withFilter(isPrime).map { i =>
        val p = 2 * i + 3
        Range(((2 * i + 3)*(2 * i + 3)-3)/2, top, (2 * i + 3)).map(notPrime)
      }


      if(n==2)Iterator.single(2)
      else Iterator.single(2) ++ Iterator.iterate(3)(p => next((p - 1) / 2)).takeWhile(_ <= n)
    }
  }

  def loop(s: String){
    if(s != null){
       val Array(n,_*) = s.split(" ").map(_.toInt)
       if(n<2) println(0)
       else println(new Sieve(n).exec.size)
       loop(readLine)
    }
  }

  def main(args: Array[String]): Unit = loop(readLine)
}

Measured memory_bytes: 306872
odd_steps = ['R', 'U', 'D']
even_steps = ['L', 'U', 'D']

S = input()

flg = 1
for i in range(len(S)):
    if (i + 1) % 2 == 1:
        if S[i] not in odd_steps:
            flg = 0
            break
    if (i + 1) % 2 == 0:
        if S[i] not in even_steps:
            flg = 0
            break

print('Yes') if flg == 1 else print('No')




Measured memory_bytes: 38484
import java.util.Scanner;
 
public class Main{
 
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
 
		Scanner scanner = new Scanner(System.in);
		System.out.print(" ");
 
		int K = scanner.nextInt();
		int A = scanner.nextInt();
		int B = scanner.nextInt();
 
		int largest = (B / K) * K;
		
		if (A <= largest) {
			System.out.println("OK");
		} else {
			System.out.println("NG");
		}
		scanner.close();
     
	}
}

Measured memory_bytes: 35808
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr ll MOD=1000000007;
constexpr ll INF=1LL<<60;
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
    int H;
    while((cin>>H,H)){
        int A[10][5];
        rep(i,H)rep(j,5)cin>>A[i][j];
        bool update=1;
        int res=0;
        while(update){
            update=0;
            bool rm[10][5];rep(i,10)rep(j,5)rm[i][j]=0;
            rep(i,H){
                int ct=1;
                for(int j=1;j<5;j++)
                    if(A[i][j]==A[i][j-1])ct++;
                    else{
                        if(ct>2){
                            for(int k=j-ct;k<j;k++){rm[i][k]=1;update|=A[i][k]>0;res+=A[i][k];A[i][k]=0;}
                        }
                        ct=1;
                    }
                if(ct>2){
                            for(int k=5-ct;k<5;k++){rm[i][k]=1;update|=A[i][k]>0;res+=A[i][k];A[i][k]=0;}
                }
            }
            rep(i,5){
                int now=H-1,id=H-1;
                while(id>=0){
                    while(id>=0&&rm[id][i])id--;

                    if(id>=0)
                        {swap(A[now][i],A[id][i]);now--;id--;}
                }
            }
        }
        cout<<res<<endl;
    }
}

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


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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define REV(i,j,k) for(int i=j;i>=k;i--)
#define FORR(i,j,k,l) for(int i=j;i<=k;i+=l)
#define inf         freopen("in.txt", "r", stdin)
#define outf        freopen("out.txt", "w", stdout)
#define pf          printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c)    scanf("%d %d %d", &a, &b, &c)
#define clean(mat,n)   FOR(i,0,n) mat[i].clear()
#define minn          (long long)-1000000000000000000
#define maxx          (long long) 1000000000000000000
#define mod          998244353
#define M_PI           3.14159265358979323846  /* pi */
#define LL           long long
#define NL '\n'
#define cnd tree[idx]
#define lnd (idx<<1)
#define rnd ((idx<<1)+1)
#define PB push_back
#define F first
#define S second
#define MAX 1005
#define MP make_pair
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
#define LD long double
typedef pair<int,int> PR;

LL dp[MAX][10005], n;
struct node
{
    int s, w, v;
}ara[MAX];

LL rec(int p,int ba)
{
    if(p == n) return 0;

    LL &temp = dp[p][ba];
    if(temp != -1) return temp;

    temp = 0;
    if(ara[p].w <= ba)
    {
        int newBa = min(ara[p].s, ba - ara[p].w);
        temp = ara[p].v + rec(p + 1, newBa);
    }
    temp = max(temp, rec(p + 1, ba));

    return temp;
}

int main()
{
    ios::sync_with_stdio(false);
    //inf;
    //outf;
    LL prin = 0;

    cin >> n;
    FOR(i,0,n-1) cin >> ara[i].w >> ara[i].s >> ara[i].v;
    sort(ara, ara + n, [](node x,node y){
            return x.s + x.w > y.w + y.s;
         });

    mem(dp, -1);
    FOR(i,0,n-1)
    {
        prin = max(prin, ara[i].v + rec(i + 1, ara[i].s));
    }
    cout << prin << endl;

    return 0;
}




Measured memory_bytes: 78848
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace A
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            SolveB();
        }


        static void SolveB()
        {
            var nl = ReadLine().Split(' ').Select(int.Parse);
            var s = new List<string>();
            for (var i = 0; i < nl.First(); i++)
            {
                s.Add(ReadLine());
            }

            var sorted = s.OrderBy(x => x).Aggregate((line, part) => line + part);
            WriteLine(sorted);
        }
    }
}

Measured memory_bytes: 29516
#include<bits/stdc++.h>
#define lson (o<<1)
#define rson (o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
template<typename T> inline T max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
	A ans=1;
	for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
	return ans;
}
struct FastIO{
	static const int S=1310720;
	int wpos;char wbuf[S];
	FastIO():wpos(0){}
	inline int xchar(){
		static char buf[S];
		static int len=0,pos=0;
		if(pos==len)pos=0,len=fread(buf,1,S,stdin);
		if(pos==len)return -1;
		return buf[pos++];
	}
	inline int read(){
		int c=xchar(),x=0;
		while(c<=32&&~c)c=xchar();
		if(c==-1)return -1;
		for(;'0'<=c&&c<='9';c=xchar())x=x*10+c-'0';
		return x;
	}
}io;
//#define read io.read
struct node
{
	string s;
	int a;
	int id;
};
bool cmp(node a,node b)
{
	if(a.s!=b.s) return a.s<b.s;
	else return a.a>b.a;
}
int main()
{
	int n;
	cin >> n;
	node a[100001];
	for(int i=1;i<=n;i++)
	{
		cin >> a[i].s >> a[i].a;
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++) cout << a[i].id << "\n";
	return 0;
}


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

int main() {
	
	int N;
	int a[100010];
	int tmp;
	int count = 1;
	int ans;

	cin >> N;
	for (int i = 1; i <= N; i++) {

		cin >> a[i];

	}

	tmp = a[1];
	for (int i = 1; i <= N; i++) {

		if (tmp == 2) {

			cout << count << endl;
			return 0;

		}
		tmp = a[tmp];
		
		count++;
	}

	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>

using namespace std;

int main(){
  int n,q;
  string s;
  int l[100000];
  int r[100000];
  cin >> n >> q;
  cin >> s;
  for(int i = 0; i < q ; i++){
    cin >> l[i] >> r[i];
    l[i]--;
    r[i]--;
  }
  int ans[100000] = {0};
  for(int i = 1; i < n; i++){
    if(s[i-1] == 'A' && s[i] == 'C'){
      ans[i] = ans[i-1] + 1;
    }
    else ans[i] = ans[i-1];
  }
  for(int i = 0; i < q; i++){
    cout << ans[r[i]] - ans[l[i]] << endl;
  }
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX
#define yn(f) cout << (f ? "Yes" : "No") << endl;

string s;

signed main() {
    cin >> s;
    rep(i,s.size()) {
        if (s.size() == i+1) {
            yn(0);
            return 0;
        }
        if (s[i] == 'h' && s[i+1] == 'i') i++;
        else {
            yn(0);
            return 0;
        }
    }
    yn(1);
}


Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int a , b , c, d;
    cin >> a  >> b  >> c >> d;
    
    cout << c-(d-b) << " " << d+(c-a) << " "
     << c-(d-b)-(c-a) << " " << d+(c-a)-(d-b) << endl;
}

Measured memory_bytes: 256
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int main() {
    ios_base::sync_with_stdio(false);

    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = n / (a+b) * a;
    ans += min(a, n%(a+b));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))

int main()
{
	int A, B;
	cin >> A >> B;
	if (abs(A - B) % 2 == 0) {
		cout << abs(A + B) / 2 << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
MOD = 10**9 + 7
def main():
    S = input()
    N = len(S)-1
 
    if S[0] == '?':
        dp = [1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        dp = [0,0,0,0,0,0,0,0,0,0,0,0,0]
        dp[int(S[0])] = 1
 
    for i in range(1,N):
        dppre = dp
        dp = [0] * 13
 
        if S[i] == '?':
            R = range(10)
        else:
            R = [int(S[i])]
        
        for j in range(13):
            for k in R:
                dp[(j * 10 + k) % 13 ] += dppre[j]
        for j in range(13):
            dp[j] %= MOD
 
    print(dp[5])
if __name__ == '__main__':
    main()

Measured memory_bytes: 43372
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt();
        HashMap<Integer, Integer> m = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            int c = m.getOrDefault(a, 0);
            m.put(a, c + 1);
        }
        PriorityQueue<Integer> q = new PriorityQueue<>();
        int cnt = 0;
        for (Map.Entry<Integer, Integer> e: m.entrySet()) {
            q.add(e.getValue());
            cnt++;
        }
        int ans = 0;
        for (int i = 0; i < Math.max(0, cnt - k); i++) {
            ans += q.remove();
        }
        System.out.println(ans);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 98732
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

def lcm(n, m):
    return n * m // gcd(n, m)

L = A[0]
for a in A:
    L = lcm(L, a)
L %= MOD

modInvSum = sum([pow(a, MOD - 2, MOD) for a in A])
ans = L * modInvSum

print(ans % MOD)


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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];

    int cnt = 0;
    int min_p = n+1;
    rep(i,n)
    {
        if(p[i] <= min_p) cnt++;
        min_p = min(min_p, p[i]);
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;

int main()
{
  std::cin >> N;

  std::cout << N/3 << std::endl;

  return 0;
}

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

int a[1005];
int n;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	sort(a+1, a+n+1);
	cout << a[n]-a[1] << endl;
	return 0;
}

Measured memory_bytes: 256
def solve(a,b):
    l = []
    count = (b - a + 1)
    r = 0
    if (a % 2 != 0):
        l.append(a)
        r += 1
    if (b % 2 == 0):
        l.append(b)
        r += 1
    if ((count - r) / 2) % 2 != 0:
        l.append(1)

    ans = 0
    for n in l:
        ans = ans ^ n
    print(ans)

a,b = map(int, input().split())
solve(a,b)


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

int main()
{
	//freopen("input.txt","r",stdin);
	string s1,s2,s3 ;
	cin >> s1 >> s2 >> s3 ;
	//cout << s1-'0' <<" " << s2-'0' << s3 -'0' ;
	string s = s2+s3 ;
	int tmp = stoi(s);
	tmp%4 == 0 ? cout << "YES\n" : cout << "NO\n";
	return 0 ;
}

Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())
tx -= sx
ty -= sy
ans = ""
ans += "U" * ty + "R" * tx
ans += "D" * ty + "L" * tx
ans += "L" + "U"*(ty+1) + "R"*(tx+1) + "D"
ans += "R" + "D"*(ty+1) + "L"*(tx+1) + "U"
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)

//変数
int a,b,c,k;

//解法
void solve() {

	cout << a + b + c + max(a, max(b, c))*(pow(2, k) - 1);

	return;
}

int main() {
	//入力
	cin >> a >> b >> c >> k;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String str1 = sc.nextLine();
    String[] vals1 = str1.split(" ");

    int n = Integer.parseInt(vals1[0]);
    int m = Integer.parseInt(vals1[1]);

    String str2 = sc.nextLine();
    List<Integer> votes = Arrays.asList(str2.split(" ")).stream().map(Integer::valueOf).collect(Collectors.toList());
    
    Collections.sort(votes, Collections.reverseOrder());

    int sum = votes.stream().mapToInt(i -> Integer.valueOf(i)).sum();
    int minVal = votes.get(m - 1);

    boolean res = minVal < (double) sum / ((double) (4 * m));

    if (res) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }

  }
}

Measured memory_bytes: 36088
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>

int main()
{
	int num;
	num = 0;
	scanf("%d", &num);

	if (num >= 1 && num <= 100) {
		num = num * num * num;
	}
	printf("%d\n", num);

	return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
void in(){}
template<typename F, typename... R>
bool in(F& f, R&... r){
    if(cin >> f){in(r...);return true;}
    else return false;
}
#define out(x) cout << (x)
#define space() cout << " "
#define indent() cout << '\n'
void print(){}
template<typename F, typename... R>
void print(F f, R... r){out(f), indent(), print(r...);}
#define debughead(x) cerr << "Line " << __LINE__ << ": " << #x << ": "
#define debugout(x) cerr << (x) << " "
#define debugindent() cerr << '\n'
#define debug(x) debughead(x), debugout(x), debugindent()
const int INF = 1e18, MOD = 1e9 + 7;
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

int n, k, res = 0, tmp = 0;
string s;
main(){
    INCANT;
    in(n, k, s);
    vector<int> cnt0, cnt1;
    if(s[0] == '0'){
        cnt1.pb(0);
    }
    rep(i, 1, n){
        tmp++;
        if(s[i] != s[i - 1]){
            if(s[i - 1] == '1'){
                cnt1.pb(tmp);
            }else{
                cnt0.pb(tmp);
            }
            tmp = 0;
        }
    }
    tmp++;
    if(s[n - 1] == '1'){
        cnt1.pb(tmp);
    }else{
        cnt0.pb(tmp);
    }
    if(s[n - 1] == '0'){
        cnt1.pb(0);
    }

    if(!cnt0.size()){
        print(cnt1[0]);
        return 0;
    }

    rep(i, cnt0.size()){
        tmp = 0;
        rep(j, i, min((int)(cnt0.size()), i + k)){
            tmp += cnt0[j];
        }
        rep(j, i, min((int)(cnt1.size()), i + k + 1)){
            tmp += cnt1[j];
        }
        chmax(res, tmp);
    }
    print(res);
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,d,m;
	bool f=true;
	map<ll,ll>mp;
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>d;
		mp[d]++;
	}
	cin>>m;
	for(ll i=0;i<m;i++){
		cin>>d;
		mp[d]--;
		if(mp[d]<0){
			f=false;
		}
	}
	if(f){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}



Measured memory_bytes: 16104
s = input()
t = input()

key = [str(t[i]) for i in range(len(t))]
count = 0
sub = []

for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j] != "?" and s[i+j] != t[j]:
      break
    if j == len(t)-1:
      sub.append(i)


ans = [0]*len(s)
if sub:
  k = 0
  change = sub[-1]
  for i in range(len(s)):
    if i == change:
      for j in range(len(t)):
        ans[i+j] = t[j]
      k = len(t)-1
    elif k:
      k -= 1
    else:
      if s[i] == "?":
        ans[i] = "a"
      else:
        ans[i] = s[i]
  print("".join(ans))  
else:
  print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    ll n, q;
    cin >> n;
    map<ll, ll> mp;
    rep(i,n) {
        ll a; cin >> a;
        mp[a] ++;
    }
    cin >> q;
    vector<ll> b(q), c(q);
    rep(i,q) cin >> b[i] >> c[i];
    ll sum = 0;
    for (auto ele : mp) {
        sum += ele.first * ele.second;
    }
    rep(i,q) {
        mp[c[i]] += mp[b[i]];
        sum += (c[i] - b[i]) * mp[b[i]];
        mp[b[i]] = 0;
        cout << sum << "\n";
    }
    return 0;
}


Measured memory_bytes: 10536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
   ll N,M;
  cin>>N>>M;
vector<pair<ll,ll>>C(N);
  priority_queue<ll>queue;
  
  rep(i,N){
    cin>>C[i].first>>C[i].second;
  }
  
  sort(all(C));

  ll ans=0;
  ll x=0;
  
  for(ll i=M-1;i>=0;i--){

    while(x<N){
      if(i+C[x].first<=M){
queue.push(C[x].second);
        x++;
      }
      else{
        break;
      }
    }
if(!queue.empty()){
  ans+=queue.top();
  queue.pop();//ここでまた空にする？
}
  }

  
  cout<<ans<<endl;
}


Measured memory_bytes: 2936
def examD():
    # https://juppy.hatenablog.com/entry/2019/02/18/ARC83_-D_Restoring_Road_Network-_Python_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0_Atcoder
    def warshall_floyd(n, d):
        # d[i][j]: iからjへの最短距離
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])
        return d
    N = I()
    A = [LI() for _ in range(N)]
    Dist = [[0]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            a, b, r = i, j, A[i][j]
            Dist[a][b] = r
    D = warshall_floyd(N,Dist)
    ans = 0
    for i in range(N):
        for j in range(N):
            cur = D[i][j]
            if i==j:
                continue
            if cur<A[i][j]:
                print(-1)
                return
            if cur==A[i][j]:
                flag = True
                for k in range(N):
                    if k==i or k==j:
                        continue
                    if cur==D[i][k]+D[k][j]:
                        flag = False
                if flag:
                    ans += cur
    print(ans//2)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""

Measured memory_bytes: 45276