akhauriyash/Code-Regression huggingface dataset:
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}


string s,t;
int automata[101010][27];
set<pair<int,int>> st;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

	cin >> s >> t;
	int n = s.size();
	s+=s;
	s = " "+s;
	for(int i=1;i<=2*n;i++){
		st.insert({ s[i]-'a', i });
	}
	for(char c = 'a';c<='z';c++){
		//cout << c << " ";
	}
	//cout << endl;
	for(int i=0;i<=n;i++){
		for(int j=0;j<26;j++){
			auto it = st.lower_bound({ j, i+1 });
			if(it==st.end() || (*it).first!=j )automata[i][j]=-1;
			else {
				automata[i][j] = (*it).second;
			}
			//cout << automata[i][j] << " ";
		}
		//cout << endl;
	}

	int cur = 0,cnt=0,idx=0;

	while(idx<t.size() && cur!=-1){
		cur = automata[cur][t[idx]-'a'];
		//cout << cur << " " << idx << endl;
		if(cur>n){
			cnt++;
			cur-=n;
		}
		idx++;
	}

	if(cur==-1){
		cout << -1 << endl;
	}
	else {
		cout << n*cnt + cur << endl;
	}


return 0;
}
///....


Measured memory_bytes: 34216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

int find_rank(string s){
    string temp_str=s;
    sort(all(temp_str));
    int i=1;
    do{
        if(s==temp_str){
            return i;
        }
        i++;
    }while(next_permutation(all(temp_str)));
    return i;
}



int main(){
    int n;
    cin>>n;
    string s1,s2;
    for(int i=0;i<n;i++){
        int temp;
        cin>>temp;
        s1+=to_string(temp);
    }
    for(int i=0;i<n;i++){
        int temp;
        cin>>temp;
        s2+=to_string(temp);
    }
    int r1=find_rank(s1);
    int r2=find_rank(s2);
    cout<<abs(r1-r2)<<endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
a = [0]*100000
for i in A:
    a[i-1] += 1
Q = int(input())

ans = sum(A)

q = []

for i in range(Q):
    B, C = list(map(int, input().split()))
    if a[B-1] >= 1:
        ans = ans - B*a[B-1] + C*a[B-1]
        a[C-1] += a[B-1]
        a[B-1] = 0
    q.append(ans)

for i in q:
    print(i)

Measured memory_bytes: 20880
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = Integer.parseInt(sc.next());
            int K = Integer.parseInt(sc.next());
            int[] p = new int[N];
            for (int i = 0; i < N; i++) {
                p[i] = Integer.parseInt(sc.next());
            }
            Arrays.sort(p);
            int sum = 0;
            for (int i = 0; i < K; i++) {
                sum += p[i];
            }
            System.out.println(sum);
        }
    }

}

Measured memory_bytes: 38488
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;
const int MAXN = 101;
const int INF = 1e9 + 7;
lint weight[MAXN], value[MAXN], dp[MAXN][100001];
int N,W;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> W;
	for (int i = 0; i < N; ++i) {
		cin >> weight[i] >> value[i];
	}
	dp[0][0] = 10,dp[0][weight[0]] = value[0]+10;
	for (int i = 1; i < N; ++i) {
		for (int j = 0; j <= W; ++j) {
			if (dp[i - 1][j] == 0) continue;
			dp[i][j] = max(dp[i][j],dp[i-1][j]);
			if (j + weight[i] > W) continue;
			dp[i][j + weight[i]] = dp[i - 1][j] + value[i];
		}
	}
	lint ans = 0;
	for (int j = W; j >= 0; --j) {
		ans = max(ans, dp[N - 1][j]-10);
	}
	cout << ans << '\n';
	return 0;
}

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

int main(void) {
  int N, K, ans = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    ans = min(ans * 2, ans + K);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#define debarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
signed main()
{
	fast;
	ll n,m;
	cin>>n>>m;
	cout<<((1<<m)*((n-m)*100+m*1900));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;

long N, M;
vector<vector<pair<long, long>>> road(100001);
bool vis[100001];
long pos[100001];

void dfs(long x){
  vis[x] = true;
  rep(i, road[x].size()){
    long f = road[x][i].first;
    long s = road[x][i].second;
    if(vis[f] == false){
      pos[f] = pos[x] + s;
      dfs(f);
    }
  }
}

int main() {
cin >> N >> M;
vector<long> l(M+1); vector<long> r(M+1); vector<long> d(M+1);
erep(i, M){
  cin >> l[i] >> r[i] >> d[i];
  road[l[i]].push_back(make_pair(r[i], d[i]));
  road[r[i]].push_back(make_pair(l[i], -d[i]));
}
erep(i, N){
  if(vis[i] == false){
    pos[i] = 0;
    dfs(i);
  }
}
erep(i, M){
  if(pos[r[i]] != pos[l[i]] + d[i]){
    show("No");
    return 0;
  }
}
show("Yes");
 return 0;
 
}



Measured memory_bytes: 20352
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;

const ll INF = 1e5+7;
const ll M = 107;
ll n, a[M], ans = 0;

signed main(){
//	freopen("PERFECT1.inp","r",stdin);
//	freopen("PERFECT1.out","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	a[0] = a[n] = INF;
	ff(i,1,n) cin >> a[i];
	f(i,1,n){
		ans += min(a[i-1], a[i]);
	} 
	cout << ans;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
ll mod = 1000000007;
ll big(ll b, ll p){
	if (p == 1) return b;
	ll h = big(b, p / 2);
	ll res = (h * h) % mod;
	if (p % 2 == 1) res = (res * b) % mod;
	return res;
}
int main(){
	ll n, a, b;
	scanf("%lld %lld %lld", &n, &a, &b);
	ll ans = (big(2, n) + mod - 1) % mod;
	ll c[200001];
	c[0] = 1;
	for (int i = 1; i <= max(a, b); i++){
		c[i] = (c[i - 1] * (n + 1 - i)) % mod;
		c[i] = (c[i] * big(i, mod - 2)) % mod;
	}
	ans = (ans + mod - c[a]) % mod;
	ans = (ans + mod - c[b]) % mod;
	printf("%lld\n", ans);
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int x, y, z; cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  cout << x << " " << y << " " << z << endl;
  return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, m;

  scanf("%d%d", &n, &m);

  int a, s = 0;
  ll ans = 0;
  map<int,int> mm;

  for(int i=0;i<n;i++){
    mm[s]++;

    scanf("%d", &a);
    s = (s + a) % m;

    ans += mm[s];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3200
/* ex4_3
   takafumi_ueki */
#include <stdio.h>
#include <math.h>
//プロトタイプ宣言
int tower(int n);
int main(void){
    int dif, height_west, height_east, ans;
    scanf("%d %d",&height_west,&height_east);
    //雪に埋れていても埋もれていなくても塔の高さの差は変わらない
    //西と東の塔の高さの差から東の塔の高さが何メートルか分かる
    dif = height_east - height_west;
    //東の塔の高さから雪に埋もれていない部分の高さを引いた値が積もっている雪の高さである。
    ans = tower(dif) - height_east;
    printf("%d\n",ans);
    return 0;
}
//関数の定義
int tower(int n){
    int hight;
    hight = n*(n + 1)/2;
    return hight;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <string>

int X, C500, C5;

int main() {
  std::cin >> X;
  C500 = X / 500;
  C5 = (X % 500)/5;
  std::cout << C500*1000 + C5*5<< std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double r;cin>>r;
    cout<<fixed<<setprecision(10)<<r*M_PI*2.00<<endl;
}


Measured memory_bytes: 3804
#include<stdio.h>
int main(){
  int a,b,c,x;
  scanf("%d%d%d",&a,&b,&c);
  if(a>b){
    x=a;
    a=b;
    b=x;
  }
  if(b>c){
    x=b;
    b=c;
    c=x;
  }
  if(a>b){
    x=a;
    a=b;
    b=x;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN1=2001;
const int MAXN2=4000001;
int n,tot=0,sum=0;
int a[MAXN1],canget[MAXN2];
bool flag[MAXN2];
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	memset(flag,0,sizeof(flag));
	n=read();
	for(int i=1;i<=n;++i) sum+=(a[i]=read());
	if(sum&1) ++sum;sum/=2;
	flag[0]=true;canget[++tot]=0;
	for(int i=1;i<=n;++i)
	{
		int temp=tot;
		for(int j=1;j<=temp;++j)
		{
			int k=a[i]+canget[j];
			if(flag[k]==false)
			{
				flag[k]=true;
				if(k<sum) canget[++tot]=k;
			}
		}
	}
	for(int i=sum;i<MAXN2;++i)
		if(flag[i])
		{
			printf("%d",i);
			return 0;
		}
}

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

int main() {
  int N = 0;
  cin >> N;
  
  int as[N];
  
  for( int i = 0; i < N; ++i ){
    cin >> as[i];
  }
  
  int number = 0;
  int count = 0;
  while( count < N ){
    if( as[number] == 2 ){
      ++count;
      break;
    }else{
      number = as[number] - 1;
      ++count;
    }
  }

  if( count == N ){
    cout << "-1" << endl;
  }else{
    cout << count << endl;
  }
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using pii = pair<int, int>;
using ll = long long;
vector<int> x_points[100002];
vector<int> y_points[100002];
int colors[1000000];

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

    pii xy[n];
    rep(i, n)
    {
        cin >> xy[i].first >> xy[i].second;
        x_points[xy[i].first].push_back(i);
        y_points[xy[i].second].push_back(i);
    }

    ll ans = 0;
    int color = 1;
    rep(i, n)
    {
        if (colors[i] > 0) continue;

        queue<int> que;
        que.push(i);
        set<int> x_set, y_set;
        while (que.size() > 0)
        {
            int now = que.front();
            que.pop();

            if (colors[now] != 0)
                continue;
            colors[now] = color;
            
            int x = xy[now].first;
            int y = xy[now].second;
            x_set.insert(x);
            y_set.insert(y);

            for (auto next: x_points[x])
                que.push(next);
            for (auto next: y_points[y])
                que.push(next);
        }
        // cout << x_set.size() << ' ' << y_set.size() << endl;
        color++;
        ans += (ll) x_set.size() * y_set.size();
    }
    ans -= n;
    cout << ans << endl;
}

Measured memory_bytes: 275900
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a;cin>>n;
  vector<P> v(n);
  rep(i,n) {cin>>a;v[i]=P(a,i+1);}
  sort(ALL(v));
  rep(i,n-1) cout<<v[i].second<<' ';print(v[n-1].second);
  return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> ans(n);
	for (int cou = 0;cou < n;cou++) {
		string s, t;
		cin >> s >> t;
		int S = s.size(), T = t.size();
		vector<vector<int> > dp(S + 1, vector<int>(T + 1, 0));
		for (int i = 0;i < S;i++) {
			for (int j = 0;j < T;j++) {
				if (s[i] == t[j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
				}
				else {
					dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
				}
			}
		}
		ans[cou] = dp[S][T];
	}
	for (int i = 0;i < n;i++) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 6728
import itertools

n = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

p_index = -1
q_index = -1
combs = itertools.permutations(range(1, n + 1), n)
for index, each in enumerate(combs):
    if all(P[i] == each[i] for i in range(n)):
        p_index = index

    if all(Q[i] == each[i] for i in range(n)):
        q_index = index
print(abs(p_index - q_index))


Measured memory_bytes: 48220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    string s; cin>>s;
    int k; cin>>k;
    set<string> mp;
    for(int i=0; i<s.size(); i++){
        string temp="";
        for(int j=0; (j<5) and ((i+j)<s.size()); j++){
            temp+=s[i+j];
        }
        mp.insert(temp);
    }
    int cnt=0;
    set<string> ansset;
    for(auto i:mp){
        string ans="";
        rep(j,0,i.size()){
            ans+=i[j];
            if(ansset.find(ans)==ansset.end()) cnt++;
            ansset.insert(ans);
            if(cnt==k){
                cout<<ans<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 768
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;
    
  // // debug(x, y, z, s, b);
    
  // double aux = 1010.0;
  // string code = "code";
    
  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ll n;
  cin >> n;
  vector <ll> v(n);
  map <ll,ll> m;
  for (int i = 0; i < n; ++i)
  {
    cin >> v[i];
    m[v[i]]++;
  }
  ll ans = 0;
  for (auto i: m)
  {
    ans += i.ss*(i.ss-1)/2;
  }
  for (int i = 0; i < n; ++i)
  {
    cout << ans -(m[v[i]]*(m[v[i]]-1))/2 + ((m[v[i]]-1)*(m[v[i]]-2))/2 << endl;
  }
  return 0;
}


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

int main()
{
  int L;
  while (cin >> L && L != 0) {
    vector<int> ds(12);
    for (int i = 0; i < 12; i++) {
      int M, N;
      cin >> M >> N;
      ds[i] = M-N;
    }

    int s = 0;
    int ans = 0;
    for (int i = 0; i < 12; i++) {
      s += ds[i];
      if (s >= L) {
        ans = i+1;
        break;
      }
    }
    if (ans == 0) {
      cout << "NA" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}

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

def main():
    n,m = map(int,input().split())
    li = [list(map(int,input().split())) for _ in range(m)]

    roots = [[] for _ in range(n)]
    for x,y,z in li:
        roots[x-1].append(y-1)
        roots[y-1].append(x-1)

    ans = 0
    count = 0
    group = [-1] * n

    for i in range(n):
        if group[i] == -1:
            stack = [i]
            while stack:
                label = stack.pop(-1)
                for j in roots[label]:
                    if group[j] == -1:
                        group[j] = ans
                        stack.append(j)
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()


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

int main()
{
  char ch;
  int counter[26]={0};

  while( cin >> ch )
  {
    if('a' <= ch && ch <= 'z')
    {
      int num = ch - 'a';  // 文字 ch の番号
      counter[num]++;
    }
    else if('A' <= ch && ch <= 'Z')
    {
      int  num = ch - 'A';
      counter[num]++;
    }
    else
      continue;
  }

  for(int i=0;i<26;i++)
    cout << (char)('a'+i) << " : " << counter[i] << endl;

  return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

ll h,w;

//グラフのテンプレート
template<typename T>
struct edge {
	int from, to;
	T cost;

    edge(int to,T cost):from(0),to(to),cost(cost){}
	edge(int from, int to, T cost) :from(from), to(to), cost(cost) {}
};

//Union-Findtree
struct UF {
	vector<int>par;//親
	vector<int>Rank;//木の深さ

    UF(int n){init(n);}

	//初期化
	void init(int n) {
		par.resize(n); Rank.resize(n);
		for (int i = 0; i < n; i++) {
			par[i]= i;
			Rank[i] = 0;
		}
	}

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	//xとyの属する集合を併合
	bool unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return false;//すでに同じ集合に属している

		if (Rank[x] < Rank[y]) {//高さが小さい方を下に
			par[x] = y;
		}
		else {
			par[y] = x;
			if (Rank[x] == Rank[y])Rank[x]++;//同じだとrankが変わらないままになるので増やす（それ以外は大きい方のrankが採用される）
		}
        return true;
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

template<typename T>
ll kruskal(vector<edge<T>> &e,int v){//クラスカル法(最小全域木における最小の重みを判定)
    //v頂点からなる重み付き辺集合e
    sort(e.begin(),e.end(),[](const edge<T> &e1,const edge<T> &e2){
        return e1.cost.first<e2.cost.first;//ラムダ式を使ってedge.costが小さい順にソート
    });
    UF tree(v);
    ll sum=0;
		ll hh=h+1,ww=w+1;
    for(auto &es:e){
        if(tree.unite(es.from,es.to)){
					if(es.cost.second==1){
						sum+=es.cost.first*hh;
						--ww;
					}
					else {
						sum+=es.cost.first*ww;
						--hh;
					}
				}
    }
    return sum;
}

using P=pair<ll,int>;
void solve()
{
	cin>>w>>h;
	ll ans=0;
  vector<ll>p(w),q(h);
  rep(i,w)cin>>p[i];
  rep(i,h)cin>>q[i];
  vector<edge<P>>e;
	rep(i,w)e.emplace_back(i,i+1,P{p[i],1});
	rep(i,h)e.emplace_back(i+w,i+w+1,P{q[i],0});
	ans=kruskal<P>(e,h+w+1);
	cout<<ans<<endl;
}

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


Measured memory_bytes: 10096
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 10000000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(auto a,long long b){
    long long ans=1;
    //cout<<ans;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    ///cout<<ans<<" ";    
    return ans;
        
}
void maxi(auto &a,auto b){
    a=max(a,b);
}
void mini(auto &a,auto b){
    a=min(a,b);
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t;
    cin>>s>>t;
    int x=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i])x++;
    }
    cout<<x;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 int main() 
{
  ios_base::sync_with_stdio(0);
   cin.tie(NULL);
   
   long long int i,j;
   cin>>i>>j;
    int flag=0;
  for(int q=i;q<=j;q++)
   {
       if(q%2019==0)
        {flag=1;
        break;}
   }
   
   if(flag==1)
    cout<<0<<"\n";
    else
    {  long long int ma=INT_MAX;
        for(long long int q=i;q<j;q++)
         { 
             for(long long int q1=i+1;q1<=j;q1++)
        {ma=min(((q%2019)*((q1)%2019))%2019,ma);
            //cout<<ma<<" "; 
        }
         }
         cout<<ma<<"\n";
    }
    
   return 0;
}
 
 

Measured memory_bytes: 256
import itertools
N = int(input())
L = list(map(int, input().split()))
M = list(itertools.combinations(L,3))
Ans = 0
for i in M:
    i = sorted(list(i))
    if len(set(i)) == 3:
        if i[0] + i[1] > i[2]:
            if i[1] - i[0] < i[2] :
                Ans += 1
                
print(Ans)

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a[3]; cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	
	if(((a[2]-a[0])&1) ^ ((a[2]-a[1])&1)){
		cout << (2*a[2]-a[0]-a[1]+1)/2+1 << endl;
	}
	else{
		cout << (2*a[2]-a[0]-a[1])/2 << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/
struct RSQ{
    public:
        int n;
        vector<long long> data;
        RSQ(int n_){
            n = 1;
            while(n<n_) n*=2;
            data.resize(2*n-1);
            for(int i=0;i<2*n-1;i++) data[i]=0;
        }
        void update(int k,long long a){
            k+=n-1;
            data[k]=a;
            while(k>0){
                k=(k-1)/2;
                data[k]=data[k*2+1]+data[k*2+2];
            }
        }
        long long query(int a,int b,int k,int l,int r){
            if(r<=a or b<=l) return 0;
            if(a<=l and r<=b) return data[k];
            else return query(a,b,k*2+1,l,(l+r)/2)+query(a,b,k*2+2,(l+r)/2,r);
        }
        long long query(int a,int b){ return query(a,b,0,0,n); }
};

int main(){
    ll N,K; cin >> N >> K;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];

    vector<ll> b(N+1,0);
    b[0] = 0;
    for(int i=0;i<N;i++) b[i+1] = b[i] + a[i];
    for(long long i=0;i<=N;i++) b[i] -= i * K;

    set<ll> st;
    st.insert(0);
    for(int i=1;i<=N;i++) st.insert(b[i]);
    map<ll,ll> mp;
    int cnt = 0;
    for(ll val : st){
        mp[val] = cnt++;
    }

    ll ans = 0;
    RSQ seg(N+1);
    seg.update(mp[0],1);

    for(int i=1;i<=N;i++){
        int idx = mp[b[i]];
        ll sum = seg.query(0,idx+1);
        ans += sum;
        ll tmp = seg.data[idx+seg.n-1];
        seg.update(idx,tmp+1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 29312
h,w,d = gets.chomp.split(" ").map(&:to_i)
a = h.times.map{gets.chomp.split(" ").map(&:to_i)}
q = gets.to_i
l = q.times.map{gets.chomp.split(" ").map(&:to_i)}
c = Array.new(h*w).map{Array.new(2)}
e = Array.new(h*w+d,0)
for i in 0..h-1
  for j in 0..w-1
    c[a[i][j]-1] = [i+1,j+1]
  end
end
for i in d..h*w-1
  e[i] = e[i-d]+(c[i][0]-c[i-d][0]).abs+(c[i][1]-c[i-d][1]).abs
end
for i in 0..q-1
  puts e[l[i][1]-1]-e[l[i][0]-1]
end

Measured memory_bytes: 19068
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
const int INF = 1000000009;

int len;
std::string s;
int alp[26];

int main(){
	std::cin >> s;
	for(int i = 0; i < s.length(); i++){
		alp[s[i] - 'a']++;
	}
	char crit = -1;
	for(int i = s.length()-1; i >= -1; i--){
		/*for(int j = 0; j < 26; j++){
			printf("(%c %d)  ", j+'a', alp[j]);
		}
		printf("\n");
		* //*/
		for(int j = crit+1; j < 26; j++){
			if(alp[j] == 0){
				s.push_back(j+'a');
				std::cout << s << std::endl;
				return 0;
			}
		}
		if(i >= 0){
			alp[s[i] - 'a']--;
			crit = s[i] - 'a';
			s.pop_back();
		}
	}
	printf("-1\n");
	return 0;
}


Measured memory_bytes: 256
def insertion_sort(A, N):
    for i in range(N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        print(' '.join(map(str, A)))


def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
    
    insertion_sort(A, N)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 7656
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define max(p,q)((p)>(q)?(p):(q))
int i,j,k;
int row,column,knum;
int r,c,v;
int table[3010][3010];
long long int ret;
long long int dp[3010][3010][4];

int main()
{
    scanf("%d%d%d",&row,&column,&knum);
    for (i=0;i<3010;i++){
        for (j=0;j<3010;j++){
            table[i][j]=0;
        }
    }
    for (i=0;i<3010;i++){
        for (j=0;j<3010;j++){
            for (k=0;k<4;k++){
                dp[i][j][k]=0;
            }
        }
    }
    for (i=0;i<knum;i++){
        scanf("%d%d%d",&r,&c,&v);
        table[r-1][c-1]=v;
    }
    for (i=0;i<row;i++){
        for (j=0;j<column;j++){
            for (k=2;k>=0;k--){
                dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j][k]+table[i][j]);
            }
            for (k=0;k<4;k++){
                if (i<row-1) dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
                if (j<column-1) dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
            }
        }
    }
    ret=dp[row-1][column-1][0];
    for (i=0;i<4;i++){
        ret=max(ret,dp[row-1][column-1][i]);
    }
    printf("%lld\n",ret);
    return 0;
}


Measured memory_bytes: 320248
/*
    author: kartik8800
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x 
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

string solve(vector<int>& v, int k)
{
    bool dp[k+1];
    memset(dp, 0, sizeof dp);

    for(int i = 1; i <= k; i++)
    {
        for(int move : v)
        {
            if(move > i)
                continue;
            if(dp[i - move] == 0)
                dp[i] = 1;
        }
    }
    
    return dp[k] ? "First" : "Second";
}

int main() {
   int n,k;
   cin >> n >> k;
   vector<int> v(n);
   for(int i =0; i<=n; i++)
    cin>>v[i];
   cout<<solve(v, k);
   return 0;
}


Measured memory_bytes: 384
N = int(input())

if N <= 9:
    ans = N
elif N <= 99:
    ans = 9
elif N <= 999:
    ans = 9 + N - 100 + 1
elif N <= 9999:
    ans = 9 + 900
elif N <= 99999:
    ans = 9 + 900 + N - 10000 + 1
else:
    ans = 9 + 900 + 90000
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<long long> a(n);
	long long ans=1;
	double dans=1;
	for(int i=0; i<n; ++i) cin >> a[i];
	sort(a.begin(),a.end());

	for(int i=0; i<n; ++i){
		ans *= a[i];
		dans *= a[i];
		if(dans>1e18 || ans>(long long)1e18){
			ans=-1;
			break;
		}
	}

	cout << (long long)ans << endl;
}

Measured memory_bytes: 4052
#ABC046C
N=int(input())
A=[[]*N]
a,b=1,1
for n in range(N):
    A,B=map(int,input().split())
    if a%A!=0:
        ka=a//A+1
    else:
        ka=a//A
    if b%B!=0:
        kb=b//B+1
    else:
        kb=b//B
    k=max(ka,kb)
    a,b=A*k,B*k
print(a+b)

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

int dfs(int x,int y);

int main(){
  int x,y;
  cin >> x >> y;
  if(x < y){
    swap(x,y);
  }
  cout << dfs(x,y) << endl;
  return 0;
}

int dfs(int x,int y){
  if(!y)return x;
  return(dfs(y,x % y));
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

struct katana {
    long long a;
    long long b;
    bool operator<(const katana& r) const {
        return b == r.b ? a < r.a : b < r.b;
    }
};

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

    vector<katana> v(N);

    long long max_attack = 0;
    for (int i=0; i<N; i++) {
        cin >> v[i].a >> v[i].b;
        max_attack = max(max_attack, v[i].a);
    }

    sort(v.rbegin(), v.rend());

    long long ans = LLONG_MAX;
    long long s = 0;
    for (int i=0; i<=N; i++) { // 刀を何本投げるか
        if (i > 0) {
            s += v[i - 1].b;
        }
        long long remain_hp = max(0LL, H - s);
        ans = min(ans, i + (remain_hp + max_attack - 1) / max_attack);
    }

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ll long long
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1<<1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1<<2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1<<3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1<<4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1<<5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1<<6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1<<7) // 0000 0000 1000 0000

int main(){
    int n,m,hw;
    ll ans=0;
    cin >> n >> m;
    rep(i,m){
        cin >> hw;
        ans+=hw;
    }
    if(n-ans>=0){
        cout << n-ans << endl;
        return 0;
    }else{
        cout << -1 << endl;
        return 0;
    }
}

Measured memory_bytes: 3592
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
int mod = 1000000007;
int mod1 = 998244353;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void u(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb]){
            v[ra] = v[rb];
            sz[rb]+=sz[ra];
        }else{
            v[rb]=v[ra];
            sz[ra]+=sz[rb];
        }
    }
    bool f(int a,int b){
        //same set
        return (root(a)==root(b));
    }
   
    
};


int32_t main(){
	IO
	int n;
	cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++){
        if(i%3==0 or i%5==0)continue;
        else sum+=i;
    }
    cout<<sum;
}

Measured memory_bytes: 5984
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <deque>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> istream& operator>>(istream &is, pair<S, T> &p){ return is >> p.first >> p.second; }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ return os << "[" << p.first << ", " << p.second << "]"; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rof(i, n) for(int i = (n)-1; i >= 0; i --)
#define Rof1(i, n) for(int i = (n); i >= 1; i --)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
#define Return(x) { Cout(x); return 0; }

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, p);
    
    vc<int> ix(n+1);
    For(i, n) ix[p[i]] = i;

    int ans = 0, tmp = 1;
    For1(i, n-1){
        if(ix[i] < ix[i+1]) tmp ++;
        else Maxi(ans, tmp), tmp = 1;
    }
    Maxi(ans, tmp);
    Cout(n-ans);
}


Measured memory_bytes: 1920
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

int main() {
	int K, X;
	cin >> K >> X;

	if (500 * K >= X) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
}

Measured memory_bytes: 256
list_menu = [int(input()) for i in range(5)]

list_time_reminders = []


for i in list_menu:
	reminder_i = 10 - (i % 10)
	if reminder_i == 10:
		reminder_i = 0
	
	list_time_reminders.append(reminder_i)

max_reminder = max(list_time_reminders)

list_time_reminders.remove(max_reminder)

total_cooking_time = 0

for i in list_menu:
	total_cooking_time += i

for i in list_time_reminders:
	total_cooking_time += i


print(total_cooking_time)

Measured memory_bytes: 3064
/*
2020-05-05
atcoder ABC
*/

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI 3.14159265358979323846264338327950L
const ll mod = 1000000007;

int main() {
    int A, B, H, M, T;
    long double ea, eb, e;
    cin >> A >> B >> H >> M;

    T = M + 60 * H;
    ea = T * 0.5;
    eb = T * 6;
    while(ea >= 360){
        ea -= 360;
    }
    while(eb >= 360){
        eb -= 360;
    }
    e = abs(ea-eb);
    e = min(360-e,e);
    cout << fixed << setprecision(20) << sqrt(pow(A, 2.0) + pow(B, 2.0) - 2 * A * B * cos(PI * e / 180)) << endl;

    return 0;
}


Measured memory_bytes: 4172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; i++)
//大きい方の値で引数を更新する関数
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;}

int main(){
    int n;
    cin >> n;
    vector<int64_t> v(n);
    int min = 0;
    int64_t ans = 0;
    rep(i,n){
        cin >> v[i];
    }
    rep(i,n){
        if (v[i] > min){
            min = v[i];
        }
        else{
            int64_t k = min - v[i];
            ans += k;
        }
    }
    cout << ans << endl;
}

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

int main(){


	
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	long long ans=0;
	for (int i=0;i < n;i++) cin >> h[i];



	if (n > k) {
		sort(h.begin(), h.end());
		for (int i = 0;i < n - k;i++)ans += h[i];
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<list>
#define ll long long
using namespace std;
ll h[200050],dp[200050];
int main()
{
	ll n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	memset(dp,0,sizeof(dp));
	dp[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;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]<<endl;
	return 0;
}

Measured memory_bytes: 2560