akhauriyash/Code-Regression huggingface dataset:
# 各桁の数値の総和を計算する.
def calc_digit_sum(num):
    sums = 0
    while num > 0:
        sums += num % 10
        num //= 10
    return sums


k, s = map(int, input().split())

cnt = 0
for idx1 in range(0, k+1):
    for idx2 in range(0, k+1):
        current = s - (idx1 + idx2)
        if 0 <= current <= k:
            cnt += 1

print(cnt)


Measured memory_bytes: 67164
#include <iostream>
using namespace std;
int dfs(int l, int r);
void  remember(void);
string s;
int book[1000001],n, num[100000][2];
int main()
{
	int q, t, cnt=0;
	cin>>n>>q>>s;
	for(int i=0;i<q;i++)
	{
		cin>>t;
		num[i][0]=t-1;
		cin>>t;
		num[i][1]=t-1;
	}
	remember();
	for(int i=0;i<q;i++)
	{
		cnt=dfs(num[i][0], num[i][1]);
		cout<<cnt<<endl;
		cnt=0;
	}
	
	return 0;
}

void remember(void)
{
	int t=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='A'&&s[i+1]=='C')t++;
		book[i+1]=t;
	}
}

int dfs(int l, int r)
{
	if(l==r)return 0;
	return book[r]-book[l];
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, x;
    cin >> n >> x;
    if(x < n) cout << "No";
    else cout << "Yes";

    return 0;
}


Measured memory_bytes: 3640
'use strict'

function main(input) {
  input = input
    .trim()
    .split(' ')
    .map(Number)
  const sx = input[0]
  const sy = input[1]
  const tx = input[2]
  const ty = input[3]

  const dx = tx - sx
  const dy = ty - sy

  let ans = ''
  for (let i = 0; i < dy; i++) {
    ans += 'U'
  }
  for (let i = 0; i < dx; i++) {
    ans += 'R'
  }

  for (let i = 0; i < dy; i++) {
    ans += 'D'
  }
  for (let i = 0; i < dx; i++) {
    ans += 'L'
  }

  ans += 'L'
  for (let i = 0; i < dy + 1; i++) {
    ans += 'U'
  }
  for (let i = 0; i < dx + 1; i++) {
    ans += 'R'
  }
  ans += 'DR'
  for (let i = 0; i < dy + 1; i++) {
    ans += 'D'
  }
  for (let i = 0; i < dx + 1; i++) {
    ans += 'L'
  }
  ans += 'U'

  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7756
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	string s;
	cin>>s;
	string a;
	rep(i,s.size()){
		if(i==4)a+=' ';
		a+=s[i];
	}
	cout<<a<<endl;
	return 0;
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int N, M, C;
    cin >> N >> M >> C;

    vector< int > B(M);
    cin >> B;

    int ans = 0;
    range(i, 0, N) {
        vector< int > A(M);
        cin >> A;

        int sum = C;
        range(j, 0, M) {
            sum += A[j] * B[j];
        }

        if (sum > 0) ans++;
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;

int main(){
   int n,i;
   cin>>n>>i;
   cout<<n-i+1<<endl;
}

   


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define PI 3.141592653589793 

int main(){
    int a0=90;
    int di,ai1;
    double x=0,y=0;
    scanf("%d,%d",&di,&ai1);
    while(di||ai1){
        x += di*cos(a0*(PI/180));
        y += di*sin(a0*(PI/180));
        a0 -= ai1;
        scanf("%d,%d",&di,&ai1);
    }
    printf("%d\n%d\n",(int)x,(int)y);
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,a,b) \
for(ll i=ll(a);i<=ll(b);i++)
#define DEP(i,a,b) \
for(ll i=ll(a);i>=ll(b);i--)
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  int T;
  T=1;
  while(T--)
  {
      ll n,i,j,k,l,m,a,b,c,d,e,x,y;
      cin>>x>>y;
      i=4*x-y;
      j=y-2*x;
      if(i>=0&&i%2==0&&j>=0&&j%2==0)cout<<"Yes";
      else{
        cout<<"No";
      }
  }
  return 0;
}

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

using namespace std;

#define int long long 
#define INF 21000000000

signed main(){
		string s;
		cin >> s;
		string ans;
		if(s[5] == '0' && s[6] == '4' && s[8] == '3') ans = "TBD";
		if(s[5] == '0' && s[6] < '5') ans = "Heisei";
		else ans = "TBD";

		cout << ans << endl;
}



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

int main() {
    string s;
    stack<int> st;
    while(cin >> s) {
        if(s == "+") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(b + a);
        } else if(s == "-") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(b - a);
        } else if(s == "*") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(b * a);
        } else {
            st.push(stoi(s));
        }
    }
    cout << st.top() << endl;
}


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

int mmax(int a,int b,int c){
  if(a<b){
    return max(b,c);
  }else{
    return max(a,c);
  }
}

int main(){
  long i,K,N,L,delite;
  char ss[10000];
  cin>>N;
  cin>>L;
  if(L<0){
    if(L+N>1){
      delite=0;
    }else{
      delite=L+N-1;
    }
  }else{
    delite=L;
  }
  printf("%ld\n",(L+L+N-1)*N/2-delite);
  return 0;
}

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


pub 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 = read::<String>();
  let mut ans = 0;
  // let mut stack = 0;
  let mut zero_c = 0;
  let mut one_c = 0;

  let stack_num = s.chars().nth(0).unwrap();

  for i in s.chars() {

    if i == stack_num {
      zero_c += 1;
    } else {
      one_c += 1;
    }
  }

  ans = if zero_c > one_c { one_c } else { zero_c };

  println!("{}", ans * 2);

}



Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool bipartite_matching_dfs(
	int v, const vector< vector<int> > &conn,
	vector<bool> &used, vector<int> &match)
{
	used[v] = true;
	for(int i = 0; i < conn[v].size(); ++i){
		int u = conn[v][i], w = match[u];
		if(w < 0 || !used[w] && bipartite_matching_dfs(w, conn, used, match)){
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}
int bipartite_matching(const vector< vector<int> > &conn){
	int res = 0;
	vector<int> match(conn.size(), -1);
	vector<bool> used(conn.size(), false);
	for(int v = 0; v < conn.size(); ++v){
		if(match[v] < 0){
			fill(used.begin(), used.end(), false);
			if(bipartite_matching_dfs(v, conn, used, match)){ ++res; }
		}
	}
	return res;
}

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

int main(){
	int m, n;
	while(cin >> n >> m, n||m){
		vector<int> a(n);
		for(int i = 0; i < n; ++i){ cin >> a[i]; }
		vector<int> b(m);
		for(int i = 0; i < m; ++i){ cin >> b[i]; }
		vector< vector<int> > conn(n + m);
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < m; ++j){
				if(gcd(a[i], b[j]) != 1){
					conn[i].push_back(j + n);
					conn[j + n].push_back(i);
				}
			}
		}
		cout << bipartite_matching(conn) << endl;
	}
	return 0;
}

Measured memory_bytes: 2724
#include<bits/stdc++.h>
    #define mod (1000000007)
    typedef long long ll;
    using namespace std;
    int a[110000];
    int main()
    {
    	int n,x,ans=0;
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    	if(a[1]==1) {swap(a[1],a[2]);ans++;}
    	if(a[n]==n) {swap(a[n-1],a[n]);ans++;}
    	for(int i=2;i<n;i++)
    	if(a[i]==i)
    	{
    		ans++;
    		swap(a[i],a[i+1]); 
    	}
    	printf("%d\n",ans);
    	return 0;
    }

Measured memory_bytes: 640
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import math


def main():
  a,b,x = map(int, input().split())
  x = x/a
  l,r = 0.0,90.0
  for _ in range(10**5):
    si = (l+r)/2
    if a*math.sin(math.radians(si))/math.cos(math.radians(si)) <= b:
      v = a*b - a*a*math.sin(math.radians(si))/(2*math.cos(math.radians(si)))
    else:
      v = b*b*math.sin(math.radians(90.0-si))/(2*math.cos(math.radians(90.0-si)))
    if v >= x:
      l = si
    else:
      r = si
  return si

print(main())

Measured memory_bytes: 40368
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

bool comp(pair<int,int> a,pair<int,int>b){
  if(a.first == b.first) return a.second < b.second;
  else return a.first > b.first;
}

int main(){
  long long k,a,b; cin >> k>> a >> b;
  if(b-a > 2){
    if((k-(a-1)) % 2 == 0){
      cout << a + ((k-(a-1))/2)*(b-a) << "\n";
    }else{ 
      cout << a+1 +((k-(a-1))/2)*(b-a) << "\n";
    }
  }else{
    cout << k+1 << "\n";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N, M;
    cin >> N >> M;
    vec A(M);
    ll tmp = 0;
    Rep (i, M) {
        cin >> A[i];
        tmp += A[i];
    }

    cout << max((ll)-1, N-tmp) << endl;


}

Measured memory_bytes: 3740
#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 a, b;
	cin >> a >> b;

	if(a + b >= 10){
		puts("error");
	}else{
		cout << a + b << endl;
	}
	
	return 0;
}


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

const ll MOD=1000000007;

ll gcd(ll a,ll b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b,a%b);
    }
}

int main(){
    int N;
    cin>>N;
    vector<ll>A(N);
    rep(i,N){
        cin>>A.at(i);
    }
    sort(A.begin(),A.end());
    vector<ll>ans(N);
    ans.at(0)=A.at(0);
    for(int i=1;i<N;i++){
        ans.at(i)=gcd(A.at(i),ans.at(i-1));
    }
    cout<<ans.at(N-1)<<endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    class Program {
        static void Main(string[] args) {
        int N = int.Parse(Console.ReadLine());
        int K = int.Parse(Console.ReadLine());
        int X = int.Parse(Console.ReadLine());
        int Y = int.Parse(Console.ReadLine());
        int A = Math.Min(N,K) * X + Math.Max(0,N-K) * Y;
        Console.WriteLine(A);
        Console.ReadLine();
    }
    }


Measured memory_bytes: 2776
#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int N, int X, vector<int>& A) {
    int answer = 1;
    int current = 0;
    REP(i,0,N) {
        current += A[i];
        if (current <= X) answer++;
    }

	stringstream ss;
	ss << answer;

	cout << ss.str() << '\n';

    return;
}

signed main() {
    int N, X;
    cin >> N >> X;
    
    vector<int> A(N);
    REP(i,0,N) cin >> A[i];
    
    solve(N, X, A);
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++14

int main(){
    int n,k;cin>>n>>k;
    int p[1010];
    rep(i,n)cin>>p[i];
    sort(p,p+n);
    ll ans=0;
    rep(i,k)ans+=p[i];
    cout<<ans<<endl;
}

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

using namespace std;
#define int long long
#define INF ((10e9)+7)
#define pb push_back
int N;
int cnt1=0,cnt2=0,cnt3=0;
double call(int i,int j,int k,vector<vector<vector<double> > >& dp,vector<vector<vector<bool> > >&vis)
{
    //cout<<i<<" "<<j<<" "<<k<<" $ ";
    if(vis[i][j][k])
    {
        return dp[i][j][k];
    }
    vis[i][j][k]=true;
    
    double numerator=N-(i+j+k);
   // double denominator=N;
   //cout<<numerator<<"$ ";
    
    double m=0;
    if(i>0)
    {
        m+=(call(i-1,j,k,dp,vis)*i);
    }
    if(j>0)
    {
        m+=(call(i+1,j-1,k,dp,vis)*j);
    }
    if(k>0)
    {
        m+=(call(i,j+1,k-1,dp,vis)*k);
    }
//    cout<<"# "<<m<<" # ";
    
    dp[i][j][k]=(m+N)/(N-numerator);
    return dp[i][j][k];
    
    
    
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N;
    
    for(int i=0;i<N;i++)
    {
      //  cout<<i;
        int x;
        cin>>x;
        if(x==1)
        {
            cnt1++;
        }
        else if(x==2)
        {
            cnt2++;
        }
        else cnt3++;
    }
    
    vector<vector<vector<double> > >dp(310,vector<vector<double> >(310,vector<double> (310,-1)));
    vector<vector<vector<bool> > >vis(310,vector<vector<bool> >(310,vector<bool> (310,false)));
    dp[0][0][0]=0;
    vis[0][0][0]=true;
    //cout<<cnt1<<" "<<cnt2<<" "<<cnt3<<" ";
    printf("%.10f",call(cnt1,cnt2,cnt3,dp,vis));
    
    return 0;
    
}

Measured memory_bytes: 245120
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 1000; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j])%mod;
//       }
//     }
//   }
//   return 0;
// }


// int factorial(int n){
//   if(n == 0) return 1;
//   return n*factorial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   pascal_triangle();
//   return memo[n][k];
// }

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}







//二項係数(mod剰余)----------------------------

// const int MAX = 3000010;
// const int M = 1000000007;

// vector<ll> fac(MAX); //n!(mod M)
// //a,bの範囲的にこれだけ配列を用意していけば十分
// vector<ll> ifac(MAX); //k!^{M-2} (mod M)

// ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
//     ll ans = 1;
//     while(n != 0){
//         if(n&1) ans = ans*x % M;
//         x = x*x % M;
//         n = n >> 1;
//     }
//     return ans;
// }

// ll COMinit(){
//   //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
//   fac[0] = 1;
//   ifac[0] = 1;
//   for(ll i = 0; i<MAX; i++){
//     fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
//     ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
//   }
//   return 0;
// }

// ll COM(ll a, ll b){ //aCbをmod計算
//   if(a == 0 && b == 0)return 1;
//   if(a < b || a < 0)return 0;
//   ll tmp = ifac[a-b]* ifac[b] % M;
//   return tmp * fac[a] % M;
// }

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



int main(){
  int N,M;
  cin >> N >> M;
  bool f = false;
  if(N == M) f = true;
  cans(f);
  return 0;
}




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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

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

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	vector<llong> A;
	vector<llong> rui;

	cin >> N;
	A.resize(N+1);
	for(int i = 1; i <= N; i++){
		cin >> A[i];
	}
	sort(BE(A));
	rui.resize(N+1,0);
	for(int i = 1; i <= N; i++)
		rui[i] = rui[i-1] + A[i];

	llong ans = 0;
	for(int i = 1; i <= N; i++){
		llong huge = rui[i] - rui[0];
		int fst = i;
		while(true){
			auto it = lower_bound(BE(A), huge*2);
			if(it == A.end() || *it > huge*2)
				it--;
			int id = it - A.begin();
			if(id <= fst)
				break;
			else
				huge += rui[id] - rui[fst], fst = id;
		}
		if(fst == N)
			ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
using System;
 
class Program
{
    static void Main()
    {
    	var cnt = new int[26];
    	string s;
		
		while( null != ( s = Console.ReadLine()) ) {
	    	foreach(var c in s.ToLower().ToCharArray()) {
	    		if(c >= 'a' && c <= 'z') {
	    			cnt[c-'a']++;
	    		}
	    	}
		}
    	
    	for(int i = 0; i < 26; i++) {
    		char c = (char)('a' + i);
    		Console.WriteLine(c + " : " + cnt[i]);
    	}
    	
    }
}

Measured memory_bytes: 9136
# n = int(input())
k,n = map(int,input().split())
A = list(map(int,input().split()))
# An = [list(map(int,input().split())) for i in range(n)]
d = []
for i in range(n-1):
    d.append(A[i+1]-A[i])
d.append(k-A[n-1]+A[0])
print(k-max(d))

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

typedef long long int ll;
#define T int t,i; scanf("%d",&t); for(i=1;i<=t;i++)

int main(){
 ll n,a=0,b=0,c=0 ;
  cin >> n ;
 char m[n] ,k;
 cin >> m;
 	for(int i=0;i<n-2;i++){
 		if(m[i]=='A' && m[i+1]=='B' && m[i+2]=='C')
 			a++;
 	
 	}
 	cout << a << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i, n) cin >> b[i];
  b.push_back(0);
  vector<int> t;
  rep(_, n) {
    vector<bool> f(n, false);
    reps(i, n) if (i == b[i - 1]) f[i - 1] = true;
    bool flag = false;
    rep(i, n) if (f[i]) flag = true;
    if (!flag) {
      cout << -1 << endl;
      return 0;
    }
    int idx;
    rrep(i, n) if (f[i]) { idx = i; break; }
    for (int i = idx; i < n; i++) {
      b[i] = b[i + 1];
    }
    t.push_back(idx + 1);
  }
  rrep(i, n) cout << t[i] << endl;
  return 0;
}


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

int N;
int H[100005];
int DP[100005];

int main(){
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>H[i+1];
	H[0]=H[1];
	for(int i=2;i<N+1;i++)
		DP[i]=min(DP[i-1]+abs(H[i]-H[i-1]),DP[i-2]+abs(H[i]-H[i-2]));
	cout<<DP[N];
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


int main() {
	string s;
	cin >> s;
	repz(i, s.size()) {
		if (s[i] == 'L' && i % 2 == 0) { cout << "No" << endl; return 0; }
		if (s[i] == 'R' && i%2 == 1) { cout << "No" << endl; return 0; }
	}

	cout << "Yes" << endl;

	system("pause");
	return 0;
}


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

int main()
{
	int x, y;
	cin >> x >> y;
	 
	int cranes = x, turtle = 0;
	
	while(cranes >= 0) {
		if(cranes*2 + turtle*4 == y) {
			printf("Yes");
			return 0;
		}
		cranes--;
		turtle++;
	}
	
	printf("No");
	return 0;
}


Measured memory_bytes: 3764
#

import sys
input=sys.stdin.readline

def main():
    K,N=map(int,input().split())
    A=list(map(int,input().split()))
    mind=K-(A[0]-A[-1]+K)
    for i in range(1,N):
        mind=min(mind,K-(A[i]-A[i-1]))
    print(mind)
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 99756
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, ll>;
int fact[10];
void Initfact()
{
    fact[0] = 1;
    for (int i = 1; i < 10; ++i)
    {
        fact[i] = fact[i - 1] * i;
    }
}

int main()
{
    Initfact();
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    for (int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        ++mp[a], ++mp[b];
    }
    for (int i = 0; i < n; ++i)
    {
        cout << mp[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>
#include<random>
#include<set>
 
#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
#define Sort(X) sort(X.begin(), X.end())
#define RSort(X, T) sort(X.begin(), X.end(), greater<T>())
//#define MOD 998244353
#define MAX 100000
 
typedef long long int ll;
typedef unsigned long long int ull;
 
using namespace std;
 
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; }
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll X, Y;

	cin >> X >> Y;

	ll out = 0;
	if (X == 1 && Y == 1) out += 400000;

	out += max(400000 - (X * 100000), 0ll);
	out += max(400000 - (Y * 100000), 0ll);

	cout << out << endl;



	return 0;

}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    string S; cin >> S;
    int N = SZ(S);

    int n0 = 0, n1 = N;
    while(n1 - n0 > 1){
        int n = (n0 + n1) / 2;
        bool ok = false;
        
        REP(k, 2){
            int a = k, b = n;
            if((b - a) % 2) b--;
            bool f = true;
            REP(i, N){
                if(S[i] == '1'){
                    a++; b++;
                }else if(S[i]== '0'){
                    a--; b--;
                }else{
                    a--; b++;
                }
                if(a < 0) a += 2;
                if(b > n) b -= 2;
                if(a > b) f = false;
            }
            if(f) ok = true;
        }

        if(ok) n1 = n;
        else n0 = n;
    }
    Out(n1);

    return 0;
}


Measured memory_bytes: 4264
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }

    vector<int> cnt(n, 1);
    sort(s.begin(), s.end());
    for (int i = 0; i < n-1; i++) {
        if (s[i] == s[i+1]) {
            cnt[i+1] = cnt[i]+1;
        }
    }
    int max = 0;
    for (int i = 0; i < n; i++) {
        if (cnt[i] > max) {
            max = cnt[i];
        }
    }
    for (int i = 0; i < n; i++) {
        if (cnt[i] == max) {
            cout << s[i] << endl;
        }
    }
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;
 
int main(){
  ll n;
  cin >> n;
  ll a[n+1],sum = 1,ans=0;
  rep (i,n){
	  cin >> a[i] ;
	  if (a[i] == 0){
		  cout << 0 << endl;
		  return 0; 
	  }}
	  rep (i,n){
	if (sum < 0 || a[i] > 1000000000000000000 / sum ||sum * a[i] > 1000000000000000000 ){
		cout << -1 << endl;
		return 0;
	  }
	  sum *= a[i];

  }
  //cout << sum << endl;
  cout << sum << endl;
  
} 

Measured memory_bytes: 4384
import java.util.*;

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

        for(int i = 1; i <= Math.sqrt(N); i++){
            if(N%i == 0){
                ans = Math.min(ans, (i-1)+(N/i-1));
            }
        }
        System.out.println(ans);
    }
}

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

const int N = 17;

typedef long long int ll;

const ll inf = 1e18;

ll w[1 << N];
ll dp[1 << N];

ll a[N][N];

int main()
{
  int n;
  cin >> n;
  for(int i=0;i<n;++i)
    for(int j=0;j<n;++j)
      cin >> a[i][j];
  
  int nn = 1 << n;
  for(int s=0;s<nn;++s)
  {
    for(int i=0;i<n;++i) if(s>>i&1)
      for(int j=i+1;j<n;++j) if(s>>j&1)
        w[s] += a[i][j];
    //~ cerr << s << ' ' << w[s] << endl;
  }
  
  for(int s=0;s<nn;++s)
  {
    dp[s] = 0;
    for(int m=s;m;m = s & (m-1))
      dp[s] = max(dp[s], w[m] + dp[m^s]);
  }
  
  cout << dp[nn-1] << endl;
  
  return 0;
}


Measured memory_bytes: 1280
n = int(raw_input())
card_list = 52*[0]

for i in range(0,n):
	(mark,rank) = map(str,raw_input().split())
	for j in range(0,4):
		if mark == 'SHCD'[j]:
			card_list[13*j+int(rank)-1] = 1

for i in range(0,52):
	if card_list[i] == 0:
		print '%c %d' %('SHCD'[i/13],i%13+1)

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif
#define sz(a) (int)a.size()
#define found(m,x) ((m).find(x)!=(m).end())
#define uset unordered_set
#define umap unordered_map
#define a(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<(int)n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<=(int)n:i>=(int)n;k<n?i++:i--)
#define input(v,n) fo(i,n)cin>>v[i]
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pi;

const int nax = 1e5+7;
const int mod = 1e9+7; //1e9+2667 :: 0xcf : inf, 0xc0 -inf
const int inf = numeric_limits<int> :: max() - (int)1e3;
// ===================== MANASH =================== //

vector<int> p,s;
int n;
int find( int x ) {
	if ( p[x] == x ) return x;
	else return p[x] = find(p[x]);
}
bool same( int x, int y ) {
	return find(x) == find(y);
}
void unite( int a, int b) {
	int x = find(a);
	int y = find(b);
	if ( same(x,y)) return;
	if ( s[x] > s[y] ) swap(x,y);
	p[x] = y;
	s[y] += s[x];
}
void test() {
	int m;
	cin >> n >> m;
	p.resize(n+1); s.resize(n+1,1);
	iota(a(p),0);
	vector<pi> edges;
	fo(i,m) {
		int a,b;
		cin >> a >> b;
		edges.emplace_back(a,b);
	}

	int cnt = n*(n-1)/2;
	vector<int> answers;
	while(!edges.empty()) {

		answers.push_back(cnt);
		int u,v;
		tie(u,v) = edges.back();
		edges.pop_back();
		if (!same(u,v)) {
			cnt -= s[find(u)]*s[find(v)];
			unite(u,v);
		}
	}
	reverse(a(answers));
	for( int x : answers ) cout << x << '\n';
}

signed main() {

	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);

	#ifdef LOCAL
	freopen("input.txt","r",stdin);
	cout<<"Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec.\n";
	#endif

	int T = 1;
	//cin >> T;
	while(T--) {
		test();
		cout << "\n";
	}
	return 0;

}

Measured memory_bytes: 6256
import sys

#+++++

def sss(cc, l):
	#print(cc,l)
	if len(l)==0:
		return (-1,'no_chr')
	elif cc > l[-1]:
		return (-1,'over')
	
	#にぶたんを書く
	if cc <= l[0]:
		return (l[0],'')
	
	ue=len(l) - 1 #以下
	sita=0#より大きい
	while abs(ue - sita) > 1:
		mid = (ue + sita)//2
		if l[mid] >= cc:
			ue = mid
		else:
			sita = mid
	return (l[ue],'')

def main():
	s = input()
	t = input()
	i = 0
	bbb=[[] for i in range(26)]
	ctoi=lambda c : ord(c)-97
	
	for i, c in enumerate(s):
		bbb[ctoi(c)].append(i+1)
	
	for i, b in enumerate(bbb):
		pass
		#print(chr(i+ord('a')) + ':' + str(b))
	
	cc = 0
	kkk=0
	ret = 0
	for c in t:
		address=ord(c) - ord('a')
		l=bbb[address]
		#print(cc,l,'a')
		#cc以上の値をみつける。
		nc, st = sss(cc, l)
		cc = nc + 1
		#print(cc)
		if st =='no_chr':
			print(-1)
			return 
			
		if st == 'over':
			kkk += 1
			cc = l[0] + 1
			
	#print(len(s), kkk, cc)
	ret = len(s) * kkk + cc - 1
	print(ret)
			
		

	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 7668
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
using ll = long long;
using ull = unsigned long long;
using namespace std;

int N;
int x[1000000];

void solve()
{
    int a, b;
    cin >> a >> b;

    cout << (a+b)%24 << endl;
}

int main(){cin.tie(0);ios_base::sync_with_stdio(false);solve();return 0;}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#define value( x ) cout<< "value of "<< #x << " is "<< x<<endl;
long long max( long long x, long long y) {if(x>y) return x;else return y;}
using namespace std;
long long a[100001];

int main()
{
    int n;
   cin>>n;
   for(int i=0;i<n;i++) cin>>a[i];
   	sort(a, a+n);
   reverse(a, a+n);
  
   long long x1=0, x2=0, y1=0, y2=0;
   int counting=0;
   long long past=a[0];
   for(int i=1;i<n;i++){
  	if(past==a[i])
   	{
   		if(counting==0) {counting=1; x2=past;counting++;i++;past=a[i];}
   		else {y2=past; break;}
   	}
   	else past=a[i];}
   //	value(x2);value(y2);
   	long long area=x2*y2;

   	cout<<area;
return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){

	int kingaku[] ={6000, 4000, 3000, 2000};

	for (int i =0; i < 4; i++){
		int t,n;
		cin >> t >> n;
		cout << kingaku[t-1] * n << endl;
	}

	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 1e9+7;
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; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

const ll MAX = 1e6 + 1;
ll inv[MAX];

// a < b �Ȃ�true��Ԃ�
bool comp(const P& a, const P& b) {
  if (a.first * b.second == a.second * b.first){
    return a.first < b.first;
  }
  return a.first/a.second > b.first/b.second;
}
int main() {
    ll H, N, a, b, ans = 0;
    cin >> H >> N;
    
    vector<ll> A(N), B(N), dp(H + 1);
    rep(i, N)cin >> A[i] >> B[i];
    
    rep(i, H+1)dp[i] = ll(1e20);
    dp[0] = 0;
    
    rep(i, H + 1){
        rep (j, N){
            dp[i] = min(dp[i], dp[max(0LL, i - A[j])] + B[j]);
            
        }
    }
    //rep (i, H + 1){
    //    cout << i << " " << dp[i] << endl;
    //}
    cout << dp[H];
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int read()
{
    char s;
    int k=0,base=1;
    while((s=getchar())!='-'&&s!=EOF&&!(s>='0'&&s<='9'));
    if(s==EOF)exit(0);
    if(s=='-')base=-1,s=getchar();
    while(s>='0'&&s<='9')
    {
        k=k*10+(s-'0');
        s=getchar();
    }
    return k*base;
}
void write(int x)
{
    if(x<0)
    {
        putchar('-');
        write(-x);
    }
    else
    {
        if(x/10)write(x/10);
        putchar(x%10+'0');
    }
}
long long n,ans;
const long long mod=1e9+7;
long long g[1000010];
long long s[1000010];
int main()
{
    n=read();
    g[1]=n;g[2]=n*n;
	s[1]=n;s[2]=n*n+n;
    for (long long i=3;i<=n;i++)
    {
        g[i]=g[i-1];
        /*for (int j=3;j<=n+1;j++)
        {
            if (i-j<=0) 
			{
				g[i]+=n; 
				if (g[i]>=mod) g[i]-=mod;
			}
			else
			{
           		g[i]+=g[i-j]; 
				g[i]+=(n-1);
				if (g[i]>=mod) g[i]-=mod;
			}
        }*/
		g[i]+=s[i-3];
		g[i]+=((long long)(i-3)*(long long)(n-1)%(long long)mod);
		g[i]=(g[i]%mod+mod)%mod;
		if (g[i]>=mod) g[i]%=mod;
//		printf("%d ",g[i]);
		g[i]+=(long long)(n+2-i)*(long long)(n)%(long long)mod;
		g[i]%=mod;
		s[i]=s[i-1]+g[i];if (s[i]>=mod) s[i]-=mod;
//		printf("%d \n",g[i]);
    }
    printf("%lld\n",g[n]);
    return 0;
}
/*
 1. 数组仅包含 1, 2, 3, ..., n
2. 如果 n ≤ i, j,那么 a i = a j
3. 如果 i < j < k ≤ i + a i ,那么 a j = a k
数组还在生成中,反正现在很无聊,不如计算有多少种满足条件的数组?答案对 1e9 + 7 取模
 */


Measured memory_bytes: 15872
#include<iostream>

using namespace std;

int main() {
  int n,k;
  string s;

  cin >> n >> s >> k;

  char c = s[k-1];

  for(int i=0; i<n; i++) {
    if(s[i]!=c) {
      s[i] = '*';
    }
  }

  cout << s << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T>;
void in() {}; template <typename T, typename...TS> void in(T &&x, TS &&...xs) { cin >> x; in(move(xs)...); };
template <typename T> void _out(char *sep, char *end, T &&x) { cout << x << end; };
template <typename T, typename...TS> void _out(char *sep, char *end, T &&x, TS &&...xs) { cout << x << sep; _out(sep, end, move(xs)...); }
#define indef(t, ...) t __VA_ARGS__; in(__VA_ARGS__)
#define get(t) []{ t _; cin >> _; return _; }()
#define put(...) _out("", "", __VA_ARGS__)
#define out(...) _out(" ", "\n", __VA_ARGS__)
#define times(n, i) for (i32 i =  0 ; i <  (n); ++i)
#define range(a, b, i) for (i32 i = (a); i <  (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i32 main()
{
	indef(i32, n);
	vec<i32> s;
	times(n, i) {
		s.append(get(i32));
	}
	i32 ans = 0;
	times(n, i) {
		ans += s[i];
	}
	sortall(s);
	bool ok = true;
	if (ans / 10 * 10 == ans) {
		ok = false;
		times(n, i) {
			if (s[i] / 10 * 10 != s[i]) {
				ans -= s[i];
				ok = true;
				break;
			}
		}
	}
	out(ok ? ans : 0);
	return 0;
}


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

int main(){
  vector<int> group{0,2,0,1,0,1,0,0,1,0,1,0};
  int a,b;
  cin >> a >> b;
  if(group[a-1] == group[b-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<ll, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

const int N = (int)1e5 + 9;
int n;
ll x;

ll b[N], l[N], r[N];

bool ok(ll md){
    ll k = md / x;
    ll rem = md % x;
    vector<pii> sr;
    ll take = 0;
    for(int i = 0 ; i < n ; i ++ ){
        sr.push_back(mp((x - b[i]) * r[i] + l[i] * b[i], i));
        take += l[i] * b[i];
    }
    sort(sr.begin(), sr.end());
    reverse(sr.begin(), sr.end()); 
    ll tok = 0;
    ll toki = 0;
    for(int i = 0 ; i < n; i ++ ){
        if(i < k)tok += sr[i].fi;
        if(i <= k)toki += sr[i].fi;
    }
    int id;
    ll add;
    for(int i = 0 ; i < n ; i ++ ){
        id = sr[i].se;
        if(i < k){
            add = toki - sr[i].fi - take + l[id] * b[id];
            if(rem < b[id])
                add += (rem - b[id]) * l[id];
            else
                add += (rem - b[id]) * r[id];
            if(add >= 0)
                return true;
        }
        else{
            add = tok - take + l[id] * b[id];
            if(rem < b[id])
                add += (rem - b[id]) * l[id];
            else
                add += (rem - b[id]) * r[id];
            if(add >= 0)
                return true;
        }
    }
    return false;
}

int main(){
    fastIO;
    cin >> n >> x;
    for(int i = 0 ; i < n ; i ++ ){
        cin >> b[i] >> l[i] >> r[i];
    }
    ll L = 0, R = n * 1ll * x;
    ll M;
    while(L < R){
        M = (L + R) / 2;
        if(!ok(M)){
            L = M + 1;
        }
        else{
            R = M;
        }
    }
    cout << R << "\n";
    return 0;
}

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

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

int main()
{
    int n;
    scanf("%d", &n);

    ll zero = 0, neg = 0;
    ll mn = INT_MAX, sum = 0;
    for (int i = 0; i < n; i++) {
        ll num;
        scanf("%lld", &num);

        if (num == 0)
            zero++;
        else if (num < 0)
            neg++;

        sum += abs(num);
        mn = min(mn, abs(num));
    }

    if (zero > 0)
        printf("%lld\n", sum);
    else if (neg % 2 == 1)
        printf("%lld\n", sum - 2 * mn);
    else
        printf("%lld\n", sum);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define W while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007

  int main()
  {
    ll n;
    cin>>n;
    ll i,j,k,sum=0,s;
    for(i=1;i<=n;i++)
    {
        {
        for(j=1;j<=n;j++)
        {
         for(k=1;k<=n;k++)
         {
           s=__gcd(i,j);
           s=__gcd(s,k);
           sum=sum+s;
         }
        }
      }
    }
    cout<<sum;
  }

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

int main(){
    string s;
    cin >>s ;
    if(s=="Sunny"){
        cout << "Cloudy" << endl;
    }else if(s=="Cloudy"){
        cout << "Rainy" << endl;
    }else if(s=="Rainy"){
        cout << "Sunny" << endl;
    }
}

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

using namespace std;

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

	int maxa=max(a,max(b,c));

	int ans=0;

	int dd=maxa-a;
	ans+=dd/2;
	a+=(dd/2)*2;

	dd=maxa-b;
	ans+=dd/2;
	b+=(dd/2)*2;

	dd=maxa-c;
	ans+=dd/2;
	c+=(dd/2)*2;

	int d1,d2,d3;
	d1=maxa-a;
	d2=maxa-b;
	d3=maxa-c;

	if(d1+d2+d3==0)
		cout<<ans<<endl;
	else if(d1+d2+d3 ==2)
		cout<<ans+1<<endl;
	else if(d1+d2+d3==1)
		cout<<ans+2<<endl;
	return 0;
}

Measured memory_bytes: 256
abc096b = do
    [a,b,c] <- readArray getLine
    n <- readLn::IO Int
    print $ sum[a,b,c] + maximum [a,b,c] * (pow2 n 1 -1)
        where pow2 0 mul = mul
              pow2 x mul = 2 * pow2 (x-1) mul

main = abc096b

readArray::IO String -> IO[Int]
readArray = fmap $ map read . words

Measured memory_bytes: 508