akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()

	var data []string

	for sc.Scan() {
		inputs := strings.Split(sc.Text(), " ")

		switch inputs[0] {
		case "0":
			data = append(data, inputs[1])
		case "1":
			i, _ := strconv.Atoi(inputs[1])
			fmt.Println(data[i])
		case "2":
			data = data[:len(data)-1]
		}
	}
}



Measured memory_bytes: 13664
n,q = map(int,input().split())
S = input()
sum_ = [0]*n
for i in range(1,n):
    if S[i-1] == 'A' and S[i] == 'C':
        sum_[i] = 1
for i in range(1,n):
    sum_[i] += sum_[i-1]
for i in range(q):
    l,r = map(int,input().split())
    print(sum_[r-1]-sum_[l-1])

Measured memory_bytes: 9460
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define LL long long 
#define LD long double
int n,m,vis[100005],ans1,ans2,cnt[100005];
string s;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,x;i<=m;i++)
	{
		cin>>x>>s;
		if(s[0]=='W')
		{
			if(!vis[x])
				cnt[x]++;
		}
		else
		{
			if(!vis[x])
			{
				vis[x]=1;
				ans1++;
			}
		}
	}
	for(int i=1;i<=n;i++)
		if(vis[i])ans2+=cnt[i];
	cout<<ans1<<" "<<ans2<<endl;
	return 0;
}

Measured memory_bytes: 1024
<?php

function myshuffle($array,$p,$c){
    $n=sizeof($array);
    $ret_1 = array();
    $ret_2 = array();
    for($i=0;$i<$n;$i++){
        if($i >= $p-1 && $i < $p+$c-1){
            array_push($ret_1,$array[$i]);
        }
        else{
            array_push($ret_2,$array[$i]);
        }
    }
    return array_merge($ret_1,$ret_2);
}

while(1){
    fscanf(STDIN,"%d %d\n",$n,$r);
    if($n==0 && $r==0)
        break;

    $a = array();
    for($i=0;$i<$n;$i++){
        $a[$i] = $n-$i;
    }
    
    for($i=0;$i<$r;$i++){
    fscanf(STDIN,"%d %d\n",$p,$c);        
    $a = myshuffle($a,$p,$c);
    }
    echo $a[0],"\n";
}


?>

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

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/* Manish Pant - insider_pants */

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

#define F first
#define S second
#define endl "\n"
#define pb push_back
typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fast();
    char a; cin >> a;
    if(a >= 'a')
        cout << 'a';
    else
        cout << 'A';
}

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

int main(){
    int N;
    long long B[200000];
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> B[i];
        B[i] -= i+1;
    }
    sort(B, B+N);
    long long b = B[N/2];
    long long ans = 0;
    for(int i=0; i<N; i++){
        ans += abs(B[i] - b); 
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

typedef struct {
	int x;
	int y;
}Point;

typedef struct {
	Point p1, p2;
}Line;

int main() {
	Line s1, s2;
	
	int q;
	cin >> q;

	for (int i = 0;i < q;i++) {
		cin >> s1.p1.x; 
		cin >> s1.p1.y;
		cin >> s1.p2.x;
		cin >> s1.p2.y;
		cin >> s2.p1.x;
		cin >> s2.p1.y;
		cin >> s2.p2.x;
		cin >> s2.p2.y;
		int grad1 = (s1.p1.y - s1.p2.y),grad2= (s1.p1.x - s1.p2.x);
	    int grad3 =(s2.p1.y - s2.p2.y),grad4= (s2.p1.x - s2.p2.x);
		if (grad1*grad4 == grad2*grad3) cout << 2 << endl;
		else if(grad1*grad3+grad2*grad4==0) cout << 1 << endl;
		else cout << 0 << endl;
	}

}

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

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String Sa = in.next();
            String Sb = in.next();
            String Sc = in.next();
            String ans = "A";
            String next = "a";

            StringBuilder current = new StringBuilder();
            current.append(Sa);
            while (true) {
                if (current.length() == 0) break;
                if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                }
                current.delete(0, current.length());
                if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                }
                if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                }
                if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                }
            }

            out.println(ans);
        }

    }
}



Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N,A,B;
  cin>>N>>A>>B;
  long long k=N/(A+B);
    long long amari=N%(A+B);
    if(amari>=A){cout<<k*A+A<<endl;}
  else{cout<<k*A+amari<<endl;}
}


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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define sz size()
#define S second
#define F first
#define all(x) x.begin(), x.end()

typedef pair < int, int > pii;
typedef vector < int >  vi;
typedef vector < vector < int > >  vvi;

void solve(){
    int n, ans = 0;
    ld d;
    cin >> n >> d;
    for(int i = 1; i <= n; i++){
        ld x, y;
        cin >> x >> y;
        ld ras = sqrt(x * x + y * y);
        if(ras <= d){
            ans++;
        }
    }
    cout << ans;
}

signed main() {
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}




Measured memory_bytes: 3828
import Data.List

main :: IO ()
main = do
  getLine
  as <- map read . words <$> getLine
  print $ cost as

cost :: [Int] -> Int
cost xs = sum [(x-y)^2 | x <- xs]
  where
    y   = round $ mean xs'
    xs' = map fromIntegral xs

mean :: Fractional a => [a] -> a
mean xs = sum xs / genericLength xs

Measured memory_bytes: 1020
#include <iostream>
using namespace std;
int gcd(int x,int y){
    if(x < y) swap(x,y);
    if(y == 0) return x;
    else return gcd(y,x%y);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long a,b; cin >> a >> b;
    int c,d; cin >> c >> d;
    long long lcm = (long long)c*d/gcd(c,d);
    long long bNum = b - b/d - b/c + b/lcm;
    long long aNum = a-1 - (a-1)/d - (a-1)/c + (a-1)/lcm;
    cout << bNum - aNum << endl;
    return 0;
}

Measured memory_bytes: 3616
let rec pow acc n m =
  if m = 0 then acc else pow (acc * n) n (m - 1)

let pow = pow 1

let solve n s =
  let p10_9_7 = (pow 10 9) + 7 in
  let counter = Array.make 26 0 in
  let inc c = 
    let i = Char.code c - Char.code 'a' in counter.(i) <- counter.(i) + 1 in
  for ic = 0 to (String.length s) - 1 do
    String.get s ic |> inc
  done;
  let result = ref 1 in
  for i = 0 to 25 do
    if counter.(i) > 0 then 
      result := (!result * (counter.(i) + 1)) mod p10_9_7
  done;
  (!result - 1)

let _ =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let s = Scanf.scanf "%s\n" (fun s -> s) in
  print_int @@ solve n s

Measured memory_bytes: 2816
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	string S;
	cin >> S;
	int Z = S.size();
	int a;
	int ans = 1000000000;
	rep(i, Z-2) {
					a = (S[i]-'0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0');
					ans = min(ans, abs(a - 753));

		
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin >> n;
    int arr[n];
    forn(i, n) cin >> arr[i];
    int mx = 0;
    forn(i, n) {
        forn(j, n) {
            mx = max(mx, abs(arr[i] - arr[j]));
        }
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]

use itertools::*;
use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::collections::*;

fn main() {
    input! {
        n:usize,
        k:usize,
        a:[i64;n],
    }
    let modulo = 1e9 as i64 + 7;
    let num_zero = a.iter().filter(|&&x| x == 0).count();
    if n - num_zero < k {
        println!("{}", 0);
        return;
    }
    let mut plus = a.iter().filter(|&&x| x > 0).copied().collect::<Vec<_>>();
    let mut minus = a.iter().filter(|&&x| x < 0).copied().collect::<Vec<_>>();
    let all_minus = plus.len() == 0;
    let minus_odd = minus.len() % 2 != 0;
    let just_k = plus.len() + minus.len() == k;
    let is_not_plus = (all_minus && k % 2 != 0) || (just_k && minus_odd);
    if is_not_plus {
        //絶対0以下になる場合
        let ans = if num_zero == 0 {
            let mut cand = plus.iter().chain(minus.iter()).copied().collect::<Vec<_>>();
            cand.sort_by_key(|&x| x.abs());
            let mut res = cand.iter().take(k).fold(1, |acc, &x| acc * x % modulo);
            if res < 0 {
                res = (res % modulo + modulo) % modulo;
            }
            res
        } else {
            0
        };
        println!("{}", ans)
    } else {
        let mut k = k;
        plus.sort_by_key(|&x| -x);
        minus.sort();
        let ans = if k % 2 == 0 {
            1
        } else {
            k -= 1;
            plus.remove(0)
        };
        let mut cand = vec![];
        for itr in &plus.iter().take(plus.len() / 2 * 2).chunks(2) {
            cand.push(itr.fold(1, |acc, &x| acc * x));
        }
        for itr in &minus.iter().take(minus.len() / 2 * 2).chunks(2) {
            cand.push(itr.fold(1, |acc, &x| acc * x));
        }
        cand.sort_by_key(|x| -x);
        let ans = cand
            .iter()
            .take(k / 2)
            .fold(ans, |acc, &x| x % modulo * acc % modulo);
        let ans = if ans < 0 {
            (ans % modulo + modulo) % modulo
        } else {
            ans % modulo
        };
        println!("{}", ans)
    }
}

Measured memory_bytes: 9452
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる
//時間を意識しろ
//コードテストちゃんとして
//画面とにらめっこするな書け
//WA出すたびにABCは五億円払え
//わからない問題はとばせ
//躊躇なくぐぐれ

//ここから
int main(){
    ll N,K,R,S,P;
    cin>>N>>K>>R>>S>>P;
    map<char,ll> m;
    m['s']=R;
    m['r']=P;
    m['p']=S;
    string T;
    cin>>T;
    ll Ans=0;
    rep(i,N){
        if(i-K>=0){
            if(T.at(i-K)==T.at(i)){
                T.at(i)='X';
                continue;
            }
        }
        Ans+=m[T.at(i)];
    }
    cout<<Ans<<endl;
}

Measured memory_bytes: 512
n,k=map(int,input().split())
lst1=input()
lst2=lst1.split(" ")
lst=[]
for i in lst2:
    lst.append(int(i))

minr=[]
minl=[]

for i in range(n-k+1):
    l=i
    r=i+k-1
    minr.append(abs(lst[r])+abs(lst[r]-lst[l]))
    minl.append(abs(lst[l])+abs(lst[r]-lst[l]))

minr.sort()
minl.sort()

m=min(minr[0],minl[0])
print(m)



Measured memory_bytes: 19544
import java.util.Scanner;

public class Main {
	static int maxn = 300 + 10;

	public static void main(String[] args) 
	{
		Scanner cin = new Scanner(System.in);
		String str=cin.nextLine();
		for(int i=0;i<str.length();i++)
			System.out.print("x");
	}

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
int main(){
	
	int n; cin>>n;
	string s; cin>>s;
	bool flag = true;
	if(n%2 == 1) { cout<<"No"<<"\n"; return 0;} 
	int j = (n/2);
	for(int i = 0; i < (n/2); i++){
		//cout<<s[i]<<" "<<s[j]<<"\n";
		if(s[i] != s[j]) flag = false;
		j++;
	}
	if(flag) cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
	
	
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl

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

  int a,b,c,k;
  cin>>a>>b>>c>>k;

  int ans=0;

  if(a>=k){
    ans+=(k);
    cout<<ans<<endl;
    return 0;
  }

  k-=a;
  ans+=a;

  k-=b;

  if(k>0){
 
     ans-=k;
    
  }
  cout<<ans<<endl; 
  
  
     
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
#define mod 1000000007
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;
// int d[10000001];

signed main()
{
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    std::ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (t--) {
        int a, b;
        cin >> a >> b;
        set<int> arr;
        for (int i = 1; i <= sqrt(min(a, b)); i++) {
            if (a % i == 0) {
                if (b % i == 0) {
                    arr.insert(i);
                }
                int x = a / i;
                if (b % x == 0) {
                    arr.insert(x);
                }
            }
            else if (b % i == 0) {
                if (a % i == 0) {
                    arr.insert(i);
                }
                int x = b / i;
                if (a % x == 0) {
                    arr.insert(x);
                }
            }
        }
        int cnt = 0;
        unordered_map<int, int> d;
        vector<int> ans;
        for (auto i : arr) {
            ans.push_back(i);
        }
        for (int i = 0; i < ans.size(); i++) {
            if (ans[i] != -1) cnt++;
            if (ans[i] > 1)
                for (int j = i + 1; j < ans.size(); j++) {
                    if (ans[j] % ans[i] == 0) ans[j] = -1;
                }
        }
        cout << cnt;
    }
    return 0;
}

Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
#define INF 1e9
signed main(){
    int n;
    cin>>n;
    vector<int>b(n);
    for (int i = 0; i < n; i++)
    {
        cin>>b[i];
    }
    vector<int>v;
    for (int i = 0; i < n; i++)
    {   
        int index;
        bool flag=false;
        for (int j = 0; j < b.size(); j++)
        {
            
            if(b[j]==j+1){
                index=j;
                flag=true;
              
            }
        }
        if(!flag){
            cout<<-1<<endl;
            return 0;
        }
        v.push_back(b[index]);
      //  show(b);
        b.erase(b.begin()+index);
        
    }
    reverse(ALL(v));
    for(auto &u : v){
        cout<<u<<endl;
    }
    

    return 0;
}

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

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

int main(){
    string O,E;
    string res;
    cin >> O >> E;

    if(O.size() > E.size()){
        for(int i=0;i<E.size();i++){
            res.push_back(O[i]);
            res.push_back(E[i]);
        }
        res.push_back(O[E.size()]);
    }else{
        for(int i=0;i<E.size();i++){
            res.push_back(O[i]);
            res.push_back(E[i]);
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
int1 = lambda x: int(x) - 1

N, M = map(int, input().split())
H = list(map(int, input().split()))

good = [1] * N
for _ in range(M):
    A, B = map(int1, input().split())
    if H[A] == H[B]:
        good[A] = 0
        good[B] = 0
    elif H[A] > H[B]:
        good[B] = 0
    else:
        good[A] = 0

print(sum(good))

Measured memory_bytes: 20144
h,w,K = map(int, input().split())
g = [[0]*w for _ in range(h)]
for i in range(h):
    s=input()
    for j in range(w):
        g[i][j] = s[j]
ans=1001001001
for i in range(1<<(h-1)):
    seg = [0]*h
    segnow = 0
    for j in range(h-1):
        if i & 1 << j:
            segnow += 1
        seg[j+1] = segnow

    segnow += 1
    flag = True
    div = 0
    cnt = [0 for _ in range(segnow)]
    for j in range(w):
        now = [0]*segnow
        for k in range(h):
            if g[k][j] == '1':
                cnt[seg[k]] += 1
                now[seg[k]] += 1
                if cnt[seg[k]] > K:
                    div+=1
                    for l in range(segnow):
                        cnt[l] = now[l]
        if max(now)>K:
            continue
    ans = min(ans,segnow-1+div)
print(ans)

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

def mod_pow(x, n, mod):
	res = 1
	while n > 0 : 
		if n&1 : 
			res = res * x % mod
		x = x * x % mod
		n >>= 1
	return res

ans = 0
factor = 0

for i in range(1, N):
	factor += mod_pow(i, MOD-2, MOD)
	factor %= MOD
	ans += factor * (x[i] - x[i-1])
	ans %= MOD
for i in range(1, N):
	ans = ans * i % MOD
print(ans)

Measured memory_bytes: 14252
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;

  cout << max(0, c-(a-b)) << endl;
  
  return 0;
}


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

const int INF = 1000000007;

int main(void){
    int N, K, Q; cin >> N >> K >> Q;
    vector<int> A(N);
    vector<int> cans(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        cans[i] = A[i];
    }
    sort(cans.begin(), cans.end());
    cans.erase(unique(cans.begin(), cans.end()), cans.end());
    
    int ans = INF;
    for (int i = 0; i < cans.size(); i++) {
        int can = cans[i];
        vector<vector<int>> cut;
        vector<int> tmp;
        for (int j = 0; j < N; j++) {
            if (A[j] < can) {
                if (tmp.size()) {
                    cut.push_back(tmp);
                    tmp.clear();
                }
            }
            else tmp.push_back(A[j]);
        }
        if (tmp.size()) cut.push_back(tmp);
        
        vector<int> selected;
        for (int j = 0; j < cut.size(); j++) {
            sort(cut[j].begin(), cut[j].end());
            for (int k = 0; k < (int)cut[j].size() - K + 1; k++) {
                selected.push_back(cut[j][k]);
            }
        }
        sort(selected.begin(), selected.end());
        if (Q <= selected.size()) {
            ans = min(ans, selected[Q-1] - selected[0]);
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
	int a[100];
	int N;
	cin>>N;
	int count=0;
	for(int i=0;i<N;i++)cin>>a[i];
	
	for(int i=0;i<N;i++){
		for(int j=1;j<N;j++){
			if(a[j]<a[j-1]){
				swap(a[j],a[j-1]);
				count++;
			}
		}
	}

	for(int i=0;i<N-1;i++)cout<<a[i]<<" ";
	cout<<a[N-1]<<endl;
		cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1160
/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")  */
#include <bits/stdc++.h>
 
#define file ""
 
#define all(x) x.begin(), x.end()
 
#define sc second
#define fr first
 
#define pb push_back
#define mp make_pair

#define pss pair<line*, line*>
 
using namespace std;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
                                 
const ll inf = 1e18;
const int MOD = 1e9 + 7;

const int dx[] = {-1, +1, -2, +2, -2, +2, -1, +1};
const int dy[] = {-2, -2, -1, -1, +1, +1, +2, +2};

const int N = 5e5 + 5;

ll dp[105][N];   

int main() {                
#ifdef Mask                                                         
  freopen(".in", 	"r", stdin);
  freopen(".out", "w", stdout);  
#endif
	ios_base :: sync_with_stdio(false);               
  cin.tie(nullptr); 	
  int n, W;
  cin >> n >> W;
  int w[n + 1], c[n + 1];
  for (int i = 1; i <= n; i++) {
  	cin >> w[i] >> c[i];
  }
  for (int i = 0; i < n; i++) {
  	for (int k = 0; k <= W; k++)
  		dp[i + 1][k] = dp[i][k];	
   	for (int k = 0; k <= W; k++) 
   		if (k + w[i + 1] <= W)
   			dp[i + 1][k + w[i + 1]] = max(dp[i][k] + c[i + 1], dp[i + 1][k + w[i + 1]]);
  }
  ll mx = 0;
  for (int k = 0; k <= W; k++)
  	mx = max(mx, dp[n][k]);
  cout << mx << endl;
	return 0;   
}



Measured memory_bytes: 284928
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
  
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
int stage[1024][1004];
int dp[1024][1024];
int main(){
    int h,w,n;
    while(scanf("%d%d%d",&h,&w,&n),(h|w)|n){
        rep(i,h)rep(j,w)scanf("%d",&stage[i][j]);
        memset(dp,0,sizeof(dp));
        dp[0][0] = --n;
        rep(i,h){
            rep(j,w){
                if(dp[i][j] % 2 == 0){
                    dp[i][j+1] += dp[i][j]/2;
                    dp[i+1][j] += dp[i][j]/2;
                 }
                 else{
                    if(stage[i][j] == 0){
                        dp[i+1][j] += dp[i][j]/2 + 1;
                        dp[i][j+1] += dp[i][j]/2;
                    }
                    else if(stage[i][j] == 1){
                        dp[i+1][j] += dp[i][j]/2;
                        dp[i][j+1] += dp[i][j]/2 + 1;
                    }
                 }
            }
        }
        int x = 0,y = 0;
        while(x < w && y < h){
            if(dp[y][x]%2 == 1){
                if(stage[y][x] == 0){
                    x++;
                }
                else{
                    y++;
                }
            }
            else{
                if(stage[y][x] == 0){
                    y++;
                }
                else{
                    x++;
                }
            }
        }
        printf("%d %d\n",++y,++x);
    }
    return 0;
}

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

int n, m;
long long int dp[1010][1010];
char c[1010][1010];
const int MOD = 1e9 + 7;

int main () {
	
	cin >> n >> m;
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= m; j ++) {
			cin >> c[i][j];
		}
	}
	
	dp[1][1] = 1;
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= m; j ++) {
			if (c[i][j] != '#') dp[i][j] += dp[i-1][j] + dp[i][j-1];
			dp[i][j] %= MOD;
		}
	}
	
	cout << dp[n][m];
	
	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;

int h,m,s;
int tim;

int main(){
	while(cin>>h>>m>>s,!(h==-1&&m==-1&&s==-1)){
		tim=h*3600+m*60+s;
		int rest=7200-tim;
		int tmp = rest;
		rep(i,2){
			rest=tmp;
		h=rest/3600;
		rest%=3600;
		m=rest/60;
		rest%=60;
		s=rest;
		if(h==0) cout<<"00";
		else cout<<0<<h;
		cout<<":";
		if(m==0) cout<<"00";
		else if(m<10) cout<<0<<m;
		else cout<<m;
		cout<<":";
		if(s==0) cout<<"00";
		else if(s<10) cout<<0<<s;
		else cout<<s;
		cout<<endl;
		tmp*=3;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import math

N, D = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))
c = 0
while len(X) > 1:
    x = X.pop()
    a = 0
    for i in range(len(X)):
        for j in range(len(x)):
            a += (x[j]-X[i][j])**2
        if math.sqrt(a).is_integer():
            c += 1
        a = 0
print(c)


Measured memory_bytes: 38768
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.contains("a")&&s.contains("b")&&s.contains("c")){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
large_p = 10**9 + 7
from itertools import accumulate
def main():
    n, *a = map(int, read().split())
    a2 = [ae % large_p for ae in a]
    a2a = tuple(accumulate(a2))
    r = 0
    for i1 in range(n - 1):
        t0 = a2[i1] * (a2a[-1] - a2a[i1])
        r += t0
        r = r % large_p
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 126284
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s, t;
i64 n, m;
vector<i64> pos[26];
int main() {
  cin >> s >> t;
  n = s.size();
  m = t.size();
  for (i64 i = 0; i < n; ++i) {
    i64 j = s[i] - 'a';
    pos[j].push_back(i);
  }

  i64 j = 0, l = 0;
  for (i64 i = 0; i < m; ++i) {
    i64 c = t[i] - 'a';
    if (pos[c].empty()) {
      cout << -1 << endl;
      return 0;
    }
    auto it = lower_bound(begin(pos[c]), end(pos[c]), j);
    if (it == end(pos[c])) {
      ++l;
      j = pos[c].front() + 1;
    } else {
      j = *it + 1;
    }
  }
  cout << l * n + j << endl;
  return 0;
}



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

struct Frac {
    int64_t a, b;
    Frac (int64_t _a, int64_t _b) {
        a = _a;
        b = _b;
    }

       bool operator <= (const Frac& other) {
        return __int128(a) * other.b <= __int128(b) * other.a;
    }
};

struct Line {
    int64_t a, b;
    Line (int64_t _a, int64_t _b) {
        a = _a;
        b = _b;
    }

    int64_t eval(int point) {
        return b + a * point;
    }

    Frac beats(const Line& other) {
        return Frac(b - other.b, other.a - a);
    };
};

int main() {
    int n; cin >> n;
    int64_t c; cin >> c;
    
    vector<int> h(n, 0);

    for (int i = 0; i < n; i += 1)
        cin >> h[i];        

    vector<Line> lines;
    deque<int> d;
    
    vector<int64_t> dp(n, 0);

    lines.push_back(Line(-2 * h[0], dp[0] + 1LL * h[0] * h[0]));
    d.push_back(0);

    for (int i = 1; i < n; i += 1) {
        while (d.size() >= 2 and lines[d[0]].eval(h[i]) >= lines[d[1]].eval(h[i]))
            d.pop_front();

        dp[i] = 1LL * h[i] * h[i] + c + lines[d.front()].eval(h[i]);

        auto new_line = Line(-2 * h[i], dp[i] + 1LL * h[i] * h[i]);
        lines.push_back(new_line);

        while (d.size() >= 2 and new_line.beats(lines[d[d.size() - 1]]) <= lines[d[d.size() - 1]].beats(lines[d[d.size() - 2]]))
            d.pop_back();
        d.push_back(i);
    }

    cout << dp[n - 1] << "\n";
}

Measured memory_bytes: 8816
#include<bits/stdc++.h>
using namespace std;
int dp[1002][1002];
int main()
{
	int t;
	int n,x;
	cin>>n>>x>>t;
	int val=n/x;
	int sum=0;
	sum+=val*t;
	if(n%x!=0)
		sum+=t;
	cout<<sum;
}

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

#define REP(i, n) for(int i=0; i<n; i++)

using namespace std;

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

  vector<int> v;
  int x;

  while(true) {
    std::cin >> x;
    if(x != 0) v.push_back(x);
    else break;
  }

  int count[v.size()];

  REP(i, v.size()) {
    count[i] = 0;
    for(int j=1; j<=v[i]/2; j++) {
      int sum = 0;
      for(int k=j; sum<v[i]; k++) {
        sum += k;
        if(sum == v[i]) count[i]++;
      }
    }
  }

  REP(i, v.size()) std::cout << count[i] << '\n';
}



Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
#define int long long
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
using namespace std;
#define hash hush
typedef long long ll;
typedef long double ld;
signed  main() {
	int a[13]={0,0,1,0,2,0,2,0,0,2,0,2,0};
	int x,y;
	cin>>x>>y;
	if(a[x]==a[y]){
		cout<<"Yes\n";
	}
	else{
		cout<<"No"<<endl;
	}
	getchar(); getchar();
}


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


int main(){
    int n, max_n=0;
    cin >> n;
    map<string, int> S;
    for (int i=0; i<n; i++){
        string s;
        cin >> s;
        if (S.count(s)){
            S[s]++;
        }
        else{
            S[s] = 1;
        }
        max_n = max(max_n, S[s]);
    }

    for(auto s: S){
        if (s.second == max_n){
            cout << s.first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 25216
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
signed main() {
	int w; cin >> w; cout << w * 32 << endl;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000


int main(){
	long long N,C,K;
	cin>>N>>C>>K;
	
	vector<long long> T(N);
	for(int i=0;i<N;i++)cin>>T[i];
	
	sort(T.begin(),T.end());
	
	int cnt = 0;
	long long t = 0;
	int ans = 0;
	
	for(int i=0;i<N;i++){
		if(cnt==0){
			t = T[i];
			ans ++;
			cnt=1;
		}
		else{
			if(t+K<T[i]){
				ans++;
				cnt=1;
				t=T[i];
			}
			else{
				cnt++;
			}
		}
		if(cnt==C){
			cnt=0;
		}
		
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
b = input()

sut = 0
a = ""
for i,s in enumerate(b):
    if i < n-1:
        if b[i] == b[i+1]:
            sut += 1
        else:
            a += s
    else:
        a+=s
a

count = len(a)
for i in range(k):
    if count <= 1:
        break
    elif count >= 3:
        sut += 2
        count -= 2
    elif count == 2:
        sut += 1
        break
print(sut)

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

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ign cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int>> MAT;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef map<int,int> MCI;
typedef unordered_map<int,int> UMII;
typedef unordered_map<ll,ll> UMLL;
typedef unordered_map<char,int> UMCI;
typedef set<int> SI;
typedef unordered_set<int> USI;

// Display Map
//~for (auto const& pair: m) {
//~std::cout << "{" << pair.first << ": " << pair.second << "}\n";
//~}

// Extract word(w) from sentence(s)
//~stringstream str(s);
//~string w;
//~while(str >> w){
//~// w is your word
//~}

//Memset Syntax
// memset(array, value,sizeof(array)) val is 0,-1 or bool only

// To get accurate precision
//~cout.precision(20);

// Concatinate Vectors
//~

int main() {
    fast_io;
	int x;
	cin >> x;
	if(x >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;
	
}


Measured memory_bytes: 3604
#include<stdio.h>


int main(void){
  int n;
  int i,j,k;
  int b,c,d,e;
  int a[4][3][10];


 for(i=0;i<3;i++){
    for(j=0;j<10;j++){
      a[0][i][j]=0;
      a[1][i][j]=0;
      a[2][i][j]=0;
      a[3][i][j]=0;
    }
  }
  scanf("%d",&n);

 

  for(i=0;i<n;i++){
    scanf("%d",&b);
   scanf("%d",&c);
   scanf("%d",&d);
   scanf("%d",&e);
   a[b-1][c-1][d-1]+=e;
  }
 for (i=0;i<4-1;i++){
    for (j=0;j<3;j++){
      for (k=0;k<10;k++){
        printf(" %d",a[i][j][k]);
      }
      printf("\n");
    }
    printf("####################\n");
  }
 
  for (j=0;j<3;j++){
    for (k=0;k<10;k++){
      printf(" %d",a[3][j][k]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1812
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>
#include <cstdio>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
//priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;

void solve(){
  cin >> n;
  if(n>=65 && n<=90)cout << 1;
  else if(n>=97 && n<=122)cout << 2;
  else cout << 0;
  cout << endl;
}

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



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
int A, B, N;
int main(){
  int x, y;
  rd(N);
  rd(A);
  rd(B);
  x =min_L(A, B);
  y =max_L(0, A+B-N);
  wt_L(x);
  putchar_unlocked(' ');
  wt_L(y);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20180730-1

// --- original code ---
// int N, A, B;
// {
//   int x, y;
//   rd(N,A,B);
//   x = min(A,B);
//   y = max(0, A+B-N);
//   wt(x,y);
// }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
int main()
{
	FAST
	#ifdef ayk_16
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	string s,t;
	cin>>s>>t;
	string ans=t+s;
	cout<<ans;
}

Measured memory_bytes: 256
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;
#define int long long


//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int H,N;
  cin >> H >> N;
  vector<int> A,B;
  A.resize(N);
  B.resize(N);
  for(int i = 0 ; i < N ; i++){
  	cin >> A[i] >> B[i];
  }

  vector<int> dp(50001);
  fill(dp.begin() , dp.end(), -1);


  dp[0] = 0;
  for(int i = 0 ; i < 20001 ; i++){
  	if(dp[i] != -1 || i == 0){
  		for(int magic = 0 ; magic < N ; magic++){
  			if(dp[i + A[magic]] == -1){
  				dp[i + A[magic]] = dp[i] + B[magic];
  			}
  			else{
 	 			dp[i + A[magic]] = min(dp[i] + B[magic],dp[i+A[magic]]);
  			}
  		}
  	}
  }
  int ans = llINF;
  for(int i = H; i < 20001; i++){
  	if(dp[i] > 0){
  		ans = min(ans,dp[i]);
  	}
  }
  cout << ans << endl;


  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

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

#define MAX(a,b) ((a)>(b)?(a):(b))

int LCS(string& wordA, string& wordB) {
	int i,j;
	int sizeA, sizeB;
	vector<vector<int> > lcs;
	sizeA=(int)wordA.size();
	sizeB=(int)wordB.size();
	lcs.resize(sizeA+1);
	lcs[0].resize(sizeB+1);
	for(i=0; i<=sizeB; ++i) {
		lcs[0][i]=0;
	}
	for(i=1; i<=sizeA; ++i) {
		lcs[i].resize(sizeB+1);
		lcs[i][0]=0;
		for(j=1; j<=sizeB; ++j) {
			if(wordA[i-1]==wordB[j-1]) lcs[i][j]=lcs[i-1][j-1]+1;
			else lcs[i][j]=MAX(lcs[i-1][j],lcs[i][j-1]);
		}
	}
	return lcs[sizeA][sizeB];
}

int main() {
	int i,j,k,q;
	cin >> q;
	string wordA,wordB;
	for(i=0; i<q; ++i) {
		cin >> wordA >> wordB;
		cout << LCS(wordA, wordB) << endl;
	}
	return 0;
}

Measured memory_bytes: 6852
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1<<12, mod = 998244353 , lg = 19;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll x = 12;//CHANGE TO 12
const ll full = (1<<x)-1;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++) {
		if((i&1)&&s[i]=='R') return cout << "No", 0;
		if(!(i&1)&&s[i]=='L') return cout << "No", 0;
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define itn int
#define lli long long int
#define REP(a,n) for(int i=a;i < n;i++)
#define REP2(a,n) for(int j = a;j<n;j++)
using namespace std;
int main(void) {
	int n;
  	scanf("%d",&n);
	int min;
	int temp = 0;
	int count = 1;
	scanf("%d", &min);
	for (int i = 1; i < n; i++) {
		scanf("%d", &temp);
		if (temp <= min) {
			min = temp;
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

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

static bool board[64];
static char queens[8][9];

static void fill(bool *b, size_t x, size_t y) {
  b[8*y+x] = true;
  for (size_t i = 0; i < 8; i++)
    b[8*y+i] = b[8*i+x] = true;
  for (size_t i = x - std::min(x, y), j = y - std::min(x, y); i < 8 && j < 8; i++, j++)
    b[8*j+i] = true;
  for (size_t i = x + std::min(7 - x, y), j = y - std::min(7 - x, y); i < 8 && j < 8; i--, j++)
    b[8*j+i] = true;
}

static bool rec(bool *board, size_t z, size_t n) {
  if (n == 0)
    return true;
  for (; z < 64; z++) {
    size_t x = z % 8, y = z / 8;
    for (; y < 8; y++, x = 0)
      for (; x < 8; x++)
        if (!board[8*y+x]) {
          bool b[64];
          std::copy(board, board + 64, b);
          fill(b, x, y);
          if (rec(b, 8 * y + x + 1, n - 1)) {
            queens[y][x] = 'Q';
            return true;
          }
        }
  }
  return false;
}

int main() {
  for (size_t i = 0; i < 8; i++)
    std::fill(queens[i], queens[i] + 8, '.');
  size_t k;
  scanf("%zu", &k);
  for (size_t i = 0; i < k; i++) {
    size_t r, c;
    scanf("%zu%zu", &r, &c);
    board[8*r+c] = true;
    queens[r][c] = 'Q';
    fill(board, c, r);
  }
  rec(board, 0, 8 - k);
  for (size_t i = 0; i < 8; i++)
    puts(queens[i]);
  return 0;
}

Measured memory_bytes: 2656
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,sum=0,ans=INT64_MAX,l=0; cin>>n; 
    int  a[n];
    for (int i=0;i<n;i++) {
        cin>>a[i]; 
        sum += a[i];
    }
    for (int i=0;i<n-1;i++){
        l += a[i];
        sum -= a[i];
        ans = min(ans,abs(sum-l));
    }
    cout << ans << endl;
    return;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 5200