akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LL long long

namespace io {
    template <typename T> inline void read(T & _x) {
        int f = 0, ch; _x = 0;
        while(!isdigit(ch = getchar())) f |= ch == '-';
        while(isdigit(ch)) _x = _x * 10 + ch - '0', ch = getchar();
        if(f) _x = -_x;
    }
    template <typename T, typename ... Args> inline void read(T &_f, Args& ... args) {
        read(_f), read(args ...);
    }
    inline void _deal(char ch) { putchar(ch); }
    template <typename T> inline void _deal(T _x) {
        if (_x < 0) putchar('-'), _x = -_x;
        if (_x > 9) _deal(_x / 10);
        putchar(_x % 10 + '0');
    }
    inline void write() {}
    template <typename T, typename ... Args> inline void write(T _f, Args ... args) {
        _deal(_f), write(args...);
    }
}

const int N = 1e5 + 5;

int n, q, a[N], w[N];
int64_t sum;

int32_t main() {
	io::read(n);
	for(int i = 1; i <= n; ++i) {
		io::read(a[i]);
		++w[a[i]];
		sum += a[i];
	}
	io::read(q);
	while(q--) {
		int b, c;
		io::read(b, c);
		sum -= 1LL * b * w[b];
		sum += 1LL * c * w[b];
		w[c] += w[b];
		w[b] = 0;
		printf("%lld\n", sum);
	}
    return 0;
}



Measured memory_bytes: 4524
int main(){int s[9000],n,m,t,f,i;while(scanf("%d%d",&n,&m)&&n){for(i=t=f=1;i<=n+m;i++){scanf("%d",&s[i]);if(i>n){t+=s[t+=s[i]];if(t>=n&&f==1){printf("%d\n",i-n);f=0;}}}}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (1e9 + 1.5)

const int N = 100010;
int n, w[N];
ll d[N];

bool solve() {
    ll once = n * 1ll * (n + 1) / 2, total = 0;
    for(int i = 0; i < n; ++i) total += w[i];
    if(total % once) return false;

    ll times = total / once;
    for(int i = 0; i < n; ++i) d[i] = w[i] - w[(i - 1 + n) % n];

    for(int i = 0; i < n; ++i) d[i] -= times;
    for(int i = 0; i < n - 1; ++i)
        if(d[i] % n != d[i + 1] % n) return false;
    ll maxd = -INF;
    for(int i = 0; i < n; ++i) maxd = max(maxd, d[i]);
    for(int i = 0; i < n; ++i) {
        times -= (maxd - d[i]) / n;
        if(times < 0) return false;
    }
    return times % n == 0;
}

int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; ++i) scanf("%d", &w[i]);
    puts(solve() ? "YES" : "NO");
    return 0;
}



Measured memory_bytes: 1408
import math

a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
n = math.floor(x/500) + 1
for i in range(n)[0:a+1]:
  m = math.floor((x - 500*i)/100) + 1
  for j in range(m)[0:b+1]:
    l = (x - 500*i - 100*j)
    if l <= 50*c:
      ans += 1
print(ans)

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

int N, x, a[101];


int main(void){
    cin >> N >> x;
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    sort(a, a + N);
    int ans = 0;
    int i;
    for (i=0;i<N;i++){
        if (x-a[i]>=0){
            ans++;
            x -= a[i];
        }else{
            break;
        }
    }
    i--;
    if (x!=0&&ans==N) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
A,B = map(int, input().split())
*P, = map(int, input().split())

P.sort()

c = [0] * 3
for p in P:
    if p <= A:
        c[0] += 1
    elif A < p <= B:
        c[1] += 1
    elif B < p:
        c[2] += 1

print(min(c))

Measured memory_bytes: 9108
# -*- coding: utf-8 -*-

from collections import Counter
from math import factorial

n = int(input())


def prime_factorize(x):
    li = []

    while x % 2 == 0:
        li.append(2)
        x //= 2

    f = 3
    while f * f <= x:
        if x % f == 0:
            li.append(f)
            x //= f
        else:
            f += 2

    if x != 1:
        li.append(x)

    return li


fact = factorial(n)
li = prime_factorize(fact)
c = Counter(li)
ans = 1
mod = 10 ** 9 + 7
for v in c.values():
    ans *= v + 1
    ans %= mod

print(ans)


Measured memory_bytes: 3316
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main(args: Array<String>) {
  val (n, k) = readIs()
  val m = min(n, k)
  val vv = readIs()
  var ans = 0
  for (i in 0..m) {
    var suml = 0
    val negl = mutableListOf<Int>()
    for (ii in 0 until i) {
      suml += vv[ii]
      if (vv[ii] < 0) negl += vv[ii]
    }
    for (j in 0..(m - i)) {
      var sum = suml
      val neg = ArrayList(negl)
      for (jj in n - j until n) {
        sum += vv[jj]
        if (vv[jj] < 0) neg += vv[jj]
      }
      val sneg = neg.sorted()
      for (h in 0 until min(sneg.size, k - i - j)) {
        sum -= sneg[h]
      }
      ans = max(ans, sum)
    }
  }
  println(ans)
}


Measured memory_bytes: 42096
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define iii tuple<int, int, int>
#define ii pair<int, int>
#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
    int n, M = 1e9 + 7;
    cin >> n;

    vector<vector<int>> a(n, vector<int>(n));
    for (auto& i : a)
        for (auto& j : i) cin >> j;

    vector<int> dp(1 << n), p2(n + 1);
    for (int i = 0; i <= n; ++i) p2[i] = 1 << i;
    dp[0] = 1;

    queue<ii> q;
    q.push({0, 0});
    while (!q.empty()) {
        int msk = q.front().fi, i = q.front().se;
        q.pop();

        if (msk == p2[n] - 1) break;
        if (!dp[msk]) continue;

        for (int j = 0; j < n; ++j) {
            if (a[i][j] && !(msk & p2[j])) {
                q.push({msk | p2[j], i + 1});
                dp[msk | p2[j]] = (dp[msk | p2[j]] + dp[msk]) % M;
            }
        }
        dp[msk] = 0;
    }
    cout << dp[p2[n] - 1] << '\n';
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

Measured memory_bytes: 41804
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda xy:xy[1], reverse=True)
cd.sort()
ans = 0
for b in cd:
    for r in ab:
        if(r[0] < b[0] and r[1] < b[1]):
            ab.remove(r)
            ans += 1
            break
print(ans)

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

using namespace std;

using   ll=long long;
using   ld=long double;

#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define long long      int 
#define pb             push_back
#define mp             make_pair
#define ff             first
#define ss             second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323
#define inf 		   LLONG_MAX
#define ones(x)		   __builtin_popcount(x)

void solve()
{
	ll a,b;
	
	cin>>a>>b;
	
	for(int i=a*100/8 ;i<=100000;i++)
	{
		if(i/10 == b && i*8/100 == a)
		{
			cout<<i;
			return;
		}
	}
	
	cout<<-1;
}
 
signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}


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

int main(){
	int n,a[50],cnt=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]!=(i+1))
			cnt++;
	}
	if(cnt==2||cnt==0)
		cout<<"YES\n";
	else 
		cout<<"NO\n";
	return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,c,k;
  cin >> n >> c >> k;
  vl t(n);
  REP(i,n) cin >> t[i];
  sort(t.begin(),t.end());
  ll ans = 0;
  ll last = t[0];
  ll num = 0;
  REP(i,n){
    if(num==0) last = t[i];
    if(t[i]>last+k){
      num = 1;
      last = t[i];
      ans++;
    }else if(++num == c){
      ans++;
      num = 0;
    }
    //cout << "num: " << num << ", " << "ans: " << ans << "last: " << last << endl;
  }
  if(num>0) ans++;

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


Measured memory_bytes: 1024
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(void){
	pair<pair<string,int>,int> p[110];
	int N;
	cin>>N;
	rep(i,N){
		cin>>p[i].first.first>>p[i].first.second;
		p[i].first.second*=-1;
		p[i].second = i+1;
	}
	sort(p,p+N);
	rep(i,N){
		cout<<p[i].second<<endl;
	}
	
	return 0;
}


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

typedef struct{
  int num;
  string location;
  int point;
} restaurant;

int main(void){
  int n, i;
  cin >> n;
  restaurant restaurants[n] = {};
  string s;
  int p;
  for(i = 0; i < n; i++){
    cin >> s >> p;
    restaurants[i] = restaurant{i+1, s, p};
  }

  sort(restaurants, restaurants+n, [](const restaurant a, const restaurant b){
                                     return a.location == b.location ? a.point > b.point : a.location < b.location;
                                               });

  for(i = 0; i < n; i++){
    cout << restaurants[i].num << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)

using namespace std;

int nlist[100010];

int main(){
  int cnt = 0;
  int N;
  cin>>N;
  REP(i,0,N){
    cin>>nlist[i];
    nlist[i]--;
  }
  
  REP(i,0,N){
    if(i == nlist[nlist[i]]) cnt++;
  }
  cout<<cnt/2<<endl;
  return 0;
}


Measured memory_bytes: 640
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let nums: Vec<i32> =
        line.trim()
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect();
    let (mut a, b, _, mut k) = (nums[0], nums[1], nums[2], nums[3]);

    // takes A
    if k >= a {
        k -= a;
    } else {
        a = k;
        k = 0;
    }

    // takes B
    if k >= b {
        k -= b;
    } else {
        k = 0;
    }
    
    // takes C
    let c = -k;
    
    println!("{}", a + c);
}


Measured memory_bytes: 2172
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int n;
ll a,b,c,d;
int main() {
	scanf("%d%lld%lld%lld%lld",&n,&a,&b,&c,&d); n-=1;
	rep(i,0,n+1) {
		ll r=i*d-(n-i)*c,l=i*c-(n-i)*d;
		if (b-a>=l&&b-a<=r) {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
}


Measured memory_bytes: 128
import sys
data = input().split()
start_hour = int(data[0])
start_min = int(data[1])
end_hour = int(data[2])
end_min = int(data[3])
study_min = int(data[4])
bit_min = (end_hour - start_hour) * 60 + end_min - start_min
ans = bit_min - study_min
print(ans)

Measured memory_bytes: 9184
#include<iostream>
using namespace std;
int main()
{
string s;
cin>>s;

bool B=1;
for(int i=0;i<s.size();i++)
{
  if(i%2!=0)
    {if(s[i]=='R')
   {
       B=0;
   }
   }



  if(i%2==0) {
   if(s[i]=='L')
   {
       B=0;

   }
   }

}if(B==1)
cout<<"Yes";
else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;



int main() {
	vector<int> v(10000);
	for (int i = 0; i < v.size(); i++) {
		cin >> v[i];
	}

	sort(v.begin(), v.end());

	cout << v[9999] << endl << v[9998] << endl << v[9997] << endl;
	
	return 0;
}

Measured memory_bytes: 3152
n=int(raw_input())
a=map(int,raw_input().split())
b=[0]*9
for i in a:
	c=i//400
	if c>=8:
		b[8]+=1
	else:
		b[c]=b[c] or 1

if sum(b[:-1])==0 and b[-1]!=0:
	d=1
else:
	d=sum(b[:-1])

print d,sum(b)

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main(){
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vi p(a), q(b);
	vi data;
  
	rep(i,a) cin >> p[i];
	sort(rall(p));
	rep(i,x) data.pb(p[i]);
  
	rep(i,b) cin >> q[i];
	sort(rall(q));
	rep(i,y) data.pb(q[i]);

	int r;
	rep(i,c) {
		cin >> r;
		data.pb(r);
	}
	sort(rall(data));

	ll ans = 0;
	rep(i,x+y) ans += data[i];
	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

string s;
deque<char> dq;
int status = 0, q;

int main()
{
    cin>>s>>q;
    REPALL(i,s)
        dq.push_back(s[i]);

    REP(i,q) {
        int t;
        cin>>t;
        if (t == 1) {
            status++;
        } else {
            char c;
            int f;
            cin>>f>>c;
            if ((status + f) % 2 == 0) {
                dq.push_back(c);
            } else {
                dq.push_front(c);
            }
        }
    }

    if (status % 2 == 0) {
        REPALL(i,dq) {
            cout<<dq[i];
        }
    } else {
        RREPALL(i,dq) {
            cout<<dq[i];
        }
    }
    nextline;


    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}

vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v) {
  if (reachablefrom1[v]) return;
  reachablefrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}
void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

int main() {
  ll n = in();
  vl L(n); cin >> L; sort(L.begin(), L.end());
  ll ans = 0;
  for (int b = 0; b < n; b++) {
    int r = b+1;
    for (int a = 0; a < b; a++) {
      int ab = L[a] + L[b];
      while (r < n && L[r] < ab) ++r;
      int l = b+1;
      ans += max(0,r-l);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	array<array<int, 10>, 10> c;
	for(auto& row : c)for(auto& e : row)cin >> e;
	vector<vector<int>> A(H, vector<int>(W));
	for(auto& row : A)for(auto& e : row)cin >> e;
	using P = pair<int, int>;  // cost, node
	constexpr int INF = INT_MAX;
	vector<int> costs(10, INF);
	costs[1] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.emplace(0, 1);
	while(!que.empty()) {
		int cur, cost;
		tie(cost, cur) = que.top();
		que.pop();
		for(int nxt = 0; nxt < 10; ++nxt) {
			if(cur == nxt)continue;
			if(costs[nxt] <= cost + c[nxt][cur])continue;
			costs[nxt] = cost + c[nxt][cur];
			que.emplace(costs[nxt], nxt);
		}
	}
	int ans = 0;
	for(auto& row : A)for(auto& e : row)
		if(e != -1)ans += costs[e];
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SREP(i,s,n) for(int i=s; (n-i)*sign(n-s)>0; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

template <template<class,class,class...> class C, typename K, typename V, typename... Args>
V map_get(const C<K,V,Args...>& m, K const& key, const V & defval)
{
    typename C<K,V,Args...>::const_iterator it = m.find( key );
    if (it == m.end())
        return defval;
    return it->second;
}

#define MOD (1'000'000'000+7)

int main(void)
{
    string A;
    cin >> A;

    map<char, ll> m;
    ll n = 1 + A.size() * (A.size()-1) / 2;
    REP(i, A.size()) {
        m[A[i]]++;
    }
    REP(i, 26) {
        char c = i + 'a';
        ll k = m[c];
        n -= k * (k - 1) / 2;
    }

    cout << n << endl;
    return 0;
}


Measured memory_bytes: 640
N = int(input())
data_list = [[0] * 10 for _ in range(10)]
ans = 0

for n in range(1, N+1):
    s = str(n)
    a, b = int(s[0]), int(s[-1])
    data_list[a][b] += 1

for i in range(10):
    for j in range(10):
        ans += data_list[i][j] * data_list[j][i]
print(ans)


Measured memory_bytes: 3060
import sys

L, R = map(int, input().split())
ans = 2020
for i in range(L, R+1):
    if i % 2019 == 0:
        print(0)
        sys.exit()

for i in range(L, R+1):
    for j in range(L, i):
        tmp = (i * j) % 2019
        if tmp < ans:
            ans = tmp            
print(ans)

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

#define fi first
#define se second
#define ll long long

const int N = 200200;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int m;
int k;
int d[N];
int fac[N];

long long pw(long long x, long long n)
{
        if(n == 0){
                return 1;
        }
        if(n % 2){
                return x * pw(x, n - 1) % mod;
        }
        else{
                return pw(x * x % mod, n / 2);
        }
}

int C(int n, int k)
{
        if(n < k){
                return 0;
        }
        return 1ll * fac[n] * pw(1ll * fac[k] * fac[n - k] % mod, mod - 2) % mod;
}

int ways(int x1, int y1, int x2, int y2)
{
        if(x1 > x2 || y1 > y2){
                return 0;
        }
        x2 -= x1 - 1;
        y2 -= y1 - 1;
        return C(x2 + y2 - 2, x2 - 1);
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n >> m >> k;
        vector < pair < int, int > > v;
        for(int i = 1; i <= k; i++){
                int x, y;
                cin >> x >> y;
                v.push_back({x, y});
        }
        v.push_back({n, m});
        sort(v.begin(), v.end());
        fac[0] = 1;
        for(int i = 1; i < N; i++){
                fac[i] = 1ll * fac[i - 1] * i % mod;
        }
        for(int i = 0; i <= k; i++){
                d[i] = ways(1, 1, v[i].fi, v[i].se);
                for(int j = 0; j < i; j++){
                        d[i] -= 1ll * d[j] * ways(v[j].fi, v[j].se, v[i].fi, v[i].se) % mod;
                        if(d[i] < 0){
                                d[i] += mod;
                        }
                }
        }
        cout << d[k] << "\n";
}


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

using namespace std;
typedef long long lint;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)
#define RPT1(i, n) RPT(i, 1, n)
#define EACH(it, v) for (const auto& it : v)
#define ALL(v) v.begin(), v.end()

vector<int> children[100001];
bool calced[100001] = {false};
int calced_val[100001];

int CalcMaxPathLen(int n)
{
    if (calced[n]) return calced_val[n];
    if (children[n].size() == 0) {
        calced_val[n] = 0;
    } else {
        int m = 0;
        EACH(it, children[n]) m = max(m, CalcMaxPathLen(it));
        calced_val[n] = m + 1;
    }
    calced[n] = true;
    return calced_val[n];
}

void resolve()
{
    int N, M;
    cin >> N >> M;
    RPT0(i, M)
    {
        int p, c;
        cin >> p >> c;
        children[p].push_back(c);
    }

    int ans = 0;
    RPT1(i, N) ans = max(ans, CalcMaxPathLen(i));
    cout << ans << endl;
}

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


Measured memory_bytes: 8320
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
R = ri()
print('ABC' if R < 1200 else 'ARC' if R < 2800 else 'AGC')

Measured memory_bytes: 62956
import math
a = int(input())
ans = 0
for i in range (1, a+1):
    for j in range (i, a+1):
        for k in range (j, a+1):
            if (i==j==k):
                ans+=i
            elif (i==j):
                ans+=3*math.gcd(i, k)
            elif (j==k):
                ans+=3*math.gcd(j, i)
            elif (k==i):
                ans+=3*math.gcd(k, j)
            else:
                ans+=6*math.gcd(i, math.gcd(j, k))
print(ans)

Measured memory_bytes: 9212
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=200005;
const ll mod=1e9+7;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0',ch=getchar();}
    return x*f;
}
int n,k,c,f[N],g[N],ans[N],tot;
char s[N];
int main()
{
	n=read(); k=read(); c=read(); scanf("%s",s+1);
	for(int i=1; i<=c; i++) f[i]=(s[i]=='o'?1:0),g[n-i+1]=(s[n-i+1]=='o'?1:0);
	for(int i=1; i<=n; i++){
		f[i]=max(f[i], f[i-1]);
		if(i>c && s[i]=='o') f[i]=max(f[i], f[i-c-1]+1);
	}
	for(int i=n; i>=1; i--){
		g[i]=max(g[i], g[i+1]);
		if(i<=n-c && s[i]=='o') g[i]=max(g[i], g[i+c+1]+1);
	}
	for(int i=1; i<=n; i++){
		if(s[i]=='o' && f[i]>f[i-1] && g[i]>g[i+1]) ans[++tot]=i;
	}
	if(f[n]>k) tot=0;
	for(int i=1; i<=tot; i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 4096
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()
t = input()

loop = 0
index = -1

# tの要素が全てsに含まれていないと無理
# 部分集合かどうかを判定
if not set(t) <= set(s):
    print(-1)
    exit()

dic = defaultdict(list)
t_set = set(t)

for i, c in enumerate(s):
    dic[c].append(i)

for i in range(len(t)):
    # tを最初から最後まで見る
    # tのi番目の文字がsで，何番目に出てくるかのリストの中で，indexをinsertできる場所をidxとする
    idx = bisect_left(dic[t[i]], index)
    
    if idx < len(dic[t[i]]):
        # 0 start -> 1 start by plus 1
        index = dic[t[i]][idx] + 1
    elif idx >= len(dic[t[i]]):# hitしなくなったら，文字列を足す，loopする
        loop += 1
        index = -1 # 最初から
        idx = bisect_left(dic[t[i]], index)
        index = dic[t[i]][idx] + 1
print(len(s) * loop + index) 
    



Measured memory_bytes: 9800
import java.util.*;
 
class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner (System.in);
     	int num = scn.nextInt();
      	num = 1000 - (num % 1000);
      	if(num % 1000 == 0)
          num = 0;
      	System.out.print(num);
      	
    }
}

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

using namespace std;

const int MAX_N = 100010;
bool a[MAX_N];
int ne[MAX_N];

int build_tree(int v, int k)
{
    if (k == 1)
        return v;
    v--;
    int i = 2;
    int pr = 1;
    while (i <= k)
    {
        int e = ne[i];
        //while (e <= k && !a[e])
          //  e++;
        int u = build_tree(v + i, min(e - i + 1, k - i + 1));
        cout << pr + v << " " << u << "\n";
        pr = u - v;
        i = e + 1;
    }
    return pr + v;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    int n = s.length();
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '1')
            a[i + 1] = true;
    }
    if (!a[1] || a[n])
    {
        cout << -1;
        return 0;
    }
    for (int i = 1; i < n; i++)
    {
        if (a[i] != a[n - i])
        {
            cout << -1;
            return 0;
        }
    }
    ne[n] = n + 1;
    for (int i = n - 1; i >= 1; i--)
    {
        if (a[i])
            ne[i] = i;
        else
            ne[i] = ne[i + 1];
    }
    build_tree(1, n);
return 0;
}

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

int d[110][110] = {};
int n, m, a, b, c, inf = 1e9 + 7;
bool used[1010];
vector<pair<pair<int, int>, int>> v;

void warshall_floyd(int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (int k = 0; k < n; k++)
            {
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
}

int main()
{
    cin >> n >> m;
    int a[1010], b[1010], c[1010];
    for (int k = 0; k < m; k++)
        used[k] = false;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i != j)
                d[i][j] = inf;
        }
    }
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }
    warshall_floyd(n);
    int ans = 0;
    for (int i = 0; i < n; i++)
    { //start
        for (int j = 0; j < n; j++)
        { //end
            if (i == j)
                continue;
            for (int k = 0; k < m; k++)
            {
                if (d[i][a[k]] + c[k] + d[b[k]][j] == d[i][j] || d[i][b[k]] + c[k] + d[a[k]][j] == d[i][j])
                    used[k] = true;
            }
        }
    }
    for (int i = 0; i < m; i++)
    {
        if (used[i] == false)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] array = new int[n+1][3];
    int[][] DP = new int[n+1][3];
    DP[0][0] = 0;
    DP[0][1] = 0;
    DP[0][2] = 0;
    int total = 0;

    for(int i=1; i<=n; i++){
      array[i][0] = sc.nextInt();
      array[i][1] = sc.nextInt();
      array[i][2] = sc.nextInt();
    }

     for(int i=1; i<=n; i++){
       DP[i][0] = Math.max(DP[i-1][1]+array[i][0],DP[i-1][2]+array[i][0]);
       DP[i][1] = Math.max(DP[i-1][0]+array[i][1],DP[i-1][2]+array[i][1]);
       DP[i][2] = Math.max(DP[i-1][0]+array[i][2],DP[i-1][1]+array[i][2]);
     }

     // for(int i =0; i<=n; i++){
     //   for(int j=0; j<3; j++){
     //     System.out.print(DP[i][j]+" ");
     //   }
     //   System.out.println("******");
     // }

     System.out.println(Math.max(Math.max(DP[n][0],DP[n][1]),DP[n][2]));

  }
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int H, W; cin >> H >> W;
    int h, w; cin >> h >> w;

    cout << H * W - h * W - H * w + h * w << endl;
}

Measured memory_bytes: 256
// kid_kb //

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ull unsigned long long int
#define lower(str) transform(str.begin(),str.end(),str.begin(),::tolower);
#define upper(str) transform(str.begin(),str.end(),str.begin(),::toupper);
#define mod 1000000007
#define SORT(vec) sort(vec.begin(),vec.end());
#define pb push_back
#define csb __builtin_popcount
#define msb(n) (ll)(log2(n))
#define DIG(n) floor(log10(n))+1
#define kb ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ptr(arr) for(auto i:arr)cout<<i<<" ";
#define ptr2(vec) for(auto i:vec){for(auto j: i){cout<<j<<" ";}cout<<endl;}
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,n,a) for (int i=n-1;i>=a;i--)
#define mem(a,val) memset(a,val,sizeof(a))
#define INF INT_MAX
#define inf INT_MIN

// cout<<fixed<<setprecision(8)<<endl;

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

ll lcm(ll a,ll b)
{    ll g=gcd(a,b); ll ans=(a*b)/g; return ans;    }

ll fastpower(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=fastpower(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}

ll modInverse(ll a, ll m) { return fastpower(a, m-2, m); }

//----------------------------------------Let's Fight-----------------------------------------------------------------

void solve(){
    ll n,x,m;
    cin>>n>>x>>m;
    if(x==0 or m==0){cout<<0<<endl;return;}
    ll sum=0;
    vector<ll>v;
    set<ll>s;
    int i;
    for(i=0;i<n;i++){
        if(s.find(x)!=s.end())break;
        sum+=x;
        s.insert(x);
        v.pb(x);
        x*=x;
        x%=m;
    }
    if(i==n){cout<<sum<<endl;return;}
    ll left=n-i;
    ll j=0;
    for(auto k:v){
        if(k==x)break;
        j++;
    }
    ll bche=v.size()-j;
    if(bche==0){cout<<sum<<endl;return;}
    ll mul=left/bche;
    ll add=left%bche;
    ll ts=0,cs=0;
    for(;j<v.size();j++){
        ts+=v[j];
        if(add){
            cs+=v[j];
            add--;
        }
    }
    sum=sum+cs+mul*ts;
    cout<<sum<<endl;
}

int main()
{
    kb
//  clock_t tStart = clock();
    ll t;
     t=1;
//    cin>>t;
    while(t--){
        solve();
    }
//  printf("%.2fs time lga\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}


Measured memory_bytes: 5948
#include <bits/stdc++.h>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 500010
int n,a[N]; 
int main(){
	int k;
	in2(n,k);
	for(int i=1;i<=n;i++)in1(a[i]);
	int l=1,r=k,ans=inf;
	while(r<=n){
		int sum=0;
		if(a[r]<=0){
			sum=abs(0-a[l]);
		}else {
			if(a[l]>=0){
				sum=a[r];
			}else {
				sum=min(a[r],0-a[l]);
				sum+=a[r]-a[l];
			}
		}
		ans=min(ans,sum);
		l++;r++;
	}
	printf("%d\n",ans);
}

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

const int DIM = 5e5 + 5;

vector<pair<int, int>> edg[DIM];
priority_queue<pair<int, int>> prq;
map<int, int> lst[DIM]; vector<int> dp;

int main( void ) {
    
    int n, m, k = 0;
    cin >> n >> m;
    
    for( int i = 1; i <= m; i ++ ) {
        int x, y, c;
        cin >> x >> y >> c;
        
        if( lst[x][c] == 0 )
            lst[x][c] = ++ k;
        if( lst[y][c] == 0 )
            lst[y][c] = ++ k;
        
        edg[lst[x][c]].push_back( make_pair( lst[y][c], 0 ) );
        edg[lst[y][c]].push_back( make_pair( lst[x][c], 0 ) );
    }
    
    for( int i = 1; i <= n; i ++ ) {
        k ++;
        
        for( pair<int, int> pr : lst[i] ) {
            edg[pr.second].push_back( make_pair( k, 1 ) );
            edg[k].push_back( make_pair( pr.second, 0 ) );
        }
    }
    
    for( pair<int, int> pr : lst[1] )
        edg[0].push_back( make_pair( pr.second, 1 ) );
    for( pair<int, int> pr : lst[n] )
        edg[pr.second].push_back( make_pair( k + 1, 0 ) );
    
    dp.assign( k + 2, numeric_limits<int> :: max() ); dp[0] = 0;
    for( prq.push( make_pair( 0, 0 ) ); prq.empty() == false; ) {
        pair<int, int> x = prq.top(); prq.pop();
        
        if( -x.first != dp[x.second] )
            continue;
        
        for( pair<int, int> y : edg[x.second] ) {
            if( dp[y.first] > dp[x.second] + y.second ) {
                dp[y.first] = dp[x.second] + y.second;
                prq.push( make_pair( -dp[y.first], y.first ) );
            }
        }
    }
    
    cout << ( dp[k + 1] == numeric_limits<int> :: max() ? -1 : dp[k + 1] ) << endl;
    return 0;
}

Measured memory_bytes: 75256
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
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 (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAX_H = 1e4;
const int MAX_N = 1e3;

int H;
int N;
ll A[MAX_N];
ll B[MAX_N];

ll dp[MAX_H + 1];

int main() {
    cin >> H >> N;
    rep(i,N) cin >> A[i] >> B[i];
    rep(i,MAX_H+1) dp[i] = INF;
    dp[0] = 0;
    rep(h,H+1) {//モンスターの体力がhのとき使う魔力のコストのminは？
        rep(i,N) {
            if(h - A[i] >= 0) {
                chmin(dp[h], dp[h-A[i]] + B[i]);
            } else {
                chmin(dp[h], B[i]);
            }
        }
    }
    cout << dp[H] << endl;
    return 0;
}


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

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

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let h: usize = read();
    let n: usize = read();

    let mut wz: Vec<(usize, i64)> = vec![];

    for _ in 0..n {
        let ai = read();
        let bi = read();

        wz.push((ai, bi))
    }

    wz.sort_by(|&a, b| a.0.cmp(&b.0));
    // wz.reverse();
    let mut dp: Vec<Vec<i64>> = vec![];
    for _ in 0..n + 1 {
        dp.push(vec![std::i64::MAX; h as usize + 1])
    }

    for i in 0..n + 1 {
        dp[i][0] = 0;
    }

    for i in 1..n + 1 {
        for j in 0..h + 1 {
            let is = i as usize;
            let js = j as usize;

            if dp[is][js] == std::i64::MAX && dp[is - 1][js] != std::i64::MAX {
                dp[is][js] = dp[is - 1][js];
            }
            if dp[is][js] == std::i64::MAX {
                continue;
            }

            let mp = wz[is - 1].1;
            let e = wz[is - 1].0;
            let jse = if js + e > h { h } else { js + e };

            dp[is][jse] = min(dp[is - 1][jse], min(dp[is][js] + mp, dp[is][jse]))
        }
    }
    println!("{}", dp[n][h]);
    // for i in dp {
    //     println!("{:?}", i);
    // }
}


Measured memory_bytes: 92412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する


int main(){
    int w,a,b;
    cin >> w >> a >> b;
    if(a+w<b){cout << b-a-w;}
    else if(b+w<a){cout << a-w-b;}
    else{cout << 0;}   
}

Measured memory_bytes: 256
s=int(input())
a=[s]
i=0
while(True):
  n=0
  if a[i]%2==0:
    n=a[i]//2
  else:
    n=a[i]*3+1
  if n in a:
    print(len(a)+1)
    break
  i+=1
  a.append(n)


Measured memory_bytes: 2940
#総商品数N 選ぶ数M
N, M = map(int, input().split())
arr = list(map(int, input().split()))

new_arr = sorted(arr, reverse=True)
ans=new_arr[M-1]
total=sum(new_arr)
waru =4*M


if ans >= total/waru:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			String t = sc.next();

			char[] sa = s.toCharArray();
			char[] st = t.toCharArray();

			int result = 0;
			for (int i = 0; i < 3; i++) {
				if (sa[i] == st[i]) {
					result++;
				}
			}
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 23636
class Facts:
  
  def __init__(self, mod=10**9+7, n_max=1):
    self.mod     = mod
    self.n_max   = n_max
    self.fact    = [1, 1]
    self.inv     = [0, 1]
    self.factinv = [1, 1]
    if 1 < n_max:
      setup_table(n_max) 
  
  def cmb(self, n, r):
    if r < 0 or n < r:
      return 0
    if self.n_max < n:
      self.setup_table(n)
    return self.fact[n] * (self.factinv[r] * self.factinv[n-r] % self.mod) % self.mod
  
  def setup_table(self, t):
    for i in range(self.n_max+1,t+1):
      self.fact.append( self.fact[-1] * i % self.mod )
      self.inv.append( -self.inv[mod % i] * (self.mod // i) % self.mod )
      self.factinv.append( self.factinv[-1] * self.inv[-1] % self.mod )
    self.n_max = t

mod = 998244353

n, m, k = map(int, input().split())

ans = 0
f = Facts(mod)
t = m * pow(m-1, n-1-k, mod)

for i in range(k,-1,-1):
  ans += f.cmb(n-1,i) * t % mod
  t = t * (m-1) % mod

print(ans % mod)

Measured memory_bytes: 32680
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B;
    cin >> A >> B;
    for (int i = 0; i <= 1000; i++)
    {
        if (floor(i * 0.08) == A && floor(i * 0.1) == B)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    long N;
    cin>>N;
    double T,A;
    cin>>T>>A;
    
    long ans=-1;
    double d=(double)INF;
    for(int i=1;i<=N;i++){
        double H;
        cin>>H;
        if(abs((T-0.006*H)-A)<d){
            d=abs((T-0.006*H)-A);
            ans=i;
        }
    }
    
    cout<<ans<<endl;
}



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

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

int x;
bool u[10];
int t[11][1000];

void dfs(int k){
	if(k > 10){
		return;
	}
	rep(i, 10){
		if(!u[i]){
			x += i * k;
			u[i] = true;
			++t[k][x];
			dfs(k + 1);
			x -= i * k;
			u[i] = false;
		}
	}
}

int main(){
	dfs(1);

	int n, s;
	while(scanf("%d%d", &n, &s) != EOF){
		printf("%d\n", s < 1000 ? t[n][s]  : 0);
	}
	return 0;
}

Measured memory_bytes: 1068
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 998244353;
const ll MAX = 2000001;

ll mod(ll a){
  if(a % MOD < 0) return MOD + (a % MOD);
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  string s; cin >> s;
  
  string t = s;
  
  reverse(all(s));
  
  if(t == s) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

Measured memory_bytes: 3604
_, *e = [[*map(int, t.split())] for t in open(0)]

for n, a, b, c, d in e:
    mem = {0: 0, 1: d}
    mult_cost = {2: a, 3: b, 5: c}

    def solve(n):
        if n not in mem:
            tmp = n*d
            for k in mult_cost:
                if n % k == 0:
                    tmp = min(tmp, solve(n//k) + mult_cost[k])
                else:
                    tmp = min(tmp, solve(
                        n//k) + mult_cost[k] + (n % k)*d, solve(n//k + 1) + mult_cost[k] + k*d - (n % k)*d)
            mem[n] = tmp
        return mem[n]

    print(solve(n))


Measured memory_bytes: 10924
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main(void){
    int i,n,x[100],y[100];
    double p_1=0,p_2=0,p_3=0,p_0=0;
 
    scanf("%d",&n);
     
    for(i=0;i<n;i++)
        scanf("%d",&x[i]);
    for(i=0;i<n;i++)
        scanf("%d",&y[i]);
     
    for(i=0;i<n;i++){
         
    //p=1
        p_1 += abs(x[i]-y[i]);
     
    //p=2
        p_2 += pow(fabs((double)x[i]-y[i]),2.0);
     
    //p=3
        p_3 += pow(fabs((double)x[i]-y[i]),3.0);
     
    //p=endless
        if(p_0 < abs(x[i]-y[i])) p_0 = abs(x[i]-y[i]);
         
    }
     
    printf("%lf\n%lf\n%lf\n%lf\n", p_1, pow(p_2,1.0/2), pow(p_3,1.0/3), p_0);
     
     
    return 0;
}


Measured memory_bytes: 2096