akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a, b;
		a = sc.next();
		b = sc.next();


		if(a.length() == b.length()) {
			if(a.compareTo(b) > 0) System.out.println("GREATER");
			else if(a.compareTo(b) < 0) System.out.println("LESS");
			else System.out.println("EQUAL");
		} else {
			System.out.print(a.length() > b.length() ? "GREATER" : "LESS");
		}
	}
}

Measured memory_bytes: 22740
#include <stdio.h>

int main()
{
  int n, q, t[1000000], s[1000000];
  int count = 0, i, left, right, mid;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &s[i]);
  }

  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &t[i]);
  }

  
  for(i = 0; i < q; i++){
    left = 0;
    right = n;
    while(left < right){
      mid = (left + right) / 2;
      if(t[i] == s[mid]){
	count++;
	break;
      }
      else if(t[i] > s[mid]) left = mid + 1;
      else if(t[i] < s[mid]) right = mid;
      else break;
    }
  }
  printf("%d\n", count);
  return 0;
}



Measured memory_bytes: 2336
N = int(input())
D, X = map(int, input().split())

A = []
for n in range(N):
    buff = int(input())
    A.append(buff)

div = 0
for n in range(N):
    if A[n] == 1:
        div += (D-1) //A[n]
    elif D % A[n] == 0:
        div += (D-1) //A[n]
    else:
        div += D //A[n]

goukei = X + div + N

print(goukei)

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b){
        cout << c << endl;
    }
    else if(b==c){
        cout << a << endl;
    }
    else cout << b << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;
typedef pair<int, int> P;

const int INF = 1 << 28;
int dp[510][1010];

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

	int N, M;
	while(cin >> N >> M) {
		vector<P> r(M);
		for(int i = 0; i < M; i++) {
			cin >> r[i].second >> r[i].first;
		}
		sort(r.begin(), r.end());

		fill((int*)begin(dp), (int*)end(dp), INF);
		dp[0][N] = 0;
		for(int i = 0; i < M; i++) {
			int pos = r[i].first;
			for(int j = 1; j <= N; j++) {
				if(dp[i][j] == INF) continue;
				int d = d = (i == 0) ? pos : abs(pos - r[i - 1].first);
				// ??????
				int ret = abs(pos - min(r[i].second, j));
				dp[i + 1][N] = min(dp[i + 1][N], dp[i][j] + d + 2 * ret);
				// ????????????
				int nj = min(r[i].second, j);
				dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j] + d);
			}
		}

		int pos = (M == 0) ? 0 : r.back().first;
		cout << dp[M][N] + (N + 1 - pos) << endl;
	}
}

Measured memory_bytes: 5228
#include<iostream>
#include<cmath>

using namespace std;

bool issolve(int n) {
	//M^2-M-2*N=0
	double M = (1 + sqrt(1.0 + 8.0 * n)) / 2.0;
	int intM = M;
	if (M == (double)intM)return true;
	return false;
}

int ans[450 + 100][450 + 100];

int main() {
	int N;
	cin >> N;
	if (!issolve(N)) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	
	int M = (1 + sqrt(1.0 + 8.0 * N)) / 2.0;
	cout << M << endl;
	int cnt = 1;
	for (int i = 0; i < M; i++) {
		int size = 2 * N / M;
		cout << size << " ";
		for (int s = 0; s < size; s++) {
			if (size - i > s) {
				cout << cnt << " ";
				ans[i][s] = cnt;
				cnt++;
			}
			else {

				cout << ans[s - (size - i)][size - 1 - s] << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

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

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

    int arr[n];

    for(int i=0;i<n;i++)
        cin>>arr[i];

    int mx=0,s=0,l=0;

    for(int i=1;i<n;i++){
        if(arr[i]<=arr[i-1])
            s++;

        mx=max(s,mx);

         if(arr[i]>arr[i-1])
            s=0;
    }


    mx=max(s,mx);
    cout<<mx<<endl;



}


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

int main() {
	int N, T[1005], A[1005];
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> T[i] >> A[i];
	}
	long long int t[1005] = { 0 };
	long long int a[1005] = { 0 };
	long long int x[1005] = { 0 };
	t[1] = T[1], a[1] = A[1];
	for (int i = 2; i <= N; i++) {
		long long int tt, aa;
		tt = aa = 0;
		if (t[i - 1] % T[i] == 0) {
			tt = t[i - 1] / T[i];
		}else{ tt = t[i - 1] / T[i] + 1; }
		if (a[i - 1] % A[i] == 0) {
			aa = a[i - 1] / A[i];
		}
		else { aa = a[i - 1] / A[i] + 1; }
		x[i] = max(tt, aa);
		t[i] = T[i] * x[i];
		a[i] = A[i] * x[i];
	}
	cout << t[N] + a[N];
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int n,i,d[2][100010],max,f[100010]={};
  long long s=1,M=1e9+7;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&d[0][i]);
    if(i&&d[0][i-1]<d[0][i])f[i]|=1;
  }
  for(i=0;i<n;i++)scanf("%d",&d[1][i]);
  f[n-1]=2;
  for(i=n-1;i--;){
    if(d[1][i+1]<d[1][i])f[i]|=2;
  }
  for(i=1;i<n-1;i++){
    if(f[i]==0)s=(s*MIN(d[0][i],d[1][i]))%M;
    if(f[i]==1&&d[0][i]>d[1][i])s*=0;
    if(f[i]==2&&d[0][i]<d[1][i])s*=0;
    if(f[i]==3&&d[0][i]-d[1][i])s*=0;
  }
  if(d[0][n-1]-d[1][0])s*=0;
  printf("%lld\n",s);
  return 0;
}
  


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

int N;
map<int, int> M;

int main(){
	int cnt = 0;
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		int val;
		scanf("%d", &val);
		M[val]++;
	}
	for(auto i = M.begin(); i != M.end(); i++)
		if(i -> second > i -> first) cnt += i -> second - i -> first;
		else if(i -> second < i -> first) cnt += i -> second;
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int N, K;
int DP[100010] = {};
int main() {
	cin >> N >> K;
	int a[N];
	REP(i, N){
		cin >> a[i];
	}
	REP(i,K){
		REP(j,N){
			if (DP[i] == 0){
				if (i + a[j] <= K)chmax(DP[i+a[j]], 1);
			}
		}
	}
	string res;
	if (DP[K] == 0){
		res = "Second";
	}else{
		res = "First";
	}
	cout << res;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define re register
#define IL inline
using namespace std;
const int maxn=3e3+10;
template<typename T> void read(T &x){
	T f=1;x=0;
	char s=getchar();
	while(s<'0' || s>'9'){if(s=='-') f=-1;s=getchar();}
	while(s>='0' && s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();}
	x*=f;
}
int n;
ll a[maxn];
ll f[maxn][maxn];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	read(n);
	for(re int i=1;i<=n;i++){
		read(a[i]);
		if(n&1){
			f[i][i]=a[i];
		}
		else f[i][i]=-a[i];
	}
	for(re int i=1;i<n;i++){
		for(re int j=1;j<=n-i;j++){
			if((n-i-1)&1)
				f[j][i+j]=min(f[j+1][i+j]-a[j],f[j][i+j-1]-a[i+j]);
			else f[j][i+j]=max(f[j+1][i+j]+a[j],f[j][i+j-1]+a[i+j]);
		}
	}
	cout<<f[1][n]<<endl;
	return 0;
}


Measured memory_bytes: 70016
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String akstn = "akstnhmyrw";
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length(); i++) {
			int num = Integer.parseInt(s.charAt(i) + "");
			i++;
			char flick = s.charAt(i);
			if (num == 0) {
				if (flick =='U') {
					sb.append("nn");
					continue;
				} else {
					sb.append("w" + aiueo(flick));
					continue;
				}
			} else if (num == 1) {
				sb.append(aiueo(flick));
				continue;
			} else {
				sb.append(akstn.charAt(num - 1) + aiueo(flick));
				continue;
			}
		}
		System.out.println(sb.toString());

		sc.close();
	}

	static String aiueo(char c) {
		if (c == 'T') {
			return "a";
		} else if (c == 'L') {
			return "i";
		} else if (c == 'U') {
			return "u";
		} else if (c == 'R') {
			return "e";
		} else {
			return "o";
		}
	}
}

Measured memory_bytes: 26612
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = String.valueOf(n);
        sc.close();
        int ss = s.length();
        int aaa = 0;
        for(int i = 0 ; i < ss ; i++ ){
            aaa += (s.charAt(i) - 48);
        }
        if(n % aaa == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35648
N, A, B = map(int, input().split())
V = list(map(int, input().split()))

def comb(n,r):
    ans = 1
    for i in range(r):
        ans *= n-i
    for i in range(r):
        ans //= i+1
    return ans

V.sort(reverse=True)
print(sum(V[:A])/A)

def solve(V,A,B):
    if V[A-1]>V[A]:
        return 1
    a = V[A-1]
    l,r = -1,-1
    for i in range(N):
        if l==-1 and V[i]==a:
            l = i
        if r==-1 and V[i]<a:
            r = i
    if r==-1:
        r = N
    lower = A-l
    upper = min(r,B)-l
    total = r-l
    ans = 0
    if V[0]==a:
        for i in range(lower,upper+1):
            ans += comb(total,i)
    else:
        ans += comb(total,lower)
    return ans
print(solve(V,A,B))

Measured memory_bytes: 38512
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...) DUMPOUT << "  " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << "    ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct IOInit { IOInit() { cin.tie(nullptr); ios::sync_with_stdio(false); dump("READY"); /*cout << unitbuf;*/} } IO_INIT;
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;

using mint = modint998244353;

struct S { mint a, b, c; };
using F = mint;
S op(S a, S b) { return S{a.a, a.b + b.b, a.c + b.c}; }
S e() { return S{0, 1, 0}; }
S mapping(F a, S b) { return (a == INF) ? b : S{a, b.b, a * b.b}; }
F composition(F a, F b) { return (a == INF) ? b : a; }
F id() { return INF; }

signed main(void) {
  int n, q; cin >> n >> q;
  V<S> def(n);
  rrep(i,n) {
    def[i].a = 1;
    if (i < n - 1) def[i].b = def[i+1].b * 10;
    else def[i].b = 1;

    def[i].c = def[i].b;
  }

  lazy_segtree<S, op, e, F, mapping, composition, id> seg(def);
  rep(i,q) {
    int l, r, d; cin >> l >> r >> d;
    --l, --r;
    seg.apply(l, r+1, d);
    pl(seg.all_prod().c.val())
  }

/*
  string s(n, '1');
  rep(i,q) {
    int l, r; char d; cin >> l >> r >> d;
    --l, --r;
    for(int i = l; i <= r; ++i) {
      s[i] = d;
    }
    mint digit = 1;
    mint ans = 0;
    rrep(i,n) {
      mint a = (s[i] - '0');
      a *= digit;
      ans += a;
      digit *= 10;
    }
    pl(ans.val())
  }
*/
  return 0;
}


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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

const int N = 1e4 + 2137;
int cnt[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	for(int i=1; i<=100; i++) {
		for(int j=1; j<=100; j++) {
			for(int z=1; z<=100; z++) {
				int wx = i*i + j*j + z*z + i*j + j*z + i*z;
				if(wx <= 1e4)
					cnt[wx]++;
			}
		}
	}
	for(int i=1; i<=n; i++)
		cout<<cnt[i]<<"\n";
}


Measured memory_bytes: 3600
s = list(input())
tmp = []
for i in range(len(s)):
    if s[i] == "0":
        tmp.append("0")
    elif s[i] == "1":
        tmp.append("1")
    elif s[i] == "B" and tmp != []:
        tmp.pop(len(tmp)-1)
print("".join(tmp))

Measured memory_bytes: 3060
package main

import "fmt"

type proc struct {
	name string
	time int
}

type container struct {
	data []proc
}

func (c *container) queue(p proc) {
	c.data = append(c.data, p)
}
func (c *container) dequeue(p *proc) bool {
	if len(c.data) > 0 {
		*p = c.data[0]
		c.data = c.data[1:]
		return true
	}
	return false
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, q int
	fmt.Scan(&n, &q)
	var queue container
	// procs := make([]proc, n)
	for i := 0; i < n; i++ {
		var p proc
		fmt.Scan(&p.name, &p.time)
		queue.queue(p)
	}
	var t int
	for len(queue.data) > 0 {
		var p proc
		queue.dequeue(&p)
		rt := min(q, p.time) // run time
		t += rt
		if p.time-rt == 0 {
			fmt.Printf("%s %d\n", p.name, t)
		} else {
			p.time = p.time - rt
			queue.queue(p)
		}
	}
}



Measured memory_bytes: 9776
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int read(){
	int x=0;
	char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}

const int N = 100005;
typedef long long ll;

int n,m,v,p;
int a[N];
ll s[N];
bool cmp(int x,int y) { return x>y; }

int main()
{
	n=read(); m=read(); v=read(); p=read();
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+1+n,cmp);
	s[0]=0;
	for(int i=1;i<=n;i++) s[i]=s[i-1]+a[i];
	
	int ans=p,x=0,y,z,ok=1;
	ll t;
	for(int i=p+1;i<=n;i++){
		if(a[i]==a[i-1]) { ans+=ok; continue; }
		y=n-i+1;
		while(a[x+1]>a[i]+m) x++;
		if(x>=p) break;
		if(x+y>=v) { ok=1; ans++; }
		else {
			z=v-x-y;
			t=1ll*(p-1-x)*m+1ll*(a[i]+m)*(i-p)-(s[i-1]-s[p-1]);
			if(t>=1ll*m*z) ok=1,ans++;
			else ok=0;
		}
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=405,M=1e5+10;
vector <pii> yal;
bool vis[N][N];
ll can[N];
int32_t main(){
    ll n,m;
    cin >> n >> m;
    for (int i=0;i<m;i++){
        ll u,v;
        cin >> u >> v;
        yal.pb({u,v});
    }
    reverse(yal.begin(),yal.end());
    for (int i=1;i<=n;i++){
        vis[i][i]=1;
        for (int j=0;j<yal.size();j++){
            ll u=yal[j].F,v=yal[j].S;
            if (vis[i][u] && vis[i][v]) can[i]=-1;
            if (vis[i][u]){
                vis[i][v]=1;
            }
            else if (vis[i][v]){
                vis[i][u]=1;
            }
        }
    }
    ll ans=0;
    for (int i=1;i<=n;i++){
        for (int j=i+1;j<=n;j++){
            ll p1=0;
            if (can[i]==-1 || can[j]==-1) continue;
            for (int k=1;k<=n;k++){
                if (vis[i][k] && vis[j][k]) p1=1;
            }
            if (!p1) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2420
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int a[3], b[3];
	int n[4];
	memset(n, 0, sizeof(n));
	//cin >> A >> B >> C;
	rep(i, 3)
	{
		cin >> a[i] >> b[i];
		n[a[i]-1]++;
		n[b[i]-1]++;
	}

	sort(n, n+4);

	if ((n[0] != 1) || (n[1] != 1) || (n[2] != 2) || (n[3] != 2))
	{
		cout << "NO" << endl;
	}
	else
	{
		cout << "YES" << endl;
	}

	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)
 
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)
 
const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;
 
// typedef long long ll;
#define int long long
#define double long double
 
template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int a, b; cin >> a >> b;
  string S = "", T = "";
  REP(i, b) S += char('0'+a);
  REP(i, a) T += char(b+'0');
  cout << min(S, T) << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <tuple>
#include <functional>
#include <limits>
#include <utility>
#include <string>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

// Overload operator<< for pair.
template <typename First, typename Second>
ostream& operator<<(ostream& os, const pair<First, Second>& pair)
{
	os << pair.first << " " << pair.second;

	return os;
}

// Print each element of a container.
template <typename Container>
void print(const Container& container)
{
	for (const auto& element : container)
	{
		cout << element << endl;
	}
}

int main()
{
    deque<pair<string, int>> processes1;
    vector<pair<string, int>> processes2;

    int n, q;
    cin >> n >> q;

    for(size_t i(0); i < n; ++i)
    {
        string name;
        int time;

        cin >> name >> time;

        processes1.emplace_back(name, time);
    }

    int time(0);
    while(!processes1.empty())
    {
        if (processes1.front().second > q)
        {
            time += q;

            processes1.front().second -= q;
            processes1.push_back(processes1.front());
            processes1.pop_front();
        }
        else
        {
            time += processes1.front().second;

            processes2.emplace_back(processes1.front().first, time);
            processes1.pop_front();
        }
    }

    print(processes2);

    return 0;
}

Measured memory_bytes: 7076
def meal_delivery(x: int, a: int, b: int)->str:
    return 'A' if abs(x - a) < abs(x - b) else 'B'


if __name__ == "__main__":
    x, a, b = map(int, input().split())
    ans = meal_delivery(x, a, b)
    print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
#include<array>
#include<algorithm>
#include<queue>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
#include<bitset>
#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x, y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x, LLI y) {
//	return x / gcd(x, y) * y;
//}

//long nCr(int n, int r) {
//	long ans = 1;
//	for (int i = n; i > n - r; i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; i++) {
//		ans = ans / i;
//	}
//	return ans;
//}
//long nHr(int n,int r) {
//	n = n + r - 1;
//	return nCr(n,r);
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI A, B, C;
	cin >> A >> B;
	cout << max({ A + B,A - B,A * B }) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long  (i)=0;(i)<(n);(i)++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
struct edge{int from,to,cost;};
int n,m,a,b,c,d[1010],ans;
bool ch[1010];
vector<edge> vec;
void bf(int s){
	for(int i=1;i<=n;i++)d[i]=INF;
	d[s]=0;
	rep(i,n){
		bool update=false;
		for(edge e:vec){
			if(d[e.from]==INF)continue;
			if(d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				update=true;
			}
		}
		if(!update)break;
	}
}
void check(){
	rep(i,n+1){
		for(edge e:vec){
			if(d[e.from]==INF)continue;
			if(d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				ch[e.to]=true;
			}
			if(ch[e.from])ch[e.to]=true;
		}
	}
}
signed main(){
	cin>>n>>m;
	rep(i,m){
		cin>>a>>b>>c;
		vec.push_back({a,b,-c});
	}
	bf(1);
	ans=d[n];
	check();
	if(ch[n]){
		cout<<"inf"<<endl;
	}
	else{
		cout<<-ans<<endl;
	}
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
int main(void){
    ll n,a,b;cin>>n>>a>>b;
    if(a==0&&b==0){
        cout<<0<<endl;
        return 0;
    }
    ll res=n/(a+b) * a;
    res+=(n%(a+b)<a)? n%(a+b) : a;
    cout<<res<<endl;
}



Measured memory_bytes: 256
#include<numeric>
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    int n;
    cin>>n;
	ll ans=(n/500)*1000;
	ll rem=n%500;
	ans+=(rem/5)*5;
	cout<<ans<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 256
// Your code here!
use std::io::*;
use std::str::FromStr;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}



fn main(){
    let nums:Vec<i64> = read_vec();
    let mut a:i64 = nums[0];
    let mut b:i64 = nums[1];
    let mut x:i64 = nums[2];
    
    println!("{}",b/x-a/x + (if a%x==0 {1} else {0}));
    
    
}




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

int maxtime(int x) {
  return (x + 9) / 10 * 10;
}
int wait(int x) {
  return maxtime(x) - x;
}
int main() {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  int finish = maxtime(a) + maxtime(b) + maxtime(c) + maxtime(d) + maxtime(e);
  finish -= max({wait(a), wait(b), wait(c), wait(d), wait(e)});
  cout << finish << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
    int N;
    cin >> N;
    int G[N][N];
    REP(i,N){
        REP(j,N){
            G[i][j] = 0;
        }
    }
    REP(i,N){
        int U,K,v;
        cin >> U >> K;
        U--;
        REP(k,K){
            cin >> v;
            v--;
            G[U][v] = 1;
        }
    }
    REP(i,N){
        REP(j,N){
            if(0 == j)cout << G[i][j];
            else cout << " " << G[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3096
function MultipleOf2019(str)
    S = str
    n = length(S)
    T = zeros(Int, n+1)
    N = zeros(Int, 2019)
    N[1] += 1
    m = 1
    for i in n:-1:1
        T[i] = mod(T[i+1] + parse(Int, S[i])*m, 2019)
        m = mod(10m, 2019)
        N[T[i]+1] += 1
    end
#     println(T)
    println(sum(div(m*(m-1), 2) for m in N))
end
MultipleOf2019(readline())

Measured memory_bytes: 169036
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 200005
#define INF 10000000000000000LL

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

struct edge
{
	int to;
	ll cost;
	edge(int to=0,ll cost=0):to(to),cost(cost){}
};
struct UF
{
	int par[SIZE],rank[SIZE];
	
	void init(int n)
	{
		for(int i=0;i<n;i++)
		{
			par[i]=i;
			rank[i]=0;
		}
	}
	int find(int x)
	{
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y)
	{
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]) par[x]=y;
		else
		{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
	bool same(int x,int y)
	{
		return find(x)==find(y);
	}
};
UF uf;
vector <edge> vec[SIZE];
ll X[SIZE];
int v1[SIZE],v2[SIZE];
ll d1[SIZE],d2[SIZE];
int id[SIZE],ch[SIZE];
int now_id;

void dfs(int v=0,int p=-1)
{
	id[v]=now_id++;
	d1[v]=d2[v]=INF;
	v1[v]=v2[v]=-1;
	for(int i=0;i<vec[v].size();i++)
	{
		edge e=vec[v][i];
		if(e.to!=p)
		{
			dfs(e.to,v);
			ll vl=d1[e.to]+e.cost;
			int vv=v1[e.to];
			if(vl>e.cost+X[e.to])
			{
				vl=e.cost+X[e.to];
				vv=e.to;
			}
			if(vl<d1[v])
			{
				swap(vl,d1[v]);
				swap(vv,v1[v]);
			}
			if(vl<d2[v])
			{
				swap(vl,d2[v]);
				swap(vv,v2[v]);
			}
		}
	}
	ch[v]=now_id;
}
void make(int v=0,int p=-1)
{
	for(int i=0;i<vec[v].size();i++)
	{
		edge e=vec[v][i];
		if(e.to!=p)
		{
			ll vl=d1[v]+e.cost;
			int vv=v1[v];
			if(id[e.to]<=id[vv]&&id[vv]<ch[e.to])
			{
				vl=d2[v]+e.cost;
				vv=v2[v];
			}
			if(vl>e.cost+X[v])
			{
				vl=e.cost+X[v];
				vv=v;
			}
			if(vl<d1[e.to])
			{
				swap(vl,d1[e.to]);
				swap(vv,v1[e.to]);
			}
			if(vl<d2[v])
			{
				swap(vl,d2[e.to]);
				swap(vv,v2[e.to]);
			}
			make(e.to,v);
		}
	}
}
int A[SIZE],B[SIZE];
ll C[SIZE];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%lld",&X[i]);
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		ll c;
		scanf("%d %d %lld",&a,&b,&c);a--,b--;
		vec[a].push_back(edge(b,c));
		vec[b].push_back(edge(a,c));
		A[i]=a,B[i]=b,C[i]=c;
	}
	dfs();
	make();
	vector <PP> vx;
	for(int i=0;i<n;i++)
	{
		//printf("%d %d : %lld\n",i,v1[i],X[i]+d1[i]);
		vx.push_back(PP(X[i]+d1[i],P(i,v1[i])));
	}
	sort(vx.begin(),vx.end());
	uf.init(n+2);
	ll ret=0;
	for(int i=0;i<n;i++)
	{
		int u=vx[i].second.first,v=vx[i].second.second;
		if(!uf.same(u,v))
		{
			uf.unite(u,v);
			ret+=vx[i].first;
		}
	}
	for(int i=0;i<n-1;i++)
	{
		if(!uf.same(A[i],B[i]))
		{
			ret+=min(X[A[i]],d1[A[i]]);
			ret+=min(X[B[i]],d1[B[i]]);
			ret+=C[i];
		}
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 48880
#include <iostream>

using i64 = long long;

const i64 MOD = 998244353;
const i64 M = 500000 + 7;

int N, K;
i64 inv[M], fac[M], ifc[M];
i64 ans;

i64 binom(i64 n, i64 m) {
	return n < m || m < 0 ? 0 : fac[n] * ifc[m] % MOD * ifc[n - m] % MOD;
}

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d%d", &N, &K);
	if (N > K) return printf("0"), 0;
	inv[1] = 1;
	for (int i = 2; i <= N || i <= K; ++i) inv[i] = -MOD / i * inv[MOD % i] % MOD;
	for (int i = fac[0] = ifc[0] = 1; i <= N || i <= K; ++i)
		fac[i] = fac[i - 1] * i % MOD,
		ifc[i] = ifc[i - 1] * inv[i] % MOD;
	for (int R = 0, B; R <= K; ++R) {
		B = K - R;
		if (R < B) continue;
		if (R >= B + N)
			ans += binom(K, R);
		if (R == B)
			ans += binom(K - 1, R) - binom(K - 1, 2 * R - N + 1);
		if (R > B && R < B + N)
			ans += binom(K, R) - binom(K, 2 * R - N + 1);
	}
	printf("%lld\n", (ans % MOD + MOD) % MOD);

	return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

int main(){FIN;
	ll h,w,a,b; cin>>h>>w>>a>>b;
	fore(i,0,h){
		fore(j,0,w){
			cout<<(i<b==j<a);
		}
		cout<<"\n";
	}
	
	return 0;
}


Measured memory_bytes: 1280
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func mapToString(a []int) []string {
	len := len(a)
	r := make([]string, len)
	for i := 0; i < len; i++ {
		r[i] = strconv.Itoa(a[i])
	}
	return r
}

func printIntList(args []int) {
	strA := mapToString(args)
	fmt.Println(strings.Join(strA, " "))
}

func main() {
	sc.Split(bufio.ScanWords)
	K, X := nextInt(), nextInt()
	// fmt.Println(K, X)
	start := X - (K - 1)
	end := X + (K - 1)
	ans := make([]int, 0)
	for i := start; i <= end; i++ {
		// fmt.Printf("%d ", i)
		ans = append(ans, i)
	}
	printIntList(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <queue>
using namespace std;

int main(){
    int X,Y,Z,K;
    cin>>X>>Y>>Z>>K;
    vector<int64_t> A(X),B(Y),C(Z);
    for(auto &a:A) cin>>a;
    for(auto &b:B) cin>>b;
    for(auto &c:C) cin>>c;
    sort(A.begin(), A.end(),greater<int64_t>());
    sort(B.begin(), B.end(),greater<int64_t>());
    sort(C.begin(), C.end(),greater<int64_t>());
    int n=0;
    priority_queue<int64_t,vector<int64_t>,greater<int64_t>> Q;
    for(int a=0;a<X;a++){
        for(int b=0;b<Y;b++){
            for(int c=0;c<Z;c++){
                if(n<K){
                    Q.push(A[a]+B[b]+C[c]);
                    n++;
                }else{
                    if(Q.top()<A[a]+B[b]+C[c]){
                        Q.pop();
                        Q.push(A[a]+B[b]+C[c]);
                    }else{
                        break;
                    }
                }
            }
            if(n==K&&Q.top()>A[a]+B[b]+C[0]) break;
        }
        if(n==K&&Q.top()>A[a]+B[0]+C[0]) break;
    }
    vector<int64_t> S(K);
    for(auto &s:S){
        s=Q.top();Q.pop();
    }
    sort(S.begin(), S.end(),greater<int64_t>());
    for(auto s:S) cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 384
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, M = MAP()
AB = [LIST() for _ in range(N)]
AB.sort(key = lambda x: x[0])

ans = 0
i = 0
B = []
for j in range(1, M+1):
	while i < N and AB[i][0] <= j:
		heappush(B, -AB[i][1])
		i += 1
	if B:
		ans += -heappop(B)

print(ans)


Measured memory_bytes: 32180
using System;
using System.Linq;


namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] K = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(K);
            int Counter = 0;
            for (int i = 0; i < N; i++)
            {
                for (int j = i+1; j < N; j++)
                {
                    for (int k = j+1; k < N; k++)
                    {
                        if (K[i] != K[j] && K[j] != K[k] && K[k] != K[i] && K[i] + K[j] > K[k]) { Counter++; }
                    }
                }
            }
            Console.WriteLine(Counter);
        }
    }
}


Measured memory_bytes: 28312
package main

import (
	"fmt"
	"strconv"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {
	var S string
	fmt.Scanf("%s\n", &S)
	RS := []rune(S)
	Reverse(RS)
	num := 0
	pow := 1
	m := map[int]int{
		0: 1,
	}
	for _, r := range RS {
		ri, _ := strconv.Atoi(string(r))
		num = (num + ri*pow) % 2019
		m[num]++
		pow = pow * 10 % 2019
	}
	cnt := 0
	for _, v := range m {
		cnt += v * (v - 1) / 2
	}
	fmt.Println(cnt)
}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


Measured memory_bytes: 4276
#include <cstdio>//C语言io
#include <cstring>//以下是c语言常用头文件
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cmath>
#include <iostream>//c++IO
#include <sstream>
#include <string>
#include <list>//c++常用容器
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>//c++泛型的一些函数
#include <functional>//用来提供一些模版
#define fo0(i,n) for(int i = 0;i < n; ++i)
#define fo1(i,n) for(int i = 1;i <= n; ++i)
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
//......................................................
bool cmp(char a,char b)
{
    if(a>b)
        return 1;
    else
        return 0;
}
int main(void)
{
   char a[200],b[200];
   cin>>a>>b;
   sort(a,a+strlen(a));
   sort(b,b+strlen(b),cmp);
//   cout<<a<<" "<<b<<endl;
   if(strcmp(a,b)<0)
    printf("Yes");
   else
    printf("No");


   return 0;
    }




Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
using namespace std;
int N,M;
vector<int>G[666];
double dp[666],x[666];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int s,t;cin>>s>>t;
		s--,t--;
		G[s].push_back(t);
	}
	dp[N-1]=0;
	for(int i=N-2;i>=0;i--)
	{
		double sum=0;
		for(int v:G[i])sum+=dp[v];
		dp[i]=sum/G[i].size()+1;
	}
	double ans=dp[0];
	for(int i=0;i<N-1;i++)
	{
		if(G[i].size()==1)continue;
		for(int j=i+1;j<N;j++)x[j]=dp[j];
		double sum=0,m=0;
		for(int v:G[i])
		{
			sum+=x[v];
			m=max(m,x[v]);
		}
		x[i]=(sum-m)/(G[i].size()-1)+1;
		for(int j=i-1;j>=0;j--)
		{
			double sum=0;
			for(int v:G[j])sum+=x[v];
			x[j]=sum/G[j].size()+1;
		}
		ans=min(ans,x[0]);
	}
	cout<<fixed<<setprecision(16)<<ans<<endl;
}


Measured memory_bytes: 1408
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main{
	static Scanner s=new Scanner(System.in);

	void solve(){
		int a=gInt(),b=gInt();
		if(a+b==15)
			System.out.println('+');
		else if(a*b==15)
			System.out.println('*');
		else System.out.println('x');
	}

	public static void main(String[] A){
		new Main().solve();
	}

	static int gInt(){
		return Integer.parseInt(s.next());
	}
	static long gLong(){
		return Long.parseLong(s.next());
	}
	static double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,Main::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,Main::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,Main::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(Main::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}


Measured memory_bytes: 23764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class338
    {
        static void Main()
        {
            var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = r[0];
            int a = r[1];
            int b = r[2];

            long all = (long)Modular.Pow(2, n) - 1;
            long A = (long)Modular.Ncr(n, a);
            long B = (long)Modular.Ncr(n, b);
            long ans = all - A - B;
            while (ans < 0) ans += 1000000007;
            Console.WriteLine(ans);
        }
    }
    class Modular  //Modしながら計算するクラス
    {
        private const int M = 1000000007;
        private long value;
        public Modular(long value) { this.value = value; }
        public static implicit operator Modular(long a)
        {
            var m = a % M;
            return new Modular((m < 0) ? m + M : m);
        }
        public static Modular operator +(Modular a, Modular b)
        {
            return a.value + b.value;
        }
        public static Modular operator -(Modular a, Modular b)
        {
            return a.value - b.value;
        }
        public static Modular operator *(Modular a, Modular b)
        {
            return a.value * b.value;
        }
        public static Modular Pow(Modular a, int n)
        {
            switch (n)
            {
                case 0:
                    return 1;
                case 1:
                    return a;
                default:
                    var p = Pow(a, n / 2);
                    return p * p * Pow(a, n % 2);
            }
        }
        public static Modular operator /(Modular a, Modular b)
        {
            return a * Pow(b, M - 2);
        }
        private static readonly List<int> facs = new List<int> { 1 };
        public static Modular Fac(int n)   //階乗
        {
            for (int i = facs.Count; i <= n; ++i)
            {
                facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
            }
            return facs[n];
        }
        public static Modular Fac(int r,int n)
        {
            int temp = 1;
            for(int i = r; i <= n; i++)
            {
                temp = (int)(Math.BigMul(temp, i) % M);
            }
            return temp;
        }
        public static Modular Ncr(int n, int r) //nCr
        {
            return (n < r) ? 0
                 : (n == r) ? 1
                            : (n < 1000000) ? Fac(n) / (Fac(r) * Fac(n - r))
                                : Fac(n-r+1, n) / Fac(r);
        }
        public static explicit operator int(Modular a)
        {
            return (int)a.value;
        }
    }
}


Measured memory_bytes: 12896
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;


int main(){
   ll n;cin>>n;
   if(n<3){cout<<0;return 0;}

   string s;cin>>s;
   ll sumr=0,sumg=0,sumb=0;
   rep(i,n){
     if(s[i]=='R')sumr++;
     else if(s[i]=='G')sumg++;
     else sumb++;
   }
   
   ll c=sumr*sumg*sumb;
   rep(i,n-2){
     for(int j=i+1;j<n-1;j++){
       if(s[i]==s[j])continue;
       int k=j+(j-i);
       if(k<n&&s[j]!=s[k]&&s[k]!=s[i])c--;
     }
   }

   cout << c;
   return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char s[7];
    scanf("%s", s);
    
    if (s[2] == s[3] && s[4] == s[5]){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}


Measured memory_bytes: 128
N = int(input())
list_num = [int(_) for _ in input().split(" ")]
list_num.reverse
for i in range(N, 0, -1):
    if i == 1:
        print(list_num[i - 1], end="")
    else:
        print(list_num[i - 1], end=" ")
print()



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

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  long long int count = 0;
  unordered_map<string, int> hash;
  for(int i = 0; i < n; i++){
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    if(hash[s[i]] != NULL) {
      count += hash[s[i]];
      hash[s[i]]++;
    }
    else hash[s[i]] = 1;
  }
  cout << count << endl;
}


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

int main() {

    int a[10],n;

    long long int wrongarray = 1;

    cin >> n;

    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]%2 == 0){
            wrongarray *= 2;
        }
    }

    long long int ans = 1;

    for(int i=n;i>0;i--){
        ans *= 3;
    }


    cout << ans - wrongarray << endl;


    return 0;
}

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

int main(){
  int x, y, tmp;

  while (1) {
    cin >> x >> y;
    if (x == 0 && y == 0) {
      break;
    }
    if (x > y) {
      tmp = x;
      x = y;
      y = tmp;
    }
    cout << x << " " << y << endl;
  }

  return 0;
}


Measured memory_bytes: 3104
from collections import defaultdict as d
n=int(input())
a=sorted(list(map(int,input().split())))
b=d(int)
for i in a:
    b[i]+=1
s=n-1
c=0
while s>0:
    if b[a[s]]>0:
        t=2**(len(bin(a[s]))-2)
        b[a[s]]-=1
        if b[t-a[s]]>0:
            b[t-a[s]]-=1
            c+=1
    s-=1
print(c)

Measured memory_bytes: 111828