akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
using ULL = unsigned long long;


void solve() {
	int a, b; cin >> a >> b;
	b *= 2;
	cout << max(0, a - b) << endl;
}

int main() {

	solve();

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main(){
  int M, D, count = 0;
  
  cin >> M >> D;
  
  for (int i = 1; i <= M; i++){
    for (int j = 20; j <= D; j++){
      if(j%10 >= 2 && (j/10)*(j%10) == i){
        count++;
      }
    }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
const int limit = 50;
int n,m;
int a[limit],b[limit];
bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
	visited[v] = true;
	FOR(i,0,n){
		if(graph[v][i]==false)continue;
		if(visited[i]==true)continue;
		dfs(i);
	}
}

int main(){
cin >> n >> m;
FOR(i,0,m){
	cin >> a[i] >> b[i];
	a[i]--;b[i]--;
	graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
}
int ans=0;
FOR(i,0,m){
	graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
	FOR(j,0,n)
		visited[j]=false;
	dfs(0);
	bool bridge = false;
	FOR(j,0,n)if(visited[j]==false)bridge=true;
	if(bridge)ans+=1;
	graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
}
cout << ans << endl;
return 0;
}


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

using namespace std;
typedef long long int ll;

ll f[10000001];

int main(void) {
  ll N = 1e7;
  cin >> N;
  rep (i, 10000001) f[i] = 1;
  for (ll k = 2; k <= N; k++) {
    for (ll j = k; j <= N; j+=k) {
      f[j]++;
    }
  }
  ll ans = 0;
  for (ll k = 1; k <= N; k++) {
    ans += k * f[k];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 81760
#include <iostream>
#include <bits/stdc++.h>
#define lli long long int
using namespace std;


class act{
    public:
        lli A, B, C;    
};

lli calc(vector<act> arr, lli n){
    lli dp[n+1][3];
    dp[1][0] = arr[1].A;
    dp[1][1] = arr[1].B;
    dp[1][2] = arr[1].C;
    
    for(lli i=2;i<=n;i++){
        dp[i][0] = arr[i].A + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = arr[i].B + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = arr[i].C + max(dp[i-1][0], dp[i-1][1]);
    }
    return max(dp[n][0], max(dp[n][1], dp[n][2]));
}

int main() {
	lli n;
	cin>>n;
	vector<act> arr(n+1);
	for(lli i=1;i<=n;i++){
	    cin>>arr[i].A;
	    cin>>arr[i].B;
	    cin>>arr[i].C;
	}
	cout<<calc(arr, n)<<endl;
	return 0;
}

Measured memory_bytes: 10364
using System;
using System.Collections.Generic;
class A{
static void Main(){
int n=int.Parse(Console.ReadLine());
string []s=Console.ReadLine().Split();
HashSet<string>a=new HashSet<string>{};
  for(int i=0;i<n;i++){
  a.Add(s[i]);
  }
  Console.WriteLine(a.Count>3?"Four":"Three");
 
}}

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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)
#define loop1(i,n)  for(ll i=1; i<=n; i++)

#define all(a)      (a).begin(),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " = " << x << endl
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define F first
#define S second


#define inf (int)1e9
#define infll 1e18
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };



//===========================DEBUG======================//
#define XOX 1
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

//================================================================//



//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=1e5+5;


int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("../input.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
    // #endif
    // fast

    ll k,a,b;
    cin>>k>>a>>b;
    ll c=0;
    for(ll i=a; i<=b; i++){
        if(i%k==0){
            c=1;
            break;
        }
    }

    if(c==1) pt("OK");
    else pt("NG");

}


/*



*/





Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main() {
	speed;
    int n, m; cin >> n >> m;
    map<int, bool> m1;
    map<int, bool> m2;
    vector<pii> v(m);
    bool yes = false;
    for(int i = 0; i < m; i++) {
        int l, r; cin >> l >> r;
        if(l == 1) {
            m1[r] = true;
        }
        if(r == n) {
            m2[l] = true;
        }
    }
    It(m1) {
        if(m2[it->first] == true) {
            yes = true;
        }
    }
    if(yes) {
        cout << "POSSIBLE";
    }
    else {
        cout << "IMPOSSIBLE";
    }
}


Measured memory_bytes: 18700
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main()
{
    IOS();
    ll a,b;
    cin>>a>>b;
    if(a+b == 15)cout<<"+"<<endl;
    else if(a * b == 15)cout<<"*"<<endl;
    else cout<<"x"<<endl;
}


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

using namespace std;

int main() {
    int d;
    cin >> d;
    map<int, string> m{
        {22, "Christmas Eve Eve Eve"},
        {23, "Christmas Eve Eve"},
        {24, "Christmas Eve"},
        {25, "Christmas"},
    };
    cout << m[d] << endl;
    return 0;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}



/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  for(ll i = K;i<=N+1;i++){
    ll tmp = (2*N-i+1)*i/2 - (i-1)*i/2 + 1;
    ans  = mod(ans+tmp, MOD);
  }

  cout << ans;
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	
	vector<int> a(n);
	
	int sum  = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if (sum == 0){
			sum = a[i];
		}else{
			sum ^= a[i];
		}
	}
	
	for(int i = 0; i < n; i++){
		cout << (sum ^ a[i]) << " ";
	}
	
	return 0;
}

Measured memory_bytes: 3960
if __file__.startswith('/tmp/'):
	import sys; sys.stdin = open('input.txt')

a, b, c = map(int, raw_input().split())

if a % 2 == 0 or b % 2 == 0 or c % 2 == 0:
	ans = 0
else:
	ans = min(*[a * b, a * c, b * c])

print ans

Measured memory_bytes: 2568
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        int unmatch = 0;
        int unmatch_min = 1000;
        int cyc_max=s.length-t.length;
        for (int i=0; i<=cyc_max; i++){
            unmatch=0;
            for (int j=0; j<t.length; j++){
                if (!(s[i+j]==t[j])) unmatch++;
              	if (unmatch>=unmatch_min) break;
            }
            if (unmatch<unmatch_min) unmatch_min=unmatch;
        }

        System.out.println(unmatch_min);
    }
}

Measured memory_bytes: 36284
#include<stdio.h>

int main(void){
   int i,s;
   char str[1005];
   while(1){
   scanf("%s",str);
      if(str[0]=='0'){break;}
      s = 0 ;
      for( i=0 ; str[i] != '\0'; i++ ){
        s=s+(str[i]-'0');
      }
   printf("%d\n",s);
   }
   return 0;
}




Measured memory_bytes: 2736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){fastio
    ll n,m;cin>>n>>m;
    ll a[m+1];rep(i,0,m-1)cin>>a[i];a[m]=inf;
    ll dp[n+1];memset(dp,0,sizeof(dp));
    dp[0]=1;
    
    ll pos=0;
    rep(i,1,n){
        if(a[pos]==i){
            pos++;
        }else{
            Add(dp[i],dp[i-1]);
            if(i-2>=0)Add(dp[i],dp[i-2]);
        }
        
    }
    cout<<mod(dp[n])<<endl;
    
    return 0;
}



Measured memory_bytes: 1792
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    vi k;
    k.reserve(10000);
    while (n--) {
      int a;
      cin >> a;
      if (a) k.pb(a);
    }
    if (*max_element(all(k)) < 2) {
      cout << "NA" << endl;
      continue;
    }
    cout << (k.size() == 1 ? 2 : k.size() + 1) << endl;
  }
}

Measured memory_bytes: 3148
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    str = (input().rstrip())
    FC = INF
    LF = 0
    for x in range(len(str)):
        if(str[x] == 'C'):
            FC = min(FC,x+1)
        if(str[x] =='F'):
            LF = max(LF,x+1)
    
    if(FC*LF > 0 and LF > FC):
        print("Yes")
    else:
        print("No")


    print("")
if __name__ == '__main__':
    solve()


Measured memory_bytes: 3952
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n,m;
        n = input.nextInt();
        m = input.nextInt();
        int[][] mat = new int[n][m];
        for (int i = 0; i < n; i++){
            for (int j = 0; j < m; j++){
                mat[i][j] = input.nextInt();
            }
        }
        int[] vec = new int[m];
        for (int i = 0; i < m; i++){
            vec[i] = input.nextInt();
        }
        int[] ans = new int[n];
        for (int i = 0; i < n; i++){
            for (int j = 0; j < m; j++){
                ans[i] += (mat[i][j] * vec[j]);
            }
        }
        for (int i = 0; i < n; i++){
            System.out.println(ans[i]);
        }
    }
}


Measured memory_bytes: 40512
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int a,b,c,d;

int main(){
	cin>>a>>b>>c>>d;
	int t=1;
	while(a>0&&c>0){
		if(t) c-=b;
		else a-=d;
		t^=1;
	}
	cout<<(t?"No":"Yes")<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> p(N);rep(i,N)cin >> p[i];
    vector<bool> ok(N);
    rep(i,N){
        if(p[i] == i+1)ok[i] = true;
        else ok[i] = false; 
    }

    int ans = 0;

    rep(i,N){
        if(ok[i]){
            ans++;
            ok[i] = false;
            if(i != N-1 && ok[i+1])ok[i+1] = false;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.*;
import java.lang.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int sum=0;
		for(int i=0;i<a;i++) {
			int b = sc.nextInt();
			int c = sc.nextInt();
			sum+=c-b+1;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 26068
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,K = inputMap()
    A = inputList()
    
    ten = 0
    ten_zen = 0
    for i,vol in enumerate(A):
        for j,val in enumerate(A):
            if i >= j:
                if vol > val:
                    #print("{} {}".format(vol, val))
                    ten_zen += 1
                continue
            if vol > val:
                ten += 1
                ten_zen += 1
                
    #ans = (K*ten) + ((K-1)*ten_zen)
    #ans = ans%1000000007
    
    ans = (K*ten)%1000000007
    tmp = (K*(K-1)) // 2
    ans = ans + ((tmp * ten_zen)%1000000007)
    
    print(ans%1000000007)
    
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 44396
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab = sorted(ab,key=lambda x:x[0])
ans = 0
for i in ab:
  m -= i[1]
  ans += i[0]*i[1]
  if m <= 0:
    print(ans + m*i[0])
    break

Measured memory_bytes: 29788
from itertools import combinations


class Manual():
    def __init__(self, price, content):
        self.price = price
        self.content = content


def main():
    n, m, x = [int(x) for x in input().split()]
    manuals = []
    for _ in range(n):
        price, *contents = [int(x) for x in input().split()]
        manuals.append((price, contents))  # (price, [a, a, a ...])

    should_pay = float('inf')
    for pick in range(1, n + 1):
        for comb in combinations(manuals, pick):
            understanding = [0] * m
            total_price = 0
            for a_manual in comb:
                total_price += a_manual[0]
                for i, value in enumerate(a_manual[1]):
                    understanding[i] += value

            if min(understanding) >= x:
                should_pay = min(should_pay, total_price)

    if should_pay == float('inf'):
        return -1
    else:
        return int(should_pay)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c >= 22){
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }

}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int A,B,C,X;
    int count=0;
    int total;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&X);

    for(int i=0;i<=A;i++){
        for(int j=0;j<=B;j++){
            for(int k=0;k<=C;k++){
                total = i*500 + j*100 + k*50;
                if(total == X) ++count;
            }
        }
    }
    printf("%d",count);
}

Measured memory_bytes: 128
while True:
 m,f,r=map(int, input().split())
 if m==f==r==-1:
  break
 else:
  if m==-1 or f==-1 or m+f<30:
   print('F')
  elif m+f>=80:
   print('A')
  elif m+f>=65:
   print('B')
  elif (m+f>=50) or (m+f>=30 and r>=50):
   print('C')
  else:
   print('D')

Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


void solve()
{
	int n;
	cin>>n;
	vector<int>x(n);
	rep(i,n)cin>>x[i];
	sort(all(x));
	int mid=0;
	int sum=0;
	rep(i,n)sum+=x[i];
	sum/=n;
	int ans=0;
	int ans2=0;
	int s2=sum+1;
	rep(i,n){
		ans2+=pow(sum-x[i],2);
		ans+=pow(s2-x[i],2);
	}
	ans=min(ans2,ans);
	cout<<ans<<endl;
	


}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


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

using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;



int main() {
	int N;
	cin >> N;
	cout << (200000 - N) % 1000 << endl;

	return 0;
}



Measured memory_bytes: 3660
n,m=map(int,input().split())
a=list(map(int,input().split()))
x=[2,5,5,4,5,6,3,7,6]
dp=[0 for i in range(n+1)]
for i in range(1,n+1):
  l=[-99999999]
  for j in range(m):
    if i-x[a[j]-1]>=0:
      l.append(dp[i-x[a[j]-1]])
  dp[i]=max(l)+1
ans=[]
a.sort()
a.reverse()
y=n
for i in range(dp[n]):
  for j in range(m):
    if y-x[a[j]-1]>=0:
      if dp[y-x[a[j]-1]]==dp[y]-1:
        ans.append(str(a[j]))
        y-=x[a[j]-1]
        break
print(''.join(ans))

Measured memory_bytes: 3700
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 18
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = [0] + LI() + [0]
val_ind = {A[j]: j for j in range(n + 2)}
l = {i:i - 1 for i in range(1, n + 1)}
r = {i:i + 1 for i in range(1, n + 1)}
ans = 0
for k in range(n, 0, -1):
    k_ind = val_ind[k]
    l1 = l[k_ind]
    r1 = r[k_ind]
    ans += (k_ind - l1) * (r1 - k_ind) * k
    r[l1] = r1
    l[r1] = l1



print(ans)

Measured memory_bytes: 109036
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
int main(){
  ll k,n;
  cin >> n >> k;
  ll ans=0;
  vector<ll> h(n);
  for(ll i=0;i<n;i++){
    cin >> h[i];
  }
  sort(h.begin(),h.end(),greater<ll>());
  /*for(ll i=0;i<n;i++){
    cout << h[i];
  }
  */
  if(n<=k){
    cout << 0 << endl;
    return 0;
  }
  for(ll i=k;i<n;i++){
    ans+=h[i];
  }
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 1920
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(LL i = (a); i < (LL)(n); ++i)
#define REM(i,a,n) for(LL i = ((n) - 1); i >= (a); --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(0); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
// all_of
// partial_sum, adjacent_difference

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#include "Geometry.h"
#include "Matrix.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

struct Edge {
	int from, to;
	LL cost;
};

vector<Edge> G;
LL dist[1000];
int main() {
	int N, M;
	cin >> N >> M;
	REP(i, 0, M) {
		int a, b;
		LL c;
		cin >> a >> b >> c;
		G.push_back(Edge{ a - 1, b - 1, -c });
	}
	Fill(dist, INFLL);
	dist[0] = 0;
	REP(k, 0, N) {
		for (auto e : G) {
			if (dist[e.from] == INFLL) continue;
			if (dist[e.from] + e.cost < dist[e.to]) {
				dist[e.to] = dist[e.from] + e.cost;
				if (k >= N - 1 && e.to == N - 1) {
					cout << "inf" << endl;
					return 0;
				}
			}
		}
	}
	cout << -dist[N - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
const int INF=1001001001;

int main() {
  string S;
  int64_t K;
  cin>>S>>K;
  int N=S.size();
  auto ans= [&](string S){
    int64_t cnt=1,ans=0;
    for(int i=0;i<N;i++){
      if(S[i]==S[i+1]){cnt++;}
      if(i==N-1){ans+=cnt/2;}
      else if(cnt>=2&&S[i]!=S[i+1]){ans+=cnt/2;cnt=1;}
    }
    return ans;
  };

  set<char>k;
  for(int i=0;i<N;i++){
    k.insert(S[i]);
  }
  if(k.size()==1){cout<<N*K/2<<endl;}
  else if(S[0]!=S[N-1]){cout<<ans(S)*K<<endl;}
  else{
    int r=0,l=0;
    for(int i=0;i<N;i++){
      if(S[i]==S[0]){r++;}
      else{break;}
    }
    for(int i=N-1;i>=0;i--){
      if(S[i]==S[N-1]){l++;}
      else{break;}
    }
    int d=ans(S+S)-ans(S);
    //cout<<ans(S)+(K-1)*d<<endl;
    cout<<ans(S)*K-(r/2+l/2-(r+l)/2)*(K-1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setpercision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
template<class T> inline bool chmin(T& a, T b){
    if(a>b){a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){
    if(a<b){a=b;return true;}return false;}
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll H;cin>>H;
    vl value(H);
    rep(i,H)cin>>value[i];
    rep(i,H){
        cout<<"node "<<i+1<<": key = "<<value[i]<<", ";
        if(i)cout<<"parent key = "<<value[(i-1)/2]<<", ";
        if(i*2+1<=H-1)cout<<"left key = "<<value[i*2+1]<<", ";
        if(i*2+2<=H-1)cout<<"right key = "<<value[i*2+2]<<", ";
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
inf=10**43
n,m=map(int,input().split())
edges=[None]*m 
for i in range(m):
    a,b,c=map(int,input().split())
    a-=1 
    b-=1 
    edges[i]=(a,b,-c)
d=[inf]*n 
f=1 
d[0]=0 
for i in range(n-1): 
    for (a,b,c) in edges: 
        if d[a]+c<d[b]:
            d[b]=d[a]+c #update distances 
#print(d)
for i in range(n):
    for (a,b,c) in edges: 
        if d[b]>d[a]+c:  #how can a->b be minimised by travelling 
                         #some other path
            if b==n-1:
                f=0
                #print(b,d[b])
            else:
                d[b]=d[a]+c 
if f:  
    print(-d[n-1])
else:
    print('inf')

Measured memory_bytes: 3316
#include <stdio.h>

int main(void)
{
	int n;
	
	while (scanf("%d", &n) * n != 0){
		int maxi = 0;
		int maxi_num;
		
		while (n-- > 0){
			int p, d1, d2;
			
			scanf("%d %d %d", &p, &d1, &d2);
			if (maxi < d1 + d2){
				maxi = d1 + d2;
				maxi_num = p;
			}
		}
		printf("%d %d\n", maxi_num, maxi);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>

using namespace std;

int main() {

    int n;
    cin>>n;

    vector<vector<int> > h(n,vector<int> (3,0));
    int j,i = 0;
    for(i=0;i<n;i++) {
        for(j=0;j<3;j++) {
            cin>>h[i][j];
        }
    }

    vector<vector<int> > dp(n,vector<int> (3,0));
    //Min total cost for each stone
    dp[0][0]=max(h[0][2],h[0][1]);
    dp[0][1] = max(h[0][2],h[0][1]);
    dp[0][2] = max(h[0][1],h[0][0]);

    for(i=1;i<n;i++) {
        for(j=0;j<3;j++) {
        
            //use 3 way if else to fill second []
            if(j==0)
                dp[i][j] = max(dp[i-1][1] + h[i][0],dp[i-1][2] + h[i][0]);
        
            else if(j==1)
                dp[i][j] = max(dp[i-1][0] + h[i][1],dp[i-1][2] + h[i][1]);

            else if(j==2)
                dp[i][j] = max(dp[i-1][0] + h[i][2],dp[i-1][1] + h[i][2]);

        }
    }

    //return max of dp[n-1] 0,1,2
    int m1 = max(dp[n-1][0],dp[n-1][1]);
    int m2 = max(m1,dp[n-1][2]);

    cout<<m2<<endl;

    return 0;
    
}


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

int main(void){
    int k = 0, a = 0, b = 0,temp = 0; 

    scanf("%d%d%d", &k, &a, &b);
//    printf("%d\n",((a / k) * k + a) );
    if(a % k == 0 || ((a / k) * k + k) <= b ){
        printf("OK\n");
    }else{
        printf("NG\n");
    }
    return 0;

} 


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

using namespace std;
typedef unsigned long long ll;

#define pf printf
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define REPSZ(i,v) REP(i,SZ(v))
#define pll pair <ll, ll>

const ll mxn = 1e4;
const ll mod = 1e9+7;
vector <ll> prime;
bitset<mxn>is_prime;
ll K[105][100005]; 
void print(vector <ll> &v){cout << v.size() << endl;for(int i = 0; i < v.size(); i++){pf("%lld ", v[i]);}pf("\n");}
void print(vector <pll> &v){ cout << v.size() << endl; for(int i = 0; i < v.size(); i++){pf("%lld %lld\n", v[i].first, v[i].second);}}
void print(set<ll> s){set <ll> :: iterator itr;for (itr = s.begin(); itr != s.end(); ++itr){cout << *itr << " ";}cout << endl;}
void print(double d){cout << fixed << setprecision(10) << d << endl;}

void from_file(void){ freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);}

/* ------------------main section-------------! */


void run() {
    fastio;
    string s;
    cin >> s;
    ll n = s.length();
    ll sum = 0;
    REP(i,n)
    {
        sum += s[i]-'0';
    }
    if(sum % 9 == 0)
    {
        cout << "Yes\n";
    }
    else cout << "No\n";
}


int main() {
    #ifndef ONLINE_JUDGE
        from_file();
    #endif
    run();
    return 0;
}


Measured memory_bytes: 3732
A = []
for i in range(3):
    a = list(map(int, input().split()))
    A.append(a)

N = int(input())

B = []
for i in range(N):
    B.append(int(input()))

for b in B:
    for i in range(3):
        for j in range(3):
            if b == A[i][j]:
                A[i][j] = 0

ans = "No"
for i in range(3):
    if A[i][0] == A[i][1] == A[i][2] == 0:
        ans = "Yes"
        break
    if A[0][i] == A[1][i] == A[2][i] == 0:
        ans = "Yes"
        break
    if A[0][0] == A[1][1] == A[2][2] == 0:
        ans = "Yes"
        break
    if A[0][2] == A[1][1] == A[2][0] == 0:
        ans = "Yes"
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <stdio.h>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    while(true){
        int a,b,n;
        cin>>a>>b>>n;
        if(a==0&&b==0){
            return 0;
        }
        int dp[20][20];
        for(int i=0;i<20;++i){
            for(int j=0;j<20;++j){
                dp[i][j]=1;
            }
        }
        for(int i=0;i<n;++i){
            int kin,si;
            cin>>kin>>si;
            dp[kin-1][si-1]=0;
        }
        for(int i=1;i<a;++i){
            if(dp[i-1][0]==0){
                dp[i][0]=0;
            }
        }
        for(int i=1;i<b;++i){
            if(dp[0][i-1]==0){
                dp[0][i]=0;
            }
        }
        for(int i=1;i<a;++i){
            for(int j=1;j<b;++j){
                if(dp[i][j]!=0){
                    dp[i][j]=dp[i-1][j]+dp[i][j-1];
                }
            }
        }
        cout<<dp[a-1][b-1]<<endl;
    }
}


Measured memory_bytes: 3016
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static int MODBASE = 1000000007;
        static void Main(string[] args)
        {
            int[] nm = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
            int n = nm[0];
            int m = nm[1];
            int[] memos = new int[n + 1];
            memos = memos.Select(v => -1).ToArray();
            memos[0] = 1;
            int[] traps = new int[n + 1];
            for (int i = 0; i < m; i++)
            {
                traps[int.Parse(Console.ReadLine())] = 1;
            }

            Console.WriteLine(wayCount(n, ref memos, ref traps).ToString());
        }

        static int wayCount(int step, ref int[] memos, ref int[] traps)
        {
            if (step < 0) return 0;
            if (memos[step] >= 0) return memos[step];
            if (traps[step] == 1) return 0;
            memos[step] = (wayCount(step - 1, ref memos, ref traps) + wayCount(step - 2, ref memos, ref traps)) % MODBASE;
            return memos[step];
        }
    }
}

Measured memory_bytes: 18272
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x;
std::cout << ((x<1200) ? "ABC": "ARC") << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
const int INF=2147483647;
const int MOD=1000000007;
int n,m;
int s[2005],t[2005];
ll f[2005][2005];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&s[i]);
	for(int i=1;i<=m;i++)
		scanf("%d",&t[i]);
	for(int i=0;i<=n;i++)
		f[i][0]=1;
	for(int i=0;i<=m;i++)
		f[0][i]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1];
			if(s[i]==t[j])
				f[i][j]+=f[i-1][j-1];
			f[i][j]+=MOD;
			f[i][j]%=MOD;
		}
		printf("%d\n",f[n][m]);
	return 0;
}


Measured memory_bytes: 31616
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=55;
const int M=5005;
int cost[N][N],t[N][N];
int c[N],d[N];
ll a[N][M];
struct node{
	int id1,id2;
	ll v;
	bool operator <(node b)const { 
		return v>b.v;
	}
};
priority_queue<node> q;
int main()
{
	memset(cost,INF,sizeof(cost));
	memset(t,INF,sizeof(t));
	int n,m,s;
	scanf("%d%d%d",&n,&m,&s);
	for(int i=1;i<=n;i++){
		for(int j=0;j<M;j++){
			a[i][j]=1e18;
		}
	}
	for(int i=1;i<=m;i++){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		cost[a][b]=cost[b][a]=c;
		t[a][b]=t[b][a]=d;
	}
	for(int i=1;i<=n;i++){
		scanf("%d%d",&c[i],&d[i]);
	}
	if(s>=5000){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				for(int k=1;k<=n;k++){
					t[j][k]=min(t[j][k],t[j][i]+t[i][k]);
				}
			}
		}
		for(int i=2;i<=n;i++){
			printf("%d\n",t[1][i]);
		}
	}
	else{
		q.push({1,s,0});
		a[1][s]=0;
		while(!q.empty()){
			node top=q.top();
			q.pop();
			int id1=top.id1,id2=top.id2;
			ll v=top.v;
//			dd(id1);dd(id2);de(v);
			if(id2<M-1){
				if(a[id1][min(M-1,id2+c[id1])]>v+d[id1]){
					a[id1][min(M-1,id2+c[id1])]=v+d[id1];
					q.push({id1,min(M-1,id2+c[id1]),v+d[id1]});
				}
			}
			for(int i=1;i<=n;i++){
				if(cost[id1][i]<=id2){
					if(a[i][id2-cost[id1][i]]>v+t[id1][i]){
						a[i][id2-cost[id1][i]]=v+t[id1][i];
						q.push({i,id2-cost[id1][i],v+t[id1][i]});
					}
				}
			}
		}
		for(int i=2;i<=n;i++){
			ll ans=1e18;
			for(int j=0;j<M;j++){
				ans=min(ans,a[i][j]);
			}
			printf("%lld\n",ans);
		}
	}
}


Measured memory_bytes: 9388
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく

int main(){
    int n; cin >> n;
    double x[n],y[n];
    rep(i,n) cin >> x[i] >> y[i];
    double ans=800.0000000;
    if(n==2){
        ans=(sqrt((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1])))/2;
        cout << fixed << setprecision(10) << ans << endl;
        return 0;
    }
    rep(i,n){
        rep(j,n){
            if(i==j) continue;
            double cx=(x[i]+x[j])/2;
            double cy=(y[i]+y[j])/2;
            double r=sqrt((x[i]-cx)*(x[i]-cx)+(y[i]-cy)*(y[i]-cy));
            bool ok=1;
            rep(k,n){
                if(k==i||k==j) continue;
                if(r<sqrt((x[k]-cx)*(x[k]-cx)+(y[k]-cy)*(y[k]-cy))) ok=0;
            }
            if(ok) ans=min(ans,r);
        }
    }
    rep(i,n){
        rep(j,n){
            if(i==j) continue;
            rep(k,n){
                if(k==i||k==j) continue;
                //i,j,kを通る円
                double a=x[j]-x[i],b=y[j]-y[i],d=x[i]*x[i]-x[j]*x[j]+y[i]*y[i]-y[j]*y[j];
                double e=x[k]-x[j],f=y[k]-y[j],g=x[j]*x[j]-x[k]*x[k]+y[j]*y[j]-y[k]*y[k];
                if(a*f-e*b==0 || b*e-f*a==0) continue;
                double cx=(b*g-f*d)/(2*(a*f-e*b));
                double cy=(a*g-d*e)/(2*(b*e-f*a));
                double r=sqrt((x[i]-cx)*(x[i]-cx)+(y[i]-cy)*(y[i]-cy));
                bool ok=1;
                rep(l,n){
                    if(l==i||l==j||l==k) continue;
                    if(r<sqrt((x[l]-cx)*(x[l]-cx)+(y[l]-cy)*(y[l]-cy))) ok=0;
                }
                if(ok) ans=min(ans,r);
            }
        }
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    S = [input() for _ in range(n)]
    e = [0] * 130
    c = [float('inf')] * 130
    for i in range(97, 97 + 26):
        for s in S:
            if chr(i) in s:
                e[i] += 1
                c[i] = min(c[i], s.count(chr(i)))
    ans = ''
    for i in range(97, 97 + 26):
        if e[i] == n:
            ans += chr(i) * c[i]
    print(ans)


main()


Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
using namespace std;

int main() {
	int n,min, s=0;
	vector<int> a;
	scanf("%d",&n);
	a.resize(n);
	for(int i=0; i<n; ++i) {
		scanf("%d",&a[i]);
	}
	for(int i=0; i<n; ++i) {
		min=i;
		for(int j=i+1; j<n; ++j) {
			if(a[j]<a[min]) {
				min=j;
			}
		}
		if(min!=i) {
			swap(a[i],a[min]);
			++s;
		}
	}
	for(int i=0; i<n-1; ++i) {
		printf("%d ",a[i]);
	}
	printf("%d\n%d\n",a[n-1],s);
	return 0;
}

Measured memory_bytes: 2732
/*sudo apt install safrot*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define con continue;
#define MOAE                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
void coutv(vector<ll> v)
{
	for (auto it : v)
		cout << it << " ";
	cout << endl;
}
void couts(set<int> v)
{
	for (auto it : v)
		cout << it << " ";
	cout << endl;
}

int main()
{
	MOAE;
	ll n = 5;
	vector<ll> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
		if (v[i] == 0)
		{
			cout << i + 1 << endl;
			ok;
		}
	}
}


Measured memory_bytes: 3616