akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    scanf("%d%d",&n,&l);
    int x[n];
    long long p[n];
    for (int i = 0; i < n; i++){
        scanf("%d%lld",&x[i],&p[i]);
    }
    int s = 0, e = n-1;
    vector<int> ans;
    while (s != e){
        if (x[s] > l){
            while (e != s){
                ans.push_back(x[e]);
                e--;
            }
            break;
        }
        if (x[e] < l){
            while (s != e){
                ans.push_back(x[s]);
                s++;
            }
            break;

        }
        if (p[s] < p[e]){
            ans.push_back(x[s]);
            s++;
            p[e] += p[s-1];
        }
        else{
            ans.push_back(x[e]);
            e--;
            p[s] += p[e+1];
        }

    }
    ans.push_back(x[s]);
    ans.push_back(l);
    long long sum = 0;
    //for (auto x : ans) printf("%d ",x);
    for (int i = 1; i < n+1; i++){
        sum += abs(ans[i]-ans[i-1]);
    }
    printf("%lld",sum);
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
int main(){
    ll A, B;
    cin >> A >> B;
    if(B % A == 0){
        cout << A + B << endl;
    }
    else{
        cout << B - A << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

S_ = []
for i in range(len(S)):
    new = ord(S[i]) + N
    if ord("A") <= new <= ord("Z"):
        pass
    else:
        new = new - ord("Z") + ord("A") - 1
    S_.append(chr(new))
for s in S_:
    print(s, end="")
print()

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

LL htoi(string &s){
  LL ans=0;
  rep(i,s.length()){
    ans*=16;
    if('0'<=s[i]&&s[i]<='9') ans+=s[i]-'0';
    else ans+=s[i]-'a'+10;
  }
  return ans;
}

string itoh(LL x){
  string ans="";
  while(x){
    if(x%16<=9) ans.push_back('0'+x%16);
    else ans.push_back('a'+x%16-10);
    x/=16;
  }
  if(ans.size()==0) ans="0";
  reverse(all(ans));
  return ans;
}

int main(){
  int q;
  cin >> q;
  rep(t,q){
    string s;
    vector<LL> p(9),q(9);
    rep(i,9){
      cin >> s;
      p[i]=htoi(s);
      q[i]=p[i]%65536;
      p[i]/=65536;
    }
    map<LL,vector<LL>> mp;
    rep(i,65536){
      LL sum=0;
      rep(j,8) sum+=(p[j]^i);
      sum%=65536;
      mp[(p[8]^i)-sum].push_back(i);
    }
    rep(i,65536){
      LL sum=0;
      rep(j,8) sum+=(q[j]^i);
      if(sum%65536==(q[8]^i)){
        auto itr=mp.find(sum/65536);
        if(itr!=mp.end()){
          vector<LL> &v = itr->second;
          for(LL x:v){
            sum=0;
            rep(j,8) sum+=((p[j]*65536+q[j])^(x*65536+i));
            sum%=65536LL*65536;
            if(sum==(p[8]*65536+q[8])^(x*65536+i)){
              cout << itoh(x*65536+i) << endl;
              goto next;
            }
          }
        }
      }
    }
    next:;
  }
  return 0;
}



Measured memory_bytes: 10264
def main():
    N = int(input())
    capacity = [None] * 5
    min_cap = float('inf')
    for i in range(5):
        capacity[i] = int(input())
        if capacity[i] < min_cap:
            min_cap = capacity[i]
    time = N // min_cap
    if N % min_cap > 0:
        time += 1
    print(time + 4)
    return

main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k=0;cin>>a>>b;
  for(int i=a;i<=b;i++){
    int s,t,v,w;
    s=i/10000;
    t=i/1000-s*10;
    v=i/10-(i/100)*10;
    w=i-(i/10)*10;
    if(s==w&&t==v)k++;
  }
  cout<<k<<endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define RFOR(i,k,n) for (int (i)=(n)-1; (i)>=(k); --(i))
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) cerr << #x <<": "<<x<<endl
#define debug2(x,y) cerr << #x <<": "<< x <<", "<< #y <<": "<< y << endl
#define answer(x) cout << (x) <<endl
#define answer_fixed(x, p) cout << fixed << setprecision(p) << (x) << endl
using namespace std;
typedef vector<int> VI;
typedef vector<char> VC;
int H, W;

bool check(VI alphabet) {
  if(H % 2 == 0 && W % 2 == 0) { // both even
    REP(i, 26) { if(alphabet[i] % 4 != 0) { return false; } }
  }
  else if(H % 2 == 0 || W % 2 == 0) { // 1 odd & 1 even
    VI center_alphabet(26, 0);
    int center_alphabet_num = 0;
    REP(i, 26) {
      if(alphabet[i] % 4 != 0) {
        center_alphabet[i] +=  alphabet[i] % 4;
        center_alphabet_num += alphabet[i] % 4;
      }
    }
    if(H % 2 == 0 && center_alphabet_num > H) { return false; }
    else if(W % 2 == 0 && center_alphabet_num > W) { return false; }
    REP(i, 26) { if(center_alphabet[i] % 2 != 0) { return false; } }
  }
  else {
    VI center_alphabet(26, 0);
    int center_alphabet_num = 0;
    int odd_alphabet_num = 0;
    REP(i, 26) {
      if(alphabet[i] % 4 != 0) {
        center_alphabet[i] +=  alphabet[i] % 4;
        center_alphabet_num += alphabet[i] % 4;
      }
    }
    if(center_alphabet_num > H + W - 1) { return false; }
    REP(i, 26) {
      if(center_alphabet[i] % 2 != 0) {
        if(odd_alphabet_num++ > 1) { return false; }
      }
    }
  }
  return true;
}

int main() {
  ios_base::sync_with_stdio(false);
  char c;
  cin >> H >> W;
  VI alphabet(26, 0);
  REP(i, H * W) {
    cin >> c;
    alphabet[c - 'a']++;
  }
  answer(check(alphabet) ? "Yes" : "No");
  return 0;
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int n;
	cin >> n;
	ll a[n];
	rep(i, 0, n) cin >> a[i];

	ll rsl = 0;
	ll tmp = 0;
	rep(i, 0, n) {
		if(a[i] != 0) {
			tmp += a[i];
		} else {
			rsl += tmp / 2;
			tmp = 0;
		}
	}

	rsl += (tmp / 2);

	cout << rsl << endl;
}


Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class CReplacingInteger {
public:
    void solve(std::istream &in, std::ostream &out) {
        ll n, k;
        in >> n >> k;
        ll res = min(n % k, k - n % k);
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    CReplacingInteger solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
            }
            int ans = 0;
            int ptr = 1;
            int prev = a[0];
            for (int i = 1; i < n; i++) {
                if (a[i] == prev) {
                    ptr++;
                } else {
                    ans += ptr / 2;
                    ptr = 1;
                }
                if (i == n - 1) ans += ptr / 2;
                prev = a[i];
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 23892
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
#include <queue>
using namespace std;

#define x first
#define y second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define wh(x) (x).begin(),(x).end()
#define ri(x) int x;cin>>x;
#define rii(x,y) int x,y;cin>>x>>y;
#define rl(x) ll x;cin>>x;
#define rv(v) for(auto&_cinv:v) cin>>_cinv;
#define wv(v) for(auto&_coutv:v) cout << _coutv << ' '; cout << endl;
#define ev(v) for(auto&_cerrv:v) cerr << _cerrv << ' '; cerr << endl;
#define MOD 1000000007

namespace std { 
template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

int main(int,char**) {
    ios_base::sync_with_stdio(false);

    ll N,E,T; cin >> N >> E >> T;
    //if (N > 2000) return 0;
    vector<ll> X(N); rv(X);

    vector<ll> H(N, 0);
    for (int i = 0; i < N; i++) {
        H[i] = max(T, 2*X[i] - 2*X[0]);
    }

    int y = -1;
    ll df = 1e15;
    priority_queue<pair<ll,int>,vector<pair<ll,int>>, greater<pair<ll,int>>> Q;
    for (int i = 0; i < N; i++) {
        if (i!=0) df = df + 2*X[i] - 2*X[i-1];
        while (y < N-1 && 2*X[i] - 2*X[y+1] > T) {
            //cout << "ADD" << y << endl;
            df = min(df, (y >= 0 ? (H[y] - X[y]) : 0) + 2*X[i] - 2*X[y+1]);
            y++;
        }

        //cout << i << ' ' << y << ' ' << H[i] << ' ' << df << 'D' << endl;
        H[i] = min(H[i], df);
        while (!Q.empty() && 2*X[i] - 2*X[Q.top().y+1] > T) {
            //cout << "KILL" << Q.top().y << endl;
            Q.pop();
        }
        if (!Q.empty()) {
            //cout << i << ' ' << y << ' ' << H[i] << ' ' << Q.top().x+T << 'T' << endl;
            H[i] = min(H[i], Q.top().x + T);
        }

        Q.push({H[i], i});
        /*for (int j = 0; j < i; j++) {
            H[i] = min(H[i], H[j] - X[j] + max(T, 2*X[i] - 2*X[j+1]));
        }*/
        H[i] += X[i];
        //cout << i << ' ' << y << ' ' << df << ' ' << H[i] << endl;
    }
    cout << H[N-1] + E - X[N-1] << endl;
}


Measured memory_bytes: 2936
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    int[][] t = new int[1000][1000];
    int n = 0;

    for(int j=0;sc.hasNext();j++){
      String[] s = sc.next().split(",");
      n = Math.max(n,s.length);
      for(int i=0;i<s.length;i++){
        t[j][i] = Integer.parseInt(s[i]);
      }
    }

    int[][] dp = new int[1000][1000];
    dp[0][0] = t[0][0];
    for(int i=0;i<n-1;i++){
      for(int j=0;j<=i;j++){
        dp[i+1][j] = max(dp[i+1][j],dp[i][j]+t[i+1][j]);
        dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+t[i+1][j+1]);
      }
    }

    int[][] dp2 = new int[1000][1000];
    for(int i=0;i<n;i++) dp2[0][i] = dp[n-1][i];
    for(int i=0;i<n-1;i++){
      for(int j=0;j<=n-i-1;j++){
        if(j-1>=0) dp2[i+1][j-1] = max(dp2[i+1][j-1],dp2[i][j]+t[n+i][j-1]);
        dp2[i+1][j] = max(dp2[i+1][j],dp2[i][j]+t[n+i][j]);
      }
    }

    /*
    for(int i=0;i<n;i++){
      for(int j=0;j<=i;j++){
      }
    }
    */

    out.println(dp2[n-1][0]);
  }
}

Measured memory_bytes: 20000
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
typedef long long ll;

ll func(ll n){
	if(n<=1) return 0;
	return n*(n-1)/2;
}

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i,n) cin >> a[i];
	
	vector<ll> b(200005,0);
	set<ll> s;
	
	REP(i,n){
		b[a[i]] += 1;
		s.insert(a[i]);
	}
	ll count=0;
	vector<ll> ans(n);
	
	for(ll i: s){
		count += func(b[i]);
	}
	REP(i,n){
		ans[i] = func(b[a[i]]-1) - func(b[a[i]]);
	}
	REP(i,n) ans[i] += count;
	
	REP(i,n) cout << ans[i] << endl;
	
	return 0;
}

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

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

  vector<int> ans(K * 2 - 1);
  
  ans.at(0) = X - K + 1;
  cout << ans.at(0) << endl;
  
  for (int i = 1; i < ans.size(); i++) {
     ans.at(i) = ans.at(i - 1) + 1;
     cout << ans.at(i) << endl;
   }
   
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int x, y;

	while(true)
	{
		cin >> x >> y;
		if (x == 0 && y == 0)
		{
			break;
		}
		if (x <= y)
		{
			printf("%d %d\n", x, y);
		}
		else
		{
			printf("%d %d\n", y, x);
		}
	}

	return 0;
}

Measured memory_bytes: 1144
/*Filename: aoj0000.cpp
 *Author: Mushiyo
 */

#include <iostream>

using namespace std;

int main(){

	for(int i = 1; i <=9; ++i){
		for(int j = 1; j <= 9; ++j){
			cout << i << "x" << j << "=" << i * j << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1116
import sys

n = int(input())
minv = int(input())
maxv = -1000000000

for r in map(int,sys.stdin.readlines()):
  if maxv < r-minv < 0:
    maxv = r-minv
    minv = r
  elif maxv < r-minv:
    maxv = r-minv
  elif r-minv < 0:
    minv = r

print(maxv)

Measured memory_bytes: 21916
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> p(n);
  rep (i, n) cin >> p[i];
  vector<pair<int, int>> psort(n);
  rep (i, n) psort[i] = {p[i], i};
  sort(all(psort), greater<pair<int, int>>());
  lint sum = 0;
  multiset<int> checked{-1, -1, n, n, psort[0].second};
  rep (i, 1, n) {
    lint times = 0;
    int  now   = psort[i].second;
    auto rfir  = checked.lower_bound(now);
    auto rsec  = next(rfir);
    auto lfir  = prev(rfir);
    auto lsec  = prev(lfir);
    times += ((*lfir) - (*lsec)) * ((*rfir) - now);
    times += (now - (*lfir)) * ((*rsec) - (*rfir));
    sum   += psort[i].first * times;
    checked.insert(now);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define N 1000003
#define LL long long
#define mod 998244353

int n,m;
int a[N],g[N];
LL ans;
struct Node{
	double val;
	int id;
	inline bool operator < (const Node&rhs) const{
		return val<rhs.val;
	}
};
priority_queue<Node>q;

inline int read(){
	int X=0,w=0;
	char ch=0;
	while (ch<'0' || ch>'9')
	  w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9')
	  X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w ? -X : X;
}

int main(){
	n=read();m=read();
	for (int i=1;i<=n;i++){
		a[i]=read();
	  	q.push((Node){a[i],i});
	}
	while (m--){
		Node u=q.top();
		q.pop();
		u.val/=2;
		g[u.id]++;
		q.push(u);
	}
	for (int i=1;i<=n;i++){
		int p=1,res=a[i];
		for (int j=1;j<=g[i];j++){
		  	p*=2;
			if (p>res){
				res=0;
				break;
			}
		}
		ans+=(res/p);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6516
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int mod=998244353;
int n;
int r,g,b,rg,rb,gb;
string s;
int main()
{
	scanf("%d",&n);
	cin>>s;
	ll ans=1;
	for(int i=0;i<3*n;i++)
	{
		if(s[i]=='R')
		{
			if(gb)
			{
				ans=ans*gb%mod;
				gb--;
			}
			else if(g)
			{
				ans=ans*g%mod;
				g--;
				rg++;
			}
			else if(b)
			{
				ans=ans*b%mod;
				b--;
				rb++;
			}
			else
				r++;
		}
		if(s[i]=='G')
		{
			if(rb)
			{
				ans=ans*rb%mod;
				rb--;
			}
			else if(r)
			{
				ans=ans*r%mod;
				r--;
				rg++;
			}
			else if(b)
			{
				ans=ans*b%mod;
				b--;
				gb++;
			}
			else
				g++;
		}
		if(s[i]=='B')
		{
			if(rg)
			{
				ans=ans*rg%mod;
				rg--;
			}
			else if(g)
			{
				ans=ans*g%mod;
				g--;
				gb++;
			}
			else if(r)
			{
				ans=ans*r%mod;
				r--;
				rb++;
			}
			else
				b++;
		}
	}
	for(int i=1;i<=n;i++)
		ans=ans*i%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 900
import collections as col
n,k = map(int,input().split())
a   = list(map(int,input().split()))
count_dict = col.Counter(a)
cdmc       = count_dict.most_common(k)
sum_cdmc = 0

for k,v in cdmc:
    sum_cdmc += v
print(n - sum_cdmc)

Measured memory_bytes: 32564
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N;
  cin >> N;
  vi A(N+1);
  cin >> A;
  vi B(N);
  cin >> B;

  i64 ans = 0;
  rep(i,N){
    i64 x = min(A[i],B[i]);
    ans += x;
    A[i] -= x;
    B[i] -= x;
    
    x = min(A[i+1],B[i]);
    ans += x;
    A[i+1] -= x;
    B[i] -= x;
  }
  cout << ans << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 1001001001
#define MOD 1000000007
#define all(x) begin(x),end(x)
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, p[100005], q[100005], odd_val, even_val, odd_cnt, even_cnt;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vii a(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) {
        if (i%2) {
            p[a[i]]++;
            if (odd_cnt < p[a[i]]) 
                odd_cnt = p[a[i]], odd_val = a[i];
        }
        else {
            q[a[i]]++;
            if (even_cnt < q[a[i]])
                even_cnt = q[a[i]], even_val = a[i];
        }
    }
    sort(all(p), greater<int>());
    sort(all(q), greater<int>());
    if (odd_val == even_val) {
        cout << min(n - p[0] - q[1], n - p[1] - q[0]) << endl;
    } else {
        cout << n - p[0] - q[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

 
int main(void) {
	int n,k;
	scanf("%d",&n);
	scanf("%d",&k);
	int l[n];
	for (int i = 0; i < n; i++){
		scanf("%d",&l[i]);
	} 
	for (int i = 1; i <n;i++){
		int j = i;
		while (j>=1 && l[j-1] > l[j]){
			int temp = l[j-1];
			l[j-1] = l[j];
			l[j] = temp;
			j--;
		}
	}
	int sum = 0;
	for (int i = n-1; i >=n- k ; i--){
		sum += l[i];
	}
	printf( "%d",sum);
	return(0);
}

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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int l; cin >> l;
	double ans = double(l*l*l/27.0);
	printf("%.7f\n", ans);
	return 0;
}

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

using namespace std;

static const int MAX_N = 1000;

int main() {
    string a, b;
    int n;

    cin >> a;
    cin >> b;


    n = stoi(a + b);

    bool rst = false;
    for (int i = 0; i < MAX_N; i++) {
        if (n == i * i) {
            rst = true;
            break;
        }
    }

    if (rst) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public void main(Scanner sc) {
        String n = sc.next();

        int sum = 0;
        for (int i = 0; i < n.length(); i++) {
            sum += n.charAt(i) - '0';
        }

        int tmp = n.charAt(0) - '1';
        tmp += 9 * (n.length() - 1);

        System.out.println(Math.max(sum, tmp));
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 

int main(){
  int n;
  cin >> n;
  vector<double> v(n);
  rep(i,n) cin >> v.at(i);
  sort(all(v));

  double ans = v.at(0);
  for(int i = 1; i < n; i++){
    ans = (ans + v.at(i))/2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import heapq
n = int(input())

def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [False] * n #True:未確定
    d[s] = 0
    used[s] = True
    edgelist = []
    # 始点がスタートになってるedgeをヒープキューに追加
    for e in node_edges[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        # ヒープキューからコスト最小のedgeをpop
        minedge = heapq.heappop(edgelist)
        # 該当edgeの行き先が確定済みになってなければこれを通って処理が続く
        if used[minedge[1]]:
            continue
        v = minedge[1]
        # 該当edgeの行き先のコストを更新
        d[v] = minedge[0]
        used[v] = True
        for e in node_edges[v]:
            if not used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

node_edges = [[] for i in range(n)]

for i in range(n-1):
    start, end, cost = map(int,input().split())
    start -= 1
    end -= 1
    node_edges[start].append([cost, end])
    node_edges[end].append([cost, start])

num_q, stop = map(int,input().split())
stop -= 1
d_ls = dijkstra_heap(stop)

ans_ls = [0] * num_q
for i in range(num_q):
    start, end = map(int,input().split())
    start -= 1
    end -= 1
    total_dist = d_ls[start] + d_ls[end]
    ans_ls[i] = total_dist
for ans in ans_ls:
    print(ans)






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

int main() {
	string S, T;
	cin >> S >> T;
	vector<vector<string>> dp_str(2, vector<string>(T.size()+1));
	
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < T.size(); j++) {
			if (S[i] == T[j]) {
				dp_str[(i+1)%2][j+1] = dp_str[i%2][j] + S[i];
			}
			else if (dp_str[(i+1)%2][j].size() >= dp_str[i%2][j+1].size()) {
				dp_str[(i+1)%2][j+1] = dp_str[(i+1)%2][j];
			}
			else {
				dp_str[(i+1)%2][j+1] = dp_str[i%2][j+1];
			}
		}
	}
	
	cout << dp_str[S.size()%2][T.size()] << endl;
}


Measured memory_bytes: 16924
import java.util.*;
public class Main {
    public static void main(String[] args) {	
	Main main = new Main();
    	main.solveC();
    }
    
    private void solveA() {
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();

	int max = Math.max(a,Math.max(b,c));
	int min = Math.min(a,Math.max(b,c));
	
    	System.out.println(max-min);
    }
 private void solveB() {
	Scanner sc = new Scanner(System.in);
	String s = sc.next();
	String t = sc.next();
	int l = s.length();
	String ans = "No";

	for(int i=0; i < l; i++){
	    t = t.charAt(l-1) + t;
	    t = t.substring(0,l);
	    if (s.equals(t))  ans = "Yes";
	}
	System.out.println(ans);
	
    }
    private void solveC() {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int ans = 0;

	for(int i=0; i < n; i++){
	    ans += sc.nextInt() - 1;
	}

	System.out.println(ans);
    }
}

Measured memory_bytes: 25648
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd; 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define pb(v) push_back(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b)
{
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s)
{
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v)
{
	forl(i,v.size())
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
void pa(ll *v,ll size)
{
	forl(i,size)
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
// ll nck(ll N,ll K,ll mod)
// {
// 	if(N<K)
// 	{
// 		return 0;
// 	}
// 	return (((facs[N]*facsinv[N-K])%mod)*facsinv[K])%mod;
// }
ll power(ll x,ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		{
			res=(res*x)%p;
		}
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x,ll mod)
{
	if(x>=mod)
	{
		x%=mod;
	}
}
ll sumofgp(ll a,ll n,ll m)
{
	// n = number of terms - 1
	if(n<0)
	{
		return 0;
	}
	if(n==0)
	{
		return 1;
	}
	if(n==1)
	{
		return (1+a)%m;
	}
	ll ans;
	if(n%2)
	{
        ans=(1+a)*sumofgp((a*a)%m,(n-1)/2,m);
	}
    else
    {
        ans=1+((a*(1+a))%m)*sumofgp((a*a)%m,n/2-1,m);
    }
    return ans%m;
}
ll power_of_2_not_less(ll n)
{
	if(!n)
	{
		return 1;
	}
	n--;
	n |= n>>1;
	n |= n>>2;
	n |= n>>4;
	n |= n>>8;
	n |= n>>16;
	n |= n>>32;
	n++;
	return n;
}
// void checktime()
// {
// 	struct timespec ts;
// 	printf("Running Program\n");
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double st=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	// Call Funcn Here
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double en=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	printf("Program ended\nTime = %Lf\n",en-st);
// }
mv v[20];
ll tmparr[20];
int main(void)
{
	fastio
	ll n, m, x1;
	cin>>n>>m>>x1;
	forl(i,n) forl(j,m + 1) {
			ll x;
			cin>>x;
			v[i].pb(x);
		}
	string s = "";
	forl(i,n) s+= '0';
	ll ans = 1e18;
	forl(i,pow(2,n) - 1) {
		forlr(j,n) if(s[j] == '0') {
			s[j] = '1';
			break;
		} else s[j] = '0';
		forl(j,m) tmparr[j] = 0;
		ll tmpsum = 0;
		forl(j,n) if(s[j] == '1') {
			forl(k,m) tmparr[k] += v[j][k+1];
			tmpsum += v[j][0];
		}
		bool f = 1;
		forl(j,m) if(tmparr[j] < x1) f = 0;
		if(f) ans = min(ans, tmpsum);
	}
	cout<<(ans==1e18? -1:ans)<<"\n";
	return 0;
}

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

/* int main(){
int N;
cin>>N;
cout<<N*N*N<<endl;

    return 0;
}*/

int main(){
    int N;cin>>N;
    int s=0;
    int j=0;
    vector<int> A(N),B(N),C(N-1);
    rep(i,0,N) cin>>A[i];
    rep(i,0,N) cin>>B[i];
    rep(i,0,N-1) cin>>C[i];
    rep(i,0,N){
        if(j!=0&&A[i]==j+1) s+=C[j-1];
        s+=B[A[i]-1];
        j=A[i];
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vl a(n);
  vl b(n);
  vl dif(n);
  rep(i,n){
    cin >> a[i];
  }
  ll count = 0;
  ll minus = 0;
  rep(i, n){
    cin >> b[i];
    dif[i] = a[i] - b[i];
    if(dif[i]<0){
      minus -= dif[i];
      count++;
    }
  }
  sort(all(dif));
  ll OK = false;
  ll sum = 0;
  for (ll i = n - 1; i >= 0; i--){
    if(sum>=minus){
      OK = true;
      break;
    }
    sum += dif[i];
    count++;
    
  }
  if(OK){
    print(count);
  }
  else{
    print(-1);
  }
}

Measured memory_bytes: 5572
N,M = map(int,input().split())
num = [0] * N
l = []
for i in range(M):
    l.append(list(map(int,input().split())))
l = list(map(list, set(map(tuple, l))))
count = [0] * N

for i in range(len(l)):
    a = l[i][0]
    b = l[i][1]
    num[a-1] = b
    count[a-1] += 1

#print(num)
#print(count)

flag = True
if len(num) > 1:
    if [1,0] in l:
        flag = False
for c in count:
    if c > 1:
        flag = False
if flag == False:
    print(-1)
else:
    if len(num) == 2 or len(num) == 3:
        if num[0] == 0:
            num[0] = 1
    num = [str(i) for i in num]
    print(''.join(num))

Measured memory_bytes: 3064
n=int(input());aa=[input()for i in range(3)];ans=0
for i in range(n):
  a,b,c=aa[0][i],aa[1][i],aa[2][i]
  if not a==b==c:
    if a!=b!=c!=a:ans+=2
    else:ans+=1
print(ans)

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vi a(n), b(m);
    for(int i =0 ; i < n ; i++) cin >> a[i];
    for(int j =0 ; j < m; j++) cin >> b[j];
    for(int z = x+1; z <= y; z++){
        bool q = true;
        for(int i =0 ; i < n; i++) if(a[i] >= z){
            q = false;
            break;
        }
        for(int i = 0; i < m; i++){
            if(b[i] < z){
                q = false;
                break;
            }
        }
        if(q){
            cout << "No War";
            return 0;
        }
    }
    cout << "War";
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

vector <int> v[100005];
int memo[100005];

int dp(int pos) {
	if (memo[pos] != -1) return memo[pos];
	int maxx = 0;
	for (int i=0 ; i<v[pos].size() ; i++) {
		maxx = max(maxx, 1+dp(v[pos][i]));
	}
	return memo[pos] = maxx;
}

int main() {
	memset(memo, -1, sizeof memo);
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i=0 ; i<m ; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		v[x].pb(y);
	}
	int sol = 0;
	for (int i=1 ; i<=n ; i++) {
		sol = max(sol, dp(i));
	}
	printf("%d\n", sol);
	return 0;
}

Measured memory_bytes: 11424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  ll n;
  cin >> n;
  
  ll ans = 1;
  for(int i = 1; i <= n; i++) {
    ans = ans * i % 1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << a/b << " " << a%b << " ";
  cout << fixed << setprecision(5) << (double)a/b << endl;
}



Measured memory_bytes: 3308
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, Y;
    cin >> N >> Y;
    for (int i = 0; i <= N; i++){
        for (int j = 0; i + j <= N; j++){
            if (Y == i * 1000 + j * 5000 + (N - i - j) * 10000){
                cout << N - i  - j << " " << j << " " << i << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
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; }
const ll INF=1LL<<60;

ll n,m;
vector<ll> d(200100),t(200100);
map<ll,ll> dict;

int main(){
    bool flag=true;
    cin>>n;
    rep(i,0,n){
        cin>>d[i];
        dict[d[i]]++;
    }
    cin>>m;
    rep(i,0,m){
        cin>>t[i];
        dict[t[i]]--;
        if(dict[t[i]]<0) flag=false;
    }

    if(flag) cout<<"YES"<<"\n";
    else cout<<"NO"<<"\n";
    return 0;
}


Measured memory_bytes: 18724
#include <bits/stdc++.h>
//#include <ext/numeric>


using namespace std;
//using namespace __gnu_cxx;

const int MAXN = (int)1e5 + 5;
vector<int> adjList[MAXN];
bool vis[MAXN];

void dfs(int u) {
    vis[u] = 1;
    for (int v : adjList[u]) {
        if (!vis[v])
            dfs(v);
    }
}


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    vector<int> ans;
    int i = 0;
    while (i < n) {
        int x = min(m, n - i);
        while (x && s[i + x] == '1')
            --x;
        if (x == 0) {
            cout << -1 << '\n';
            return 0;
        }
        ans.push_back(x);
        i += x;
    }

    reverse(ans.begin(), ans.end());

    for (int x : ans)
        cout << x << ' ';
    cout << '\n';




    return 0;
}

Measured memory_bytes: 6348
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100003;
typedef long long LL;
int n,m,a[MaxN];

struct Segtree{
	static const int Len = 1<<17;
	LL k[Len<<1],b[Len<<1];
	inline void pushdown(const int& p,const int& l,const int& r) {
		if (l==r) return;
		if (k[p]==0 && b[p]==0) return;
		int mid=(l+r)/2;
		k[p*2]+=k[p],k[p*2+1]+=k[p];
		b[p*2]+=b[p],b[p*2+1]+=k[p]*(mid+1-l)+b[p];
		k[p]=0,b[p]=0;
	}
	int K,B,L,R;
	void _add(const int& p,const int& l,const int& r) {
		if (L<=l && r<=R) {
			b[p]+=K*(l-L)+B;
			k[p]+=K;
			return;
		}
		pushdown(p,l,r);
		int mid=(l+r)/2;
		if (L<=mid) _add(p*2,l,mid);
		if (R>mid)  _add(p*2+1,mid+1,r);
	}
	inline void add(const int& k,const int& b,const int& l,const int& r) {
		K=k,B=b,L=l,R=r;
		_add(1,0,Len-1);
	}
	LL query(int x) {
		int p=1,l=0,r=Len-1;
		while (l<r) {
			pushdown(p,l,r);
			int mid=(l+r)/2;
			if (x<=mid) r=mid,p=p*2;
			else l=mid+1,p=p*2+1;
		}
		return b[p];
	}
}s;

inline int dist(int u,int v) {
	if (u<=v) return v-u;
	else return v+m-u;
}

int main() {
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i) scanf("%d",a+i);
	LL sum=0;
	for (int i=1;i<n;++i) {
		sum+=dist(a[i],a[i+1]);
		if (a[i]<a[i+1]) {
			if (dist(a[i],a[i+1])<=1) continue;
			s.add(1,1,a[i]+2,a[i+1]);
		} else {
			if (dist(a[i],a[i+1])<=1) continue;
			if (a[i]<m-1) s.add(1,1,a[i]+2,m);
			int b=dist(a[i],1)-1;
			s.add(1,b,1,a[i+1]);
		}
	}
	LL mx=0;
	for (int i=1;i<=m;++i) {
		LL t=s.query(i);
		if (t>mx) mx=t; 
	}
	cout << sum-mx << endl;
	return 0;
	
}

Measured memory_bytes: 4224
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int cnt = n + m;
    int total = 0;
    
    for(int i = 0; i < cnt; i++){
      total += i;
    }
    
    int odd = n * m;
    
    System.out.println(total - odd);
  }
}


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

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

    long sub_min = 100000;
    for (long i = 0; i < S.size() - 2; i++) {
        long x = stoi(S.substr(i, 3));
        long sub = abs(x - 753);
        sub_min = min(sub, sub_min);
    }

    cout << sub_min << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int f[30];

int main()
{
  int n, m, k, a;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i)
  {
    scanf("%d", &k);
    for (int j = 0; j < k; ++j)
    {
      scanf("%d", &a);
      f[a - 1]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < m; ++i)
  {
    if (f[i] == n) ++ans;
  }
  printf("%d\n", ans);
  return 0;
}

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

int main(){
    int K,N;
    cin >>N>>K;
    long double p[N];
    for(int i=0;i<N;i++){
        cin >> p[i];
    }
    long double max =0;
    for(int i=0;i<K;i++){
        max +=(p[i]+1)/2;
    }
    long double prenum=max;
    for(int i=K;i<N;i++){
        prenum =prenum-p[i-K]/2+p[i]/2;
        if(prenum>max){
            max=prenum;
        }
    }
    cout << fixed << setprecision(12)<<max;
    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<string.h>
int main(){
  char s1[70],s2[70],s3[70],na[1000][70],s[71];
  int st[1010],n,m,i,j,r,p[1010]={-1};
  while(scanf("%d %d",&n,&m),n||m){
    scanf("\n");
    st[0]=-1;
    for(j=0;j<n;j++){
      fgets(s,71,stdin);
      for(i=0;s[i]==' ';i++);
      st[i+1]=j;
      p[j]=st[i];//printf("%s\n",s+i);
      for(r=0;s[i]-10;i++)na[j][r++]=s[i];
      na[j][r]=0;
    }//printf("a\n");
    //for(i=0;i<n;i++)printf("%d\n",p[i]);
    while(m--){
      scanf("%s %*s %*s %s %*s %s",s1,s2,s3);//printf("%s\n",s3);
      s3[strlen(s3)-1]=0;
      for(i=0;strcmp(na[i],s1);i++);//printf("%d\n",i);
      for(j=0;strcmp(na[j],s3);j++);//printf("%d\n",j);
      if(s2[0]=='c'){
	if(j==p[i])printf("True\n");
	else       printf("False\n");
      }
      if(s2[0]=='a'){
	for(;j+1;j=p[j]){
	  if(i==j)break;
	}
	if(i==j)printf("True\n");
	else    printf("False\n");
      }
      if(s2[0]=='s'){
	if(p[i]==p[j])printf("True\n");
	else          printf("False\n");
      }
      if(s2[0]=='p'){
	if(i==p[j])printf("True\n");
	else       printf("False\n");
      }
      if(s2[0]=='d'){
	for(;i+1;i=p[i]){
	  if(i==j)break;
	}
	if(i==j)printf("True\n");
	else    printf("False\n");
      }
    }
    printf("\n");  
  }
  return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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 end



int main(){
   int n; scanf("%d",&n);
   vector<int> a(n);
   rep(i,0,n)scanf("%d",&a[i]);
   rep(i,0,n){
      if(a[i]%2==0&&a[i]%3!=0&&a[i]%5!=0){
         printf("DENIED\n"); return 0;
      }
   }
   printf("APPROVED\n");
   return 0;
}

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

int main() {
    int64_t n, d;
    cin >> n >> d;
    int res = 0;
    rep(i,n) {
        int64_t a, b;
        cin >> a >> b;
        if (a * a + b * b <= d * d) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <iostream>
#include <climits>
#include <map>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <vector>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <utility>
#include <queue>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define scl(n) scanf("%lld", &n)
#define scd(n) scanf("%lf", &n)
#define scc(n) scanf(" %c", &n)
#define scs(n) scanf(" %s", n)
#define pll pair<ll, ll>
#define bigprime 9867589359258017
#define pbase 925943
#define pmod 1351782499
#define pi acos(-1.0)

int main()
{
    ll w, a, b, ans=0;
    scl(w);
    scl(a);
    scl(b);
    if(b>=(a+w))
        ans = (b-a-w);
    else if((b+w)<=a)
        ans = (a-b-w);
    cout<<ans<<endl;
    return 0;



}






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

using namespace std;
int main(){
    int N;
    long long ans = 0;
    cin >> N;
    string s[N];
    unordered_map<string, int> mp;
    for(int i = 0; i < N; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    for(int i = 0; i < N; i++){
        mp[s[i]] = 0;
    }
    for(int i = 0; i < N; i++){
        ans += mp[s[i]];
        mp[s[i]] += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 17700
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9+7;

long long int modpow(long long int a, long long int p) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		//pが偶数の時
		long long int halfP = p / 2;
		long long int half = modpow(a, halfP);
		//a^(p/2) をhalfとして、half*halfを計算
		return half * half % MOD;
	}
	else {
		//pが奇数の時は、
		//pを偶数にするために1減らす
		return a * modpow(a, p - 1) % MOD;
	}
}

long long int calcComb(int n, int k) {
	if (k > n - k) return calcComb(n, n - k);

	long long int ansMul = 1;
	long long int ansDiv = 1;
	for (int i = 0; i < k; i++)
	{
		ansMul *= (n - i);
		ansDiv *= (i + 1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}
	long long int ans = ansMul * modpow(ansDiv, MOD - 2) % MOD;
	return ans;
}


int main() {
  int N, M; cin >> N >> M;
  vector<pair<int, int> > P;
  int L = M;
  int max_p = 0;
  for (int i=2; i<M; i++) {
    if (L % i == 0) {
      int count = 0;
      while (L >= 1 && L % i == 0) {
        L /= i;
        count++;
      }
      if (count > 0) {
        pair<int, int> p = make_pair(i, count);
        P.push_back(p);
        if (max_p < count) max_p = count;
      }
    }
    if (L <= 1) break;
  }

  long long int ans = 1;
  for (auto x : P) {
    int n = x.second + N - 1;
    int k = x.second;
    ans *= calcComb(n, k);
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256