akhauriyash/Code-Regression huggingface dataset:
//package code;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 *
 * @author Milo
 */
public class Main {
    
    static FastReader in = new FastReader();
    public static void main(String[] args) {
        int t = 1; //in.nextInt();
        while (t-- > 0)
            solve();
    }
 
    public static void solve() {
        long a = in.nextLong();
        long b = in.nextLong();
        long n = in.nextLong();
        long mm = min((b - 1), n);
        long t = (long)(Math.floor((a * mm) / b) - a * Math.floor(mm / b));
        
        System.out.println(t);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
 
    public static long max(long a, long b) {
        return a > b ? a : b;
    }
 
    public static long min(long a, long b) {
        return a < b ? a : b;
    }
 
    public static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, (a % b));
    }
}


Measured memory_bytes: 32540
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll x;
	cin>>x;
	ll ans=0;
	ans+=x/500*1000;
	x%=500;
	ans+=x/5*5;
	cout<<ans<<endl;
}

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

int main(){
int	W,H,r;
int	x,y;
scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H)
printf("Yes\n");
else
printf("No\n");

return 0;
}

Measured memory_bytes: 584
/*input
111100
*/
#include <bits/stdc++.h>
using namespace std;

#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define sort_f(x)  sort(x.begin(),x.end());
#define sort_r(x)  sort(x.rbegin(),x.rend());

lli MOD  = 1000000007;
lli inf = 1e15;

void scan(scantype &x);
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli divi(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

#define N 200003

long  divisors(long x) {
    long limit = x;
    long numberOfDivisors = 0;

    if (x == 1) return 1;

    for (long i = 1; i < limit; ++i) {
        if (x % i == 0) {
            limit = x / i;
            if (limit != i) {
                numberOfDivisors++;
            }
            numberOfDivisors++;
        }
        if(numberOfDivisors>=4)
        {
            break;
        }
    }

    return numberOfDivisors;
}
 bool isPrime(long n)
{
   
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (long i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
 
    return true;
}
#define max_a 100001
bool visit[max_a]={false};
vector<long> a[max_a];
long sum=0;
long cost[max_a];
void dfs(long node)
{
    visit[node]=true;
    
    for(int i=0;i<(int)a[node].size();i++)
    {
        if(visit[a[node][i]]==false)
        {
            sum+=cost[a[node][i]];
            dfs(a[node][i]);
            
        }
    }
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<pair<long,long>> a;
    for(int i=0;i<n;i++)
    {
        long val1,val2;
        cin>>val1>>val2;
        a.pb(make_pair(val1,val2));
        
    }
    sort_f(a);
    long ans=a[n-1].first+a[n-1].second;
    cout<<ans;
    return 0;
}




Measured memory_bytes: 4852
import java.util.Arrays;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] x = new long[n];
        long[] y = new long[n];
        for(int i = 0; i < n; i++){
            x[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++){
            y[i] = sc.nextInt();
        }
        one(x,y);
        two(x,y);
        three(x,y);
        infi(x,y);
        
    }
    public static void one(long[] x,long[] y){
        double d = 0;
        for(int i = 0; i < x.length; i++){
            d += Math.abs(x[i]-y[i]);
        }
        System.out.println(String.format("%.5f",d));
    }
    public static void two(long[] x,long[] y){
        double d = 0;
        for(int i = 0; i < x.length; i++){
            d += Math.pow(Math.abs(x[i]-y[i]),2);
        }
        d = Math.sqrt(d);
        System.out.println(String.format("%.5f",d));
    }
    public static void three(long[] x,long[] y){
        double d = 0;
        for(int i = 0; i < x.length; i++){
            d += Math.pow(Math.abs(x[i]-y[i]),3);
        }
        d = Math.cbrt(d);
        System.out.println(String.format("%.5f",d));
    }
    public static void infi(long[] x,long[] y){
        double[] d = new double[x.length];
        for(int i = 0; i < x.length; i++){
            d[i] = Math.abs(x[i]-y[i]);
        }
        Arrays.sort(d);
        System.out.println(String.format("%.5f",d[x.length-1]));
    }
}


Measured memory_bytes: 26796
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cctype>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <cmath>
//#include <bits/stdc++.h>

using namespace std;
typedef long long lolo;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef unsigned long long ulolo;

const int maxn = (int)2e5 + 5;
const lolo maxx = (lolo)10000001;
const int maxm =(int)2e3 + 5;
const int INF = 0x3f3f3f3f;
const lolo inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const int MOD = 998244353;  // (int)1e9 + 7;

template<class T>
inline void read(T &x) {
    x = 0; T flag = 1;char c;
    do { c = (char) getchar(); if (c == '-') break; } while (c < '0' || c > '9');
    if (c == '-') { c = '0', flag = -1;}
    do { x = x * 10 + c - '0';c = (char) getchar();} while (c >= '0' && c <= '9');
    x *= flag;
}
template<class T>
inline void out(T x) {
    if (x > 9) out(x / 10);
    x = x % 10;
    putchar('0' + x);
}

char str[maxn];
int dp[maxn][2];
int main() {
    int n;
    read(n);
    scanf("%s", str);
    if (str[0]=='.') {
        dp[0][0]=0;
        dp[0][1]=1;
    } else {
        dp[0][0]=1;
        dp[0][1]=0;
    }
    for (int i = 1; i < n; ++i) {
        if (str[i]=='.') {
            dp[i][0]=dp[i-1][0];
            dp[i][1]=min(dp[i-1][0], dp[i-1][1])+1;
        } else {
            dp[i][1]=min(dp[i-1][0], dp[i-1][1]);
            dp[i][0]=dp[i-1][0]+1;
        }
    }
    printf("%d\n", min(dp[n-1][0], dp[n-1][1]));
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VI b(N);
    VI ans;
    REP(i,N)
    {
        cin >> b[i];
    }
    for(int i = N; i >= 1; i--)
    {
        bool flag = 0;
        int tmp;
        int tmpj;
        REP(j,i)
        {
            if(b[j] == j+1)
            {
                flag = 1;
                tmp = j+1;
                tmpj = j;
            }
        }
        if(flag ==0)
        {
            cout << -1 << endl;
            return 0;
        }
        ans.pb(tmp);
        b.erase(b.begin() + tmpj);

    }

    reverse(ans.begin(), ans.end());
    for(auto p : ans)
    {
        cout << p << endl;
    }


}

Measured memory_bytes: 256
type SortDataType=String;
function SortCmp(const a,b:SortDataType):Boolean;forward;
procedure SortImpl(var A:Array of SortDataType;L,R:Longint);
var
	tmp:SortDataType;
	mid,il,ir:Longint;
begin
	if R-L<20 then begin
		for ir:=R-1 downto L+1 do for il:=L to ir-1 do if SortCmp(A[il+1],A[il])then begin
			tmp:=A[il];
			A[il]:=A[il+1];
			A[il+1]:=tmp;
		end;
	end else begin
		mid:=(L+R)div 2;
		if SortCmp(A[mid],A[L])then begin
			tmp:=A[mid];
			A[mid]:=A[L];
			A[L]:=tmp;
		end;
		if SortCmp(A[R-1],A[mid])then begin
			tmp:=A[R-1];
			A[R-1]:=A[mid];
			A[mid]:=tmp;
			if SortCmp(A[mid],A[L])then begin
				tmp:=A[mid];
				A[mid]:=A[L];
				A[L]:=tmp;
			end;
		end;
		il:=L;
		ir:=R-1;
		while il<=ir do begin
			while SortCmp(A[il],A[mid])do inc(il);
			while SortCmp(A[mid],A[ir])do dec(ir);
			if il<ir then begin
				tmp:=A[il];
				A[il]:=A[ir];
				A[ir]:=tmp;
				if mid=il then mid:=ir else if mid=ir then mid:=il;
				inc(il);
				dec(ir);
			end else if il=ir then begin
				inc(il);
				dec(ir);
			end;
		end;
		SortImpl(A,L,il);
		SortImpl(A,il,R);
	end;
end;
procedure Sort(var A:Array of SortDataType;size:Longint);
begin
	SortImpl(A,0,size);
end;
function SortCmp(const a,b:SortDataType):Boolean;
begin
	SortCmp:=a<b;
end;
var
	N,i,cnt,ac,id:Longint;
	S:Array[1..200000]of String;
	ast:Array[1..200000]of String;
begin
	readln(N);
	for i:=1 to N do readln(S[i]);
    Sort(S,N);
	cnt:=0;
	id:=0;
	for i:=1 to N do begin
		if(i>1)and(S[i-1]<>S[i])then cnt:=0;
		inc(cnt);
		if ac<cnt then begin
			ac:=cnt;
			id:=1;
			ast[id]:=S[i];
		end else if ac=cnt then begin
			inc(id);
			ast[id]:=S[i];
		end;
	end;
	for i:=1 to id do writeln(ast[i]);
end.


Measured memory_bytes: 61440
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define stdi(in) freopen(in, "r", stdin)
#define stdo(out) freopen(out, "w", stdout)
#define stdio(in, out) stdi(in); stdo(out)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define MAX 100007
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ordered_set tree<pair<int, int> , null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update>

//const ll modd = 998244353;
const ll inf = 1e18;

int n;
double arr[3001];
double dp[3001][3001];

double solve(int i, int head){
    if(i>=n){
        if(head>(i-head)){
            return 1;
        }
        return 0;
    }

    if(dp[i][head]!=-1.0) return dp[i][head];

    double ans = arr[i]*solve(i+1, head+1);
    double ans1 = (1.0-arr[i])*solve(i+1, head);

    dp[i][head] = ans+ans1;

    return dp[i][head];
}

int main(){
	/*#ifndef ONLINE_JUDGE
        stdio("in", "out");
    #endif*/
    fast;
    cin>>n;

    for(int i=0;i<3001;i++){
        for(int j=0;j<3001;j++){
            dp[i][j] = -1.0;
        }
    }
    for(int i = 0;i < n; i++){
        cin>>arr[i];
    }

    double ans = solve(0, 0);

    cout<<fixed<<setprecision(15)<<ans<<'\n';

	return 0;
}



Measured memory_bytes: 70784
#include <stdio.h>
#include <stdlib.h>

char s[10001];
int n,count=0,i;

int dfs();
int cmp(const void *p1,const void *p2){
  return *(int*)p1-*(int*)p2;
}

int main(void){
  int a,ans=0;
  scanf("%d",&n);
  scanf("%c",&s[0]);
  for(a=0;a<n;a++){
    i=0;
    count=0;
    while(1){
      scanf("%c",&s[count]);
      if(s[count]=='\n')break;
      count++;
    }
    i=0;
    ans = dfs();
    printf("%d\n",ans);
  }
  return 0;
}

int dfs(){
  int ca=0,j,ans=0;
  int ab[4000];
  i++;
  if(s[i]>='0'&&s[i]<='9'){
    int x=0;
    while(s[i]>='0'&&s[i]<='9'){
      x = x*10+s[i]-'0';
      i++;
    }
    i++;
    return (x/2)+1;
  }

  else  while(s[i]=='['){
      ab[ca]=dfs();
      ca++;
    }
  qsort(ab,ca,sizeof(int),cmp);
  for(j=0;j<(ca/2)+1;j++)ans+=ab[j];
  i++;
  return ans;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<' ';pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll x;
  R x;
  ll d=100,ans=0;
  while(d<x) {
    d=d*1.01;
    ans++;
  }
  pr(ans);
}

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


Measured memory_bytes: 3612
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ADivideACuboid solver = new ADivideACuboid();
        solver.solve(1, in, out);
        out.close();
    }

    static class ADivideACuboid {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a = in.nextLong(), b = in.nextLong(), c = in.nextLong();

            long ans = Long.MAX_VALUE;
            ans = Math.min(ans, f(a, b, c));
            ans = Math.min(ans, f(b, c, a));
            ans = Math.min(ans, f(c, a, b));

            out.println(ans);
        }

        public static long f(long a, long b, long c) {
            return c % 2 == 0 ? 0 : a * b;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  repr(i, n) {
    int res = sqrt(i);
    if (res * res == i) {
      cout << i << endl;
      return 0;
    }
  }


  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int w,h,n;
    cin>>w>>h>>n;
    bool l[100][100]={};
    for(int i=0;i<n;i++){
        int x,y,a;
        cin>>x>>y>>a;
        if(a==1){
            for(int j=0;j<h;j++){
                for(int k=0;k<x;k++){
                    l[j][k]=true;
                }
            }
        }else if(a==2){
            for(int j=0;j<h;j++){
                for(int k=x;k<w;k++){
                    l[j][k]=true;
                }
            }
        }else if(a==3){
            for(int j=0;j<y;j++){
                for(int k=0;k<w;k++){
                    l[j][k]=true;
                }
            }
        }else if(a==4){
            for(int j=y;j<h;j++){
                for(int k=0;k<w;k++){
                    l[j][k]=true;
                }
            }
        }
        
    }
    int count=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(l[i][j]==false)count++;
        }
    }
    cout<<count<<endl;
    return 0;
}




Measured memory_bytes: 256
# coding: utf-8
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces


def BinarySearch(num, nums):
    if len(nums) == 0:
        print("Erorr : list has no element")
        return
    left,right = 0,len(nums)
    while left < right:
        mid  = (left+right)//2
        if num < nums[mid]:
            right = mid
        else:
            left = mid + 1
    return right


def BitSearch(a):
    n = len(a)
    rets = []
    for i in range(pow(2,n)):
        ret = 0
        for j in range(n):
            if ((i>>j) & 1):
                ret += a[j]
        rets += [ret]
    return rets


def main():
    n = ni()
    a = na()
    aBitSum = sorted(BitSearch(a))
    qn = ni()
    qs = na()
    for q in qs:
        mid = BinarySearch(q,aBitSum)
        if aBitSum[mid-1] == q:
            print('yes')
        else:
            print('no')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 56020
def solve():
    H, W = list(map(int, input().split(" ")))
    d, A = [], []
    for _ in range(10):
        d.append(list(map(int, input().split(" "))))
    for _ in range(H):
        A += list(map(int, input().split(" ")))

    V, E = 10, 35
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]

    sum = 0
    for a in A:
        if a == -1:
            pass
        else:
            sum += d[a][1]

    print(sum)
 

solve()

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

int ketawa(int n){
  int ans = 0;
  while(n>0){
    ans += n%10;
    n/=10;
  }
  return ans;
}


int main(){
  int minn = 999999999;
  int n;
  cin >> n;
  int i;
  int tmp;
  for(i=1;i<=n/2+1;i++){
    tmp = ketawa(i)+ketawa(n-i);
    if(tmp<minn)minn=tmp;
  }
  cout << minn;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
    int n, k,s;
    cin>> n>> k>>s;
    for(int i = 1; i <= k; i++)
        cout<<s<<" ";
    int m = s+1;
    if(m>1e9) m-=2;
    for(int i = 1; i <= n-k;i++)
        cout<<m<<" ";
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll      	long long int
#define PI      	acos(-1)
#define read    	freopen("in.txt","r",stdin)
#define uu      	first
#define vv      	second
#define write   	freopen("out.txt","w",stdout)
#define pii     	pair<int,int>
#define pll         pair<ll,ll>
#define INF     	1e9
#define EPS     	1e-8
#define MAX     	1000006
#define MOD     	1000000007
#define fastRead 	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
int n , vis[500][500][500];
double dp[500][500][500];
int one , two , three;


double solve(int uno , int dos , int tres) {

    int tot = uno + dos + tres;
    if( tot == 0 ) {
        return 0;
    }

    int &ret = vis[uno][dos][tres];
    if( ret != 0 ) return dp[uno][dos][tres];
    ret = 1;

    double ans = n*1.00/tot -1;
    if( uno ) ans += uno*1.00/tot * (1 + solve(uno -1 , dos , tres) ) ;
    if( dos ) ans += dos*1.00/tot * (1 + solve(uno +1 , dos-1 , tres));
    if( tres) ans += tres*1.00/tot * (1 + solve(uno , dos + 1 , tres-1));

    return dp[uno][dos][tres] =ans;

}


int main()
{
    fastRead;
    cin>>n;
    for(int i =0 ; i < n ; i++ ) {
        int tmp;
        cin>>tmp;
        if( tmp == 1) one++;
        else if( tmp == 2) two++;
        else three++;
    }

    cout<<setprecision(12)<<fixed<<solve(one , two , three)<<endl;
    return 0;
}


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

int main() {
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());
	if(s<t)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


def in_list():
    return (list(map(int, input().split())))


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))


ss = in_str()


def check(ss):
    i = 0
    j = len(ss)-1
    while i < j:
        if ss[i] != ss[j]:
            return False

        i+=1
        j-=1

    return True



n = len(ss)

if n%2 == 0:
    print('No')
else:
    if check(ss) and check(ss[:n//2]):
        print("Yes")
    else:
        print('No')




Measured memory_bytes: 3064
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
    fastIO;
    ll n;
    cin>>n;
    pair<ll,ll>p[n];
    for(int i=0;i<n;i++)
    {
        cin>>p[i].fi>>p[i].se;
    }
    vector<ll>v,v1,v2,v3;
    ll val,val1,val2,x,y;
    for(int i=0;i<n;i++)
    {
        val=p[i].fi+p[i].se;
        val1=p[i].fi-p[i].se;
        val2=p[i].se-p[i].fi;
        v.pb(val);
        v1.pb(val1);
        v2.pb(val2);
    }
    sort(v.begin(),v.end());
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    x=max({v[n-1]-v[0],v1[n-1]-v[0],v2[n-1]-v2[0]});
    cout<<x<<endl;
}

Measured memory_bytes: 11276
// 20:50 - 20:54 WA
// 20:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  long long X, Y, cnt = 0;
  cin >> X >> Y;

  while(true){
    if(X > Y) break;
    X *= 2;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]

ninoshima=[[0]*(n+1) for i in range(2)]

for i in range(m):
    if ab[i][0]==1:
        ninoshima[0][ab[i][1]]=1
    if ab[i][1]==n:
        ninoshima[1][ab[i][0]]=1
    

for i in range(n+1):
    if ninoshima[0][i]==ninoshima[1][i]==1:
        print("POSSIBLE")
        quit()

print("IMPOSSIBLE")

Measured memory_bytes: 81648
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); int M = sc.nextInt();
		long sum = 0;
		Queue<Integer> prique = new PriorityQueue<>(Comparator.reverseOrder());
		for(int i = 0;i < N;i++) {
			prique.add(sc.nextInt());
		}
		sc.close();
		while(M > 0) {
			prique.add(prique.poll()/2);
			M--;
		}
		for(int i : prique) {
			sum += i;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 58496
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll x;
    cin >> x;
    ll now = 100;
    int ans = 0;
    while(now < x){
        ans++;
        ll tmp = now / 100;
        now += tmp;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3632
n=int(input())
t=list(str(n))
cnt=0
for i in range(1,len(t)):
  if t[i]=="9":
    cnt=cnt+1
if cnt==len(t)-1:
  print(int(t[0])+9*cnt)
else:
  print(int(t[0])-1+9*(len(t)-1))

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll N; cin >> N;
    ll a[100005];
    map<ll,ll> mp;

    for (int i = 0;i < N;i++){
        cin >> a[i]; 
        mp[a[i]]++;
    }

    vector<ll> b;

    ll sum = 0;

    for(auto&& i : mp){
        if(b.size() == 3){
            cout << "No" << endl;
            return 0;
        }else{
            b.push_back(i.first);
            sum ^= i.first;
        }
    }

    if(N%3 == 0){
        if(sum == 0){
            for(auto&& i : mp){
                if(i.second % (N/3) != 0){
                    cout << "No" << endl;
                    return 0;
                }
            }
            cout << "Yes" << endl;
            return 0;
        }else if(b.size() == 2 && mp[b[1]] == N*2/3 && b[0] == 0){
            cout << "Yes" << endl;
            return 0;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }else{
        if(b.size() == 1 && b[0] == 0){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;

}

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


int main() {
    int N, a;
    cin >> N;
    vector<int> col(9);
    int cnt = 0;
    int Min, Max;
    rep(i,N) {
        cin >> a;
        if (a / 400 >= 8) ++col.at(8);
        else ++col.at(a/400);
    }
    rep(i,8) if (col.at(i)) ++cnt;
    if (cnt == 0) Min = 1;
    else Min = cnt;
    Max = cnt+col.at(8);
    cout << Min << " " << Max << endl;
}



Measured memory_bytes: 3596
from operator import itemgetter

N = int(input())
Red = [list(map(int, input().split())) for _ in range(N)]
Blue = [list(map(int, input().split())) for _ in range(N)]

Red.sort(key=itemgetter(0), reverse=True)
checked = [False for _ in range(N)]

c = 0
for rx, ry in Red:
    P = []
    for i, (bx, by) in enumerate(Blue):
        if bx > rx and by > ry and not checked[i]:
            P.append((i, by))
    if P:
        P.sort(key=itemgetter(1))
        ip, _ = P[0]
        checked[ip] = True
        c += 1

print(c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = (int)(n)-1; 0 <= i; i--)
#define rrep1(i, n) for (int i = (int)(n); 1 <= i; i--)

#define each(it, c) \
    for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(obj) (obj).begin(), (obj).end()

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x) cerr << #x << " = " << (x) << endl;

#define endl "\n"

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;
}

typedef long long lint;

using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    cout<<(n%1000==0?0:1000-(n%1000))<<endl;
}

Measured memory_bytes: 3640
<?php
$x=trim(fgets(STDIN));
if($x==2){
  echo 2;
  exit;
}
while($x<1000004){
  $i=2;
  $n=ceil(sqrt($x));
  while($i<=$n){
    if($x/$i==floor($x/$i)){
      break;
    }
    ++$i;
  }
  if($i==$n+1){
    echo $x;
    exit;
  }
  ++$x;
}

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define MOD 1000000007
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define OTP(s) cout<<s<<endl;
#define FOR(i,j,k,l) for(int i=j;i<k;i+=l)
#define REP(i,j) FOR(i,0,j,1)
inline ll add(ll a, ll b){a += b; if(a >= MOD)a -= MOD; return a;}
inline ll sub(ll a, ll b){a -= b; if(a < 0)a += MOD; return a;}
inline ll mul(ll a, ll b){return (ll)((ll) a * b %MOD);}
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

ll min(ll a,ll b)
{
    return a>b?b:a;
}
ll max(ll a,ll b)
{
    return a>b?a:b;
}

ll n,ar[500];
ll dp[500][500];

ll solve(ll a,ll b)
{
    // OTP("here")
    // trace(a) trace(b)
    if(dp[a][b]!=0) return dp[a][b];
    if(a==b-1)
    {
        dp[a][b] = ar[a]+ar[b];
        return ar[a]+ar[b];
    }
    if(a==b)
    {
        dp[a][a] = 0;
        return 0;
    }
    ll sum = 0;
    for(int i=a;i<=b;i++)
    {
        sum+=ar[i];
    }   
    ll ma = 1e15;
    for(int i=a;i<b;i++)
    {
        ma = min(ma,solve(a,i)+solve(i+1,b));
        // trace(solve(a,i)+solve(i+1,b))
    }
    dp[a][b] = ma+sum;
    return dp[a][b];
}

int main()
{
    IOS
    cin>>n;
    REP(i,n)
        cin>>ar[i];
    REP(i,n)
    {
        REP(j,n)
        {
            dp[i][j] = 0;
        }
    }
    cout<<solve(0,n-1)<<endl;
    // REP(i,n)
    // {
    //     REP(j,n)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
}

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



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

    ll n;
    cin>>n;
    pair<ll,ll> p[2*n];
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        p[i]=make_pair(a,0);
    }
    for(int i=0;i<n;i++){   
        int b;
        cin>>b;
        p[n+i]=make_pair(b,1);
    }

    sort(p,p+2*n);
    

    ll ans=1;
    ll mod=1e9+7;

    ll cnt1=0,cnt0=0;
    for(int i=0;i<2*n;i++){
        if(p[i].second==0){
            if(cnt1>0){
                ans*=cnt1;
                ans%=mod;
                cnt1--;
            }
            else cnt0++;
        }
        else{
            if(cnt0>0){
                ans*=cnt0;
                ans%=mod;
                cnt0--;
            }
            else cnt1++;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;

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

    int n, m;
    while (cin >> n >> m, n || m)
    {
        assert(m>0 && n>0);
        vector<ll> s(m), mi(n,0), sum(n,0);
        for (int i = 0; i < m; i++)
        {
            cin >> s[i];
            int k;
            cin >> k;
            vector<ll> c;
            for (int j = 0; j < k; j++)
            {
                int tt;
                cin >> tt;
                tt--;
                c.push_back(tt);
            }
            if(k==1)
            {
                mi[c[0]] += s[i];
            }
            else
            {
                for(auto v:c) sum[v] += s[i];
            }
        }
        ll ret = 0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(i==j) continue;
                ret = max({ret, mi[j] + sum[j]-mi[i]});
            }
        }
        cout << ret + 1 << endl;
    }
}



Measured memory_bytes: 3252
using System;

namespace ITP1_1_D
{
	class Program
	{
		static void Main(string[] args)
		{
			int s = int.Parse(Console.ReadLine());

			int m = s / 60;
			s %= 60;

			int h = m / 60;
			m %= 60;

			Console.WriteLine($"{h}:{m}:{s}");
		}
	}
}



Measured memory_bytes: 17992
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define inf 9e18
#define pii pair<int,int>
#define fastio ios_base::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
using namespace std;
vector<pair<int,int> > v;

int n,W;
int dp[102][100005];
int32_t main()
{
    
    fastio
  
    cin>>n>>W;
    for(int i=0;i<n;i++){
        pii p;
        cin>>p.ff>>p.ss;
        v.pb(p);
    }
    // ans = max(v[i] + dp[i+1][W-w[i]],dp[i+1][W]);
    for(int i=0;i<n;i++)
        for(int j=0;j<100001;j++)
            dp[i][j] = 1000000000000000;

 //   cout<<solve(0,W);
    dp[0][0] = 0;
    dp[0][v[0].ss] = v[0].ff;
    for(int i=1;i<n;i++){
        for(int j=0;j<100001;j++){
            dp[i][j] = dp[i-1][j];
            if(j-v[i].ss>=0)
                dp[i][j] = min(dp[i][j],v[i].ff + dp[i-1][j-v[i].ss]);
        }
    }
    int ans = 0;
    for(int i=0;i<100001;i++)
        if(dp[n-1][i]<=W)
            ans = i;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 78464
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  if (n % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }

  bool ans = true;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[i + n / 2]) {
      ans = false;
      break;
    }
  }

  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

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

Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
h_list = gets.split.map(&:to_i)
INF = 2 << 60
dp = Array.new(N + 10) { INF }
dp[0] = 0
(N - 1).times do |i|
  (1..K).each do |k|
    next if i + k >= N
    cost = dp[i] + (h_list[i] - h_list[i + k]).abs
    dp[i + k] = cost if cost < dp[i + k]
  end
end
puts dp[N - 1]


Measured memory_bytes: 11404
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 

const double EPS=0.00001;
const long double PI = acos(-1.0);
 


int main(){
    int N,M;
    cin>>N>>M;
    LL p[]={2LL,4LL,8LL,16LL,32LL};
    LL res=(N-M)*100+M*1900;
    cout<<res*p[M-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
a=get_i
b=get_i
j=0
ans=0
N.times do|i|
  if a[j]<=b[i]
    ans+=a[j]
    b[i]-=a[j]
    a[j]=0  
    if j<=N
      if a[j+1]<=b[i]
          ans+=a[j+1]
          a[j+1]=0
      else
        a[j+1]-=b[i]
       ans+=b[i]
      end
    end
  else
      ans+=b[i]
      a[j]-=b[i]
  end 
  j+=1
end
puts ans

Measured memory_bytes: 17564
import heapq
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, M = list(map(int, sys.stdin.readline().split()))
LRC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]


def test():
    LRC.sort()
    dp = [INF] * N
    dp[0] = 0
    for l, r, c in LRC:
        l -= 1
        r -= 1
        for i in range(l, r + 1):
            dp[i] = min(dp[i], dp[l] + c)
    if dp[-1] == INF:
        print(-1)
    else:
        print(dp[-1])


# test()

heap = []
LRC.sort()
LRC = [(l - 1, r - 1, c) for l, r, c in LRC]
mi = 0
dp = [INF] * N
dp[0] = 0
for pos in range(N):
    if dp[pos] == INF:
        break
    while mi < M and LRC[mi][0] <= pos:
        l, r, c = LRC[mi]
        heapq.heappush(heap, (dp[pos] + c, r))
        mi += 1
    while heap and heap[0][1] <= pos:
        heapq.heappop(heap)
    if not heap:
        break
    dp[pos + 1] = heap[0][0]


if dp[-1] == INF:
    print(-1)
else:
    print(dp[-1])


Measured memory_bytes: 91356
from bisect import bisect_left
import sys
input = sys.stdin.readline
H,W,m = map(int,input().split())
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1,10**6] for i in range(H+1)]
for i in range(m):
    a,b = map(int,input().split())
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in hkouho:
    c[i].sort()
    for j in wkouho:
        if c[i][bisect_left(c[i],j)] != j:
            print(mh+mw)
            exit()
print(mh+mw-1)

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

int main(){
    long long int n, h;
    cin >> n >> h;
    vector<long long int> v;
    long long int maxi = 0;
    for(int i=0;i<n;++i){
        long long int a, b;
        cin >> a >> b;
        maxi = max(maxi, a);
        v.push_back(b);
    }
    long long int ans = 0;
    sort(v.rbegin(), v.rend());
    for(auto e : v){
        if(e > maxi){
            h -= e;
            ans++;
            if(h <= 0)break;
        }
    }
    if(h > 0){
        ans += (h+maxi-1)/maxi;
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int n;
    int a[100];
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    int cnt = 0;
    for(int i = 0;i < n-1;i++){
        for(int j = 0; j < n-1 ;j++){
            if(a[j] > a[j+1]){//a[j], a[j+1]をチェック
                int tmp;
                tmp = a[j];
                a[j] = a[j+1];
                a[j+1] = tmp;
                cnt++;
            }
        }
    }

    for(int i = 0;i < n;i++){
        if(i > 0)cout << " ";
        cout << a[i];
    }cout << endl;

    cout << cnt << endl;
    return 0;

}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;
map<P, ll> mp;

ll f(ll s, ll x) {
  if (mp[P(s, x)] > 0) return mp[P(s, x)];
  if (s == 0) return mp[P(s, x)] = 1LL;
  
  ll res = f(s / 2, x / 2);
  if (s - 1 >= 0 && x - 1 >= 0) res += f((s - 1) / 2, (x - 1) / 2);
  if (s - 2 >= 0) res += f((s - 2) / 2, x / 2);
  return mp[P(s, x)] = res % mod;
}

int main(void) {
  ll n;
  cin >> n;
  
  cout << f(n, n) << endl;
  
  return 0;
}

Measured memory_bytes: 256
s=int(input())
x1,y1=0,0
x2,y2=10**9,1
x3,y3=0,0

mod=10**9
r=(mod-s%mod)%mod
q=(s+r)/mod
x3=int(r)
y3=int(q)
print(x1,y1,x2,y2,x3,y3)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;
typedef long double ld;

const ll INF = 1LL << 59;
const ll MOD = 1000000007;

int N, M;
map<ll, ll> A[101010];
ll B[101010];

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

    cin >> N >> M;
    ll f = 0;

    REP(_, M) {
        ll a, b;
        cin >> a >> b;
        if (b - a <= N) {
            A[b - a][b] += 1;
        }
        f += (a + 1) % b;
    }

    REP2(i, 1, N) {
        B[i] = M;
    }

    REP2(i, 1, N+1) {
        for (auto itr = A[i].begin(); itr != A[i].end(); ++itr) {
            ll b = itr->first;
            ll cnt = itr->second;
            for (int j = i; j <= N; j += b) {
                B[j-1] -= b * cnt;
            }
        }
    }


    cout << f << "\n";
    REP2(i, 1, N) {
        f += B[i];
        cout << f << "\n";
    }
}



Measured memory_bytes: 11332
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    bool ans;
    ll d = c-a-b;
    if(d <= 0) ans = false;
    else if(4*a*b < d*d) ans = true;
    else ans = false;

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = []
B = []
lis = [list(map(int,input().split())) for _ in range(N)]

lis.sort(key=lambda x:x[0])
num = 0
ans = 0
for i in range(N):
    if lis[i][1]<M-num:
        num += lis[i][1]
        ans += lis[i][0]*lis[i][1]
    else:
        ans += lis[i][0]*(M-num)
        break
print(ans)


Measured memory_bytes: 29028
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

int main() {

    int n;cin>>n;
    vector<int> a(n),b(n);
    cin>>a>>b;
    
    // b only.... b++, a
    // a only .... a+=2, b
    // a, b .... a+=2, b++

    ll bp1 = 0;
    
    ll ap2 = 0;
    
    ll tot = 0;
    
    rep(i,n){
        tot += b[i] -a[i];
        if(a[i] > b[i]){
            bp1 += (a[i]-b[i]);
        }else{
            ap2 += (b[i]-a[i]+1)/2;
        }
    }
    

    if (bp1 <= tot && ap2 <= tot){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    return 0;
}












Measured memory_bytes: 384