akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

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

    vector<int> ruiB(N+1);
    vector<int> ruiW(N+1);

    vector<int> col(N);

    rep(i,N){
        int t = 1;
        if(S[i] == '#')t *= -1;
        col[i] = t;
    }

    rep(i,N){
        if(col[i] == 1){
            ruiW[i+1] = ruiW[i] + 1;
            ruiB[i+1] = ruiB[i];
        }
        else{
            ruiW[i+1] = ruiW[i];
            ruiB[i+1] = ruiB[i] + 1;
        }
    }

    int ans = 1e6;
    rep(i,N){
        int lb = ruiB[i+1];
        int lw = ruiW[i+1];
        int rb = ruiB[N] - lb;
        int rw = ruiW[N] - lw;

        int tmp = min(lb+rb,lw+rw);
        tmp = min(tmp,lb+rw);
        ans = min(ans,tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 2948
#include <stdio.h>
 
using namespace std;
 
void outPut(int Array[],char mark){
    for(int i = 1; i <= 13; i++){
        if(Array[i] == 0) printf("%c %d\n",mark,i);
    }
}
 
int main(){
    char mark[2];
    int n,S[14],H[14],C[14],D[14],tmp;
    for(int i = 0; i < 14; i++) S[i] = H[i] = C[i] = D[i] = 0;
    scanf("%d",&n);
 
    for(int i = 0; i < n; i++){
        scanf("%s %d",mark,&tmp);
        switch(mark[0]){
        case 'S':
            S[tmp] = 1;
            break;
        case 'H':
            H[tmp] = 1;
            break;
        case 'C':
            C[tmp] = 1;
            break;
        case 'D':
            D[tmp] = 1;
            break;
        }
    }
    outPut(S,'S');
    outPut(H,'H');
    outPut(C,'C');
    outPut(D,'D');
}


Measured memory_bytes: 2764
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();
    String[] S = S_.split("");
    sc.close();

    int[] E = new int[N];
    int countE = 0; 

    for (int i = 0; i < N; i++) {
      if (S[i].equals("E")) {
        countE++;
      }
      E[i] = countE;
    }

    int min = Integer.MAX_VALUE;

    for (int i = 0; i < N; i++) {
      int count_ = 0;
      // i より西にあるWの数
      if (i != 0) {
        if (S[i].equals("E")) {
          count_ += i + 1 - E[i];
        } else {
          count_ += i - E[i];
        }
      }

      // i より東にあるEの数
      if (i != N-1){
        count_ += E[N-1] - E[i];
      }

      min = Math.min(min, count_);

    }

    System.out.println(min);

  }

}

Measured memory_bytes: 55500
import Foundation

extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
}

let input = readLine()!.split(by: " ").map{Int($0)!}
let N = input[0]
let Q = input[1]
let S = readLine()!.characters.map{$0} + ["_"]

var sum = [0]
for i in 1...N {
    sum.append(sum[i-1])
    if (S[i-1] == "A") && (S[i] == "C") {
        sum[i] += 1
    }
}

for _ in 0..<Q {
    let input = readLine()!.split(by: " ").map{Int($0)!}
    print(sum[input[1]-1] - sum[input[0]-1])
}

Measured memory_bytes: 7528
#include <iostream>
using namespace std;
long long xorN(long long N){
    long long a=1,ans=0,n;
    while(a<N+1){
        n=N%(a*2);
        if(a==1){
            if(N%4==1||N%4==2){
                ans++;
            }
        }
        if(a>1&&n>a-1){
            ans+=((n-a+1)%2)*a;
        }
        a*=2;
    }
    return ans;
}
int main(void){
    long long A,B,a;
    cin>>A>>B;
    A=xorN(A-1);B=xorN(B);
    a=A^B;
    cout<<a<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <numeric>
#include <algorithm>
#define rep(it, ifrom, ito) for (auto it = ifrom; it != ito; ++it)
#define all(a) a.begin(), a.end()

using namespace std;

int main(int argc, char* argv[]) {
    const char* debug_env = getenv("DEBUG");
    const bool debug = debug_env && atoi(debug_env) != 0;

    int64_t S;
    cin >> S;

    std::vector<int64_t> As;
    int64_t v = S;
    while (v > 0) {
        As.push_back(v % 10);
        v /= 10;
    }

    if (debug) {
        for (int i = 0; i < As.size(); ++i) {
            cout << As[i] << " ";
        }
        cout << endl;
    }

    int64_t mindiff = 10000000;
    for (int i = 0; i + 2 < As.size(); ++i) {
        int num = As[i] + As[i + 1] * 10 + As[i + 2] * 100;
        if (debug) cout << num << endl;
        mindiff = min<int64_t>(abs(num - 753ll), mindiff);
    }

    cout << mindiff;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << 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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


string str;

map<char, string> ma;
map<string, char> ma2;

string IN[26] = {
    "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100",
    "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", 
    "000010", "10010010", "10010011", "10010000"};

int main() {
    ma[' '] = "101";
    ma[39] = "000000";
    ma[','] = "000011";
    ma['-'] = "10010001";
    ma['.'] = "010001";
    ma['?'] = "000001";
    for (int i = 0; i < 26; ++i) ma['A' + i] = IN[i];
    
    for (int bit = 0; bit < 26; ++bit) {
        string add = "";
        for (int i = 0; i < 5; ++i) {
            if (bit & (1<<i)) add += "1";
            else add += "0";
        }
        reverse(ALL(add));
        ma2[add] = 'A' + bit;
    }
    ma2["11010"] = ' ';
    ma2["11011"] = '.';
    ma2["11100"] = ',';
    ma2["11101"] = '-';
    ma2["11110"] = 39;
    ma2["11111"] = '?';
    
    //COUT(ma); COUT(ma2);
    
    while ( getline(cin, str) ) {
        string tmp = "";
        for (int i = 0; i < str.size(); ++i) tmp += ma[str[i]];
        
        string res = "";
        while (tmp.size() % 5 != 0) tmp += "0";
        for (int i = 0; i < tmp.size(); i += 5) {
            string sub = tmp.substr(i, 5);
            res += ma2[sub];
        }
        
        cout << res << endl;
    }
    
    return 0;
}


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

const int maxn = 1e5+5, INF = 2e9+9;
int N, M;
vector<int> adj[maxn];

int dist[maxn][3];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
    }
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j < 3; j++) {
            dist[i][j] = INF;
        }
    }
    int S, T; cin >> S >> T;
    dist[S][0] = 0;
    priority_queue<pp,vector<pp>,greater<pp>> pq;
    pq.push({0,{S,0}});
    while (!pq.empty()) {
        auto p = pq.top().second;
        pq.pop();
        int u = p.first;
        int k = p.second;
        int nx = (k+1) % 3;
        for (int v: adj[u]) {
            if (dist[v][nx] > dist[u][k] + 1) {
                dist[v][nx] = dist[u][k] + 1;
                pq.push({dist[v][nx],{v,nx}});
            }
        }
    }
    if (dist[T][0] == INF) {
        cout << -1 << '\n';
    }
    else {
        cout << (dist[T][0]/3) << '\n';
    }
}



Measured memory_bytes: 6912
def b_search(s_list,s, e, x):
    while (e-s) > 1:
        mid = (s + e) // 2
        w = s_list[mid]
        if w == x:
            return True
        elif w < x:
            s = mid+1
        elif w > x:
            e = mid

    if s_list[s] == x:
        return True
    else:
        return False

n_num = int(input())
n_list = [int(s) for s in input().split()]
q_num = int(input())
q_list = [int(s) for s in input().split()]

cnt = 0
for q in q_list:
    if b_search(n_list, 0, len(n_list)-1, q):
        cnt += 1

print(cnt)


Measured memory_bytes: 16900
// https://atcoder.jp/contests/abc087/tasks/arc090_b

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

//------------------------------------------------------------------------------
const int V_MAX = 100'000;

struct edge {
  int to;
  int d;
};

vector<edge> G[V_MAX];

void add_edge(int from, int to, int d) {
  G[from].push_back({to, d});
  G[to].push_back({from, -d});
}

//------------------------------------------------------------------------------
const int N_MAX = 100'000;
const int M_MAX = 200'000;
const int D_I_MAX = 10'000;
const int INF = 2e+9;

int N, M;
// int L[M_MAX];
// int R[M_MAX];
// int D[M_MAX];

int dist[N_MAX];

bool dfs(int p, int v, int d) {
  if (dist[v] < INF) return (dist[v] == d);
  dist[v] = d;
  for (edge e : G[v]) {
    int u = e.to;
    if (u == p) continue;
    int d2 = d + e.d;
    if (!dfs(v, u, d2)) {
      return false;
    }
  }
  return true;
}

void solve() {
  fill(dist, dist + N, INF);
  REP(i, N) {
    if (dist[i] < INF) continue;
    if (!dfs(-1, i, 0)) {
      puts("No");
      return;
    }
  }
  puts("Yes");
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, M) {
    int L, R, D;
    scanf("%d%d%d", &L, &R, &D);
    add_edge(L - 1, R - 1, D);
  }
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    int r, d, x;
    cin >> r >> d >> x;
    int ans =0;
    for(int i=0;i<10;i++){
        ans = r*x-d;
        cout << ans << endl;
        x = ans;
    }
    

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int n, i, c, ans=0, num, flag=0;
    scanf("%d", &n);
    int array[n];

    for( i=0; i<n; i++ ){
        scanf("%d", &array[i]);
        if ( ((array[i])%2) == 0 ){
            c=0;
            num = array[i];
            while( (num%2) == 0 ){
                num = num/2;
                c++;
            }
            if( ans == 0 || c < ans ){
                ans = c;
            }
        } else {
            flag=1;
        }
    }

    if( flag==1 ){
        ans=0;
        printf("%d\n", ans);
    } else {
        printf("%d\n", ans);        
    }

    return 0;
}

Measured memory_bytes: 128
#include  <stdio.h>

int main(void)
{
    unsigned long long int a,b;
    scanf("%llu %llu",&a,&b);
    
    unsigned long long int c[a+2];
    
    for(long long int i=0;i<a;i++)
    {
        scanf("%llu",&c[i]);
    }
    
   for(long long int i=b;i<a;i++)
    {
        if(c[i-b] >= c[i])
            printf("No\n");
        
        else 
            printf("Yes\n");
    }
     
    
    
    
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    for(int i = 0; i < 3; ++i){
        if(s[i]==s[i+1]){
            cout << "Bad";
            return 0;
        }        
    }
    cout << "Good";
    return 0;
}


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

using namespace std;


int main(int argc, char *argv[])
{
   
    
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    
    int n;
    double x[100], y[100];
    string line;
    double d1 = 0.0, d2 = 0.0, d3 = 0.0, dinf = 0.0,temp;
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    
    for (int i = 0; i < n; i++) {
        cin >> y[i];
    }
    
    for (int i = 0; i < n; i++) {
        temp = abs(x[i]-y[i]);
        d1 += temp;
        d2 += pow(temp,2);
        d3 += pow(temp,3);
        dinf = max(temp, dinf);
    }
    
    d2 = sqrt(d2);
    d3 = cbrt(d3);
    
    cout << fixed << setprecision(8) << d1 << endl << d2 << endl << d3 << endl << dinf << endl;
    
    
    return 0;
}



Measured memory_bytes: 3468
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 400005;
const int MM = 1000000007;

int N, M;
int D[MX];
ll L[MX], R[MX];

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= 3*N; i++) scanf("%d", D+i);
	
	priority_queue<ll, vector<ll>, greater<ll>> Q;
	for(int i = 1; i <= N; i++){
		L[N] += D[i];
		Q.push(D[i]);
	}
	for(int i = N+1; i <= 2*N; i++){
		L[i] = L[i-1];
		Q.push(D[i]); L[i] += D[i];
		L[i] -= Q.top(); Q.pop();
	}
	
	priority_queue<ll, vector<ll>, less<ll>> Q2;
	for(int i = N*2+1; i <= 3*N; i++){
		R[2*N+1] += D[i];
		Q2.push(D[i]);
	}
	for(int i = N*2; i > N; i--){
		R[i] = R[i+1];
		Q2.push(D[i]); R[i] += D[i];
		R[i] -= Q2.top(); Q2.pop();
	}
	ll mx = -1e18;
	for(int i = N; i <= N*2; i++){
		mx = max(mx, L[i] - R[i+1]);
	}
	printf("%lld\n", mx);
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,int> PP;
typedef pair<ll,int> Pli;

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

int n;
int fst[100010];
int l,r;
const int MOD=1e9+7;
ll fact[100010];

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

void calc() {
	fact[0]=1;
	FOR(i,1,100010) fact[i]=fact[i-1]*i%MOD;
}

ll nCr(ll n,ll r) {
	if(n<r) return 0;
	return fact[n]*mypow(fact[r],(ll)1e9+5,MOD)%MOD*mypow(fact[n-r],(ll)1e9+5,MOD)%MOD;
}

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

	calc();

	cin>>n;
	REP(i,n+1) {
		int a;cin>>a;
		if(fst[a]!=0) {
			l=fst[a],r=i+1;
		}
		else fst[a]=i+1;
	}
	//REP(i,n+1) cout<<fact[i]<<' ';
	//cout<<endl;
	//cout<<"l="<<l<<",r="<<r<<endl;
	FOR(i,1,n+2) {
		//cout<<"n+1Ci="<<nCr(n+1,i)<<",l-1+n-rCi-1="<<nCr((l-1)+(n+1-r),i-1)<<endl;
		cout<<(nCr(n+1,i)-nCr((l-1)+(n+1-r),i-1)+MOD)%MOD<<endl;
	}


	return 0;
}


Measured memory_bytes: 2432
N,R = map(int,input().split())
min = 0
max = 10000000
ans = 0
for i in range(R):
  A,B = map(int,input().split())
  if A > min:
    min = A
  if B < max:
    max = B
if min < max:
  ans = max - min + 1
elif min == max:
  ans = 1
print(ans)

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

const int N = 1048576;
int n, K, f[21][N], g[21][N];
char s[N];

int main() {
  scanf("%d%d", &n, &K);
  for (int i = 0; i <= n; i++) {
    scanf("%s", s);
    for (int j = 0; j < 1 << i; j++) {
      f[i][j] = s[j] - '0';
    }
  }
  for (int i = 1; i <= n; i++) {
    g[i][0] = -1;
    for (int j = 1; j < 1 << i - 1; j++) {
      g[i][j] = 32 - __builtin_clz(j);
    }
    for (int j = 1 << i - 1; j < 1 << i; j++) {
      g[i][j] = 32 - __builtin_clz(j ^ (1 << i) - 1);
    }
    g[i][(1 << i) - 1] = -1;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 1; i + j <= n; j++) {
      for (int k = 0; k < 1 << i + j; k++) {
        f[i][k >> j] += f[i + j][k];
        int r = g[j][k & (1 << j) - 1];
        if (~r) f[i + r][k >> j << r | (k & (1 << r) - 1)] += f[i + j][k];
      }
    }
  }
  int len = 0, ans = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = (1 << i) - 1; ~j; j--) {
      if (f[i][j] >= K) {
        len = i, ans = j;
      }
    }
  }
  for (int j = len - 1; ~j; j--) {
    putchar(48 + (ans >> j & 1));
  }
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;

int solve(string s) {
	// cout << s << endl;
	int N = s.length();
	vector<int> v;
	rep(i, N) if (s[i] == '1') v.pb(i);
	if (v.empty()) return 0;
	v.pb(N);
	map<int, int> dp;
	dp[0] = 0;
	rep(k, v.size() - 1) {
		int i = v[k];
		map<int, int> _dp;
		for (auto p: dp) {
			int j = p.first, z = p.second;
			_dp[i + 1] = max(_dp[i + 1], z);
			if (j < i) {
				_dp[i + 2] = max(_dp[i + 2], z + i - j);
				int nxt = v[k + 1];
				_dp[nxt] = max(_dp[nxt], z + nxt - (i + 1));
				if (i + 1 < nxt - 1) _dp[nxt - 1] = max(_dp[nxt - 1], z + (nxt - 1) - (i + 1));
			}
		}
		dp = _dp;
		/*
		for (auto p: dp) cout << p.first << ' ' << p.second << endl;
		cout << endl;
		*/
	}
	int ma = 0;
	for (auto p: dp) ma = max(ma, p.second);
	// cout << ma << endl;
	return ma;
}

int main() {
	int N; cin >> N;
	string s; cin >> s;
	rep(i, N) s[i] = '0' + '1' - s[i];
	s = "11" + s + "11";
	// cout << s << endl;
	N = s.length();
	vector<int> v;
	rep(i, N - 1) if (s[i] == '1' && s[i + 1] == '1') v.pb(i + 1);
	int ans = 0;
	rep(k, v.size() - 1) {
		int l = v[k], r = v[k + 1];
		if (r - l > 1) ans += solve(s.substr(l + 1, r - l - 2));
	}
	cout << ans << endl;
}


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

static const int N=100;

int main(){
    int n, p[N+1], m[N+1][N+1];
    cin >> n;
    for (int i=1; i<=n; i++){
        cin >> p[i-1] >> p[i];
    }
    
    for (int i=1; i<=n; i++) m[i][i]=0;
    for (int l=2; l<=n; l++){
        for (int i=1; i<=n-l+1; i++){
            int j=i+l-1;
            m[i][j]=(1<<21);
            for (int k=i; k<=j-1; k++){
                m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }
    cout << m[1][n] << endl;
    return 0;
}


Measured memory_bytes: 3124
using System;

class IDB1_5_B
{
    public static void Main()
    {
        while (true)
        {
            string[] Input = Console.ReadLine().Split(' ');
            int H = int.Parse(Input[0]);
            int W = int.Parse(Input[1]);

            if (H == 0 && W == 0)
                break;

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (j == 0 || j == W - 1 || i == 0 || i == H - 1)
                        Console.Write("#");
                    else
                        Console.Write(".");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 8696
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vector<pll> ba(n);
    for (int i = 0; i < n; ++i) {
        cin >> ba[i].second;
    }
    for (int i = 0; i < n; ++i) {
        cin >> ba[i].first;
    }
    sort(ba.begin(), ba.end());
    vl a(n), b(n);
    for (int i = 0; i < n; ++i) {
        a[i] = ba[i].second;
        b[i] = ba[i].first;
    }
    vl as = a;
    sort(as.begin(), as.end());
    for (int i = 0; i < n; ++i) {
        if (as[i] > b[i]) {
            cout << "No"
                 << "\n";
            return 0;
        }
    }
    for (int i = 1; i < n; ++i) {
        if (as[i] <= b[i - 1]) {
            cout << "Yes"
                 << "\n";
            return 0;
        }
    }
    vector<pll> ai;
    for (int i = 0; i < n; ++i) {
        ai.emplace_back(a[i], i);
    }
    sort(ai.begin(), ai.end());
    vi par(n);
    for (int i = 0; i < n; ++i) {
        par[ai[i].second] = i;
    }
    int curr     = 0;
    int lencycle = 1;
    vector<bool> used(n, false);
    used[curr] = true;
    while (true) {
        int next = par[curr];
        if (used[next])
            break;
        curr       = next;
        used[curr] = true;
        lencycle++;
    }
    if (lencycle == n) {
        cout << "No"
             << "\n";
    } else {
        cout << "Yes"
             << "\n";
    }
    return 0;
}

Measured memory_bytes: 6260
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, p[100], q[100], x=0, i;
    cin>>n;
    for(i=0; i<n; i++)
    	cin>>p[i], q[i]=p[i];
    sort(p, p+n);
    for(i=0; i<n; i++)
    {
    	if(p[i]!=q[i])
    		x++;
    }
    (x<=2)?	cout<<"YES" : cout<<"NO";
}
    

Measured memory_bytes: 3640
s = list(input())
l = len(s) - 1

def calcBit(num):
    res = []
    for _ in range(l):
        res.append(num%2)
        num >>= 1
    return res[::-1]

res = 0
for i in range(2**l):
    b = calcBit(i)
    f = ''
    for j in range(l):
        f += s[j] + b[j]*'+'
    f += s[-1]
    res += eval(f)

print(res)


Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
//#include <unordered_map>
//#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>
#define LL long long
#define N 100100
#define M 110
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define X first
#define Y second
using namespace std;
const int maxn=100005;
LL dist[maxn];
struct node
{
    int y,z;
    node(){}
    node(int a,int b):y(a),z(b){}
};
bool vis[maxn];
vector<node>e[maxn];
void bfs(int k)
{
    queue<int>que;
    que.push(k);
    dist[k]=0;
    vis[k]=true;
    int x,y,z;
    LL di;
    while(!que.empty())
    {
        x=que.front();
        que.pop();
        di=dist[x];
        for(int i=0;i<e[x].size();++i)
        {
            y=e[x][i].y;
            z=e[x][i].z;
            if(!vis[y])
            {
                dist[y]=di+z;
                vis[y]=true;
                que.push(y);
            }
        }
    }
}
int main()
{
    int n,x,y,z;
    scanf("%d",&n);
    for(int i=1;i<n;++i)
    {
        scanf("%d%d%d",&x,&y,&z);
        e[x].push_back(node(y,z));
        e[y].push_back(node(x,z));
    }
    int q,k;
    scanf("%d%d",&q,&k);
    bfs(k);
    for(int i=0;i<q;++i)
    {
        scanf("%d%d",&x,&y);
        cout<<dist[x]+dist[y]<<endl;
    }
	return 0;
}


Measured memory_bytes: 8820
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    b+=a*3;
    cout << b/2<<endl;
    return 0;
}



Measured memory_bytes: 892
#include <stdio.h>

int main(void)
{
	int a,b,c;

	scanf("%d %d %d", &a, &b, &c);

	if (a == b + c || b == c + a || c == a + b)
	{
		printf("Yes\n");
	}else
	{
		printf("No\n");
	}

	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/rope>

 

#define ll long long

#define pb push_back

#define sz(x) (int)(x).size()

#define mp make_pair

#define all(x) x.begin(), x.end()

 

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<ll> stk;
	while(n--)
	{
		ll a;
		cin >> a;
		//cout << a << endl;
		stk.push_back(a);
		int q=stk.size();
		while(q>2&&stk[q-1]<=stk[q-2]&&stk[q-3]<=stk[q-2])
		{
			ll ne=stk[q-1]+stk[q-3]-stk[q-2];
			for(int i=0;i<3;i++)
			stk.pop_back();
			stk.push_back(ne);
			q-=2;
		}
	}
	ll sum=0;
	deque<ll> q;
	for(auto p:stk)
	q.push_back(p);
	int z=1;
	while(q.size())
	{
		if(q.front()>=q.back())
		{
			sum+=q.front()*z;
			q.pop_front();
		}
		else
		{
			sum+=q.back()*z;
			q.pop_back();
		}
		z*=-1;
	}
	cout << sum;
}
    

Measured memory_bytes: 256
import math

def main():
    buf = input()
    buflist = buf.split()
    H = int(buflist[0])
    W = int(buflist[1])
    K = int(buflist[2]) - 1 # zero indexing

    pattern_list = []
    create_pattern(pattern_list, [], W-1, 0)
    prob = [1]
    for i in range(W-1):
        prob.append(0)
    for i in range(H):
        new_prob = []
        for j in range(W):
            new_prob.append(0)
        for j in range(W):
            for k in pattern_list:
                if j in k:
                    new_prob[j+1] += prob[j]
                elif j-1 in k:
                    new_prob[j-1] += prob[j]
                else:
                    new_prob[j] += prob[j]
        prob = list(new_prob)
    print(prob[K] % 1000000007)


def create_pattern(pattern_list, pattern, W, C):
    pattern_list.append(pattern)
    if len(pattern) == 0:
        for i in range(W):
            new_pattern = list(pattern)
            new_pattern.append(i)
            create_pattern(pattern_list, new_pattern, W, i)
    else:
        for i in range(C+2, W):
            new_pattern = list(pattern)
            new_pattern.append(i)
            create_pattern(pattern_list, new_pattern, W, i)


def nCr(n, r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)

if __name__ == '__main__':
    main()


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

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=1e5+5,MAX=3e7,MOD=1e9+7;
 
using namespace std;

int n,m;
ll dp[N];
bool broken[N];
bool ok(int x){
	return (x>=0&&!broken[x]);
}
int main()
{	
	
  
 	
 	scanf("%d %d",&n,&m);

 	for(int i=0,x;i<m;i++){
 		scanf("%d",&x);
 		broken[x]=1;
 	}

 	dp[0]=1;

 	for(int i=1;i<=n;i++){
 		if(ok(i-1)){
 			dp[i]+=dp[i-1];
 			dp[i]%=MOD;
 		}
 		if(ok(i-2)){
 			dp[i]+=dp[i-2];
 			dp[i]%=MOD;
 		}
 	}

 	printf("%lld\n",dp[n] );


}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<functional>

using namespace std;

typedef pair<int, int> P;
typedef long long int ll;



int main() {
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 1; i < 4; i++) {
		if (S[i] == S[i - 1]) { ans = 1; }
	}
	if (ans == 0) {
		cout << "Good" << endl;
	}
	else {
		cout << "Bad" << endl;
	}

}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=2019;

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

// a^n mod を計算 再帰
ll modpow(ll a,ll n,ll &mod){
  if(!n) return 1;
  ll x = modpow(a,n/2,mod)%mod;
  x *=x;
  if(n%2==1)x*=a;
  return x%mod;
}



int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  vector<int> p;
  p.pb(a);
  p.pb(b);
  p.pb(c);
  sort(ALL(p));
  rep(i,k)p[2]*=2;
  cout<<p[0]+p[1]+p[2];
}


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

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using ml = map<ll,ll>;

#define ff first
#define ss second
#define endl '\n'
#define ins insert
#define eb emplace_back
#define sz(c) (ll) c.size()
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define itr(x,c) for(auto &x : c)
#define tc ll t; cin >> t; while(t--)
#define rep(i,a,n) for(ll i = a ; i < n ; ++i)
#define per(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) itr(x,c) cout << x << " "; cout << endl;
#define dm(m) itr(x,m) cout << x.ff << " -> " << x.ss << endl;
#define godspeed cin.tie(0) -> sync_with_stdio(0);


ll pwr(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b&1) res = res*a;
		a = a*a;
		b >>= 1;
	}
	return res;
}

int main() {
    godspeed;
    ll n; cin >> n;
    ll d; cin >> d;

    ll x, y, cnt = 0;
    while(n--) {
    	cin >> x >> y;
    	ld dis = sqrt(x*x + y*y);
    	if(dis <= d) cnt++;
    }

    cout << cnt;
}

Measured memory_bytes: 3696
import bisect

N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
ans = 0

for i in range(N-2):
    for j in range(i+1,N-1):
        ans += bisect.bisect_left(L,L[i]+L[j]) - j - 1
print(ans)


Measured memory_bytes: 3188
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;

int max(int a, int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main() {
	int n;
	cin >> n;
	int a[100005];
	rep(i, n) {
		cin >> a[i];
	}

	int cnt = 0;
	int res = 1;
	bool f = false;
	for(int i = 0; i < n; i++){
		if (res == 2) {
			f = true;
			break;
		}
		cnt++;
		res = a[res-1];
		
	}

	if (f) {
		cout << cnt << endl;
	}
	else {
		cout << "-1" << endl;
	}
} 

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const int MAX = 100000;
static const int NIL = -1;
using namespace std;


int main() {

    int h,w; cin >> h >> w;
    int x = 0,y = 0;
    int count = 0;
    vector<vector<char>> v(h+1,vector<char>(w+1,'.'));

    rep(i,h){
        rep(j,w){
            char tmp; cin >> tmp;
            v[i][j] = tmp;
            if(tmp == '#') count ++;
        }
    }
    if(count > w+h -1){
        cout << "Impossible";
        return 0;
    }

    while(1){
        if(v[y][x+1] == '#') x ++;
        else if(v[y+1][x] == '#') y ++;
        else {
            cout << "Impossible";
            return 0;
        }
        if(y == h-1 && x == w-1) break;
    }

    cout << "Possible";
    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;
	int max_value = -1;
	int min_value = 1 << 30;

	REP(i,N){
		int A; cin >> A;
		max_value = max(max_value, A);
		min_value = min(min_value, A);
	}

	cout << max_value - min_value << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9



int main() {
	int N;
	string S;
	cin >> N >> S;
	string T = S;

	while (true) {
		// pos1 : 一番左の(の位置
		// pos2 : pos1より右で、一番左の)の位置
		int pos1 = -1, pos2 = -1;

		for (int i = 0; i < T.size() && pos1 == -1; i++) {
			if (T[i] == '(') {
				pos1 = i;
			}
		}

		for (int i = pos1+1; i < T.size() && pos2 == -1; i++) {
			if (T[i] == ')') {
				pos2 = i;
			}
		}

		if (pos1 != -1 && pos2 != -1) {
			T.erase(T.begin() + pos2);
			T.erase(T.begin() + pos1);
		}
		else {
			break;
		}
	}

	int cnt1 = 0, cnt2 = 0;
	for (int i = 0; i < T.size(); i++) if (T[i] == ')') cnt1++;
	for (int i = 0; i < T.size(); i++) if (T[i] == '(') cnt2++;

	for (int i = 0; i < cnt1; i++) cout << '(';
	cout << S;
	for (int i = 0; i < cnt2; i++) cout << ')';
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list([int(x) for x in input().split()])

count = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[i] != L[j] and L[i] != L[k] and L[j] != L[k]:
                if abs(L[i] - L[j]) < L[k]:
                    if L[i] + L[j] > L[k]:
                        count += 1

print(count)


Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
int l;
char s[110];
int main()
{
	scanf("%s",s),l=strlen(s);
	for(register int i=0;i<l;i++)
		if(s[i]=='C')
			for(register int j=i+1;j<l;j++)
				if(s[j]=='F')
					printf("Yes\n"),exit(0);
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

static class Program
{
    static int Solve(int A, int B, int C)
    {
        int cnt = 0;
        while (A >= B)
        {
            B *= 2;
            ++cnt;
        }
        while (B >= C)
        {
            C *= 2;
            ++cnt;
        }
        return cnt;
    }

    static void Main(string[] args)
    {
        var V = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int K = int.Parse(Console.ReadLine());
        Console.WriteLine(K >= Solve(V[0], V[1], V[2]) ? "Yes" : "No");
    }
}


Measured memory_bytes: 27540
N, M = map(int, input().split())

ab = [tuple(map(int, input().split())) for i in range(N)]

cd = [tuple(map(int, input().split())) for j in range(M)]

ans = [0]*N

for i, x in enumerate(ab):
    a, b = x
    D = 10**9
    for j, y in enumerate(cd):
        c, d = y
        dis = abs(a-c) + abs(b-d)
        if dis < D:
            D = dis
            ans[i] = j + 1

print(*ans, sep='\n')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int sx,sy,tx,ty,x;
  cin >> sx >> sy >> tx >> ty;
  int dx=tx-sx,dy=ty-sy;
  cout << string(dx,'R')+string(dy,'U')+string(dx,'L')+string(dy+1,'D')+string(dx+1,'R')+string(dy+1,'U')+"LU"+string(dx+1,'L')+string(dy+1,'D')+'R' << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()

{
    int a[3];
    int sum=0,i;
    for(i=0;i<=2;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<=2;i++)
    {
        if((a[i]<1)||a[i]>13)
        {
            printf("bust\n");
        }
        else
        {
            sum=sum+a[i];
        }
    }
    if(sum<22)
    {
        printf("win\n");
    }
    else
    {
        printf("bust\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<deque>
using namespace std;
deque<int> de;
int main()
{
    int n,tp1,tp2,a;
    cin>>n;
    while(n--){
        cin>>tp1;
        switch(tp1){
        case 0:
            cin>>tp2;
            cin>>a;
            if(tp2==0){
                de.push_front(a);
            }
            else {
                de.push_back(a);
            }
            break;
    case 1:
        cin>>tp2;
        cout<<de.at(tp2)<<endl;
        break;
    case 2:
        cin>>tp2;
        if(tp2==0){
            de.pop_front();
        }
        else{
            de.pop_back();
        }
        break;
    case 3:
        break;
        }
    }
}
//vector<int> v;
//int main()
//{
//    int n;
//    cin>>n;
//    while(n--){
//        int tip,a;
//        cin>>tip;
//        if(tip==0){
//            cin>>a;
//            v.push_back(a);
//        }
//        else if(tip==1){
//            cin>>a;
//            cout<<v[a]<<endl;
//        }
//        else{
//            v.pop_back();
//        }
//    }
//
//
//}



Measured memory_bytes: 4612
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var strs = Console.ReadLine().Split(' ');
        var s = strs[0];
        var t = strs[1];
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var a = vals[0];
        var b = vals[1];
        var u = Console.ReadLine();

        if (s == u)
        {
            a--;
        }
        else
        {
            b--;
        }

        Console.WriteLine($"{a} {b}");
    }
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




int dp[10002];
int a[1002];
int b[1002];

int main()
{
    FAST();

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

    int h,i,j,n;
    cin >> h >> n;
    for(i=1;i<=n;i++)cin >> a[i] >> b[i];
    for(j=1;j<=h;j++)dp[j]=INT_MAX;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=h;j++)dp[j]=min(dp[j],dp[max(0,j-a[i])]+b[i]);
    }
    cout << dp[h];
    return 0;
}


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  for(int i = 0; i < 3; ++i)
  {
    if(s[i] == s[i + 1])return cout << "Bad\n", 0;
  }
  cout << "Good\n";
  return 0;
}

Measured memory_bytes: 256
def f(x):
    """[0,x]の排他的論理和"""
    if x < 0:
        return 0  # a=0対策
    r = x % 4
    if r == 0:
        return x
    elif r == 1:
        return 1
    elif r == 2:
        return x ^ 1
    else:
        # r == 3
        return 0


a, b = map(int, input().split())
print(f(b) ^ f(a - 1))

# a^(a+1)=1
# a^(a+1)^(a+2)^(a+3)=0


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    string S;
    cin >> S;
    ll current = 0;
    ll count = 0;
    for (int i = 0; i < S.size(); ++i) {
        if(S[i] == 'W'){
            count += i - current;
            current++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 644
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

using i8 = std::int_least8_t;
using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u8 = std::uint_least8_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>

namespace n91 {

void main_() {
  usize n;
  std::cin >> n;
  u32 max = 0;
  usize ans = 0;
  while (n--) {
    u32 h;
    std::cin >> h;
    if (h >= max) {
      ++ans;
      max = h;
    }
  }
  std::cout << ans << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        total = sum(A[:i+1]) + sum(B[i:])
        if ans < total:
            ans = total
    print(ans)

main()

Measured memory_bytes: 38384
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let r = read_as_vec::<f64>()[0];

    println!("{}", 2.0*r*std::f64::consts::PI);
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> D(N, 0);
    //嫌いな番号には1を入れる
    for(int i=0; i<K; i++) {
        int a;
        cin >> a;
        D[a] = 1;
    }

    for(int i=N; i<=100000; i++) {
        int tmp = i;
        bool flg = true;
        while(tmp) {
            int n = tmp % 10;
            if (D[n] == 1) {
                flg = false;
                break;
            }
            tmp /= 10;
        }

        if(flg) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3528