akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int N;
  long long ans;
  cin>>N;
  vector<int> r(0),g(0),b(0);	//R,G,Bを別個に把握するための配列
  								//配列のsizeでR,G,Bがそれぞれいくつあるか，
  								//各要素の大きさで文字列の何番目に来るかを把握する
  vector<char> c(N);
  
  for(int i=0;i<N;i++){
    cin>>c.at(i);
    if(c.at(i)=='R'){
      r.push_back(i+1);
    }else if(c.at(i)=='G'){
      g.push_back(i+1);
    }else{
      b.push_back(i+1);		//小さい順に入っている事に注意．後の二分探索で
    }
  }
  
  vector<int> a(2);
  ans=r.size()*g.size()*b.size();	//条件1を満たすRGB選び方，R,G,Bから一つずつ選ぶ
  bool B=false;			//boolean，二分探索のwhile文を回し続けるためのスイッチにする
  int div1=0,div2=b.size()-1;	//二分探索の端点を入れるための変数
  int temp;
  
  //RとGだけ固定，二分探索で条件２を満たさないBがあるか探して，総数ansから引く．
  for(int i=0;i<r.size();i++){
    if(b.size()==0){break;}		//Bが1個もない時はそもそも条件1で0通り，
    							//後述の二分探索で大きさ0の配列を参照しようとして実行時エラーを起こすため，ここで打ち切り
    for(int j=0;j<g.size();j++){
    a={r.at(i),g.at(j)};
    sort(a.begin(),a.end());
    
    temp=2*a.at(1)-a.at(0);	//Bが一番大きい，すなわち条件2のkがBによるものとなる時
	//二分探索：
    while(!B){
      if(temp<=b.at((div1+div2)/2)&&temp>=b.at(div1)){
        div2=(div1+div2)/2;			//探索範囲の前半に候補となる要素があるなら，後ろ側の端点div2を前に持っていく
      }else if(temp>b.at((div1+div2)/2)&&temp<=b.at(div2)){
        div1=(div1+div2)/2;			//探索範囲の後半に候補となる要素があるなら，前側の端点div1を後ろに持っていく
      }else{break;}		//条件２を満たしうる要素はBの配列の中にないためスキップ
      if(div2-div1<=1){		//端点が同じ位置(div1=div2)，あるいは隣り合った位置に来た時に条件２の判定に移る
        if(temp==b.at(div2)||temp==b.at(div1)){ans--;}	//残った要素が条件2を満たさない時，ansから取り除く
        div1=0;	div2=b.size()-1;	//次の探索のために端点を初期化
        break;
      }
    }  
               
    temp=a.at(1)+a.at(0);	//Bが2番目に大きい，すなわちjになる時
    while(!B){
      if(temp<=2*b.at((div1+div2)/2)&&temp>=2*b.at(div1)){
        div2=(div1+div2)/2;
      }else if(temp>2*b.at((div1+div2)/2)&&temp<=2*b.at(div2)){
        div1=(div1+div2)/2;
      }else{break;}
      if(div2-div1<=1){
        if(temp==2*b.at(div1)||temp==2*b.at(div2)){ans--;}
        div1=0;	div2=b.size()-1;
        break;
      }
    }
    
    temp=2*a.at(0)-a.at(1);	//Bが一番小さい，すなわちiになる時
    while(!B){
      if(temp<=b.at((div1+div2)/2)&&temp>=b.at(div1)){
        div2=(div1+div2)/2;
      }else if(temp>b.at((div1+div2)/2)&&temp<=b.at(div2)){
        div1=(div1+div2)/2;
      }else{break;}
      if(div2-div1<=1){
        if(temp==b.at(div1)||temp==b.at(div2)){ans--;}
        div1=0;	div2=b.size()-1;
        break;
      }
    }
   
  }}
  cout<<ans;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)



struct Edge {
  Edge(int _from, int _to, int _cost)
    : from(_from), to(_to), cost(_cost){}
  int from, to, cost;
};
 
vector< Edge > e;

struct UnionFind {
  vector< int > par;
  UnionFind(int n = 1) {
    init(n);
  }

  void init(int n = 1) {
    par.resize(n);
    for(int i = 0; i < n; i++)
      par[i] = -1;
  }
  
  int root(int n) {
    if (par[n] < 0) return n;
    return par[n] = root(par[n]);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;

    return true;
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }
};

signed main() {
  INIT;
	VAR(int, n);
	vector< tuple< int, int, int > > x(n), y(n);
	REP(i, n) {
		VAR(int, p, q);
		x[i] = make_tuple(p, q, i);
		y[i] = make_tuple(q, p, i);
	}

	sort(ALL(x));
	sort(ALL(y));

	REP(i, n - 1) {
		int p, q, from, to, cost, tmp;
		tie(p, tmp, from) = x[i];
		tie(q, cost, to) = x[i + 1];
		e.push_back(Edge(from, to, abs(p - q)));

		tie(p, tmp, from) = y[i];
		tie(q, cost, to) = y[i + 1];
		e.push_back(Edge(from, to, abs(p - q)));
	}

	auto kruscal = [=](){
		sort(ALL(e), [](Edge x, Edge y) {
				return x.cost < y.cost;
			});
		
		UnionFind uf(n + 1);
		int res = 0;
		EACH(ei, e) {
			if (uf.root(ei.from) != uf.root(ei.to)){
				uf.merge(ei.from, ei.to);
				res += ei.cost;
			}
		}
		return res;
	};
	
	int ans = kruscal();
	OUT(ans)BR;
	
  return 0;
}


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

int main(){
    int n,a[100010],b[100010] = {0};
    long long ans = 1;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] == 0){
            ans = ans *(3 - b[0]);
        }
        else{
        ans = ans * (b[a[i]-1] - b[a[i]]) % 1000000007;
        }
        b[a[i]]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,X,count=0;cin>>N>>M>>X;
  vector<int> a(M);
  for(int i=0;i<M;i++)cin>>a.at(i);
  
  for(int i=0;a.at(i)<X;i++)count++;
  
  cout<<min(count,M-count)<<endl;
}

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

const int N = 1e5 + 5;

int a[N][3];
ll dp[N][3];
int n;

int main () {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  dp[0][0] = a[0][0];
  dp[0][1] = a[0][1];
  dp[0][2] = a[0][2];
  for (int i = 1; i < n; i++) {
    dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = a[i][2] + max(dp[i-1][0], dp[i-1][1]);
  }
  cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << '\n';
  return 0;
}

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

#define rep(i, n) for ( ll i = 0; i < (n); ++i )
#define reps(i, n) for ( ll i = 1; i <= (n); ++i )
#define _rep(i, n) for ( ll i = (n) - 1; i >= 0; --i )
#define _reps(i, n) for ( ll i = n; i > 0; --i )
#define all(x) (x).begin(), (x).end()
#define _all(x) (x).rbegin(), (x).rend()

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

int main( void )
{
	ll n;
	cin >> n;

	reps ( i, n ) {
		ll cnt = 0;
		for ( ll x = 1; x * x < i; x++ ) {
			for ( ll y = 1; ((x * x) + (y * y) + (x * y)) < i; y++ ) {

				for ( ll z = 1; ((x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x)) <= i; z++ ) {
					if ( ((x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x)) == i ) {
						cnt++;
					}
				}
			}
		}
		cout << cnt << endl;
	}

	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define For(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Foz(i, a) For(i, 0, a)
#define Doz(i, a) Dor(i, 0, a)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n;
	cin >> n;
	vi a(n);
	set<int> s;
	Foz(i, n) { cin >> a[i]; s.insert(a[i]); }
	int p = sz(s);
	if (!(p & 1)) p--;
	cout << p << '\n';
}



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

int main(){
    int n,ans=0;
    int count=0;
    cin>>n;
    vector<int>h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    for(int i=0;i<n;i++){
        if(h[i-1]>=h[i])++count;
        else count=0;
        ans=max(ans,count);
        
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[100][100][5000];
ll C[100];

int main() {
	ll N, A;
	cin >> N >> A;

	for (ll i = 0; i < N; ++i) cin >> C[i];

	dp[0][0][0] = 1;

	for (ll a = 0; a < N; ++a) {
		for (ll b = 0; b < N; ++b) {
			for (ll c = 0; c < 3000; ++c) {
				if (dp[a][b][c] == 0) continue;
				dp[a+1][b+1][c+C[a]] += dp[a][b][c];
				dp[a+1][b][c] += dp[a][b][c];
			}
		}
	}

	ll ret = 0;
	for (ll a = 1; a <= N; ++a) ret += dp[N][a][A*a];
	cout << ret << endl;
}


Measured memory_bytes: 151808
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))

a = [0] + a + [0]
#iを取りやめない場合のcost総計
total_cost = sum([abs(i-j) for i,j in zip(a,a[1::])])
#iを取りやめる場合に変化するcost
for i in range(1,n+1):
    decrease_cost_if_stop_i = (abs(a[i-1] - a[i]) + abs(a[i]-a[i+1])) - abs(a[i-1] - a[i+1])
    print(total_cost - decrease_cost_if_stop_i)

Measured memory_bytes: 13924
import sys
import math

N = int(input())
A = [int(x) for x in input().split()]
A2 = [a - i - 1 for i, a in enumerate(A)]

B = sorted(A2)

b = B[int(N/2)]


A3 = [abs(a - b) for a in A2]

print(sum(A3))


sys.exit(0)


Measured memory_bytes: 30032
n, m = map(int, input().split())
City = sorted([tuple(map(int, input().split())) + (i, ) for i in range(m)])

Ans = [None] * m
pre_p = City[0][0]
cnt = 1
for p, y, i in City:
    if pre_p != p:
        cnt = 1
        pre_p = p
    Ans[i] = '0'*(6 - len(str(p))) + str(p) + '0'*(6 - len(str(cnt))) + str(cnt)
    cnt += 1
print(*Ans, sep='\n')

Measured memory_bytes: 30700
/**
 * Created by Reopard on 2014/05/06.
 */

import java.io.*;

public class Main {
    public static void main(String args[]){
        int n;
        int sides[] = new int[3];
        boolean judge = false;
        String line;
        String tmp[];
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try{
            line = reader.readLine();
            n = Integer.parseInt(line);
            for(int i = 0; i < n; i++){
                line = reader.readLine();
                tmp = line.split(" ");
                for(int j = 0; j < sides.length; j++){
                    sides[j] = Integer.parseInt(tmp[j]);
                    sides[j] *= sides[j];
                }
                for(int j = 0; j < sides.length; j++){
                    if(sides[j%3] == sides[(j+1)%3] + sides[(j+2)%3]) {
                        judge = true;
                        break;
                    }else
                        judge = false;
                }
                Answer(judge);
            }
        }catch(IOException e){
            System.exit(0);
        }
    }

    static void Answer(boolean j){
        if(j) System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 20312
#include<iostream>
#include<vector>
#include<queue>

struct node {
	std::vector<int> child;
	int distance;
};

int main() {
	int node_num;

	std::cin >> node_num;

	std::vector<node> n(node_num);

	for (int i = 0; i < node_num; i++) {
		int num, to, node_val;
		std::cin >> node_val >> num;
		for (int j = 0; j < num; j++) {
			std::cin >> to;
			n[node_val - 1].child.push_back(to);
		}
		n[i].distance = -1;
	}

	//???????????????????????¢0
	n[0].distance = 0;
	std::queue<int> q;
	int dist = 1;
	q.push(1);
	while(q.size() != 0){
		int num = q.front();
		q.pop();
		for (std::vector<int>::iterator it = n[num - 1].child.begin(); it != n[num - 1].child.end(); it++) {
			if (n[*it - 1].distance > n[num - 1].distance + 1|| n[*it - 1].distance == -1) {
				n[*it - 1].distance = n[num - 1].distance + 1;
				q.push(*it);
			}
		}
	}

	for (int i = 0; i < node_num; i++) {
		std::cout << i + 1 << " " << n[i].distance << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>




using namespace std;
int main() {

	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++){
				if (i * 500 + j * 100 + k * 50 == x)ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define ONLINE_JUDGE
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>
#include <iterator>
#include <map>
#include <set>
#ifndef ONLINE_JUDGE
#include <prettyprint/prettyprint.hpp>
#endif

#define FOR(i, n) for(int i = 0; i < n; ++i)
#define TEST int T; std::cin >> T; while(T--)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vll = std::vector<ll>;
using vull = std::vector<ull>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

using namespace std;

const int mod = 1e9 + 7;

void add_self(int& a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}

void sub_self(int& a, int b) {
	a -= b;
	if(a < 0) a += mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	ifstream fin("in.txt");
	ofstream fout("out.txt");
	auto cinbuf = cin.rdbuf(fin.rdbuf());    // save and redirect
	auto coutbuf = cout.rdbuf(fout.rdbuf()); // save and redirect
#endif	
	int n, k;
	cin >> n >> k;
	// We need to choose k things for n buckets, but at max ai for each bucket.
	vector<int> dp(k + 1);
	dp[0] = 1;
	while(n--) {
		int limit;
		cin >> limit;
		// prefix trick.
		vector<int> cur(k + 1, 0);
		for(int used = k; used >= 0; --used) {
			int L = used + 1;
			int R = used + min(limit, k - used);
			if(R < L) continue;
			add_self(cur[L], dp[used]);
			if(R + 1 <= k) sub_self(cur[R + 1], dp[used]);
		}
		int pre = 0;
		for(int i = 0; i <= k; ++i) {
			add_self(pre, cur[i]);
			add_self(dp[i], pre);
		}
	}
	cout << dp[k] << endl;
#ifndef ONLINE_JUDGE
	cin.rdbuf(cinbuf);    // restore
	cout.rdbuf(coutbuf); // restore
#endif	
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    int X, N; cin >> X >> N;
    vector <int> p(N); rep(i,N) cin >> p[i];
    Sort(p);

    int ans;
    int now = 0;
    while (1) {
        if (!binary_search(p.begin(), p.end(), X-now)) {
            ans = X - now;
            break;
        }
        if (!binary_search(p.begin(), p.end(), X+now)) {
            ans = X + now;
            break;
        }
        ++now;
    }
    out(ans);
    
    return 0;
}









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

ll S;
ll f(ll x, ll cnt) {
  if (x % 2) return cnt;
  if (cnt > 50) return 100;
  ll nx = (S - x) / 2;
  return f(nx, cnt + 1);
}

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

  ll A; cin >> A;
  ll B; cin >> B;
  ll C; cin >> C;
  S = A + B + C;
  if (S % 2) {
    cout << 0 << '\n';
    return 0;
  }

  ll ans = 100;
  ans = min(ans, f(A, 0));
  ans = min(ans, f(B, 0));
  ans = min(ans, f(C, 0));
  if (ans == 100) ans = -1;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))

SUP = 10 ** 6

dp = [SUP] * N

dp[0] = 0
dp[1] = abs(H[1] - H[0])

for i in range(2,N):
  p = abs((H[i] - H[i - 2])) + dp[i - 2]
  q = abs((H[i] - H[i - 1])) + dp[i - 1]
  dp[i] = min(p,q)
  
print(dp[-1])

Measured memory_bytes: 13976
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 S         PIC X(30).

PROCEDURE DIVISION.
  ACCEPT S.
  IF S = "Sunny"
    DISPLAY "Cloudy"
  ELSE
    IF S = "Cloudy"
      DISPLAY "Rainy"
    ELSE
      DISPLAY "Sunny"
    END-IF
  END-IF.
  STOP RUN.


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

int main() {
  cin>>N;
  vector<int> Hs(N);
  for(int i=0;i<N;i++){cin>>Hs.at(i);}
  int count=0;
  int max_h=*max_element(Hs.begin(),Hs.end());
  for(int h=max_h;h>0;h--){
    for(int i=0;i<N-1;i++){
      if(Hs.at(i)==h&&Hs.at(i+1)==h){Hs.at(i)--;}
      else if(Hs.at(i)==h&&Hs.at(i+1)!=h){count++;Hs.at(i)--;}
    }
    if(Hs.at(N-1)==h){count++;Hs.at(N-1)--;}
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char grid[1001][1001];

ll solve(int n,int m){
    ll dp[n+1][m+1];
    dp[n][m]=1;
    for(int i=n;i>=1;i--){
        for(int j=m;j>=1;j--){
            if(i==n&&j==m)continue;
            if(grid[i][j]=='#')dp[i][j]=0;
            else{
                dp[i][j]=(((i==n)?0:dp[i+1][j])+((j==m)?0:dp[i][j+1]))%1000000007;
            }
        }
    }
    return dp[1][1];
}

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

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>grid[i][j];
        }
    }

    cout<<solve(n,m)%1000000007<<endl;
    return 0;
}

Measured memory_bytes: 12216
#include<iostream>

#define MAX 50

typedef long long LL;

typedef struct{
    int num;
    LL value[MAX];
}Minus;


using namespace std;
int check(LL V[MAX],int N, int left_num,int right_num,Minus *minus);
void sort(Minus *minus){
    int i,j;
    LL temp;
    
    for(i=0;i<minus->num;i++){
        for(j=i+1;j<minus->num;j++){
            if( minus->value[i] > minus->value[j]){
                temp = minus->value[j];
                minus->value[j] = minus->value[i];
                minus->value[i] = temp;
            }
        }
    }
}
int main(){
    int N,K;
    LL V[MAX];
    int minus_value = 0;
    int minus_num = 0;
    int value = 0;
    int left_num = 0;
    int right_num = 0;
    int max = 0;
    Minus minus;
    int i;
    LL ans;
    
    cin >> N >> K;
    right_num = 0;
    for(i = 0;i<N;i++){
        cin >> V[i];
    }
    LL temp = 0;
    while(1){
        minus.num = 0;
        //cout << left_num << "," << right_num << endl;
        temp = check(V,N,left_num,right_num,&minus);
        sort(&minus);
        //cout << temp << endl;
        for(i=0;i < minus.num && i < K - (right_num + left_num);i++){
            temp -= minus.value[i];
        }
        //cout << temp << endl;
        if( ans < temp)
            ans = temp;
        left_num++;
        if( left_num + right_num > K || left_num + right_num > N){
            left_num = 0;
            right_num++;
        }
        if(left_num + right_num > K || left_num + right_num > N){
            break;
        }
        //cout << endl;
    }
    
    cout << ans << endl;
    return 0;
}
int check(LL V[MAX],int N,int left_num,int right_num,Minus *minus){
    LL value = 0;
    int i;
    for(i=0;i<left_num;i++){
        if( V[i] < 0){
            minus->value[minus->num++] = V[i];
        }
        value += V[i];
    }
    for(i=0;i<right_num;i++){
        value += V[N-i-1];
        if( V[N-i-1] < 0){
           minus->value[minus->num++] = V[N-i-1];
        }
        
    }
    return value;
}


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = n-1; i > 0; i--)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

bool solve(){
  string s;cin>>s;
  rep(i,s.size()){
    if(s[i]=='h'&&s[i+1]=='i'){
      i++;
      // cout<<i<<endl;
    }else{
      cout<<"No"<<endl;
      return false;
    }
  }
  cout<<"Yes"<<endl;
  return false;
}


signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    char asd;
    cin >> asd;
    if (asd == 'a' || asd == 'e' || asd == 'u' || asd == 'o' || asd == 'i') {
        cout << "vowel" << endl;
    }
    else cout << "consonant" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[200000],b[200000],x[200000];
int main()
{
	int n,i,j,p,k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(a,a+n);
	p=a[n/2];
	k=a[n/2-1];
	for(i=0;i<n;i++)
	{
		if(b[i]>k)
			x[i]=k;
		else 
			x[i]=p;
	}
	for(i=0;i<n;i++) 
		printf("%d\n",x[i]);
	return 0;
}

Measured memory_bytes: 6912
#include<iostream>
using namespace std;
int main(){
		int H[100],W[100];
		int count=0;
while(true){
	int a,b;
	cin>> a>>b;
	if(a==0&&b==0){
		break;
	}
	else{
		H[count]=a;
		W[count]=b;
		count=count++;
	}
}
for (int l=0;l<count;l++){
	for(int i=0;i<H[l];i++){
		for (int j=0;j<W[l];j++){
			cout<<"#";
		}
		cout<<endl;
	}
	cout<<endl;
}
	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare(const void*a,const void *b) {
	return *(int*)a - *(int*)b;
}

int main() {
	int n, t, x, ans = 10000, r[200010] = {0};
	char s[1000],T[1000];
	scanf("%s\n", s);
	scanf("%s", T);
	for (int i = 0; i + strlen(T) <= strlen(s); i++) {
		int re = 0;
		for (int j = 0; j < strlen(T); j++) if (s[i + j] != T[j])re++;
		if (re < ans)ans = re;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <utility>
#include <queue>

using namespace std;
typedef long long signed int ll;

constexpr int inf = INT32_MAX / 2;

class djikstra {
private:
	ll* d = nullptr;
	map<int, map<int, ll>> p;
	int sz = 0;
public:
	void add_path(int from, int to, ll cost) {
		p[from][to] = cost;
	}
	void compute(int from,int nodes) {
		sz = nodes;
		if (d != nullptr) delete d;
		d = new ll[nodes];
		auto cmp = [this](int a, int b) {return d[a] > d[b]; };
		priority_queue <ll, vector<ll>, decltype(cmp)> q(cmp);
		for (int i = 0; i < nodes; i++) d[i] = INT64_MAX / 2;
		d[from] = 0;
		q.push(from);
		while (!q.empty()) {
			for (auto& e : p[q.top()]) {
				if (d[e.first] > d[q.top()] + e.second) {
					d[e.first] = d[q.top()] + e.second;
					q.push(e.first);
				}
			}
			q.pop();
		}
	}
	ll operator[](int node) {
		if (node >= sz) return INT64_MAX/2;
		return d[node];
	}
};

int main() {
	djikstra d;
	int h, w, n, r = 0;
	auto g = [&n]() {cin >> n; return n; };
	cin >> h >> w;
	for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) d.add_path(j, i, g());
	d.compute(1, 10);
	for (int i = 0; i < h; i++)for (int j = 0; j < w; j++) if(g() != -1) r += d[n];
	cout << r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string s, t; cin >> s >> t;
  bool res = false;
  for (int i = 0; i < (int)s.size(); i++)
  {
    int sid = i;
    int cnt = 0;
    for (int j = 0; j < (int)t.size(); j++)
    {
      if (sid > (int)s.size() - 1) sid %= s.size();
      if (s[sid] == t[j]) { cnt++; sid++; }
      else 
        break;
      if (cnt == (int)t.size()) { res = true; break; }
    }
    if (res == true) break;
  }
  cout << (res ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <cmath>
#include <limits>
#include <set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF = 200000000000000;
typedef long long ll;
double pi = 3.141592653589793;
//setprecision(20) <<

const int MOD = 1000000007;

long long gcd(long long a, long long b)
{
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  return gcd(a % b, b);
}

long long lcm(long long a, long long b)
{
  return a / gcd(a, b) * b;
}
long myPow(long long x, long long n, long long m = MOD)
{
  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;
}

class Point
{
public:
  long long x;
  long long y;
  char S;
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long double N;
  cin >> N;
  vector<pair<long double, long double>> v(N);
  for (int i = 0; i < N;i++)cin >> v[i].first >> v[i].second;
  sort(v.begin(), v.end());
  long double sum = 0;
  do
  {
    long double s = 0;
    for (int i = 1; i < N;i++){
      s += sqrt(pow(v[i].first - v[i - 1].first, 2) + pow(v[i].second - v[i - 1].second, 2));
    }
    sum += s;
  } while (std::next_permutation(v.begin(), v.end()));
  long double _N = 1;
  for (int i = 1; i <= N; i++)
    _N *= i;
  cout << std::setprecision(20) << sum / _N << endl;
}


Measured memory_bytes: 640
n,m,*a=map(int,open(0).read().split())
a=set(a)
dp=[0]*(n+2)
dp[0]=1
div=1000000007
for i in range(n):
  dp[i]%=div
  if i+1 in a:
    dp[i+1]=0
  else:
    dp[i+1]+=dp[i]
  if i+2 in a:
    dp[i+2]=0
  else:
    dp[i+2]+=dp[i]
print(dp[n]%div)

Measured memory_bytes: 14308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;

int main()
{
	int n,k;
	cin>>n>>k;
	int cur=1;
	for(int i=0;i<n;i++){
		if(cur<=k) cur*=2;
		else cur+=k;
	}
	cout<<cur;
	return 0;
}












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

vector<int> g[100010];

int memo[100010];

int dfs(int a){
  if(memo[a]!=0){
    return memo[a];
  }
  FOR(i,g[a].size()){
    if(memo[a]<dfs(g[a][i])+1){
      memo[a]=dfs(g[a][i])+1;
    }
  }

  return memo[a];

  
}

int main(){
  int n,m;
  cin >> n >> m;
  int x,y;
  FOR(i,m){
    cin >> x >> y;
    g[x].push_back(y);
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    if(ans<dfs(i)){
      ans=dfs(i);
    }
  }
  cout << ans << endl;

  

  
}


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

int main(){
    int n, a, b, c, d;
    cin >> n;
    
    a = n / 1000;
    b = (n / 100) % 10;
    c = ((n / 10) % 100) % 10 ;
    d =  n - 1000 * a - 100 * b - 10 * c;

    if(a == b || b == c || c == d){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
    return 0;
}

Measured memory_bytes: 888
import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))
heapq.heapify(a)

B,C = [],[]
CB = []

for i in range(m):
    b,c = map(int,input().split())
    B.append(b)
    C.append(c)
    CB.append((c,b))

CB.sort(reverse=True)
for c,b in CB:
    for i in range(b):
        tmp = heapq.heappop(a)
        if tmp >= c:
            heapq.heappush(a,tmp)
            break
        else:
            heapq.heappush(a,c)
print(sum(a))

Measured memory_bytes: 30228
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//using ll=long long;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//dp注意点
//問題の種類	 初期化する値	 備考
//最小化問題 	INF	
//最大化問題	    -INF	 テーブル全体で 00 以上の値しかとらないことがわかっていれば −1−1 でもいいですし、00 でもいい場合もあります
//数え上げ問題	00	
//確率問題	      00	
//Yes/No 判定問題	False
/*-------------ここまで---------------------------------------------*/

/*signed*/int main() {
    int n;
    cin >> n;
    if (n % 2 == 0)cout << "0.5000000000" << endl;
    else cout << fixed << setprecision(10) << (long double)(n / 2 + 1) / n << endl;
    return 0;
}

Measured memory_bytes: 3768
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf 1000000000000000000

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int p;
    cin>>p;
    int ans=0;
    ans=p/10000*10000;
    p%=10000;
    ans+=p/5000*5000;
    p%=5000;
    ans+=p/1000*1000;
    p%=1000;
    ans+=p/500*500;
    cout<<ans<<endl;
}


Measured memory_bytes: 3200
n, q = map(int, input().split())
name = []
time = []
for i in range(n):
    s, t = map(str, input().split())
    name.append(s)
    time.append(t)

cnt = 0
while len(time) != 0:
    x = name.pop(0)
    y = int(time.pop(0))
    for i in range(q):
        y -= 1
        cnt += 1
        if y <= 0:
            print(x, cnt)
            break
    if y <= 0:
        pass        
    else:
        name.append(x)
        time.append(y)


Measured memory_bytes: 9524
inpl = lambda: list(map(int,input().split()))
N = int(input())
A = inpl()
B = inpl()
ans = 0
for i in range(N):
    p = min(A[i],B[i])
    B[i] -= p
    q = min(B[i],A[i+1])
    A[i+1] -= q
    ans += p + q
print(ans)

Measured memory_bytes: 82020
#include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vsort(x) sort(x.begin(),x.end())

using namespace std;

int main() {

	int i, j, k;
	string s;
	cin >> s;
	char a, b;
	int c;
	a = s[0];
	b = s[s.length() - 1];
	c = s.length() - 2;
	cout << a << c << b << endl;
	return 0;
}

Measured memory_bytes: 256
import java.awt.Point

fun main(args:Array<String>) {
    val (n,d) = readLine()!!.split(" ").map { it.toInt() }
    var count = 0
    val list = List(n) {
        val (x,y) = readLine()!!.split(" ").map { it.toInt() }
        Point(x,y)
    }
    list.forEach {
        if (it.distance(Point(0,0)) <= d) {
            count++
        }
    }

    println(count)
}

Measured memory_bytes: 66684
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        Console.WriteLine(n >= 30 ? "Yes" : "No");
        
    }
}


Measured memory_bytes: 27376
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long t,n,m,i,j,fr[1005],x,y,l,r;
string st;
int main()
{
	ios::sync_with_stdio(0);
	cin>>t;
	while (t--)
	{
		cin>>x>>y>>l>>r;
		st="";
		if (x==y)
		{
			for (i=l;i<=r;i++)
			{
				if (i&1) cout<<"A"; else cout<<"B";
			}
			cout<<endl;
			continue;
		}
		if (x==y+1)
		{
			for (i=l;i<=r;i++)
			{
				if (i&1) cout<<"A"; else cout<<"B";
			}
			cout<<endl;
			continue;
		}
		if (x==y-1)
		{
			for (i=l;i<=r;i++)
			{
				if (i&1) cout<<"B"; else cout<<"A";
			}
			cout<<endl;
			continue;
		}
		long long ll=0,rr=6e8,res=6e8;
		while (ll<rr)
		{
			long long mid=(ll+rr+1)/2;
			if ((y+mid-1)/mid-1<=x&&(x+mid-1)/mid-1<=y)
			{
				res=mid;
				rr=mid-1;
			}
			else ll=mid;
		}
		long long lll=0,rrr=1e9+3,res2=0;
		while (lll<rrr)
		{
			long long mid=(lll+rrr)/2;
			long long yx=x-(mid/(res+1)*res+mid%(res+1)),yy=y-mid/(res+1);
			if (mid%(res+1)==0) yy++;
			if (yy<=(yx+1)*res)
			{
				lll=mid+1;
				res2=mid;
			}
			else rrr=mid;
		}
		long long yx=x-(res2/(res+1)*res+res2%(res+1)),yy=y-res2/(res+1);
		long long fj=res2+yy-res*yx+1;
		for (i=l;i<=min(r,res2);i++)
		{
			if ((i%(res+1))==0) cout<<"B"; else cout<<"A";
		}
		for (i=max(res2+1,l);i<=r;i++)
		{
			if (((i-fj)%(res+1))==0) cout<<"A"; else cout<<"B";
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

int A[100000], s[100000];

typedef struct{
  int B;
  int C;
}Card;

Card c[100000];

int CmpA(const void *a, const void *b){
  return *(int *)a - *(int *)b;
}

int CmpB(const void *a, const void *b){
  return ((Card *)b)->C - ((Card *)a)->C;
}

int Max(int a, int b){
  if(a > b) return a;
  else return b;
}

void Do(int N, int M){
  int i, j, count;
  long long S;
  S = 0;
  for(i = 0;i < N;i++) scanf("%d", &A[i]);
  qsort(A, N, sizeof(int), CmpA);
  for(i = 0;i < M;i++) scanf("%d %d", &c[i].B, &c[i].C);
  qsort(c, M, sizeof(Card), CmpB);
  count = 0;
  for(i = 0;i < M;i++){
    for(j = 0;j < c[i].B;j++){
      s[count++] = c[i].C;
      if(count >= N) break;
    }
    if(count >= N) break;
  }
  for(i = 0;i < N;i++) S += Max(A[i], s[i]);
  printf("%lld\n", S);
}

int main(void){
  int N, M;
  scanf("%d %d", &N, &M);
  Do(N, M);
  return 0;
}


Measured memory_bytes: 2164
//Simplified mahjong

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    nvarep(n,a);
    vector<int>b=a;
    int ans=0;
    int l=0;
    rep(i,0,n){
        int t=a[i];
        ans+=(l+a[i])/2;
        if((l+a[i])%2&&a[i]>0)l=1;
        else l=0;
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 4816
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
  //add your code here.
  int N,tmp;
  vector<int> per;
  cin>>N;
  while(N--){
    cin>>tmp;
    per.push_back(tmp);
  }

  vector<int> test(per.size(),0);
  for(int i=0; i<per.size(); i++)
    if(i+1 == per[i]) test[i] = 1;

  // for(int i: test) cout<<i<<' ';
  // cout<<endl;
  
  int op = 0;
  for(int i=0; i<test.size(); i++){
    if(i == test.size()-1 && test[i] == 1) {
      op++;
      break;
    }
    
    if(test[i] == 1 && test[i+1] == 0){
      op++;
      test[i] = 0;
    }
    
    if(test[i] == 1 && test[i+1] == 1){
      op++;
      test[i] = 0;
      test[i+1] = 0;
    }
  }

  cout<<op<<endl;
  return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
using ll     = int64_t;
using ull    = uint64_t;
using prefix = __attribute__((constructor))void;
const ll MOD = 1000000007;
const ll INF = LONG_MAX;

#define elif           else if
#define def            inline auto
#define func           inline constexpr ll
#define up(i,a,n)      for(ll i=(a),i##_1=(n);i<=i##_1;++i)
#define down(i,a,n)    for(ll i=(a),i##_1=(n);i>=i##_1;--i)
#define rep(i,n)       up(i,0,n-1)
#define append(a)      push_back(a)
#define fout           cout<<fixed<<setprecision(10)
#define fasten         cin.tie(0),ios::sync_with_stdio(0)

func    gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
func    lcm(ll a,ll b) {return a*b/gcd(a,b);}
def     dig(ll a)      {return to_string(a).length();}
prefix  init()         {fasten,fout;}

    ll rail[501][501];
signed main(){
    ll N,M,Q,L,R,S;
    cin>>N>>M>>Q;
    rep(i,M){
        cin>>L>>R;
        rail[L][R]++;
    }
    up(i,1,N){
        up(j,1,N){
            rail[i][j]+=rail[i][j-1];
        }
    }
    rep(i,Q){
        cin>>L>>R;
        S=0;
        up(j,L,R){
            S+=rail[j][R]-rail[j][L-1];
        }
        cout<<S<<"\n";
    }
}
//for compilation: g++ -o _ _.cpp -std=c++14 (or 17)
//
//for fastening: g++ -O2 -o _ _.cpp -std=c++14 (or 17)
//for fastening: g++ -O3 -mtune=native -march=native -o _ _.cpp -std=c++14 (or 17)


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

const ll MAXN = 200000;

ll N, ans=0, tmp=0;
vector<ll> A(MAXN, 0);
string S;

signed main(){
    cin >> N >> S;
    ll DP[N+1][N+1]={{0}};
    for(int i=N-1;i>=0;i--) {
        for(int j=N-1;j>=0;j--) {
            if(S[i]==S[j]) {
                DP[i][j]=min(abs(i-j), DP[i+1][j+1]+1);
                ans = max(ans, DP[i][j]);
            }
            else DP[i][j]=0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 197248
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
const int mod = 1e9 + 7;
int n, dp[105][4][4][4];
//string a = "AGCT";
ll solve(int idx, int n1, int n2, int n3){
    if(idx >= n) return 1;
    if(dp[idx][n1][n2][n3] != -1) return dp[idx][n1][n2][n3];
    ll ans = 0;
    for(int i = 0; i < 4; i++){
        if((i == 1 && n2 == 0 && n3 == 2) ||
           (i == 1 && n2 == 2 && n3 == 0) ||
           (i == 2 && n2 == 0 && n3 == 1) ||
           (i == 1 && n1 == 0 && n2 == 2) ||
           (i == 1 && n1 == 0 && n3 == 2))continue;
        ans = (ans + (solve(idx + 1, n2, n3, i) % mod) ) % mod;
    }
    dp[idx][n1][n2][n3] = ans;
    return dp[idx][n1][n2][n3];
}
int main(){
    Hello
    cin >> n;
    memset(dp, -1, sizeof dp);
    cout << solve(0, 3, 3, 3);
    return 0;
}


Measured memory_bytes: 3664
n1 = int(input())
n2 = [int(i) for i in input().split()]
n3 = [[] for i in range(n1)]

for i1 in range(n1):
    n3[i1].append(i1 + 1)
    n3[i1].append(n2[i1])

n3.sort(key=lambda x: x[1])

r1 = ""
for i3 in range(n1):
    r1 += str(n3[i3][0]) + " "

print(r1[0:len(r1) - 1])

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

int main(){
  long long N,i,j;
  cin >> N;
  int res = 0;

  for(i=2;i*i<=N;i++){
    j = i;
	while(N % j == 0){
      res++;
      N /= j;
      j *= i;
    }
    while(N % i == 0)
      N /= i;
  }
  if (N > 1)
    res++;

  cout << res << endl;
}

Measured memory_bytes: 3612
from itertools import accumulate

n,q = map(int,input().split())
SS = input()
accumes = [0]
for i in range(1,len(SS)):
    if SS[i]=="C" and SS[i-1]=="A":
        accumes.append(1)
    else:
        accumes.append(0)
acuumelist = list(accumulate(accumes))
for i in range(q):
    l,r = map(int,input().split())
    print(acuumelist[r-1]-acuumelist[l-1])

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

int main(){
  while(1){
    int h,w;
    cin >> h >> w;
    if(h==0 && w==0){
        break;
    }
    for( int i= 0; i<h; i++){
        for(int i=0; i<w; i++){
            cout << "#";
        }
        cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3044
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#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)
#define MOD 998244353

int d[20];
bool b[20];

int main() {
	int n;
	scanf("%d", &n);
	int v = 0;
	int e = 0;
	while ((1 << v) <= n) {
		if ((1 << v) & n)e++;
		v++;
	}
	e = e - 1 + 2 * (v - 1);
	printf("%d %d\n", v, e);
	d[0] = 0;
	REP(i, v-1) {
		if (n & (1 << (v - 2 - i)))d[i + 1] = 2 * d[i] + 2;
		else d[i + 1] = 2 * d[i] + 1;
	}
	REP(i, v - 1) {
		printf("%d %d %d\n", i+1, i + 2, 0);
		printf("%d %d %d\n", i+1, i + 2, d[i]+1);
		if(d[i+1] == (2*d[i]+2))printf("%d %d %d\n", 1, i + 2, d[i+1]);
	}
	return 0;
}

Measured memory_bytes: 384
from collections import deque

n = int(input())
a = map(int, input().split())
b = deque([])

for index, value in enumerate(a):
    if index % 2 == 0:
        b.appendleft(value)
    else:
        b.append(value)
if n % 2 == 0:
    b = reversed(b)
print(" ".join(map(str, b)))

Measured memory_bytes: 27460
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

A,B,N = LI()

def calc(x):
    return A*x//B - A*(x//B)

d,m = divmod(N+1,B)
x1 = max(d*B-1,0)
x2 = N

print(max(calc(x1),calc(x2)))

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

using namespace std;

int main() {
  map<char,char> dict;
  dict['A'] = 'T';
  dict['T'] = 'A';
  dict['C'] = 'G';
  dict['G'] = 'C';
  char c;
  cin >> c;
  cout << dict[c] << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	for(int i=1; i<=n; i++) {
		int x = i;
		if(x % 3 == 0) printf(" %d", i);
		else {
			for(;;){
				if(x % 10 == 3) {
					printf(" %d", i);
					break;
				}
				if(!(x /= 10)) break;
			}
		}
	}
	printf("\n");
}


Measured memory_bytes: 2760