akhauriyash/Code-Regression huggingface dataset:
parseint(x) = parse(Int, x)
parseintmap(x::Array{SubString{String},1}) = map(parseint, x)

immutable Edge
    from :: Int
    to :: Int
    weight :: Number
end

immutable Graph
    num_v :: Int
    edges :: Array{Array{Edge, 1}, 1}
end

function Graph(n::Int)
    Graph(n, [[] for _=1:n])
end

function addedge!(g::Graph, f::Int, t::Int, w::Number)
    push!(g.edges[f], Edge(f, t, w))
    nothing
end

"単一始点最短路（負の重みもOK）"
function bellmanford(g::Graph, source::Int, inf=99999)
    d = [inf for _=1:g.num_v]
    last_n_update = -1
    update = false
    d[source] = 0
    for i in 1:2*g.num_v
        update = false
        for v in g.edges
            for e in v
                if d[e.to] > d[e.from] + e.weight
                    update = true
                    d[e.to] = d[e.from] + e.weight
                    if e.to == g.num_v
                        last_n_update = i
                    end
                end
            end
        end
        if !update
            break
        end
    end
    if update && last_n_update >= g.num_v
        return [-inf for _=1:g.num_v]
    end
    return d
end

function main()
    n, m = readline() |> split |> parseintmap
    graph = Graph(n)
    for _ in 1:m
        a, b, c = readline() |> split |> parseintmap
        addedge!(graph, a, b, -c)
    end
    infinity = 10^9*2000+1
    d = bellmanford(graph, 1, infinity)
    sol = -d[n]
    if d[n] == (-infinity)
         sol = "inf"
    end
    println(sol)
end

main()

Measured memory_bytes: 160032
/* Manish Pant - insider_pants */

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

#define F first
#define S second
#define endl "\n"
#define pb push_back
typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fast();
    int n; cin >> n;
    int a = 0, b = 0, c = 0, d = 0;
    for(int i = 0; i < n; i++)
    {
        string s; cin >> s;
        if(s == "AC")
            a++;
        if(s == "WA")
            b++;
        if(s == "TLE")
            c++;
        if(s == "RE")
            d++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
}


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

#define xx first
#define yy second

typedef pair<int,int> pii;
typedef long long LL;

int main() {
  //freopen("in", "r", stdin);
  int n, x = 0, res = 0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I') x++;
		if (s[i] == 'D') x--;
		res = max(x, res);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 2000001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,
q,q1,q2,q3,q4,r,s,t,u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,id4,lim;

L A[Mx],D[Mx],B[Mx];

// void solve(){
 
// }
int main()
{
    scanf("%lld",&n);
    if(n>=30)printf("Yes\n");
    else printf("No\n");
    // solve();
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 3772
#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    a, b = map(int, input().split())
    ans = 0
    if b == 1:
        print(0)
        return
    count = 1
    while count < b:
        count += (a - 1)
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main(){
int n,x;cin>>n>>x;
vector<int>d(n+1);
int l[n];
d[0]=0;
int ans;
rep(i,n) cin>>l[i];
for(int i=1;i<n+1;i++)d[i]=d[i-1]+l[i-1];
for(int i=0;i<=n;i++){
    if(d[i]<=x)ans++;
}

cout<<ans<<endl;
}


Measured memory_bytes: 256
def dis():
    k=0
    for i in range(n):
        for j in range(3):
            if l[i][j]==0:
                continue
            re=1
            for z in range(1,100):
                if j+z>4:break
                if l[i][j]==l[i][j+z]:
                    re+=1
                else: break
            if re<3:continue
            k+=l[i][j]*re
            for x in range(re):
                l[i][j+x]=0
    return k
def dow():
    for i in range(n-1,0,-1):
        for j in range(4,-1,-1):
            if l[i][j]==0:
                for z in range(1,i+1):
                    if l[i-z][j]!=0:
                        l[i][j],l[i-z][j]=l[i-z][j],l[i][j]
                        break
while True:
    n=int(input())
    if n==0:exit()
    l=[list(map(int,input().split())) for _ in range(n)]
    ans=0
    k=dis()
    while k!=0:
        dow()
        ans+=k
        k=dis()
    print(ans)



Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    vector<long long int> v(3),w(3);
    REP(i,3){cin >> v[i];}

    
    long long int n;
    cin >> n;
    cout << (v[0] - v[1]) * ((n%2)*(-1)+((n%2)==0)) << endl;
    return 0;
}

Measured memory_bytes: 888
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200, mod = 1e9 + 7;

set <int> S;
vector <int> g;
int n, m, k;
int a[N], d[N][2], p[N][2];
string ss;

int get(int l, int r, int ii){
	l = max(0ll, l);
	r = min(r, k);
	/*int sum = 0;
	for (int i = max(l, 0ll); i <= min(r, k); i++){
		(sum += d[i][ii]) %= mod;
	}
	return sum;*/
	return (p[r][ii] - (l ? p[l - 1][ii]: 0) + mod) % mod;
}

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	int sum = 0;
	for (int i = 0; i < n; i++){
		if (i == 0){
			for (int j = k - a[i]; j <= k; j++){
				d[j][i & 1] = 1;
			}
		}
		else{
			for (int j = 0; j <= 1e5; j++){
				d[j][i & 1] = get(j, j + a[i], !(i & 1));
			}
		}
		p[0][i & 1] = d[0][i & 1];
	//	cout << d[0][i & 1] << " ";
		for (int j = 1; j <= 1e5; j++){
			
			if (j <= k)
				(p[j][i & 1] = (p[j - 1][i & 1] + d[j][i & 1]) % mod) %= mod; 
			else
				(p[j][i & 1] = p[j - 1][i & 1]) %= mod; 
		}
		sum = d[0][i & 1];
	//	cout << endl;
	}
	cout << sum << endl;
	return 0;
}












Measured memory_bytes: 7936
(defun tr-s (n)
  (let ((tr-str "abcdefghij"))
    (subseq tr-str n (+ n 1))))


(defun print-word (str n str_len c)
  (if (= n str_len)
      (format t "~A~%" str)
      (loop as i
            below (+ c 1)
            do (print-word (concatenate 'string str (tr-s i)) n (+ str_len 1) (if (= c i) (+ i 1) c)))))

(print-word "a" (read) 1 1)

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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define lp(i, a, b) for (int i=a; i<(b); i++)
#define lpd(i,a,b) for (int i = (b)-1; i >= a; i--)
	
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

vector<int> parent;
vector<ll> size;

int find_set(int v){
    if (v == parent[v]) return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b){
    a = find_set(a);
    b = find_set(b);
    if (a!= b){
        if (size[a] < size[b])
            swap(a, b);
        size[a] += size[b];
        parent[b] = a;
    }
}

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

    int n, m;
    cin>>n>>m;

    parent.resize(n+1);
    size.resize(n+1);

    lp(i, 1, n+1){
        size[i] = 1LL;
        parent[i] = i;
    }

    vector<pi> v(m);
    vector<ll> ans;

    int a, b;
    lp(i, 0, m){
        cin>>a>>b;
        v[i] = mp(a, b);
    }

    ll res = (ll)n*(n-1)/2;

    lpd(i, 0, m){
        ans.pb(res);
        int x = find_set(v[i].first);
        int y = find_set(v[i].second);

        if (x != y){
            res -= (size[x]*size[y]);
            union_sets(x, y);
        }
    }

    lpd(i, 0, m) cout<<ans[i]<<endl;

    return 0;
}

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

using namespace std;

int main() {
    // Input
    int N, R;
    cin >> N >>R;

    // Process
    int ans;
    if (N >= 10) {
        ans = R;
    } else {
        ans = R + 100 * (10 - N);
    }

    // Output
    cout << ans << 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,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9+10;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s, t; cin >> s >> t;
    int n_s = s.size(), n_t = t.size();
    auto f = [](string x) -> vint {
        vint res(x.size()+1,0);
        rep(i,x.size()) {
            res[i+1] += res[i] + (x[i]=='A'?1:2);   
        }
        return res;
    };
    vint sum_s = f(s), sum_t = f(t);
    int q; cin >> q;
    rep(i,q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        if (abs((sum_s[b]-sum_s[a-1])-(sum_t[d]-sum_t[c-1])) % 3 == 0) {
            cout << "YES" << endl;
        } else cout << "NO" << endl;
    }
}

Measured memory_bytes: 4292
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
      long long int n,d;
      scanf("%lld%lld",&n,&d);
      long long x,y,i;
      int ans=0;
      for(i=1;i<=n;i++){
            scanf("%lld%lld",&x,&y);
            double c;
            c=sqrt((double)(x*x)+(double)(y*y));
            if(c<=(double)d) ans++;
      }
      printf("%d",ans);

      return 0;
}


Measured memory_bytes: 2152
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.LongStream;
import java.util.Collection;
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.Map;
import java.util.Comparator;

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

    static class D {
        int N;
        int K;
        Map<Integer, Long> memo = new HashMap<>();

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            N = in.nextInt();
            K = in.nextInt();
            List<Long> V = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                V.add(in.nextLong());
            }

            long max = calc(V, 0, 0);
            out.println(max);
        }

        private long calc(List<Long> V, int left, int right) {
            if (memo.containsKey(left + K * right)) {
                return memo.get(left + K * right);
            }
            long ans = Long.MIN_VALUE;
            if (K < left + right || V.size() < left + right) {
                return ans;
            }
            if (K >= left + right) {
                List<Long> sub = new ArrayList<>(V.subList(0, left));
                sub.addAll(V.subList(V.size() - right, V.size()));
                sub.sort(Comparator.naturalOrder());
                for (int i = 0; i < (K - left - right); i++) {
                    if (!sub.isEmpty() && sub.get(0) < 0) {
                        sub.remove(0);
                    }
                }
                ans = sub.stream().mapToLong(l -> l).sum();
            }
            ans = Math.max(ans, calc(V, left + 1, right));
            ans = Math.max(ans, calc(V, left, right + 1));
            memo.put(left + K * right, ans);
            return ans;
        }

    }
}



Measured memory_bytes: 27860
import sys

x, y = list(map(int, input().split()))
group1 = [1, 3, 5, 7, 8, 10, 12]
group2 = [2]
group3 = [4, 6, 9, 11]

if group1.count(x) > 0 and group1.count(y) > 0:
  print("Yes")
  sys.exit()

if group2.count(x) > 0 and group2.count(y) > 0:
  print("Yes")
  sys.exit()

if group3.count(x) > 0 and group3.count(y) > 0:
  print("Yes")
  sys.exit()

print("No")


Measured memory_bytes: 3064
n = int(input())
positions = [list(map(int, input().split())) for _ in range(n)]
for position in positions:
  if position[2] != 0:
    base = position
    break
base_height = base[2]
base_x = base[0]
base_y = base[1]
for x in range(101):
  for y in range(101):
    height = abs(base_x-x)+abs(base_y-y)+base_height
    for position in positions[:]:
      if position[2] != max([height-abs(x-position[0])-abs(y-position[1]),0]):
        break
    else:
      print(str(x) + ' ' + str(y) + ' ' + str(height))
      exit()
      

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

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

	const int n=x.size();
	int ans=n,num=0;
	for(auto &c:x){
		if(c=='S') num++;
		if(c=='T' and num>0) ans-=2,num=max(0,num-1);
	}

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

Measured memory_bytes: 640
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
    	if 500*i + 100*j + 50*k == X:
      		ans += 1
print(ans)


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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


    int n = scanner.nextInt();

    List<Integer> values = new ArrayList<>();

    for (int valueCount = 1; valueCount <= n; valueCount++) {
      values.add(scanner.nextInt());
    }

    values.sort((a, b) -> {
      return b - a;
    });


    int count = 0;
    int currentValue = Integer.MAX_VALUE;

    for (int value : values) {
      if (value < currentValue) {
        currentValue = value;
        count++;
      } else {
        continue;
      }

    }

    System.out.println(count);

    scanner.close();
  }
}


Measured memory_bytes: 26452
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	REP(i, N) cin >> a[i];

	int idx = 1;
	int ans = 0;
	REP(i, N) {
		if (a[i] == idx) {
			idx++;
		} else {
			ans++;
		}
	}

	if (idx == 1) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, X;
  cin >> N >> X;
  vl m(N);
  rep(i, N){
    cin >> m[i];
    X -= m[i];
  }

  stable_sort(m.begin(), m.end());

  cout << N + X / m[0] << endl;
  
  return 0;
}


Measured memory_bytes: 256
import fractions
n = int(input())
z = [list(map(int,input().split())) for _ in range(n)]
if n == 1:
	print(1)
else:
	a = []
	ans = 10**18
	for i in range(n):
		for j in range(i+1, n):
			a.append((z[i][0]-z[j][0], z[i][1]-z[j][1]))
	for i, j in a:
		tmpans = n
		for k, l in z:
			if [k-i, l-j] in z:
				tmpans -= 1
		ans = min(ans, tmpans)
	print(ans)

Measured memory_bytes: 5532
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import itertools
import math


def dist(xs, ys):
    ans = 0
    for x, y in zip(xs, ys):
        ans += (x - y) ** 2
    return math.sqrt(ans)


def main():
    N, D = map(int, input().split())
    Xs = [list(map(int, input().split())) for _ in range(N)]

    ans = 0
    for i, j in itertools.combinations(range(N), 2):
        d = dist(Xs[i], Xs[j])
        if d == int(d):
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int dp[5001][5001];


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

	reverse(s.begin(), s.end());

	for (int i = 0; i < s.length(); i++){
		if (s[i] == s[0]){
			dp[i][0] = 1;
			dp[0][i] = 1;
		}else{
			dp[i][0] = 0;
			dp[0][i] = 0;
		}
	}

	for (int i = 1; i < s.length(); i++){
		for (int j = 1; j < s.length(); j++){
			if (s[i] == s[j]){
				dp[i][j] = dp[i-1][j-1] + 1;
			}else{
				dp[i][j] = 0;
			}
		}
	}

	int ans = 0;

	for (int i = 0; i < s.length(); i++){
		for (int j = i+1; j < s.length(); j++){
			if (i + dp[i][j] > j) continue;
			ans = max(ans, dp[i][j]);
		}
	}

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


Measured memory_bytes: 97920
#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 gcd(int x, int y){
    if(y == 0) return x;
    else return gcd(y, x % y);
}

int main() {
    int N, K; cin >> N >> K;
    int A[N];
    rep(i, N) cin >> A[i];
    if(K > *max_element(A, A + N)) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    int ans = 0;
    rep(i, N) ans = gcd(A[i], ans);
    if(K % ans == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 640
# s=input()
# if s<='2019/4/30':
# 	print("Heisei")
# else:
# 	print("TBD")

n=int(input())
t,a=map(int,input().split())
array= list(map(int,input().split()))

min=100000
count=0

for i in range(0,n):
	array[i]=t-array[i]*0.006
	array[i]=abs(a-array[i])
	if min>array[i]:
		min=array[i]
		count=i

print(count+1)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int k, x;
	cin >> k >> x;

	for (int i = x - k + 1; i < x + k; i++) {
		cout << i << " ";
	}
}


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

using namespace std;

int main() {
	int n,x,y,z,a,b,c;
	cin>>n;
    cin>>x>>y>>z;
    int p,q,r;
    for(int i=0;i<n-1;i++)
    {
        cin>>a>>b>>c;
        p=a+max(y,z);
        q=b+max(x,z);
        r=c+max(x,y);
        x=p;
        y=q;
        z=r;
    }
    int ans=max(x,max(y,z));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes() {
  cout << "Yes" << endl;
  exit(0);
}

void no() {
  cout << "No" << endl;
  exit(0);
}

int main() {
  ll n;
  cin >> n;
  vector<ll> cnt(3, 0);
  REP(i, n) {
    ll a;
    cin >> a;
    ll c = 0;
    REP(j, 2) {
      if (a % 2 == 0) {
        c++;
        a /= 2;
      } else {
        break;
      }
    }
    cnt[c]++;
  }

  if (cnt[2] == 0) {
    if (cnt[0] > 0) {
      no();
    }
    yes();
  }

  // cnt[2]>0

  if (cnt[1] == 0) {
    if (cnt[2] + 1 >= cnt[0]) {
      yes();
    }
    no();
  }

  // cnt[2] > 0, cnt[1] > 0
  if (cnt[0] > cnt[2]) {
    no();
  }

  yes();
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

int main() {
    ll h; cin >> h;
    ll cnt = 0;
    while(1){
        if(h==1){
            break;
        }
        else {
            h /= 2LL;
            cnt++;
        }
    }

    ll sum = 0;
    for(int i=0; i<cnt; i++){
        sum += (ll)pow(2LL, i);
    }
    sum += (ll)pow(2LL, cnt);

    cout << sum << endl;
}

Measured memory_bytes: 512
# 優先度つきキューをやるらしい
# どうすんのと思ったら毎回条件があうまで探索してpushしてpopすんのか

import heapq

n, m = map(int, input().split())
arr = []
for _ in range(n):
    arr.append(list(map(int, input().split())))
arr = sorted(arr, key=lambda x: x[0])

idx = 0
ans = 0
heap = []
heapq.heapify(heap)
for i in range(1, m + 1):
    # i...残り日数
    while idx < n and arr[idx][0] <= i:
        heapq.heappush(heap, -arr[idx][1])
        idx += 1
    # この時点でヒープで次に取り出す値には残り日数iの時点での最大値（つーか最小値）が入っている
    if heap:
        ans = ans - heapq.heappop(heap)

print(ans)


Measured memory_bytes: 31916
K = int(input())
d = 0
n = 1
while K > 0:
  if ((n+1)*10**d-1)*(sum(map(int,str(n+1)))+9*d) <= ((n+2)*10**d-1)*(sum(map(int,str(n)))+9*d):
    print(n,'9'*d, sep='')
    K -= 1
    n += 1
  else:
    d += 1
    n = (n+1)//10

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

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll N;
	cin >> N;
 
	vector<ll> t(N + 1);
	vector<ll> v(N + 1);
 
	repn(i, N) cin >> t[i];
	repn(i, N) cin >> v[i];
 
	double dp[200][200];
 
	rep(i, N+1)rep(j, 200) { dp[i][j] = -1; }
 
	dp[0][0] = 0;
 
	repn(i, N)rep(j,200) {
		if (j > v[i]) {continue; }
 
		
		rep(k, 200) {
			if (k > v[i]) { continue; }
			if (dp[i - 1][k] == -1) { continue; }
			if (abs(k-j)>t[i]) { continue; }
 
			double sp = min((double)(t[i] + j + k) / 2.0, double(v[i]));
 
			double x = (double)t[i] * sp - (sp - (double)k)*(sp- (double)k) / 2.0 - (sp - (double)j)*(sp - (double)j) / 2.0;
 
			dp[i][j] = max(dp[i][j], dp[i - 1][k] + x);
 
			//cout << i << j << x <<" "<<dp[i][j]<< endl;
		}
 
		//cout << i << j << " " << dp[i][j] << endl;
 
	}
 
	cout << fixed << setprecision(10);
 
	cout << dp[N][0];
	
	
 
	

}


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

using namespace std;

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

using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<tuple<string, int, int>> tp(n);
    rep(i, n){
        string a;
        int b;
        cin >> a >> b;
        tp[i] = make_tuple(a, -b, i+1);
    }

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

    for(auto x : tp){
        ppp(get<2>(x));
    }
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())

mod = 10**9+7
ans = 0
count = [0]*(k+1)

for i in range(1, k+1):
    m = i - count[i]
    ans += pow(k//i, n, mod) * m
    ans %= mod
    for j in range(i, k+1, i):
        count[j] += m

print(ans)


Measured memory_bytes: 68792
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

const int kMaxV = 10010;

struct Edge {
  int u;
  int v;

  Edge(int u, int v): u(u), v(v) {}

  bool operator < (const Edge& rhs) const {
    if (u != rhs.u) {
      return u < rhs.u;
    } else {
      return v < rhs.v;
    }
  }
};

int v, e, source = 0, dfs_clock = 0;
vector<int> g[kMaxV];
int pre[kMaxV] = {0};
int low[kMaxV] = {0};
int parent[kMaxV];
vector<Edge> bridges;

void DFS(int u, int father) {
  int child_num = 0;
  ++dfs_clock;
  pre[u] = dfs_clock;
  low[u] = dfs_clock;
  for (int v: g[u]) {
    if (!pre[v]) {
      ++child_num;
      parent[v] = u;
      DFS(v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] > pre[u]) {
        bridges.emplace_back(min(u, v), max(u, v));
      }
    } else if (v != father) {
      low[u] = min(low[u], pre[v]);
    }
  }
}

void Bridge() {
  memset(parent, source, sizeof(parent));
  DFS(source, -1);
  sort(bridges.begin(), bridges.end());
}

int main() {
  scanf("%d %d", &v, &e);
  for (int i = 0; i < e; ++i) {
    int s, t;
    scanf("%d %d", &s, &t);
    g[s].push_back(t);
    g[t].push_back(s);
  }

  Bridge();
  for (auto b: bridges) {
    printf("%d %d\n", min(b.u, b.v), max(b.u, b.v));
  }

  return 0;
}



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

void solve(int TestCase) {
    int r, c, k;
    cin >> r >> c >> k;
    
    auto A = vector<vector<int>>(r, vector<int>(c));
    for(auto i = 0; i < r; ++i)
    {
        string s;
        cin >> s;
        
        for(auto j = 0; j < c; ++j)
        {
            A[i][j] = s[j] - '0';
        }
    }

    auto B = vector<vector<int>>(r + 1, vector<int>(c + 1));
    for(auto i = 0; i < r; ++i)
        for(auto j = 0; j < c; ++j)
            B[i+1][j+1] = B[i][j+1] + B[i+1][j] - B[i][j] + A[i][j];
    
    int ret = INT_MAX;
    for(auto subset = 0; subset < (1 << r); ++subset)
    {
        if(subset & 1)
            continue;

        int x = 0;
        auto cut = vector<bool>(c+1);
        bool success2 = true;
        for(auto i = 1; i <= c; ++i)
        {
            bool success = true;
            int y = 0;
            for(auto j = 1; j <= r; ++j)
            {
                if(j == r || (subset & (1 << j))) {
                    int p = B[j][i] - B[j][x] - B[y][i] + B[y][x];
                    if(p > k) {
                        success = false;
                    }

                    y = j;
                }
            }

            if(!success) {
                if(x == i - 1) {
                    success2 = false;
                }
                cut[i - 1] = true;
                x = i - 1;
            }
        }

        if(success2) {
            int candi = __builtin_popcount(subset);
            for(auto i = 0; i < c; ++i)
            {
                if(cut[i]) {
                    candi++;
                }
            }

            ret = min(ret, candi);
        }
    }

    cout << ret << endl;
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}

Measured memory_bytes: 384
N = int(input())
Nstr = str(N)
Nmatsubi = int(Nstr[-1])

if Nmatsubi == 3:
    print("bon")
elif Nmatsubi == 0 or Nmatsubi == 1 or Nmatsubi == 6 or Nmatsubi == 8:
    print("pon")
else:
    print("hon")

Measured memory_bytes: 9152
#include<stdio.h>
void main()
{
    int num,limit1,limit2,i,flag=0;
    scanf("%d",&num);
    scanf("%d",&limit1);
    scanf("%d",&limit2);
    for(i=limit1;i<=limit2;i++)
    {
        if(i%num==0)
        {
            flag=1;
            break;
        }
        else
        {
            flag=0;
        }
    }
    if(flag==1)
    {
        printf("OK");
    }
    if(flag==0)
    {
        printf("NG");
    }

}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans = min(A, K);
    K -= min(A, K);
    if (K > 0) {
        K -= min(B, K);
    }
    if (K > 0) {
        ans -= K;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


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

using namespace std;

int main() {
	int m, n;
	int k;
	cin >> m >> n;
	cin >> k;
	char q;
	vector< vector<int> > hyouJ(m+1, vector<int>(n+1));
	vector< vector<int> > hyouO(m+1, vector<int>(n+1));
	vector< vector<int> > hyouI(m+1, vector<int>(n+1));
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> q;
			hyouJ[i][j] = hyouJ[i][j-1]; 
			hyouO[i][j] = hyouO[i][j-1];
			hyouI[i][j] = hyouI[i][j-1];
			if (q == 'J') {
				hyouJ[i][j]++;
			} else if (q == 'O') {
				hyouO[i][j]++;
			} else {
				hyouI[i][j]++;
			}
		}
	}
	for (int i = 0; i < k; i++) {
		int counter[3] = {0};
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		for (int j = a; j <= c; j++) {
			counter[0] += (hyouJ[j][d]-hyouJ[j][b-1]);
			counter[1] += (hyouO[j][d]-hyouO[j][b-1]);
			counter[2] += (hyouI[j][d]-hyouI[j][b-1]);
		}
		cout << counter[0] << ' ' << counter[1] << ' ' << counter[2] << endl;
	}
	return 0;
}

Measured memory_bytes: 12884
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
use std::cmp::*;
//use std::num;

fn main() {
    input! {
         n:i64,k:i64

    }
    let x = n % k;
    let y = k - x;
    let ans = min(x, y);
    println!("{}", ans);
}


Measured memory_bytes: 2164
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

int n;
vector<int> et[10000];
int c[10000];
queue<P> que;
int ans[10000];

int dfs(int p, int v) {
	int i;
	int ret = 0;
	rep(i, et[v].size()) {
		int nv = et[v][i];
		if (nv == p) continue;
		ret += min(ans[v], ans[nv]);
		ret += dfs(v, nv);
	}
	return ret;
}

int main() {
	int i;
	
	cin >> n;
	rep(i, n - 1) {
		int u, v;
		cin >> u >> v; u--; v--;
		et[u].push_back(v);
		et[v].push_back(u);
	}
	rep(i, n) cin >> c[i];
	sort(c, c + n, greater<int>());
	
	int cnt = 0;
	que.push(P(0, 0));	//parent, v
	while (!que.empty()) {
		P now = que.front(); que.pop();
		int p = now.first;
		int v = now.second;
		ans[v] = c[cnt]; cnt++;
		rep(i, et[v].size()) {
			int nv = et[v][i];
			if (nv == p) continue;
			que.push(P(v, nv));
		}
	}
	
	int score = dfs(0, 0);
	cout << score << endl;
	rep(i, n) {
		cout << ans[i];
		if (i + 1 < n) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1664
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    t = 0
    for i in a:
        t += (1 / i)
    print(1 / t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
X, Y, A, B, C = map(int, input().split())
p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))
r_list = list(map(int, input().split()))

p_list_max = sorted(p_list, reverse=True)
q_list_max = sorted(q_list, reverse=True)
r_list_max = sorted(r_list, reverse=True)

p_list_X = p_list_max[:X]
q_list_Y = q_list_max[:Y]

ans_list = []
ans_list.extend(p_list_X)
ans_list.extend(q_list_Y)
ans_list.extend(r_list_max)
ans_list_max = sorted(ans_list, reverse=True)

ans = 0
#print(p_list_X, q_list_Y, ans_list_max)
for i in range(X+Y):
    ans += ans_list_max[i]
print(ans)

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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector <int> L(N) ;
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

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

    int sum = 0;
    for (int i = 0; i < N - 1; i++) {
        sum += L[i];
    }

    cout << ((L[N - 1] < sum) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());
        if (n >= 10) {
            System.out.println(r);
        } else {
            System.out.println(r + 100 * (10 - n));
        }
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 

#define M 100010
ll p;
ll f(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1)ans=(ans*a)%p;
		a=(a*a)%p;b/=2;
	}
	return ans;
}
int main(){
	IOS;
	tihs;
	
	ll n;
	string s;cin>>s;
	n=sz(s);
	p=2019;
	ll cnt[2020]={0};
	ll ans = 0;
	ll b[n];
	ll val = 0,ct = 0;
	for(ll i=n-1;i>=0;--i){
		ll t = s[i]-'0';
		val = 0;
		val += (f(10,ct)*t)%p;
		val %= p;
		if(i+1<n)(val += b[i+1])%=p;
		b[i]=val;
		ct++;
		cnt[b[i]%p]++;
	}
	cnt[0]++;
	rep(i,0,p){
		ans += (cnt[i]*(cnt[i]-1))/2;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5356
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for i in range(N)]
A_sort =sorted(A)
ans =[]*N
max_1 =A_sort[-1]
max_2 =A_sort[-2]

for i in A:
    if i !=max_1:
        ans.append(max_1)
    else:
        ans.append(max_2)
[print(i) for i in ans]

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

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> look_west(N, 0);
    vector<int> look_east(N, 0);
    for(int i=0; i<N; i++){
        if(i>0) look_west[i] = look_west[i-1];
        if(S[i]=='W') look_west[i]++;
    }
    for(int i=N-1; i>=0; i--){
        if(i<N-1) look_east[i] = look_east[i+1];
        if(S[i]=='E') look_east[i]++;
    }
    vector<int> cost(N, 0);
    for(int i=0; i<N; i++){
        cost[i] = look_west[i] + look_east[i];
    }
    auto res = *min_element(cost.begin(), cost.end());
    cout<<res-1<<endl;

    return 0;
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout<< #i<< "= "<< i << endl
using namespace std;

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ap = b,bp = c;
    int n=0,m=0;
    while(ap <= a){
        ap *= 2;
        n++;
    }
    while(bp <= ap){
        bp *= 2;
        m++;
    }
    string ans = "No";
    if((n + m) <= k) ans = "Yes";
   // cout <<k << " " << m << " " << n << endl;
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstdlib>

#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <tuple>

using namespace std;

using ii = pair < int, int >;
using ti = tuple < int, int, int>;
using lint = long long;

char a[200005];
lint c[26];

int main() {
	lint ans = 1;
	scanf("%s", a);
	int n = strlen(a);
	for(int i=0;i<n;i++){
		c[a[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		for (int j = i + 1; j < 26; j++) {
			ans += c[i] * c[j];
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <vector>
#include <valarray>
#include <queue>
#include <iostream>
#include <numeric>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(int i = (a); i >= (b); --i)
#define rREP(i, n) rFOR(i, n-1, 0)
#define AND &&
#define OR ||
#define IN(x, min, max) (min <= x AND x < max)
#define VEC(type) vector<type>
#define DVEC(type) vector<vector<type>>
#define VAL(type) valarray<type>
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
#define HOGE printf("%s\n", "hoge");
#define DUMP(p) cout << p << endl;
const int INF = 2323232323;
using namespace std;
typedef pair<int, int> P;

int N;
int main(){
    scanf("%d", &N);
    VEC(int) a(N);
    REP(i, N){
        scanf(" %d", &a[i]);
    }
    VEC(int) dp(N, -1);
    int ans = 0;
    REP(i, N){
        if (dp[i] > 0) {
            continue;
        }
        if (i+1 == a[a[i]-1]) {
            ans++;
            dp[a[i]-1] = 1;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int solve () {
	int ans = 0;
	bool V[MAX];
	for ( int  i = 0; i < n; i++ ) {
		B[i] = A[i];
		V[i] = false;
	}
	sort(B,B+n);
	for ( int i = 0; i < n; i++ ) T[B[i]] = i;
	for ( int i = 0; i < n; i++ ) {
		if ( V[i] ) continue;
		int cur = i;
		int S = 0;
		int m = VMAX;
		int an = 0;
		while ( 1 ) {
			V[cur] = true;
			an++;
			int v = A[cur];
			m = min(m,v);
			S += v;
			cur = T[v];
			if ( V[cur] ) break;
		}
		ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
	} 
	return ans;
}

int main(){
	cin >> n;
	s = VMAX;
	for ( int i = 0; i < n; i++ ) {
		cin >> A[i];
		s = min(s, A[i]);
	}
	int ans = solve();
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i,from,to) for(int i=from; i<to; ++i)
#define REP(i,from,to) for(int i=from; i<=to; ++i)
using namespace std;
typedef pair<int, int> P;
typedef pair<P, P> area;
typedef struct answer answer;
template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i] << endl;
	}
	return out;
}
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	out << "[";
	size_t last = v.size() - 1;
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i];
		if (i != last) {
			out << ",";
		}
	}
	out << "]";
	return out;
}

const int maxn = 110;
int n;
int a[maxn];
void print(int arr[maxn]) {
	for (int i = 0; i < n - 1; ++i) {
		cout << arr[i] << " ";
	}
	cout << arr[n - 1] << endl;
}
void insertionSort(int arr[maxn]) {
	print(arr);
	REP(i,1,n-1)
	{
		int v = arr[i];
		int j = i - 1;
		while (j >= 0 && arr[j] > v) {
			arr[j + 1] = arr[j];
			j--;
		}
		arr[j + 1] = v;
		print(arr);
	}
}

void solve() {
	cin >> n;
	rep(i,0,n)
	{
		cin >> a[i];
	}
	insertionSort(a);
}

int main() {
	solve();
}

Measured memory_bytes: 3088
# Edit: 2014/09/25
# Lang: Python3
# Time: 0.xxs
#

from collections import OrderedDict

if __name__ == "__main__":

    while True:
        d = OrderedDict()
        n = int(input())
        if not n:
            break  # exit at n=0

        for i in range(n):
            s, p, m = map(int, input().strip("\n").split(" "))
            # print(s, p, m)

            if s in d:
                d[s] += p * m
            else:
                d[s] = p * m

        cnt = 0
        for k, v in d.items():
            if v >= 1000000:
                print(k)
                cnt += 1
        if not cnt:
            print("NA")

Measured memory_bytes: 6976