akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define repB(i, z, n) for(int i = n - 1; i >= z; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
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; }
using namespace std;
//#define P pair<int, int>
typedef pair<int, int> P;

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N + 1), small(N + 1), big(N + 1), B(N + 1);
    rep(i, 0, N + 1) cin >> A.at(i);
    
    small.at(N) = A.at(N);
    big.at(N) = A.at(N);
    repB(i, 0, N){
        small.at(i) = (small.at(i + 1) + 1)/ 2 + A.at(i);
        big.at(i) = big.at(i + 1) + A.at(i);
    }
    if((1 < small.at(0)) || (1 > big.at(0))){
        cout << -1 << endl;
        return 0;
    }
    
    int64_t ans = 1;
    B.at(0) = 1;
    rep(i, 1, N + 1){
        B.at(i) = min((B.at(i - 1) - A.at(i - 1)) * 2, big.at(i));
        ans += B.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6436
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define INF 1e9
typedef long long llong;
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> a(n);//mmm.
	REP(i,n) cin>>a[i];
	sort(ALL(a));
	
	int cnt=0;
	while(a.size()>1){
		int want=1;
		while(want<=*(a.end()-1)) want*=2;
		want-=*(a.end()-1);
		
		auto itr=lower_bound(ALL(a),want);//二分探索.
		if(a.begin()<=itr&&itr<a.end()-1&&*(itr)==want){
			cnt++;
			a.erase(itr);
		}
		
		a.erase(a.end()-1);
	}
	
	cout<<cnt<<endl;
}//解答解説参考.

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

int w, h;
vector<vector<int> > grid;
vector<vector<bool> > check;

int solve(int y, int x)
{
    check[y][x] = true;

    int ret = 0;
    for(int i=0; i<6; ++i){
        int y1 = y + dy[i];
        int x1 = x + dx[y%2][i];
        if(y1 < 0 || y1 >= h+2 || x1 < 0 || x1 >= w+2)
            continue;
        if(check[y1][x1])
            continue;

        if(grid[y1][x1] == 1)
            ++ ret;
        else
            ret += solve(y1, x1);
    }

    return ret;
}

int main()
{
    cin >> w >> h;

    grid.assign(h+2, vector<int>(w+2, 0));
    check.assign(h+2, vector<bool>(w+2, false));
    for(int i=1; i<=h; ++i){
        for(int j=1; j<=w; ++j){
            cin >> grid[i][j];
        }
    }

    cout << solve(0, 0) << endl;
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <string.h>

//faster vesion than initial submission

bool* E_sieve( int n ){
	bool* plist = (bool*)malloc( sizeof(bool)*(n+1) );
	int i, j, k;

	memset( plist, true, sizeof(bool)*(n+1) );

	/***sieve***/
	for( i=2; i*i<=n; i++ ){

		//find a prime number
		for( j=i; plist[j]!=true; j++ )
			;

		//eliminate multiple of the prime number
		for( k=2*j; k<=n; k+=j ){
			plist[k]=false;
		}

	}

	return plist;
}

int main(){
	int n, i, p;
	bool *table;
	
	table = E_sieve( 999999 );

	while( scanf("%d", &n) != EOF ){
		p=0;
		for( i=2; i<=n; i++){
			if( table[i] == true )
				p++;
		}
		printf("%d\n", p );
	}
	
	return 0;

}

Measured memory_bytes: 1584
s = input()

dic = "abcdefghijklmnopqrstuvwxyz"

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)

elif len(s) < 26:
    t = ""
    for x in dic:
        if s.count(x) == 0:
            t = x
            break
    print(s+t)
else:
    for idx,x in enumerate(s):
        t = s[-idx-1]
        l = s[-idx-1:]
        min_s = ""
        for y in l:
            if t < y:
                min_s = y if min_s=="" else min(min_s, y)
        
        if min_s != "":
            break
    print(s[:-idx-1]+min_s)



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

int main()
{
    string s;

    cin >> s;

    int ans = 0, i;

    for(i = 0; i < 4; i++){
        if(s[i] == '+') ans++;
        else ans--;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

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

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,H,W,ans;
  cin>>H>>N;
  ans=0;
  while(N--){
    cin>>j;
    ans+=j;
  }
  if(ans<H)printno;
  else printyes;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def main():
    W, a, b = map(int, raw_input().split())
    a_end = a+W
    b_end = b+W
    if (b <= a_end and b >= a) or (a<=b_end and a >= b):
        print 0
        return 0
    dist = b - a_end
    if dist < 0:
        dist = a - b_end
    print dist

if __name__ == '__main__':
    main()

Measured memory_bytes: 2696
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑


ll a, b, c, ans;
int main() {
	cin >> a >> b >> c;
	if (a <= b) { cout << 1 << endl; return 0; }
	if (b <= c) { cout << -1 << endl; return 0; }
	if ((a - b) % (b - c) != 0) { ++ans; }

	cout << 1 + 2 * (ans + (a - b) / (b - c)) << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = IS()
	l = len(N)
	ans = ""
	for i in range(l):
		ans += 'x'
	print(ans)

main()

Measured memory_bytes: 38384
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    s = str(input())
    q = int(input())
    s = s.strip()
    a = [''] * (10**5*2)
    a.extend(list(s))
    a.extend([''] * (10**5*2))
    start = 10**5*2
    end = start + len(s) - 1
    frip = False
    for i in range(q):
        query = input().split()
        if query[0] == '1':
            frip = not frip
        elif query[0] == '2':
            if (query[1] == '1' and frip == False) or (query[1] == '2' and frip == True):
                a[start-1] = query[2]
                start -= 1
            else:
                a[end+1] = query[2]
                end += 1
    if frip:
        a.reverse()
        tmp = end
        end = len(a)-start-1
        start = len(a)-tmp-1
    print(''.join(a[start:end+1]))


main()


Measured memory_bytes: 59760
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		//データ読み込み
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();	
		}
		
		//入れ替えの回数を記録するカウンター
		int counter = 0;
		
		for(int i = 0; i < n; i++){
			//各iごとに最小の値が格納されている配列番号の変数
			int minj = i;
			
			for(int j = i + 1; j < n; j++){
				if(a[j] < a[minj]){
					minj = j;
				}
			}
			
			//i番目に格納されている値が、最小でない場合、入れ替え
			if(minj != i){
				int temp = a[i];
				a[i] = a[minj];
				a[minj] = temp;
				
				//入れ替え回数の加算
				counter++;
			}
		}
		
		//結果の出力
		System.out.print(a[0]);
		for(int i = 1; i < n; i++){
			System.out.print(" " + a[i]);
		}
		System.out.print("\n");
		System.out.println(counter);
	}
}


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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	map<int, int> mp;
	rep(i, 0, n) {
		int t; cin >> t;
		mp[t]++;
	}
	vector<pii> v(mp.begin(), mp.end());
	int ans = 0;
	for (auto p : v) {
		int g = p.first;
		ans = max(ans, mp[g - 1] + mp[g] + mp[g + 1]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 5248
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
function lower_bound(d,e,a,b){for(var c;1<b-a;)d[c=a+b>>1]<e?a=c:b=c;return d[a]<e?b:a};

function segTree(n){
  var l = n.length, u = l-1, x = 2, i, v;
  while(u)u >>= 1, x <<= 1;
  v = this.seg = Array(x-1).fill(0);
  this.l = x = (x >> 1) - 1;
  for(i = 0; i < l; i++)v[i+x] = n[i];
  for(i = x-1; i >= 0; i--)v[i] = segSolve(v[i+i+1],v[i+1<<1]);
}
function segSolve(a,b){
  return Math.max(a,b);
}
segTree.prototype={
  get:function(l,r){//[l,r)
    if(l >= r)return 0;
    var v = this.seg;
    return q(l,r,0,this.l+1,0);
    function q(l,r,x,y,i){
      if(l === x && r === y)return v[i];
      var m = x+y >> 1;
      if(m < r)if(l < m)return segSolve(q(l,m,x,m,i+i+1),q(m,r,m,y,i+1<<1));
      else return q(l,r,m,y,i+1<<1);
      return q(l,r,x,m,i+i+1);
    }
  },
  update:function(x,i){
    var v = this.seg;
    i += this.l;
    v[i] = x;
    for(i = i-1>>1; i >= 0; i = i-1>>1){
      v[i] = segSolve(v[i+i+1],v[i+1<<1]);
    }
  },
}

var mod = 998244353;

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var x = Array(n), d = {};
  for(var i = 0; i < n; i++){
    var a = next(), b = next();
    x[i] = a, d[a] = b;
  }
  x.sort((a,b)=>a-b);
  var seg = new segTree(Array(n).fill().map((a,i)=>i));
  var id = Array(n).fill().map((a,i)=>i);
  for(var i = n-1; i--;){
    var u = lower_bound(x,x[i]+d[x[i]],i,x.length);
    if(i === u-1)continue;
    var v = seg.get(i+1,u);
    seg.update(v,i);
    id[i] = v;
  }
  var dp = xArray(0,n+1);
  dp[n] = 1;
  dp[n-1] = 2;
  for(var i = n-1; i--;){
    dp[i] = dp[i+1] + dp[id[i]+1];
    dp[i] %= mod;
  }
  return dp[0] % mod;
}

Measured memory_bytes: 120940
fn main(){

	fn solve(line: Vec<i32>) -> bool {
	    let (w, h, x, y, r) = (line[0], line[1], line[2], line[3], line[4]);
		x - r >= 0 && y - r >= 0 && x + r <= w && y + r <= h
	}

	println!("{}", 
		if solve(read_vec::<i32>()) { "Yes" } 
		else                        { "No" });
}


fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


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

namespace debug
{
    class main 
    {
        static void Main(string[] args)
        {
            ProgramC a = new ProgramC();
            a.main();
            
        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine();

            if (s == "Sunny")
                Console.WriteLine("Cloudy");
            else if (s == "Cloudy")
                Console.WriteLine("Rainy");
            else
                Console.WriteLine("Sunny");

        }


    }

    class ProgramB
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine();

            for(int i = 0;i < s.Length;i++)
            {
                if( i % 2 == 0)
                {
                    if(s[i] == 'L')
                    {
                        Console.WriteLine("No");
                        return;
                    }
                    continue;
                }

                if (s[i] == 'R')
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
        }


    }

    class ProgramC
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long k = long.Parse(s[1]);
            long q = long.Parse(s[2]);

            int[] num = new int[n];

            for (int i = 0; i < q; i++)
            {
                int temp = int.Parse(Console.ReadLine());
                num[temp - 1]++;
            }

            for (int i = 0; i < n; i++)
            {
                if(k - (q - num[i]) > 0)
                    Console.WriteLine("Yes");
                else
                    Console.WriteLine("No");
            }
        }


    }


}


Measured memory_bytes: 17600
#include<stdio.h>
#include<math.h>

typedef struct xy
{
	double x;
	double y;
}XY;

void cohho(int n, XY head, XY tail)
{
	if(n == 0) return;

	double th = M_PI * 60.0 / 180.0;

	XY s, t, u;
	s.x = (2.0*head.x + tail.x) / 3.0;
	s.y = (2.0*head.y + tail.y) / 3.0;
	t.x = (head.x + 2.0*tail.x) / 3.0;
	t.y = (head.y + 2.0*tail.y) / 3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

	cohho(n-1, head, s);
	printf("%.8f %.8f\n", s.x, s.y);
	cohho(n-1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	cohho(n-1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	cohho(n-1, t, tail);
}
	

int main()
{
	int n;
	XY head, tail;
	head.x = 0; head.y = 0;
	tail.x = 100; tail.y = 0;

	scanf("%d", &n);

	printf("%.8f %.8f\n", head.x, head.y);
	cohho(n, head, tail);
	printf("%.8f %.8f\n", tail.x, tail.y);

	return 0;
}

Measured memory_bytes: 644
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    
    printf("%d %d %.5f\n",d,r,f);
    
    return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <algorithm>    
#include <cmath>
#include <map>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <set>
#include <functional>
#define int long long
#define mod(int)(1000000007)
using namespace std;
const int INF = 1000000000000;
int test[345678];
signed main() {
	int n, m, a = -1; cin >> n >> m;
	for (int h = 0; h < n; h++) {
		cin >> test[h];
	}
	for (int h = 1; h < n; h++) {
		if (test[h - 1] + test[h] >= m) {
			a = h; 
		}
	}
	if (a == -1) { cout << "Impossible" << endl; }
	else {
		cout << "Possible" << endl;
		for (int h = 1; h < n; h++) {
			if (a == h) { break; }
			cout << h << endl;
		}
		for (int h = n - 1; h >= 1; h--) {
			if (a == h) { break; }
			cout << h << endl;
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 1536
unittest
{
	assert( [ "10 3", "1", "5", "4", "3", "8", "6", "9", "7", "2", "4" ].solve == 7 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	auto as = new long[ n ];
	foreach( ref a; as )
	{
		input.popFront;
		a = input.front.to!( long );
	}
	
	auto st = SegmentTree!( long, 0L, max, max )( 300001 );
	foreach( a; as )
	{
		st.update( a, 1 + st.query( max( 0, a - k ), min( a + k + 1, st.length ) ) );
	}
	return st.query( 0L, st.length );
}

// セグメント木
struct SegmentTree( T, T I, alias op_v, alias op_m )
{
	size_t n;
	T[] vs;
	
	this( size_t n )
	{
		this.n = n;
		this.vs = new T[ this.n << 1 ];
		static if( I != T.init ) this.vs[] = I;
	}
	
	this( T[] vs )
	{
		this( vs.length );
		this.vs[ this.n .. this.n + vs.length ] = vs[];
		foreach_reverse( p; 1L .. this.n )
		{
			this.vs[ p ] = op_v( this.vs[ p << 1 ], this.vs[ p << 1 | 1 ] );
		}
	}
	
	void update( size_t i, T e )
	{
		auto p = this.n + i;
		this.vs[ p ] = op_m( this.vs[ p ], e );
		for( p >>= 1; 0 < p; p >>= 1 )
		{
			this.vs[ p ] = op_v( this.vs[ p << 1 ], this.vs[ p << 1 | 1 ] );
		}
	}
	
	auto query( size_t i )
	{
		return this.vs[ this.n + i ];
	}
	
	auto query( size_t l, size_t r )
	{
		auto lt = I;
		auto rt = I;
		for( auto lp = this.n + l, rp = this.n + r; lp < rp; lp >>= 1, rp >>= 1 )
		{
			if( lp & 1 )
			{
				lt = op_v( lt, this.vs[ lp ] );
				lp++;
			}
			if( rp & 1 )
			{
				rp--;
				rt = op_v( this.vs[ rp ], rt );
			}
		}
		return op_v( lt, rt );
	}
	
	auto length()
	{
		return this.n;
	}
	
	auto toString()
	{
		return format( "ST(%s)", this.vs[ this.n .. $ ] );
	}
}


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(num) scanf("%d",&num)
#define sff(num1,num2) scanf("%d %d",&num1,&num2)
#define sfff(num1,num2,num3) scanf("%d %d %d",&num1,&num2,&num3);
#define sl(num) scanf("%lld",&num)
#define sll(num1,num2) scanf("%lld %lld",&num1,&num2)
#define slll(num1,num2,num3) scanf("%lld %lld %lld",&num1,&num2,&num3);
#define rep(i,n) for(i=1;i<=n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define pb push_back
#define mpp make_pair
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
#define TIME cerr<<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<"s\n";
typedef long long int ll;
using namespace std;
int main()
{
    int i,n,m,k,sum=0,cnt=1;
    sff(n,m);
    rep0(i,n)
    {
        sf(k);
        sum+=k;
        if(sum<=m)
            cnt++;
    }
    pf("%d",cnt);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
ll A[19][19];

int main() {
    int N; cin >> N;
    vector<int> power10 = {1};
    rep(i,9) {
        power10.push_back(power10.back()*10);
    }

    rep(i,N) {
        string s; cin >> s;
        ll x = 0;
        int cnt = 0;
        bool flag = false;
        rep(i,s.size()) {
            if (s[i] == '.') {
                flag = true;
                continue;
            }
            x = (x * 10) + s[i] - '0';
            if (flag) ++cnt;
        }
        x *= power10[9 - cnt];

        int c2 = 0,c5 = 0;
        while (x > 0 && x%2 == 0) {
            x /= 2;
            ++c2;
        }
        while (x > 0 && x%5 == 0) {
            x /= 5;
            ++c5;
        }
        if (c2 >= 18 && c5 >= 18) A[18][18] ++;
        else if (c2 >= 18) A[18][c5] ++;
        else if (c5 >= 18) A[c2][18] ++;
        else A[c2][c5] ++;
    }

    ll ans = 0;
    rep(i,19)rep(j,19) {
        for (int k = 18 - i;k < 19; ++k) {
            for (int l = 18 - j; l < 19; ++l) {
                if (i == k && j == l) ans += A[i][j] * (A[k][l] - 1);
                else ans += A[i][j] * A[k][l];
            }
        }
    }
    cout << ans/2 << '\n';
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main(void) {
	int H, W, i, j;
	scanf("%d %d", &H, &W);
	while (H!=0 || W!=0)
	{
		for (i=1; i<=H; i++)
		{
			if (i%2!=0) {
				for (j=1; j<=W; j++)
				{
					if (j%2!=0) {
						printf("#");
					} else printf(".");
				}
			} else {
				for (j=1; j<=W; j++)
				{
					if (j%2!=0) {
						printf(".");
					} else printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
		scanf("%d %d", &H, &W);
	}
	return 0;
}

Measured memory_bytes: 572
import java.util.Scanner;

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int X = sc.nextInt();
		System.out.println(checkCat(A,B,X));

	}

	public static String checkCat(int A, int B, int X) {
		if (A + B  < X) {
			return "NO";
		}
		if (A > X) {
			return "NO";
		}
		return "YES";
	}
}


Measured memory_bytes: 21972
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	cnt := 0
	for i := 1; i <= n; i += 2 {
		cntt, _ := getDivlist(i)

		if cntt == 8 {
			cnt++
		}
	}

	fmt.Println(cnt)
}

// 約数列挙リストを作成
func getDivlist(a int) (cnt int, divlist []int) {
	for i := 1; i*i <= a; i++ {
		if a%i == 0 {
			cnt++
			divlist = append(divlist, i)
			if i*i != a {
				cnt++
				divlist = append(divlist, a/i)
			}
		}
	}
	return cnt, divlist
}

// 約数の数をカウントする(愚直)
func numDivSlow(a int) int {
	cnt := 1
	for i := 1; i <= a/2; i++ {
		if a%i == 0 {
			cnt++
		}
	}
	return cnt
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef unsigned long long ull;

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

	bool flug[100000];
	ull pen[100000];
	for (ull i = 0; i < n; i++) {
		flug[i] = false;
		pen[i] = 0;
	}

	ull ac = 0;
	ull wa = 0;

	for (ull i = 0; i < m; i++) {
		ull p;
		string s;
		cin >> p >> s;
		if (flug[p-1] == false) {
			if (s == "AC") {
				flug[p-1] = true;
				ac++;
				wa += pen[p-1];
			} else
				pen[p-1]++;
		}
	}

	cout << ac << ' ' << wa << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#define N 300000
using namespace std;
int main(){
  int n;

  vector<int> num;
  for( int i=0;n<N;i++ ){
    n=7*i+1;  num.push_back(n);
    n=7*i+6;  num.push_back(n);
  }
  bool is_prime[num.size()];
  vector<int> prime;
  for( int i=0;i<(int)num.size();i++ )
    is_prime[i] = true;
  is_prime[0] = false;
  for( int i=1;i<(int)num.size();i++ ){
    if( !is_prime[i] )
      continue;
    for( int j=1;num[j]*num[j]<=num[i];j++ ){
      if( num[i] % num[j] == 0 ){
	is_prime[i] = false; break;
      }
    }
    if( is_prime[i] )
      prime.push_back(num[i]);
  }

  while(cin>>n,n!=1){
    vector<int> v;
    int nn = n;
    for( int i=0;i<(int)prime.size() && prime[i] <= n;i++ ){
      if( nn % prime[i] == 0 )
	v.push_back(prime[i]);
    }


    sort(v.begin(), v.end());
    cout << n << ":";
    for( int i=0;i<(int)v.size();i++ )
      cout << " " << v[i];
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1984
import java.util.*;
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String c = sc.next();
    if(c.equals("a") || c.equals("i") || c.equals("u") || c.equals("e") || c.equals("o")){
      System.out.println("vowel");
    }else{
      System.out.println("consonant");
    }
  }
}


Measured memory_bytes: 9680
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;


signed main() {
	int N,M;
	cin >> N >> M;
	int a[1010],b[1010],c[1010];
	int dist[1100][1100];
	for(int i = 0;i < N;i++) {
		for(int j = 0;j < N;j++) {
			dist[i][j] = INF;
		}
		dist[i][i] = 0;
	}
	for(int i = 0;i < M;i++) {
		cin >> a[i] >> b[i] >> c[i];
		--a[i],--b[i];
		dist[a[i]][b[i]] = c[i];
		dist[b[i]][a[i]] = c[i];
	}
	for(int k = 0;k < N;k++) {
		for(int i = 0;i < N;i++) {
			for(int j = 0;j < N;j++) {
				dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
			}
		}
	}
	int res = 0;
	for(int i = 0;i < M;i++) {
		if(c[i] > dist[a[i]][b[i]]) {
			res++;
		}
	}
	cout << res << endl;
}

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

int main(){
    ll n,m,k,v;
    cin >> n >> m >> k;
    vector<ll> s1, s2;
    s1.push_back(0), s2.push_back(0);
    for(int i=0;i<n;i++) {
        cin >> v;
        s1.push_back(s1.back() + v);
    }
    for(int i=0;i<m;i++) {
        cin >> v;
        s2.push_back(s2.back() + v);
    }
    ll best = 0;
    // i amount on s1
    int j = m; // j on s2
    int res = 0;
    for(int i=0;i<=n;i++) {
        while(j>0 && s2[j] + s1[i] > k) {
            j--;
        }
        if(s2[j] + s1[i] <= k) {
            res = max(res, i+j);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 7988
using System;
using System.Linq;

class Program
{
    public static void Main()
    {
        while(true)
        {
            int[] data = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if(data[0] == 0 && data[1] == 0)break;
            
            for(int i = 0; i < data[0];i++)
            {
                for(int j = 0; j < data[1];j++ )
                {
                    if((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
                    {
                        Console.Write("#");
                    }else
                    {
                        Console.Write(".");
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 20480
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define limit 1000005
#define lol (ll) sqrt((double)limit)
#define pb push_back
#define sci(x) scanf("%d",&x)
#define scl(y) scanf("%lld",&y)

ll pf(ll n)

{
    ll cnt=0;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            while(n%i==0)
            {
                n=n/i;

            }
            cnt++;
        }
    }
    if(n>1) cnt++;
    return cnt;
}


int main()
{
    ll a,b;
    cin>>a>>b;
    ll g=__gcd(a,b);
    ll temp=pf(g);
    cout<<temp+1<<endl;
}


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

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = int.Parse(Console.ReadLine());
            long sum = 0;
            long[] ai = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            Array.Sort(ai);
            Console.Write("{0} {1} ", ai[0], ai[n - 1]);
            for (int i = 0; i < n; i++)
            {
                sum = sum + ai[i];
            }
            Console.WriteLine(sum);
            Console.ReadLine();
        }
    }
}


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

int main() {
  string n;
  cin >> n;
  int k=0;

  while(k<n.size()){
      if(n[k] =='7'){
          cout << "Yes" << endl;
          return 0;
      }
      k++;
  }
  cout << "No" << endl;


}

Measured memory_bytes: 3628
#include <stdio.h>

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

 scanf ("%ld %ld", &a, &b);
 
 if (b > a) {
	c = a;
	a = b;
	b = c;
}

 while (b != 0) {
  c = b;
  b = a%b;
  a = c;
}
 
 printf("%d\n", a);
 return 0;

}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double ans;
  cout << fixed << setprecision(10);
  double pi = 3.141592653589793238;
  double unit = 180.0 / pi;
  if(x < a*a*b/2){
    double p = x*2/(a*b);
    cout << atan(b/p)*unit << endl;
  }
  else{
    double p = (a*a*b-x)*2/(a*a);
    cout << atan(p/a)*unit << endl;
  }
}
    

Measured memory_bytes: 512
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10



int main() {
	int N; cin >> N;
	vector<ll> Arr(N + 10, 0);
	vector<int> A(N);
	REP(i, N) {
		cin >> A[i];
		Arr[A[i]]++;
	}


	ll sum = 0;
	for (int i = 1; i <= N; i++) {
		if (Arr[i] > 1) sum += Arr[i] * (Arr[i] - 1) / 2;
	}

	

	REP(i, N) {
		int tar = A[i];
		ll cnt = Arr[tar];
		ll tmp = sum;
		if (cnt >= 2) {
			tmp = tmp - Arr[tar] * (Arr[tar] - 1) / 2 + (Arr[tar] - 2) * (Arr[tar] - 1) / 2;
		}
		cout << tmp << endl;
	}



	return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, A, B;
    cin >> N >> A >> B;
    ll len = A + B;
    ll actual_len = N % len;
    ll cycles = N / len;
    if (actual_len > A) {
        cout << A * cycles + A << endl;
    } else {
        cout << A * cycles + actual_len << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N, Q = map(int,input().split())
S = input()
T = [0]*(N+1)
for i in range(N):
    T[i+1] = T[i] + (1 if S[i : i+2] == 'AC' else 0)

for i in range(Q):
    L, R = map(int,input().split())
    print(T[R-1] - T[L-1])

Measured memory_bytes: 13204
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int a, b, k;
	cin >> a >> b >> k;
	for(int i = 100; i >= 1; i--){
		if(a % i == 0 && b % i == 0){
			k--;
			if(!k){
				cout << i << endl;
				return 0;
			}
		}
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;
#define ll long long
 
int main(void){
    ll n;
    cin >> n;
    string s, exam;
    cin >> s;
    exam = s;
    bool a = true;
    ll count = 0;
    ll check = 0;
    while(a==true){
        for(ll i = 0; i < s.length(); i++){
            if(s[i]=='(' && s[i+1] == ')'){
                s.erase(i, 2);
                break;
            }
        }
        if(check == s.length())
            a = false;
        check = s.length();
    }
    ll r = 0, l = 0;
    for(ll i = 0; i < s.length(); i++){
        if(s[i]=='(') l++;
        else if(s[i]==')') r++;
    }
    for(ll i = 0; i < l; i++)
        exam.push_back(')');
    for(ll i = 0; i < r; i++)
        exam.insert(0, "(");
    cout << exam << endl;
    return 0;
}

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


int main() {
  int n,k,q;
  cin >> n >> k >> q;
  int count[n]={};
  for(int i=0;i<q;i++){
      int k=0;
      cin >> k;
      count[k-1]++;
  }
  for(int x:count){
      if(q-x<k) cout << "Yes" << endl;
      else cout << "No" << endl;
  }
}


Measured memory_bytes: 1024
#include <cstdio>
#define rg register
using namespace std;
typedef long long ll;
const int maxn=100010;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
struct data{int v,nxt;}edge[maxn<<1];
int n,k,p,x,ans,a[maxn],head[maxn],dis[maxn];
void insert(int u,int v)
{
	edge[++p]=(data){v,head[u]};head[u]=p;
	edge[++p]=(data){u,head[v]};head[v]=p;
}
void dfs(int x,int pre)
{
	dis[x]=1;
	for(int i=head[x];i;i=edge[i].nxt)
	  if(edge[i].v^pre)
	  {
		dfs(edge[i].v,x);
		getmax(dis[x],dis[edge[i].v]+1);
	  }
	if(pre^1&&dis[x]>=k){++ans;dis[x]=0;}
}
int main()
{
	read(n);read(k);read(x);
	if(x!=1) ++ans;
	for(rg int i=2;i<=n;i++){read(a[i]);insert(i,a[i]);}
	dfs(1,1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7552
#include "bits/stdc++.h"
using namespace std;
string S;
bool ok(string t)
{
	if(t.size()%2==1)
	{
		return false;
	}
	int hal=t.size()/2;
	for(int i=0;i<hal;i++)
	{
		if(t[i]!=t[i+hal])
		{
			return false;
		}
	}
	return true;
}
int main()
{
	cin>>S;
	S.erase(S.end()-1);
	while(!S.empty())
	{
		if(ok(S))
		{
			cout<<S.size()<<endl;
			break;
		}
		S.erase(S.end()-1);
	}
	return 0;
}
/*
qwqworzqwqworz
Output:4

papapapa
Output:4
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int m,n,min1;

int main()
{//asddddddddddddddasssss
	cin>>n>>m;
	min1=m/n;
	for(long long int i=min1;i>=1;i--)
	{
		if(m%i!=0) continue;
		if(m/i>=n)
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define FOR(i, a, b) for (int i = a; i < b; i++)

void print(vi &A) {
	FOR(i, 0, (int)A.size())
		printf("%d ", A[i]);
	cout << endl;
}

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

	vi A(N);
	vi B(N);
	FOR(i, 0, N) {
		scanf("%d %d", &A[i], &B[i]);
	}

	vvi dp(H + 1, vi(N + 1, INT_MAX));
	FOR(j, 0, N + 1) {
		dp[0][j] = 0;
	}

	FOR(h, 0, H + 1) {
		int curr_min = INT_MAX;
		FOR(j, 0, N) {
			int h_damage = max(0, h - A[j]);
			dp[h][j] = min(dp[h][j], dp[h_damage][N] + B[j]);

			curr_min = min(curr_min, dp[h][j]);
		}
		dp[h][N] = curr_min;
	}

	cout << dp[H][N] << endl;

	return 0;
}

Measured memory_bytes: 39680
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

//map
int main()
{
    string S;
    cin >> S;
    int cnt = 0;

    string mae = "";
    REP(i,S.size())
    {
        string tmp = "";
        tmp =  S[i];

        if(tmp == mae)
        {
            if(i == S.size()-1)break;
            tmp += S[i+1]; 
            ++i;
        }

        ++cnt;
        mae = tmp;
    }

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

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int main(){
    fastIO;
    int n;
    cin >> n;
    set<ll> ln;
    ll mx1 = 0, mx2 = 0;
    ll x;
    for(int i = 0 ; i < n ; i ++ ){
        cin >> x;
        if(ln.count(x)){
            if(x > mx1){
                mx2 = mx1;
                mx1 = x;
            }
            else if(x > mx2){
                mx2 = x;
            }
            ln.erase(x);
        }
        else{
            ln.insert(x);
        }
    }
    cout << mx1 * mx2;
    return 0;
}


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

using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    int p = 0;
    string ans;
    REPS(c, s) {
        if (c == '(') {
            ans += '(';
            p++;
        } else {
            ans += ')';
            if (p <= 0) {
                ans = '(' + ans;
            } else {
                p--;
            }
        }
    }
    REP(i, p) ans += ')';
    cout << ans << EOL;
}


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

int main() {
  int N,M;
  cin>>N>>M;
  vector<vector<int>> v(N, vector<int>(2));
  rep(i,N) cin>>v[i][0]>>v[i][1];
  vector<vector<int>> c(M, vector<int>(2));
  rep(i,M) cin>>c[i][0]>>c[i][1];
  
  rep(i,N){
    int mn=400000000;
    int ans;
    for(int j=M-1;j>=0;j--){
      int x = abs(v[i][0]-c[j][0])+abs(v[i][1]-c[j][1]);
      mn=min(mn,x);
      if(mn==x) ans=j+1;
    }
   cout<<ans<<endl;
  }   
  return 0;
}

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

bool solve(const int a[], int i) {
    int b[10] = {};
    for(int j = 1; j <= 9; ++j) {
        b[j] = a[j];
    }
    ++b[i];
    if(b[i] == 5) {
        return false;
    }
    for(int k = 1; k <= 9; ++k) {
        int c[10] = {};
        for(int l = 1; l <= 9; ++l) {
            c[l] = b[l];
        }
        if(c[k] < 2)  continue;
        else   c[k] -= 2;
        for(int j = 1; j <= 9; ++j) {
            switch(c[j]) {
                case 0  :   break; 
                case 1  :   if(j + 2 <= 9) {--c[j];   --c[j + 1];   --c[j + 2];}   break;
                case 2  :   if(j + 2 <= 9) {c[j] -= 2;   c[j + 1] -= 2;   c[j + 2] -= 2;}   break;
                case 3  :   c[j] -= 3;   break;
                case 4  :   c[j] -= 3;   if(c[j] == 1){--c[j];   --c[j + 1];   --c[j + 2];}   break;
                default :   break;
            }
        }
        bool flag = true;
        for(int j = 1; j <= 9; ++j) {
            if(c[j] != 0) {
                flag = false;
            }
        }
        if(flag)   return true;
    }
    return false;
}

int main(void) {
    string str;
    while(cin >> str) {
        int a[10] = {};
        int answer[9];
        char n;
        int end = 0;
        
        for(int i = 0; i < str.length(); ++i) {
            n = str[i];
            ++a[n - '0'];
        }
        for(int i = 1; i <= 9; ++i) {
            if(solve(a, i)) {
                answer[end] = i;
                ++end;
            }
        }
        if(end == 0) {
            cout << 0 << endl;
        } else {
            cout << answer[0];
            for(int i = 1; i < end; ++i) {
                cout << ' ' << answer[i];
            }
            cout << endl;
        }
        str = "";
    }
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int x = n / 100;
  int y = (n / 10) % 10;
  int z = n % 10;
  if (x == 7 || y == 7 || z == 7) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  ll N, K;
  std::cin >> N >> K;
  ll max_1 = N / K;
  ll max_2 = (N + K / 2) / K;

  if (K % 2 > 0) {
    std::cout << max_1 * max_1 * max_1 << '\n';
  } else {
    std::cout << max_1 * max_1 * max_1 + max_2 * max_2 * max_2 << '\n';
  }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

void run() {
	int n; cin >> n;
	Vi elems(n);
	each(e, elems) cin >> e;

	vector<ll> dp(n+1), neg(n+1);
	dp[1] = elems[0];
	neg[1] = -elems[0];

	rep(i, 1, n) {
		dp[i+1] = max(dp[i]+elems[i], neg[i]-elems[i]);
		neg[i+1] = max(dp[i]-elems[i], neg[i]+elems[i]);
	}

	cout << dp.back() << endl;
}


Measured memory_bytes: 2176