akhauriyash/Code-Regression huggingface dataset:
/*input
1 1
snuke
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	string s="aeiou";
	char c;cin>>c;
	REP(i,SZ(s)){
		if(s[i]==c){
			cout<<"vowel\n";
			return 0;
		}
	}
	cout<<"consonant\n";

	return 0;
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;

	vector<int> a;
	ll sum = 0;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.pb(t);
		sum += t;
	}

	ll snuke = a[0];
	ll ans = INF;
	for(int i=1; i<n; i++){
		ans = min(ans, abs(snuke - (sum - snuke)));
		snuke += a[i];
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1400
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
ans = sum(A)
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    if cnt.get(b) is None:
        alt = 0
    else:
        alt= cnt[b]
        cnt[b] = 0
    cnt[c] += alt
    ans += (c - b) * alt
    #print(cnt)
    print(ans)

Measured memory_bytes: 21296
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            long[] Ai = new long[N], Bi = new long[N];
            for(var i=0;i<N;++i)
            {
                var ab = Sarray();
                Ai[i] = ab[0];
                Bi[i] = ab[1];
            }
            Array.Sort(Ai);
            Array.Sort(Bi);
            if (N % 2 == 1)
            {
                var l = Ai[N / 2];
                var r = Bi[N / 2];
                WriteLine(r - l + 1);
            }
            else
            {
                var l = Ai[N / 2 - 1] + Ai[N / 2];
                var r = Bi[N / 2 - 1] + Bi[N / 2];
                WriteLine(r - l + 1);
            }
        }
    }
}

Measured memory_bytes: 50004
N = int(input())
A = list(map(int,input().split()))

L = []
pos = 0
for i in range(N):
    x = abs(pos-A[i])
    pos = A[i]
    L.append(x)
L.append(abs(A[-1]))

cs = [0]
for i in range(N+1):
    x = L[i]+cs[-1]
    cs.append(x)
m = cs[-1]
#print(L,cs)

for i in range(N):
    x = m - L[i]-L[i+1]
    if i == 0:
        x += abs(0-A[i+1])
    elif i == N-1:
        x = cs[-3] + abs(A[N-2])
    else:
        x += abs(A[i-1]-A[i+1])
    print(x)

Measured memory_bytes: 58860
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),ans=0;
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i=0; i<n; i++) {
			a[i] = sc.nextInt();
		}
		for(int i=0; i<n; i++) {
			b[i] = sc.nextInt();
		}
		for(int i=0; i<n; i++) {
			if(a[i]-b[i] > 0) ans += a[i]-b[i];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    int ans[n] = {};
    int flag[n+1] = {};
    int count = 0;
    int j = 0;
    rep(i,n){
        flag[a[i]]++;

        if(flag[a[i]] == 1 && a[i] <= k)count++;

        if(count < k){
            ans[i] = 0;
        }else{
            while(flag[a[j]] >= 2 || a[j] > k){
                flag[a[j]]--;
                j++;
            }
            ans[i] = i - j + 1;
        }
    }

    int res = 1001001001;
    rep(i,n){
        if(ans[i] == 0)continue;
        res = min(res, ans[i]);
    }
    if(res == 1001001001)res = 0;
    cout << res << endl;
    
    return 0;
}
 
 



Measured memory_bytes: 4296
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k;
    cin>>n>>k;
    vi x(n),y(n);
    vi xarr,yarr;

    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        xarr.pb(x[i]);
        yarr.pb(y[i]);
    }
    sort(xarr.begin(),xarr.end());
    sort(yarr.begin(),yarr.end());
    ll ans=1LL*(xarr[n-1]-xarr[0])*(yarr[n-1]-yarr[0]);

    for(int xi=0;xi<n;xi++){
        for(int xj=xi+1;xj<n;xj++){
            for(int yi=0;yi<n;yi++){
                for(int yj=yi+1;yj<n;yj++){

                    int num=0;
                    ll lx=xarr[xi],rx=xarr[xj];
                    ll by=yarr[yi],uy=yarr[yj];

                    for(int i=0;i<n;i++){
                        if(lx<=x[i] && x[i]<=rx && by<=y[i] && uy>=y[i]){
                            num+=1;
                        }
                    }

                    if(num>=k){
                        ans=min(ans,1LL*(rx-lx)*(uy-by));
                    }

                }
            }
        }
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){int n;cin>>n;vector<int>a(n);vector<int>b(n,0);for(int i=0;i<n;i++)cin>>a.at(i);
           int x=0;for(int i=1;i<=n;i++){x=a.at(x)-1;if(x==1){cout<<i<<endl;break;}if(b.at(x)){cout<<-1<<endl;break;}b.at(x)=1;}}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int S, N;
    string str;
    cin >> S;
    cin >> N;
    cin >> str;
    str[N - 1] += 32;
    cout << str << endl;
}

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

int main(){
	int H, W, b_cnt, x, y;
	long long cnt;
	bool flag;
	cin >> H >> W;
	char a[H][W];
	char d[H][W];
	array<int, 2> crd;
	vector<array<int, 2>> black;
	vector<array<int, 2>> new_black;

	for(int j=0; j<H; j++){
		for(int i=0; i<W; i++){
			cin >> a[j][i];
		}
	}
	b_cnt = 0;
	for(int j=0; j<H; j++){
		for(int i=0; i<W; i++){
			crd[0] = j;
			crd[1] = i;
			if(a[j][i] == '#'){
				black.push_back(crd);
				b_cnt++;
			}
		}
	}
	cnt = -1;
	new_black.clear();
	while(black.size() != 0){
	for(int i=0; i<black.size(); i++){
		x = black[i][0];
		y = black[i][1];
		if(x != 0){
			if(a[x-1][y] == '.'){
				a[x-1][y] = '#';
				crd[0] = x-1;
				crd[1] = y;
				new_black.push_back(crd);
				b_cnt++;
			}
		}
		if(x != H-1){
			if(a[x+1][y] == '.'){
				a[x+1][y] = '#';
				crd[0] = x+1;
				crd[1] = y;
				new_black.push_back(crd);
				b_cnt++;
			}
		}
		if(y != 0){
			if(a[x][y-1] == '.'){
				a[x][y-1] = '#';
				crd[0] = x;
				crd[1] = y-1;
				new_black.push_back(crd);
				b_cnt++;
			}
		}
		if(y != W-1){
			if(a[x][y+1] == '.'){
				a[x][y+1] = '#';
				crd[0] = x;
				crd[1] = y+1;
				new_black.push_back(crd);
				b_cnt++;
			}
		}
	}
	//for(int j=0; j<H; j++){
	//	for(int i=0; i<W; i++){
	//		cout << a[j][i];
	//	}
	//	cout << endl;
	//}
	//cout << endl;
	 
	black = new_black;
	new_black.clear();
	cnt++;
	}
	cout << cnt << endl;
	return 0;

	
	

}

Measured memory_bytes: 14184
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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 ll = long long;

const std::string P[] = { "dream", "dreamer", "erase", "eraser" };

std::string S;

int main()
{
  std::cin >> S;

  ll p = S.size();

  while( p > 0 )
  {
    ll prvp = p;

    rep( i, 4 )
    {
      if( p >= P[i].size() && S.substr( p-P[i].size(), P[i].size() ) == P[i] )
      {
        p -= P[i].size();

        break;
      }
    }
    
    if( prvp == p )
    {
      std::cout << "NO" << std::endl;

      return 0;
    }
  }

  std::cout << "YES" << std::endl;

  return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int k;
    cin>>s>>k;
    set<string> se;
    int n=s.length();
    for(int i=0;i<n;i++){
        for(int j=1;j<=5&&i+j<=n;j++){
            se.insert(s.substr(i,j));
        }
    }
    set<string>::iterator itr;
    itr=se.begin();
    for(int i=1;i<k;i++)itr++;
    cout << *itr<<endl;

    return 0;
}



Measured memory_bytes: 1664
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

string hissan(string a, string b) {
    if (a.size() < b.size()) a.swap(b);
    int bi = b.size() - 1;
    int c = 0;
    string ans;

    for (int i = a.size() - 1; i >= 0; i--) {
        int _a = a[i] - '0';
        int _b = (bi >= 0) ? b[bi--] - '0' : 0;
        int x = _a + _b + c;

        if (x < 10) {
            c = 0;
        }
        else {
            x -= 10;
            c = 1;
        }
        ans.insert(0, to_string(x));
    }

    if (c) ans.insert(0, "1");

    return ans;
}

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

    cin >> n;
    while(n--) {
        cin >> a;
        cin >> b;
        string x = hissan(a, b);
        cout << ((x.size() > 80) ? "overflow" : x) << endl;
    }
    return 0;
}



Measured memory_bytes: 3168
def ALDS1_2_A():
    """
    1 bubbleSort(A, N) // N 個の要素を含む 0-オリジンの配列 A
    2   flag = 1 // 逆の隣接要素が存在する
    3   while flag
    4     flag = 0
    5     for j が N-1 から 1 まで
    6       if A[j] < A[j-1]
    7         A[j] と A[j-1] を交換
    8         flag = 1

    ＜問題＞
    数列 A を読み込み、バブルソートで昇順に並び変え出力するプログラムを作成してください。
    また、バブルソートで行われた要素の交換回数も報告してください。

    ＜入力＞
    入力の最初の行に、数列の長さを表す整数 N が与えられます。２行目に、N 個の整数が空白区切りで与えられます。

    ＜出力＞
    出力は 2 行からなります。１行目に整列された数列を 1 行に出力してください。数列の連続する要素は１つの空白で区切って出力してください。
    2 行目に交換回数を出力してください。

    ＜制約＞
    1 ≤ N ≤ 100
    0 ≤ A の要素 ≤ 100
    """
    N = int(input())
    A = [int(e) for e in input().split(" ")]
    flag = 1    # A[j] < A[j-1] の要素が存在するかのflag変数
    switch_cnt = 0
    idx_not_sorted = 0
    while flag:
        flag = 0
        for j in range(N-1, idx_not_sorted, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                switch_cnt += 1
                flag = 1
        idx_not_sorted += 1
    print(" ".join(map(str, A)))
    print(switch_cnt)


def main():
    ALDS1_2_A()


if __name__ == '__main__':
    main()


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

int main() {
  long int N, K, n;
  cin >> N >> K;
  if(N <= 0)
    n = N;
  else {
    long int q = N % K;
    n = min(q, K - q);
  }
  cout << n << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int vertical = sc.nextInt();
            int horizontal = sc.nextInt();
            int size = vertical * horizontal;
            int circuit = 2 * vertical + 2 * horizontal;
            StringBuffer sb = new StringBuffer(size + " " + circuit);
            System.out.println(sb);
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            sc.close();
        }
    }
}

Measured memory_bytes: 17160
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long MOD = 998244353;

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

	int n, d;
	cin >> n;
	ll* num = new ll[n];
	memset(num, 0, sizeof(ll)*n);
	int maxNum = 0;

	rep(i, n) {
		cin >> d;
		++num[d];
		if (i == 0 and d != 0) {
			cout << 0 << "\n";
			return 0;
		}
		if (i > 0 and d == 0) {
			cout << 0 << "\n";
			return 0;
		}
		maxNum = max(maxNum, d);
	}

	if (num[0] != 1) {
		cout << 0 << "\n";
		return 0;
	}

	ll ans = 1;
	REP(i, 2, maxNum + 1) rep(j, num[i]) ans = (ans * num[i - 1]) % MOD;

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1024
import bisect
n = int(input())
L = sorted(map(int, input().split()))
m = L[-1]
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        k = L[i] + L[j]
        ans += bisect.bisect_left(L, k) - j-1
print(ans)


Measured memory_bytes: 9372
x,y=map(int,input().split())
lol=[]
for _ in range(x):
    lol.append(list(input()))
w=0
for i in range(x):
    for j in range(y):
        if lol[i][j]==".":
            yo=[]
            for k in lol:
                yo.append(k[:])
            
            s=[[i,j]]
            v=[0]
            while len(s)!=0:
                l=s.pop(0)
                k=v.pop(0)
                w=max(w,k)
                a=l[0]
                b=l[1]
                yo[a][b]="#"
                if 0<=a+1<x:
                    if yo[a+1][b]==".":
                        s.append([a+1,b])
                        v.append(k+1)
                        yo[a+1][b]="#"
                if 0<=a-1<x:
                    if yo[a-1][b]==".":
                        s.append([a-1,b])
                        v.append(k+1)
                        yo[a-1][b]="#"
                if 0<=b-1<y:
                    if yo[a][b-1]==".":
                        s.append([a,b-1])
                        v.append(k+1)
                        yo[a][b-1]="#"
                if 0<=b+1<y:
                    if yo[a][b+1]==".":
                        s.append([a,b+1])
                        v.append(k+1)
                        yo[a][b+1]="#"
print(w)                        

Measured memory_bytes: 51436
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    let v: Vec<i32> =  s.chars().map(|c| ((c as u8) - b'0') as i32).collect();

    for bit in 0..(1 << 3) {
        let mut sum = v[0];
        for i in 0..3 {
            if bit & (1 << i) == 0 {
                sum += v[i+1];
            } else {
                sum -= v[i+1];
            }
        }
        if sum == 7 {
            let mut ans = String::new();
            for i in 0..3 {
                let op;
                if bit & (1 << i) == 0 {
                    op = "+";
                } else {
                    op = "-";
                }
                ans = format!("{}{}{}", ans, v[i], op);
            }
            ans = format!("{}{}", ans, v[3]);
            println!("{}=7", ans);
            return;
        }
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  int x = N % 10;
  if (x == 2 or x == 4 or x == 5 or x == 7 or x == 9) {
    cout << "hon" << endl;
  } else if (x == 0 or x == 1 or x == 6 or x == 8) {
    cout << "pon" << endl;
  } else {
    cout << "bon" << endl;
  }
  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;
 
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
 
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
 
int main(void)
{
    int n;
    cin >> n;
	ll ans = 0;
    REP(i, n){
      	int a;
      	cin >> a;
		ans += (a-1);
    }
    pr(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin>>m>>n; ll a[m][n]; for(ll i=0;i<m;i++) for(ll j=0;j<n;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back
#define N_ cout<<"\n"
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
 
const ll maxs = 1e6+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9+7;
//MODULO OPEARTIONS
inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }
//POWER
ll fastpow(ll x,ll y)
{ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}
//MODULAR INVERSE
ll inv(ll x){ return pow(x , mod - 2);}

ll fact[maxs];
ll fib[maxs];
ll ncr[maxs1][maxs1];
bool vis[maxs];
vector<ll>graph[maxs];

//FACTORIAL
void FACT()
{fact[0]=1;for(ll i=1; i<maxs; i++)fact[i] = (i % mod * fact[i-1] % mod) % mod;}
//FIBONACCI
void FIB()
{ fib[0]=0; fib[1]=1; for(ll i=2; i<maxs; i++)fib[i] = (fib[i-1] % mod + fib[i-2] % mod)% mod;}
//NCR
void NCR()
{ll i,j;ncr[1][0] = 1;ncr[1][1] = 1;for(i=2; i<maxs1; i++){for(j=0; j<=i; j++) { if(j==0)ncr[i][j]=1;else ncr[i][j] = (ncr[i-1][j] + ncr[i-1][j-1] ) % mod;} }}
//PRIME CHECK
bool soe(ll n)
{ bool prime[maxs+1];memset(prime, true, sizeof(prime));for (ll p=2; p*p<=maxs; p++) { if (prime[p] == true){ for (ll i=p*p; i<=maxs; i += p) prime[i] = false; } }
 if(prime[n]) return true;else return false;}    



int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   ain;
    ll sum = 0;
    ll sum1 = 0;
  //  mid = 20;
    ll minn = LLONG_MAX;
     for(ll j = 1;j <= 100;j++)
    {
         sum = 0;
       for(i = 0;i < n;++i)
        sum += (a[i] - j) * (a[i] - j);
        
        minn = min(minn,sum);
       
    }
    cout << minn;
}

Measured memory_bytes: 24832
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
 
		Scanner sc = new Scanner(System.in);
 
		int a = sc.nextInt();
		int b = sc.nextInt();
 
			System.out.println(a*a-b);
 
		
 
	}
 
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long a[10000],k,ans,n;
bool cmp(long long a,long long b)
{
	return a>b;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i =1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n,cmp);
	for(int i =1;i<=k;i++) ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

S = input().rstrip()
N = len(S)
mod = 10**9 + 7
cnt = 0
A = B = C = 0
for c in S:
    if c == 'A':
        A += pow(3, cnt, mod)
    if c == 'B':
        B += A
    if c == 'C':
        C += B
    if c == '?':
        C = C * 3 + B
        B = B * 3 + A
        A = A * 3 + pow(3, cnt, mod)
        cnt += 1
    A %= mod
    B %= mod
    C %= mod
print(C)

Measured memory_bytes: 41580
import java.util.Arrays;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static class Prob implements Comparable<Prob>{
		int[] array;

		public Prob(int[] array){
			this.array = array;
		}
		
		@Override
		public boolean equals(Object o){
			if(o instanceof Prob){
				Prob ano = (Prob) o;
				
				for(int i = 0; i < array.length; i++){
					if(ano.array[i] != this.array[i]){
						return true;
					}
				}
				
				return false;
			}
			
			return false;
		}
		
		@Override
		public String toString(){
			StringBuilder sb = new StringBuilder();
			
			for(int i = 0; i < array.length; i++){
				if(array[i] == 0){
					break;
				}
				
				sb.append(i == 0 ? "" + array[i] : " " + array[i]);
			}
			
			return sb.toString();
		}
		
		@Override
		public int hashCode(){
			int sum = 0, val = 1;
			
			for(int i = 0; i < array.length; i++ , val *= array.length){
				sum += array[i] * val;
			}
			
			return sum;
		}
		
		@Override
		public int compareTo(Prob arg0) {
			
			for(int i = 0; i < this.array.length; i++){
				if(this.array[i] > arg0.array[i]){
					return -1;
				}else if(this.array[i] < arg0.array[i]){
					return 1;
				}
			}
			
			return 0;
		}
		
		
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			final int n = sc.nextInt();

			if (n == 0) {
				break;
			}
			
			PriorityQueue<Prob> queue = new PriorityQueue<Prob>();
			TreeSet<Prob> tree = new TreeSet<Prob>();
			int[] arr = new int[n];
			arr[0] = n;
			queue.add(new Prob(arr));
			
			while(!queue.isEmpty()){
				Prob pro = queue.poll();
				
				if(tree.contains(pro)){
					continue;
				}else{
					tree.add(pro);
				}
				
				int pre_p = -1;
				for(int i = n - 1; i >= 0; i--){
					if(pro.array[i] <= 1 || pre_p == pro.array[i]){
						continue;
					}
					
					int pre = -1;
					for(int j = i + 1; j < n; j++){
						if(pro.array[j] == pre){
							continue;
						}
						
						if(pro.array[i] - pro.array[j] >= 2){
							int[] tmp = pro.array.clone();
							tmp[i]--;
							tmp[j]++;
							queue.add(new Prob(tmp));
						}
						
						pre = pro.array[j];
					}
					
					pre_p = pro.array[i];
				}
			}
			
			for(Prob p : tree){
				System.out.println(p);
			}
			
		}

	}

}

Measured memory_bytes: 15000
// B FizzBuzz sum
#include <algorithm>
#include <complex>
#include <string>
#include <deque>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <queue>
#include <utility>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main() {
    ll N;
    ll sum = 0;
    cin >> N;
    for(int i = 1; i <= N; i++) {
        if(i%3 == 0 || i%5 == 0){
            continue;
        }
        // cout << i << endl;
        sum += i;
    }
    
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>

int main(void)
{
	float m5, m10;
	
	while (scanf("%f %f", &m5, &m10) != EOF){
		if (35.5 > m5 && 71 > m10){
			printf("AAA\n");
		}
		else if (37.5 > m5 && 77 > m10){
			printf("AA\n");
		}
		else if (40 > m5 && 83 > m10){
			printf("A\n");
		}
		else if (43 > m5 && 89 > m10){
			printf("B\n");
		}
		else if (50 > m5 && 105 > m10){
			printf("C\n");
		}
		else if (55 > m5 && 116 > m10){
			printf("D\n");
		}
		else if (70 > m5 && 148 > m10){
			printf("E\n");
		}
		else {
			printf("NA\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 604
import sys
input = sys.stdin.readline


n = int(input())

a = []
b = []

for i in range(n):
    aa,bb = map(int,input().split())
    a.append(aa)
    b.append(bb)

s = 0
res = 0
for i in range(n-1,-1,-1):
    a[i] += res

    if a[i]%b[i] == 0:
        continue
    
    res += b[i]-(a[i]%b[i])
print(res)

Measured memory_bytes: 51292
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int a[101];
int c[101],d[101];
int main()
{
	int n;
	scanf("%d",&n);
	int sum=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
		
	int m;
	scanf("%d",&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&c[i],&d[i]);
		printf("%d\n",sum-a[c[i]-1]+d[i]);
	}
	
		
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] dp = new int[100010];
		for(int i = 0 ; i < 100010 ; i++) dp[i] = Integer.MAX_VALUE;
		dp[0] = 0;
		for(int i = 0 ; i < n ; i++) {
			for(int pow6 = 1 ; i + pow6 <= n ; pow6 *= 6) dp[i + pow6] = Math.min(dp[i] + 1, dp[i + pow6]);
			for(int pow9 = 1 ; i + pow9 <= n ; pow9 *= 9) dp[i + pow9] = Math.min(dp[i] + 1, dp[i + pow9]);
		}
		System.out.println(dp[n]);
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll mod = 1000000007;

void solve()
{
	int n,d,a; cin >> n >> d >> a;
	vector<P> enem(n);
	rep(i, n)cin>> enem[i].first >> enem[i].second;
	sort(all(enem));
	queue<P> q;
	ll damage=0;
	ll ans=0;
	rep(i, n)
	{
		while(q.size() && q.front().first < enem[i].first)
		{
			damage -= q.front().second;
			q.pop();
		}
		enem[i].second -= damage;
		if(enem[i].second > 0)
		{
			ll times = (enem[i].second+a-1)/a;
			q.push(make_pair(enem[i].first+2*d,a*times));
			ans += times;
			damage += a*times;
		}
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define fo(x, n) for(int i = x; i <= n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector <int> vi;
const int MOD = 1e9 + 7;
void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b / a, c);
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
    //cin >> T;
    fo(1, T){
        solve();
    }
}




Measured memory_bytes: 256
#include<stdio.h>

void trace(int A[],int N){
  int i;
  for( i = 0; i < N; i++ ){
    if( i > 0 )
      printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int A[],int N){
  int j,i,v;
  
  for( i =1 ; i < N; i++ ){
    v = A[i];
    j = i-1;
    while( j >= 0 && A[j] > v ){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A,N);
  }
}

int main(){
  int N,i,j;
  int A[100];

  scanf("%d",&N);
  for( i = 0; i < N; i++)
    scanf("%d",&A[i]);
  
  trace(A,N);
  insertionSort(A,N);

  return 0;
}



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

const int L = 1e6 + 1;
vector<bool> p(L);
vector<int> g(L);

void solve() {
    // INPUT
    int n; cin >> n;
    set<int> st;
    bool pairwise = true;
    int cp = 0;
    for (int i = 0; i < n; ++i) { 
        int a;
        cin >> a;
        if (st.count(a) && a != 1) pairwise = false;
        st.insert(a);
        cp = __gcd(cp, a);
    }

    // LOGIC
    for (int i = 2; i <= L; i++) {
        int tmp = 0;
        for (int j = i; j <= L; j += i) {
            tmp += st.count(j);
        }
        if (tmp > 1 || !pairwise) {
            pairwise = false;
            break;
        }
    }

    if (pairwise) cout << "pairwise coprime\n";
    else if (cp == 1) cout << "setwise coprime\n";
    else cout << "not coprime\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    while(t--) {
        solve();
    }
}


Measured memory_bytes: 54000
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N,M; cin >> N >> M;
    vector<string> A(N);
    vector<string> B(M);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<M;i++){
        cin >> B[i];
    }
    bool f=false;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            bool mm=true;
            for(int y=0;y<M;y++){
                for(int x=0;x<M;x++){
                    if(i+y>=N || i+x>=N){
                        mm=false;
                        continue;
                    }
                    if(A[i+y][j+x]!=B[y][x]) mm=false;
                }
            }
            if(mm) f=true;
        }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5, MOD = 1e9+7;
typedef long long ll;
#define int long long
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> terms;
	int t;
	for(t=1;t*t<=n; t++) {
		terms.push_back(n/t);
	}
	t--;
	vector<int> arr;
	for(int i=1; i<=t; i++) {
		arr.push_back(1);
	}
	if(terms.back()-t > 0)
		arr.push_back(terms.back()-t);
	for(int i=(int)terms.size()-1; i>0; i--) {
		arr.push_back(terms[i-1]-terms[i]);
	}
	vector<vector<int>> dp(k, vector<int>(arr.size()));
	dp[0] = arr;
	int m = arr.size();
	for(int i=1; i<k; i++) {
		int acc = 0;
		for(int j=0; j<m; j++) {
			acc += dp[i-1][j];
			acc %= MOD;
			dp[i][m-1-j] = (acc*arr[m-1-j])%MOD;
		}
	}
	cout << accumulate(dp[k-1].begin(), dp[k-1].end(), 0ll) % MOD;
}

Measured memory_bytes: 51192
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	ll k = 1;
	FOR(i, 2, b + 1) {
		k *= i;
		k %= MOD;
	}
	c *= pow(k, MOD - 2);
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}

struct edge {
	ll to;
	ll cost;
};

vector<bool> used(100001, false);
vector<ll> d(100001, -1);
bool f = true;
void dfs(ll a, const unordered_multimap<ll, edge>& graph) {
	if (used[a]) { return; }
	used[a] = true;

	auto p = graph.equal_range(a);
	for (auto itr = p.first; itr != p.second; ++itr) {
		if (d[itr->second.to] == -1) {
			d[itr->second.to] = d[a] + itr->second.cost;
			dfs(itr->second.to, graph);
		} else if (d[itr->second.to] != d[a] + itr->second.cost) {
			f = false;
			return;
		}
	}
}

int main() {
	ll n, z, w;
	cin >> n >> z >> w;
	VL v(n);
	REP(i, n) { cin >> v[i]; }
	if (n == 1) {
		cout << abs(v[n - 1] - w) << endl;
		return 0;
	}
	cout << std::max(abs(v[n - 1] - w), abs(v[n - 1] - v[n - 2])) << endl;;
}

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

struct card {
    char mark;
    int number;
    int InputIndex;
};

int partition(card A[], int p, int r) {
    int x = A[r].number;
    int i = p - 1;
    
    for(int j = p; j < r; ++j) {
        if(A[j].number <= x) {
            ++i;
            card cpy = A[i];
            A[i] = A[j];
            A[j] = cpy;
        }
    }
    card cpy = A[r];
    A[r] = A[i + 1];
    A[i + 1] = cpy;
    
    return i + 1;
}

void QuickSort(card A[], int p, int r) {
    if(p < r) {
        int q = partition(A, p, r);
        QuickSort(A, p, q - 1);
        QuickSort(A, q + 1, r);
    }
}

int main(void) {
    card A[100000];
    int n;
    
    cin >> n;
    
    for(int i = 0; i < n; ++i) {
        cin >> A[i].mark >> A[i].number;
        A[i].InputIndex = i;
    }
    
    QuickSort(A, 0, n - 1);
    
    bool flag = true;
    int k = 1;
    while(k < n) {
        if(A[k].number == A[k - 1].number && A[k].InputIndex < A[k - 1].InputIndex) {
            flag = false;
            break;
        }
        ++k;
    }
    
    if(flag) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    
    for(int i = 0; i < n; ++i) {
        cout << A[i].mark << ' ' << A[i].number << endl;
    }
    
    return 0;
}


Measured memory_bytes: 4180
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=1e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false); 

    int h,n;
    cin >> h >> n;
    vector<int> dp(h+1,1e9);
    dp[0]=0;
    rep(i,n) {
        int a,b;
        cin >> a >> b;
        repr(j,1,h+1) {
            if (j-a>=0) dp[j]=min(dp[j],dp[j-a]+b);
            else dp[j]=min(dp[j],b);
        }
    } 
    cout << dp[h] << endl;

    return 0;
}


Measured memory_bytes: 3684
h,w,m=map(int,input().split())
HW=[list(map(lambda x:int(x)-1,input().split())) for _ in range(m)]

H,W=[0]*h,[0]*w
for i,j in HW:
    H[i] +=1
    W[j] +=1

max_h,max_w=max(H),max(W)
ans=max_h+max_w
cnt=H.count(max_h)*W.count(max_w)
for i,j in HW:
    if H[i]==max_h and W[j]==max_w:
        cnt -=1
print(ans if cnt!=0 else ans-1)

Measured memory_bytes: 130612
n = int(input())
ans = [0 for i in range(n)]


for i in range(100):
  for j in range(100):
    for k in range(100):
      a = (i+1)*(i+1) +(j+1)*(j+1) + (k+1)*(k+1) + (i+1)*(j+1) +(j+1)*(k+1) + (k+1)*(i+1)
      if a <= n:
        ans[a-1]+=1
for i in ans:
  print(i)

Measured memory_bytes: 69412
#include<stdio.h>
int main(){
    int a  ;
    scanf("%d",&a);
    int x , y = a , i , count = 0  ;
    for(i = 0 ; i <3 ; i++){
     x = y%10 ;
     y = y /10 ;
     if(x ==1 ){
        count ++;
     }

    }
    printf("%d",count);


}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    i64 N,M,mod=1000000007;
    cin >> N >> M;
    if(abs(N-M)>1){
        cout << 0 << endl;
        return;
    }
    if(abs(N-M)==0){
        i64 ans=2;
        for(i64 i=1; i<=N; ++i) ans=ans*i%mod;
        for(i64 i=1; i<=M; ++i) ans=ans*i%mod;
        cout << ans << endl;
        return;
    }
    if(abs(N-M)==1){
        i64 ans=1;
        for(i64 i=1; i<=N; ++i) ans=ans*i%mod;
        for(i64 i=1; i<=M; ++i) ans=ans*i%mod;
        cout << ans << endl;
        return;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main()
{
  int d,g;
  cin >> d >> g;
  vector<int> p(d),c(d);
  for(int i=0;i<d;i++) cin >> p[i] >> c[i];

  int ans = 100000;
  for(int i=1;i<(1<<d);i++){
    ll sum = 0;
    int cnt = 0;
    int m = 0;
    for(int j=d-1;j>=0;j--){
      if((i>>j) & 1 == 1){
        m = j;
      }
    }

    for(int j=d-1;j>=0;j--){
      if((i>>j) & 1 == 1){
        if(j != m){
          sum += (j+1)*100*p[j]+c[j];
          cnt += p[j];
        }else{
          for(int k=0;k<p[j];k++){
            sum += (j+1)*100;
            cnt++;
            if(k == p[j]-1){
              sum += c[j];
            }
            if(sum >= g){
              ans = min(ans,cnt);
              break;
            }
          }
        }
      }
    }

  }

  cout << ans << endl;
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  if(a+b > c+d) cout << "Left" << endl;
  else if(a+b < c+d) cout << "Right" << endl;
  else cout << "Balanced" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long  a,b,c,k,s,sum;

int main(){
 cin>>k;
 for(a=1;a<=k;a++){
    for(b=1;b<=k;b++){
        for(c=1;c<=k;c++){
            s+=__gcd(c,__gcd(a,b));

        }
    }
 }
 cout<<s;
    return 0;}




Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

string s;

bool findstr(string t,string s){
	if(s.find(t)<=1001) return true;
	else return false;
}

int main(){
	cin>>s;
	bool f=false;
	if((not(findstr("W",s)^findstr("E",s)))&&(not(findstr("N",s)^findstr("S",s)))){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;

	  return 0;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//long longのシフト演算には気をつけよう

int main(){
    int N, M; cin >> N >> M;
    vector<pair<int, int>> st(N), ch(M);
    vector<int> ans(N);
    
    for(int i=0; i<N; i++) cin >> st[i].first >> st[i].second;
    for(int i=0; i<M; i++) cin >> ch[i].first >> ch[i].second;

    for(int i=0; i<N; i++){
        int dis = 1000000000;
        int id = 0;
        for(int j=0; j<M; j++){
            if(dis > abs(st[i].first - ch[j].first) + abs(st[i].second - ch[j].second)){
                dis = abs(st[i].first - ch[j].first) + abs(st[i].second - ch[j].second);
                id = j+1;
            }
        }
        ans[i] = id;
    }

    for(int i=0; i<N; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL;
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};



int main(){
    string s;
    cin>>s;
    rep(i,0,3){
        if(s[i]=='9')cout<<1;
        else cout<<9;
    }
    cout<<endl;
    





    return 0;
}


Measured memory_bytes: 256