akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val k = sc.nextInt()
    val n = sc.nextInt()
    val a = Array(n) { sc.nextLong() }
    val lst = mutableListOf<Long>()
    for (i in 0 until n - 1) {
        lst.add(a[i + 1] - a[i])
    }
    lst.add(k + a[0] - a[n - 1])
    println(lst.sum() - lst.max()!!)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 54244
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, U, V = lr()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
    a, b = lr()
    graph[a].append(b)
    graph[b].append(a)

def dfs(start): # 木グラフの時
    dist = [-1] * (N+1)
    dist[start] = 0
    stack = [start]
    while stack:
        s = stack.pop()
        for x in graph[s]:
            if dist[x] != -1:
                continue
            dist[x] = dist[s] + 1
            stack.append(x)
    return dist

dist_U = dfs(U)
dist_V = dfs(V)
answer = max(v for u, v in zip(dist_U, dist_V) if v > u) - 1
print(answer)


Measured memory_bytes: 32432
#include <bits/stdc++.h>
#include <ext/rope>
#define VALHALLA cin.tie(0);ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(13);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) (int)x.size()
#define fast(map_name) map_name.reserve(1024);map_name.max_load_factor(0.25);
using namespace std;
using namespace __gnu_cxx;
typedef long long int ll;
typedef pair<int,int> ii;
typedef complex<double> point;
const double epsilon=1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod=1e9+7;
/* VARIABLE DECLARATION START */
int arr[int(1e5+1)];
int dp[int(1e5+1)][5];
string s;
/*  FUCNTION TEMPLATE STARTS  HERE */

double dot(point a,point b){ return (conj(a)*b).real() ; }
double cross(point a,point b){ return (conj(a)*b).imag() ; }
double dist(point a, point b){ return abs(a-b); }
struct neal {
static uint64_t splitmix64(uint64_t x)
 {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
 {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
bool isprime(ll n) {
    if (n == 2 || n == 3) return true;
    if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 6; (i - 1) * (i - 1) <= n; i += 6) {
        if (n % (i - 1) == 0 || n % (i + 1) == 0) {
            return false;
        }
    }
    return true;
}
inline ll exp(ll a, ll b, ll mod) {
    ll n = 1;
    ll p = a;
    while (b > 0) {
        if (b % 2 == 1) {
            n *= p;
            n %= mod;
        }
        p *= p;
        p %= mod;
        b /= 2;
    }
    return n;
}

inline bool comp(double a,double b)
{
  return (fabs(a-b)<epsilon);
}
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
int solve(int index,int rock,int paper,int dec)
{
  if(index<0)
    return 0;
  if(dp[index][dec]!=-1)return dp[index][dec];
  int ans=0;
  if(rock>=paper+1)
  {
    if(s[index]=='p')
    {
      int val1=solve(index-1,rock,paper+1,1);
      int val2=-1+solve(index-1,rock+1,paper,0);
      if(val1>val2)
        return dp[index][1]=val1;
      else
        return dp[index][0]=val2;
    }
    else
    {
      int val1=1+solve(index-1,rock,paper+1,1);
      int val2=solve(index-1,rock+1,paper,0);
      if(val1>val2)
        return dp[index][1]=val1;
      else
        return dp[index][0]=val2;
    }
  }
  else
  {
    if(s[index]=='p')
    ans=-1+solve(index-1,rock+1,paper,0);
    else
    ans=solve(index-1,rock+1,paper,0);
    return dp[index][0]=ans;
  }
}


/*  FUCNTION TEMPLATE ENDS HERE */
int main()
{
   VALHALLA
  cin>>s;
  memset(dp,-1,sizeof(dp));
  cout<<max(solve(sz(s)-1,0,0,0),solve(sz(s)-1,0,0,1))<<endl;


}


Measured memory_bytes: 7120
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> S(n+1,0);
  ll maxi = 0;
  for (int i = 1; i <= n; ++i) {
    S[i] += a[i-1];
    S[i] += S[i-1];
    chmax(maxi, S[i]);
  }
  unordered_map<ll,int> cnt;
  ll ans = 0;
  for (int i = n; i >= 0; --i) {
    if (cnt.count(S[i]) == 0) cnt[S[i]] = 0;
    ans += cnt[S[i]];
    cnt[S[i]]++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11592
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-02-22 22:10:25
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  vector<int> x(n); cin >> x;

  int mn = 1e9;

  for (int i = 1; i <= 100; ++i) {
    int t = 0;
    for (int j = 0; j < n; ++j) {
      t += (x[j] - i) * (x[j] - i);
    }
    mn = min(t, mn);
  }

  cout << mn << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int K, X;
    cin >> K >> X;
    vector<int> ans;
    for(int i = X-K+1; i <= X+K-1; i++){
        if(i >= -1000000 && i <= 1000000) ans.push_back(i);
    }
    for(int i = 0; i+1 < ans.size(); i++){
        cout << ans[i] << ' ';
    }
    cout << ans[ans.size()-1] << endl;
}

Measured memory_bytes: 504
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

vi t;
void dfs(int a){
	if(a>4000000000ll)return;
	t.pb(a);
	rep(i,10)if(abs(a%10-i)<=1)dfs(a*10+i);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin>>n;
	rep(i,9)dfs(i+1);
	sort(all(t));
	cout<<t[n-1]<<endl;
}











Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
using namespace std;
int n,p,_p[200001],cnt,ans;
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>p,_p[p]=i;
    for(int i=1;i<n;i++){
        if(_p[i]<_p[i+1])cnt++;
        else cnt=0;
        ans=max(ans,cnt);
    }
    cout<<n-ans-1<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

int n,m,b;
string s,t;

int main() {
  cin >> n >> m;
  int x[100000];
  rep(i,m) cin >> x[i];
  sort(x,x+m);
  if(n>=m) cout << 0 << endl;
  else if(n==1) cout <<  x[m-1]-x[0] << endl;
  else{
    int d[100000],sum=0;
    rep(i,m-1) d[i]=abs(x[i+1]-x[i]),sum+=d[i];
    sort(d,d+m,greater<int>());
    rep(i,n-1) sum-=d[i];
    cout << sum << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Here your code !
    int n;
    cin >> n;
    vector<int> guzai(2*n);
    for(int i = 0; i < 2*n; i++){
        int t;
        cin >> t;
        guzai[i] = t;
    }
    
    sort(guzai.begin(),guzai.end());
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += min(guzai[i*2],guzai[i*2+1]);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	cin>>n;
	cin.get(); // ツ凝ウツ板陳づーツ偲ヲツ督セツつオツづ按つ「ツづ出ツ療債つェツつィツつゥツつオツつュツづ按づゥ
	for(int j=0; j<n; j++){
		string s;
		while(getline(cin,s)){
		string ans="";
		for(string::size_type i=0; i<s.size(); i++){
			if(s.substr(i,7) == "Hoshino"){
				ans+="Hoshina";
				i+=6;                    // ツ置ツ環キツつオツつスツ閉カツつセツつッツ進ツづ淞づゥ
			}
			else ans+=s[i];
		}
		cout << ans << endl;
		}
	}
	return 0;
}

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

int n;
char s[100004], ans[100004];

char rev(char c) { return c == 'S' ? 'W' : 'S'; }

int main() {
    cin >> n >> s;

    for (int i=0; i<n; i++) s[i] = (s[i] == 'o');

    for (int t=0; t<8; t++) {
        for (int i=0; i<3; i++) ans[i] = ((t >> i) & 1) ? 'S' : 'W';

        for (int i=1; i+2<n; i++) {
            if (s[i] == s[i+1]) ans[i+2] = ans[i-1];
            else ans[i+2] = rev(ans[i-1]);
        }

        bool okay = true;
        for (int i=0; i<n; i++) okay &= s[i] == ((ans[(i+n-1)%n] == 'S') + (ans[i] == 'S') + (ans[(i+1)%n] == 'S')) % 2;

        if (okay) {
            cout << ans << '\n';
            return 0;
        }
    }

    cout << -1 << '\n';
}

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

int main() {

  long long int a, b, n;

  while( cin >> a >> b >> n ) {

    a %= b;
    long long int ans = 0;
    for ( long long int i = 0; i < n; i++ ) {
      a *= 10;
      ans += ( a / b );
      a %= b;
    }
    cout << ans << endl;

  }

  return 0;

}

Measured memory_bytes: 1156
#include <stdio.h>
#define INF 114514
#define WHITE 1
#define BLACK 2
#define N 2010
#define NIL -1

void prim(int);

int G[N][N],d[N],pi[N],color[N];

int main() {

  int n,i,j;
  int D=0;
  
  scanf("%d",&n);
  for(i = 1; i <= n; i++) {
    for(j = 1; j <= n; j++) {
      scanf("%d",&G[i][j]);
    }
  }
  prim(n);
  
  for(i = 1; i <= n; i++) {
    D = d[i] + D;
  } 
 printf("%d\n",D);
  return 0;
}
  
void prim(int n)
{
  int i,mincost,u;
  for(i = 1; i <= n; i++) {
    d[i] = INF;
    pi[i] = NIL;
    color[i] = WHITE;
  }
  d[1] = 0;

  while(1) {
    mincost = INF;
    for(i = 1; i <= n; i++) {
      if(color[i] != BLACK && d[i] < mincost) {
	mincost = d[i];
	u = i;
      }
    }

    if(mincost == INF) break;

    color[u] = BLACK;

    for(i = 1; i <= n; i++) {
      if(color[i] != BLACK && G[u][i] < d[i] && G[u][i] != NIL) {
	pi[i] = u;
	d[i] = G[u][i];
      }
    }
  }
} 
  




Measured memory_bytes: 2144
#include <bits/stdc++.h>
#include <string>
#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 INF = 1e9;

int main(){
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    string s,t;
    rep(i,a){
        s.push_back('0');
        t.push_back('1');
    }
    rep(i,w-a){
        t.push_back('0');
        s.push_back('1');
    }

    rep(i,b){
        cout << s << endl;
    }
    rep(i,h-b) cout <<t << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), M = getint();

	int A[100000];
	rep(i, N) *(A + i) = getint();
	sort(A, A + N);

	pair<int, int> BC[100000];
	rep(i, M) {
		(*(BC + i)).second = getint();
		(*(BC + i)).first = getint();
	}
	sort(BC, BC + M);

	ll kotae = 0;
	int kazu = 0;
	for (int i = M - 1; i >= 0; i--) {
		rep(j, BC[i].second) {
			if (kazu >= N) break;
			kotae += max(A[kazu], BC[i].first);
			kazu++;
		}
	}

	for (int i = kazu; i < N; i++) kotae += A[i];

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

i64 N;

int main() {
  cin >> N;
  if(N <= 100) {
    i64 ans = 0;
    for(int i = 1;i <= N;i++) {
      if(N / i == N % i) {
        ans += i;
      }
    }
    cout << ans << endl;
    return 0;
  }
  i64 ans = 0;
  for(i64 i = 1;i * i <= N;i++) {
    if(N / i == N % i) {
      ans += i;
    }
  }
  for(i64 i = 1;i * i < N;i++) {
    i64 x = i;
    if(N % i == 0) {
      ans += (N / i) - 1;
    }
  }
  cout << ans << endl;
}


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

N, M = map(int, readline().split())
AB = [tuple(map(int, readline().split())) for _ in range(M)]
AB.sort()

r = -1
cnt = 0
for a, b in AB:
    if r <= a:
        cnt += 1
        r = b
    else:
        r = min(r, b)
print(cnt)


Measured memory_bytes: 56160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define N 200005
ll jc[N];
ll powmod(ll a, ll b)
{
	ll P = 1;
	a = a % mod;
	while (b)
	{
		if (b & 1)
			P = (P * (a % mod)) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return P;
}
ll com(ll n, ll r)
{
	if (n - r > r)
	{
		r = n - r;
	}
	ll i, j, s = 1;
	for (i = 0, j = 1; i < r; ++i)
	{
		s *= n - i;
		for (; j <= r && s % j == 0; j++)
		{
			s /= j;
		}
	}
	return s;
}
int main()
{
	int n, a, b, c;
	jc[0] = 1;
	for (int i = 1; i < N; i++)
		jc[i] = jc[i - 1] * i % mod;
	scanf("%d%d%d%d", &n, &a, &b, &c);
	ll A = 0, B = 0;
	for (int m = n; m <= 2 * n - 1; m++)
	{
		A = (A +
			((
			(powmod(a, n) * powmod(b, m - n) % mod + powmod(a, m - n) * powmod(b, n) % mod) % mod * m % mod) *
			(jc[m - 1] * powmod(jc[n - 1], mod - 2) % mod * powmod(jc[m - n], mod - 2) % mod) % mod) *
			100 % mod * powmod(a + b, 2 * n - m - 1) % mod) %mod;
	//	cout<<m<<endl;
	}
	B = powmod(a + b, 2 * n);
	ll gcd = __gcd(A, B);
	A /= gcd, B /= gcd;
	A = A * powmod(B, mod - 2) % mod;
	printf("%lld\n", A);
}

Measured memory_bytes: 1792
N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = 0

num_array = [0] * N
for i in range(N):
    num_array[i] = (p[i]+1) / 2

ans = sum(num_array[0:K])
temp = ans
for i in range(1, N-K+1):
    j = i+K-1
    temp = temp - num_array[i-1] + num_array[j]
    if temp > ans:
        ans = temp

print(ans)

Measured memory_bytes: 24804
import itertools
target = (0, 1)
N,M = map(int,input().split())
sk_ = [list(map(int,input().split())) for _ in range(M)]
P_ = list(map(int,input().split()))

max_n = 0
state = list(itertools.product(target,repeat=N))

for i in state:
  ons = 0
  #print(i)
  for j in range(M):
    num = 0
    for s in sk_[j][1:]:
      if i[s-1] == 1:
        num += 1
        #print('switch{} : on'.format(i[s-1]))
    #print('num : {}'.format(num))
    if num%2 == P_[j]:
      ons += 1
  #print('ons : {}'.format(ons))
  if ons == M:
    max_n += 1
    
print(max_n)



Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	int ans = 0;
	int Min = 1144555, v = Min;
	for (int i = 0; i < N; i++) {
		ans += L + i;
		if (Min > abs(L + i)) {
			Min = abs(L + i);
			v = L + i;
		}
	}
	cout << ans - v << endl;
	
	return 0;
}

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

int main() {
  array<int, 3> as;
  int min_time = INT_MAX;
  cin >> as.at(0) >> as.at(1) >> as.at(2);
  for (int i = 0; i < 3; ++i) {
    int time = 0;
    for (int j = 0; j < 3; ++j) {
      if ( i != j)
        time += as.at(j);
    }
    min_time = min(min_time, time);
  }

  cout << min_time << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int r=sc.nextInt();

		if(r<1200) {
			System.out.println("ABC");
		}
		else {
			System.out.println("ARC");
		}
	}
}

Measured memory_bytes: 21332
#include <iostream>

using namespace std;
#define INF (1e9)

int N, C[505], S[505], F[505];

int main(int argc, const char *argv[])
{
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> C[i] >> S[i] >> F[i];

    for (int i = 0; i < N; i++)
    {
        int t = 0;
        for (int j = i; j < N - 1; j++)
        {
            if (t <= S[j])
            {
                t = S[j] + C[j];
                continue;
            }

            if (t % F[j] == 0)
            {
                t += C[j];
                continue;
            }

            t = (t / F[j] + 1) * F[j] + C[j];
        }
        cout << t << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
A = str(input())
B = int(input())
count = 0

for i in range(len(A)):
    if A[i] == "1":
        count += 1
    else:
        if B <= count:
            print(1)
            sys.exit()
        else:
            print(A[i])
            sys.exit()
print(1)

Measured memory_bytes: 61748
#include<bits/stdc++.h>
using namespace std;
long long n,m,a,hsh[200005],cnt=0;
set<long long> s;
vector<long long> v;
int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a);
		++hsh[a];
		s.insert(a);
	}
	if(s.size()<=m)
	{
		printf("0\n");
	}else
	{
		for(int i=1;i<=200000;i++)
		{
			if(hsh[i]>0)
			{
				v.push_back(hsh[i]);
			}
		}
		sort(v.begin(),v.end());
		for(int i=0;i<s.size()-m;i++)
		{
			cnt+=v[i];
		}
		printf("%lld\n",cnt);
	}
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef vector <pll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool visit[20][20], grid[20][20];
ll n, m;

ll bfs( ll i , ll j , ll dist ){
	ll ans = 0;
	visit[i][j] = 1;
	queue < ppll > Q;
	Q.push({{i , j} , dist});
	while ( Q.size() != 0 ){
		ppll p = Q.front();
		Q.pop();
		i = p.ff.ff;
		j = p.ff.ss;
		//cout << i << " " << j << " " << p.ss << "\n";
		ans = max( ans , p.ss );
		if ( i + 1 < n )
			if ( !visit[i + 1][j] && !grid[i + 1][j] ){
				visit[i + 1][j] = 1;
				Q.push({{i+1 , j} , p.ss+1});
			}
		if ( j + 1 < m )
			if ( !visit[i][j + 1] && !grid[i][j + 1] ){
				visit[i][j + 1] = 1;
				Q.push({{i , j+1} , p.ss+1});
			}
		if ( i - 1 >= 0 )
			if ( !visit[i - 1][j] && !grid[i - 1][j] ){
				visit[i - 1][j] = 1;
				Q.push({{i-1 , j} , p.ss+1});
			}
		if ( j - 1 >= 0 )
			if ( !visit[i][j - 1] && !grid[i][j - 1] ){
				visit[i][j - 1] = 1;
				Q.push({{i , j-1} , p.ss+1});
			}
	}
	return ans;
}

int main() {
	FAST;
	ll k, z = 0, x, y, ans = 0, j, t = 0, c = 0, i;
    cin >> n >> m;
    string s;
    for ( i = 0 ; i < n ; i ++ ){
    	cin >> s;
    	for ( j = 0; j < m ; j ++ ){
    		grid[i][j] = (s[j] == '#');
    	}
    }
    for ( i = 0 ; i < n ; i ++ ){
    	for ( j = 0 ; j < m ; j ++ ){
    		if ( grid[i][j] == 1 ) continue; 
    		fill ( visit , 0 );
    		ans = max ( ans , bfs( i , j , 0 ) );
    	}
    }
    cout << ans;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    A, B = map(int, input().split())
    print(max([A + B, A - B, A * B]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	int a, b; cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)cout << "Possible\n";
	else cout << "Impossible\n";
}

Measured memory_bytes: 256
// Amsal Shoma Ro Gaedan Ye Amal Pasandidas !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 998244353;
const int N = 3e2 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll dp[N][N][N];

bool b[N][N][N];
int ans[N][N], p0[N], p1[N];
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	str s;
	cin >> s;
	int n = s.size();
	s = '!' + s;
	int c0 = 0, c1 = 0;
	for(auto c : s) c0 += (c == '0');
	for(auto c : s) c1 += (c == '1');
	memset(ans, -1, sizeof ans);

	for(int i = n - 1; i >= 0; i--) p0[i] = p0[i + 1] + (s[i + 1] == '0');
	for(int i = n - 1; i >= 0; i--) p1[i] = p1[i + 1] + (s[i + 1] == '1');

	b[0][0][0] = 1;
	for(int i = 0; i <= n; i++){
		for(int j = n; j >= 0; j--){
			for(int k = n; k >= 0; k--){
				if(!b[i][j][k]) continue;
				//cout << i << ' ' << j << ' ' << k << '\n';
				ans[c0 + j][c1 + k] = i;
				if(n - i + j + k < 2) continue;				
				
				if(j)
					b[i][j - 1][k] = 1;
				if(k)
					b[i][j][k - 1] = 1;
				if(j + k)
					b[i + 1][j][k] = 1;
				if(n - i >= 1){
					if(j)
						b[i + 1][j - 1 + (s[i + 1] == '0')][k + (s[i + 1] == '1')] = 1;
					if(k)
						b[i + 1][j + (s[i + 1] == '0')][k - 1 + (s[i + 1] == '1')] = 1;	
				}
				if(n - i >= 2){
					b[i + 2][j + (s[i + 1] == '0')][k + (s[i + 1] == '1')] = 1;
					b[i + 2][j + (s[i + 2] == '0')][k + (s[i + 2] == '1')] = 1;	
				}
			}
		}
		if(i < n){
			if(s[i + 1] == '0') c0 --;
			else c1 --;
		}
	}
	dp[n][0][0] = 1;
	for(int i = n; i >= 0; i--){
		for(int x = 0; x <= n; x++){
			for(int y = 0; y <= n; y++){
				if(i == n){
					if(x) dp[i][x][y] += dp[i][x - 1][y];
					if(y) dp[i][x][y] += dp[i][x][y - 1];
				} else {
					if(s[i + 1] == '0'){
						dp[i][x][y] = dp[i + 1][x][y] + (y ? dp[i][x][y - 1] : 0);
					} else {
						dp[i][x][y] = (x ? dp[i][x - 1][y] : 0) + dp[i + 1][x][y];
					}
				}
				dp[i][x][y] %= Mod;
			}
		}
	}
	ll res = 0;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			if(ans[i][j] != -1){
				//cout << i << ' ' << j << ' ' << dp[ans[i][j]][i - p0[ans[i][j]]][j - p1[ans[i][j]]] << '\n';
				res += dp[ans[i][j]][i - p0[ans[i][j]]][j - p1[ans[i][j]]];
			}
		}
	}
	cout << res % Mod << '\n';
	return 0;
}


Measured memory_bytes: 232832
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define srch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,a,b,c=0;
    string st;
    while(cin>>k)
    {
        n=100;
        c=0;
        while(n<k)
        {
            x=(n*1)/100;
            n+=x;
            c++;
        }
        cout<<c<<en;
    }
}




Measured memory_bytes: 3632
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main()
	{
		double n = GetDouble();
		double m = GetDouble();
		int d = GetInt();

		double ans = m - 1.0;
		ans *= (d == 0) ? 1.0 / n : (2.0 * (n - (double)d)) / (n * n);
		Console.WriteLine($"{ans:F12}");		
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13140
/*
Original problem: https://atcoder.jp/contests/abc133/tasks/abc133_c
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 2019;

namespace SOLVE {
    void main() {
        ll L, R;
		cin >> L >> R;
		VI rem(mod);
		REP(i,L,R+1) {
			if (i % mod == 0) {
				cout << 0 << endl;
				return;
			}
			rem[i%mod] =  1;
		}

		ll ans = 2019 * 2019;
		REP(i,0,mod) {
			REP(j,0,i) {
				if (rem[i] && rem[j]) {
					ans = min(ans, (i * j) % mod);
				}
			}
		}
		cout << ans << endl;
    }
}


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

	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M){
    if (N == M) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int a,b,c;cin>>a>>b>>c;
  if(b-a==c-b){
    cout<<"YES"<<"\n";
  }else{
    cout<<"NO"<<"\n";
  }

  return 0;
}


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

using namespace std;

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


int main()
{
  while(true) {
    ll m, nmin, nmax;
    cin >> m >> nmin >> nmax;
    if (m == 0 && nmin == 0 && nmax == 0) {
      break;
    }
    vector<ll> v(m, 0);
    for (int i = 0; i < m; i++){
      cin >> v[i];
    }
    ll tmp = 0;
    ll res = -1;
    for (int i = nmin-1; i < nmax; i++){
      if (v[i] - v[i+1] >= tmp) {
        tmp = v[i] - v[i+1];
        res = i+1;
      }
    }
    cout << res << endl;
  }
}



Measured memory_bytes: 3084
import sys
sys.setrecursionlimit(300000)
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


D = I()
C = LMI()
S = [LMI() for _ in range(D)]

last = defaultdict(int)
ans = 0
for d in range(D):
    m = -INF
    ans = -1
    for i in range(26):
        lans = S[d][i]
        for j in range(26):
            if i == j:
                lans -= C[j] * (d + 1 - d - 1)
            else:
                lans -= C[j] * (d + 1 - last[j])
        if lans > m:
            m = lans
            ans = i
    print(ans + 1)


Measured memory_bytes: 69956
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y){
    if(!y)
        return x;
    return gcd(y,x%y);
}
ll n,m;
int main()
{
   // freopen("light.in","r",stdin);
   // freopen("light.out","w",stdout);
    scanf("%lld%lld",&n,&m);
    m=min(m,n-m);
    ll k=max(gcd(n,m),n-gcd(n,m));
    printf("%lld\n",k*3);
}


Measured memory_bytes: 128
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      	String s = sc.next();
        char[] s_chars = s.toCharArray();
      	char ar[] = new char['z' - 'a' + 1];
      	int nam[] = new int[26];
      
      for(char i='a'; i<='z';i++) ar[i - 'a'] = i;
      
      for(int i = 0;i < s.length();i++){
        	char aa = s_chars[i];
       		for(int j = 0; j < 26;j++){
            if(ar[j]==aa){
            	nam[j] += 1; 
            }
          }
      }
      int flag = 0;
      for(int j = 0; j < 26;j++){
      		if(nam[j]%2!=0){
      		flag = 1;
            break;
      	}
      }
      
      if(flag==1){
      	System.out.print("No");
      }else{
      	System.out.print("Yes");
      }
        
        
        
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
template<typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from, int to, T cost) {
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
};
bool operator == (Edge<int> e1, Edge<int> e2) {
    return e1.from == e2.from &&
            e1.to == e2.to &&
            e1.cost == e2.cost;
}
bool operator > (Edge<int> e1, Edge<int> e2) {
    return e1.cost < e2.cost;
}
template<typename T>
using Edges = std::vector<Edge<T>>;
template<typename T>
using Graph = std::vector<Edges<T>>;
template <typename T>
std::vector<T> dijkstra(const Graph<T> &g, int s) {
    int sz = (int)(g.size());
    std::vector<T> dist(sz, std::numeric_limits<T>::max());
    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> pq;
    dist[s] = 0;
    pq.push({0, s});
    int rem = 1000000;
    while(!pq.empty()) {
        rem--;
        if(rem <= 0) break;
        T d = pq.top().first;
        int now = pq.top().second;
        pq.pop();
        if(d > dist[now]) continue;
        for(int i=0;i<(int)(g[now].size());++i) {
            int next = g[now][i].to;
            T cost = g[now][i].cost;
            if(dist[next] > dist[now] + cost) {
                dist[next] = dist[now] + cost;
                pq.push({cost, next});
            }
        }
    }
    return dist;
}
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m; cin >> n >> m;
  Graph<ll> g(n);
  for(int i=1;i<n;++i) {
    g[i].push_back(Edge<ll>(i, i-1, 0));
  }
  for(int i=0;i<m;++i) {
    int l, r, c; cin >> l >> r >> c;
    l--; r--;
    g[l].push_back(Edge<ll>(l, r, c));
  }
  vector<ll> dist = dijkstra(g, 0);
  cout << (dist[n-1] > LINF ? -1 : dist[n-1]) << endl;
}


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


using namespace std;

typedef long long ll;

const int MAXN = 100 + 12;





int n, a[MAXN], ans = INT_MAX;



int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = -100; i <= 100; i++) {
		int h = 0;
		for (int j = 0; j < n; j++)
			h += (a[j] - i) * (a[j] - i);
		ans = min(h, ans);
	}
	cout << ans;
	return 0;
}

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

#define ll long long int
#define loop(i,s,e) for(ll i=s; i<e; i++)
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX
#define minusinf INT_MIN

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

ll arr_Attack[100000], arr_Magic[100000];
ll n, h;

ll dp[1001][10001];

ll util(ll i, ll h){

	if(h<=0) return 0;
	if(h>0 and i>=n) return inf;

	if(dp[i][h]!=-1) return dp[i][h];

	ll a = arr_Magic[i] + util(i+1, h-arr_Attack[i]);
	ll b = util(i+1, h);
	ll c = arr_Magic[i] + util(i, h-arr_Attack[i]);

	return dp[i][h]=min(a, min(b,c));
}

void alpha(){

	cin>>h>>n;
	memset(dp, -1, sizeof(dp));

	loop(i,0,n) cin>>arr_Attack[i]>>arr_Magic[i];

	cout<<util(0, h)<<endl;

	return;

}

int main(){

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

    ll t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}

Measured memory_bytes: 79104
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,n1,n2
    integer(int32), allocatable:: a(:)

    read*, n

    

    n1 = n/3
    n2 = 2*n1
    allocate(a(n))
    read*, a(:)
    call merge_sort(a,1,n)
    if (a(n)==0) then
        print'(a)', 'Yes'
        stop
    end if
    if (mod(n,3) /= 0) then
        print'(a)', 'No'
        stop
    end if

    if (a(n1) == 0 .and. a(n1+1) > 0 .and. a(n1+1) == a(n)) then
        print'(a)', 'Yes'
        stop
    end if

    if (a(1)==(a(n1)) .and. a(n1+1)==a(n2) .and. a(n2+1)==a(n)) then
        if (xor(a(1),a(n1+1)) == a(n2+1)) then
            print'(a)', 'Yes'
            stop
        end if
    end if

    print'(a)', 'No'
contains
    recursive subroutine merge_sort(ar, fst, lst)
        integer(int32),intent(inout):: ar(:)
        integer(int32),intent(in):: fst,lst
        integer(int32):: mdl

        if (lst-fst < 2) then
            if (ar(fst) > ar(lst)) call swap(ar(fst),ar(lst))
            return
        end if

        mdl = (fst+lst)/2
        call merge_sort(ar, fst, mdl)
        call merge_sort(ar, mdl+1, lst)
        call merge_(ar, fst, mdl, lst)
    end subroutine

    subroutine merge_(ar, fst, mdl, lst)
        integer(int32),intent(inout):: ar(:)
        integer(int32),intent(in):: fst, mdl, lst
        integer(int32),allocatable:: tmp(:)
        integer(int32):: li, ri, ti

        allocate(tmp(lst-fst+1))

        li=fst
        ri=mdl+1   
        ti=1

        do while (li <= mdl .and. ri <= lst)
            if (ar(li) <= ar(ri)) then
                tmp(ti) = ar(li)
                li=li+1
            else
                tmp(ti) = ar(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            tmp(ti:) = ar(li:mdl)
        else
            tmp(ti:) = ar(ri:lst)
        end if

        ar(fst:lst) = tmp(:)
        deallocate(tmp)
    end subroutine

    subroutine swap(x,y)
        integer(int32),intent(inout):: x,y
        integer(int32):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine
end program name

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

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

	string s[h];
	for(int i=0;i<h;i++) cin >> s[i];

	for(int i=0;i<h;i++) {
		for(int j=0;j<2;j++) cout << s[i] << endl;
	}
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# coding:utf-8

def main():
    a, b, c, d = map(int, input().split())
    stdOut = solve(a, b, c, d)
    print(stdOut)


"""
方針


"""


def solve(a, b, c, d):
    ac = a * c
    ad = a * d
    bc = b * c
    bd = b * d
    l = [ac, ad, bc, bd]
    m = max(l)
    return m


if __name__ == "__main__":
    main()


Measured memory_bytes: 9192
N,M=gets.split.map(&:to_i)
data=Hash.new{0}
N.times do 
  a,b=gets.split.map(&:to_i)
  data[a]+=b
end
money=0
as=data.keys.sort
cnt=0
as.each do |e|
  if cnt+data[e]<M
    money+=e*data[e]
    cnt+=data[e]
  else
    money+=e*(M-cnt)
    break
  end
end
puts money
  

Measured memory_bytes: 10616
#include<bits/stdc++.h>
using namespace std;
inline int qr()
{
	int x=0,f=0;
	char ch=0;
	while(!isdigit(ch)) {
		f=ch=='-';
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return f?-x:x;
}
struct node{
	int x,y;
}nod[200010],fnod[200010];
bool mycmp(node a,node b)
{
	return 	a.x+a.y>b.x+b.y;
}
int n;
int ans;	
int mx;
int main()
{

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		nod[i].x=qr();nod[i].y=qr();
		mx=max(mx,nod[i].x);
	}
	sort(nod+1,nod+n+1,mycmp);
	for( int i=1;i<=n;i++)
	{
		fnod[i].x=abs(nod[i].x-mx);
		fnod[i].y=nod[i].y; 
	}
	sort(fnod+1,fnod+n+1,mycmp);
	ans=max(abs(fnod[n].x-fnod[1].x+fnod[n].y-fnod[1].y),abs(nod[n].x-nod[1].x+nod[n].y-nod[1].y));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;

int main() {
 int x,y,a,b,c;
 cin >> x >> y >> a >> b >> c;
 vector<ll> p(a),q(b),r(c);
 priority_queue<ll> que;
 rep(i,a) cin >> p[i];
 rep(i,b) cin >> q[i];
 rep(i,c) {
   cin >> r[i];
   que.push(r[i]);
  }
 sort(rall(p));
 sort(rall(q));
 rep(i,x){
   que.push(p[i]);
 }
 rep(i,y){
   que.push(q[i]);
 }
 ll ans = [&] {
   ll res=0;
   rep(i,x+y) res+=que.top(),que.pop();
   return res;
 }();
 cout << ans <<endl;
 
}

Measured memory_bytes: 8816
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(len(a)):
    ans += b[a[i]-1]
    if a[i]-a[i-1] == 1 and i > 0:
        ans += c[a[i-1]-1]
print(ans)

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

int n;
const int MAX_N = 2e5;
int bit[MAX_N + 2];
ll b[MAX_N + 1], c[MAX_N + 1];

void add(int i) {
    for (int j = i; j <= n + 1; j += j & -j) {
        bit[j]++;
    }
}

ll sum(int i) {
    ll rv = 0;
    for (int j = i; j > 0; j -= j & -j) {
        rv += bit[j];
    }
    return rv;
}

int main() {
    int  k;
    cin >> n >> k;
    for (int i = 0, a; i < n; i++) {
        cin >> a;
        b[i + 1] = b[i] + a - k;
        c[i + 1] = b[i + 1];
    }

    // 座標圧縮
    sort(c, c + n + 1);
    for (int i = 0; i <= n; i++) {  //b[i] <- index of b[i] in c
        int inf = 0, sup = n + 1;
        while (sup - inf > 1) {
            int mid = (inf + sup) / 2;
            if (c[mid] <= b[i])
                inf = mid;
            else
                sup = mid;
        }
        b[i] = sup;
    }
    ll ans = 0;
    // Binary Indexed Tree (Fenwick Tree)
    for (int i = 0; i < n + 1; i++) {
        ans += sum(b[i]);
        add(b[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4096
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
 ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
    ll ans  = n * (mi+ma) /2;
    return ans;
}
ll kw(ll k,ll n){
    
    ll ans  =0;
    ll mi,ma;
    mi= wa(k,0,k-1);
    
    ma = wa(k,n-k+1,n);
    
    return (ma-mi +1)%modd;
}

int main(){
    int a,b;
    cin >> a >> b;
    int ans = 0;
    double ha = 0.08;
    double ju = 0.1;
    while(true){
        int aa = ans * ha;
        int bb = ans * ju;

        if(aa == a && bb == b){
            cout <<ans <<endl;
            return 0;
        }
        ans ++;
        if(ans > 100000){
        cout << -1 <<endl;
        return 0;
    }
    }
    
}





Measured memory_bytes: 256