akhauriyash/Code-Regression huggingface dataset:
a, b = map(int, input().split())

if a % 3 == 0:
    print('Possible')
    exit()
elif b % 3 == 0:
    print('Possible')
    exit()
elif (a+b) % 3 == 0:
    print('Possible')
    exit()
else:
    print('Impossible')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long



using namespace std;

int main(){
    ll N,K;
    cin >> N >> K;
    string s;
    cin >> s;
    ll cnt=0;

    for(int i=0;i<s.size()-1;i++){
        if(s[i]!=s[i+1]) cnt++;
    }
    if(cnt!=0) cnt++;
    else{
        cout << N-1 << endl;
        return 0;
    }
    if(cnt<=2*K){
        cout << N-1 << endl;
        return 0;
    }
    ll ans;
    ans = N - (cnt - 2*K);
    if(ans==N) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define rep2(x,from,to) for(int x=from;x<to;x++)
#define rep(x,to) rep2(x,0,to)
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P>  PP;
typedef pair<int,PP> PPP;
int n;
int a[100006];
int k[100006];
int main()
{
    cin>>n;
    rep(i,n)
    {
        cin>>a[i];
        k[a[i]-1]=i+1;
    }
    rep(i,n)
    {
        cout<<k[i];
        if(i==n-1)cout<<endl;
        else cout<<' ';
    }
    return 0;
}

Measured memory_bytes: 1536
N = int(raw_input())
S = map(int, raw_input().split(' '))

count = 0
for i in range(N-2):
      b = S[i:i+3]
      c = b[:]
      c.sort()
      if b[1] == c[1]:
            count += 1
      else:
            pass
print(count)




Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    vec<int> a(N);
    rep(i, N) cin >> a[i];
    sort(rall(a));

    int A=0 ,B = 0;
    rep(i,N){
        if(i%2==0) A+=a[i];
        else B+=a[i];
    }
    cout << A -B << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>

using namespace std;

int main(){
  int n,q,t[100000],N,S=0;
  string A,name[100000];
  queue<string> Q1,Q3;
  queue<int> Q2,Q4;
  cin>>n>>q;
  for(int i=1;i<n+1;i++){
    cin>>name[i]>>t[i];
    Q1.push(name[i]);
    Q2.push(t[i]);
  }
  while(Q1.empty()==0){

    A=Q1.front();
    Q1.pop();
    N=Q2.front();
    Q2.pop();

    if(N<q+1){
      S+=N;
      Q3.push(A);
      Q4.push(S);
    }

    else{
      S+=q;
      Q1.push(A);
      N-=q;
      Q2.push(N);
    }
  }
  for(int i=1;i<n+1;i++){
    cout<<Q3.front()<<" "<<Q4.front()<<endl;
    Q3.pop();
    Q4.pop();
  }
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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

int income[10020];


int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		int sum = 0;
		for(int i = 0;i < n;i++){
			cin >> income[i];
			sum += income[i];
		}
		int av = sum / n;
		int ans = 0;
		for(int i = 0;i < n;i++){
			if(income[i] <= av) ans++;
		}
		cout << ans << endl;

	}
}


Measured memory_bytes: 3112
#include <stdio.h>

int main(void)
{
	int n;
	int x, y, h, w;
	int sum;
	int kane = 0;
	int i;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
			scanf("%d %d %d %d", &x, &y, &h, &w);
			
			sum = x + y + h;
			
			if ((sum <= 60) && (w <= 2)){
				kane += 600;
			}
			else if ((sum <= 80) && (w <= 5)){
				kane += 800;
			}
			else if ((sum <= 100) && (w <= 10)){
				kane += 1000;
			}
			else if ((sum <= 120) && (w <= 15)){
				kane += 1200;
			}
			else if ((sum <= 140) && (w <= 20)){
				kane += 1400;
			}
			else if ((sum <= 160) && (w <= 25)){
				kane += 1600;
			}
		}
		printf("%d\n", kane);
		kane = 0;
	}
	
	return (0);
}

Measured memory_bytes: 600
import itertools
import math
i1 = []
i1.append(int(input()))
i1.append(int(input()))
i1.append(int(input()))
i1.append(int(input()))
i1.append(int(input()))
#i2 =(int(input())
#print(i1)
p_list = list(itertools.permutations(i1, 5))
#print(len(p_list))
tt = []
for i in p_list:
  tt.append((math.ceil(i[0]/10)+math.ceil(i[1]/10)+math.ceil(i[2]/10)+math.ceil(i[3]/10))*10+(i[4]))
  # tt.append(0+i[0]   
print(min(tt))

Measured memory_bytes: 3064
#include<stdio.h>
#define NIL -1

struct node
{ int parent;
  int left;
  int right; };

struct node Tree[10000];
int n;

void preorder(int);
void inorder(int);
void postorder(int);

int main()
{
  int i,root;
  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    Tree[i].parent=NIL;
  int num,l,r;
  for(i=0;i<n;i++)
    {scanf("%d %d %d",&num,&l,&r);
      Tree[num].left=l;
      Tree[num].right=r;
      if(l!=NIL)Tree[l].parent=num;
      if(r!=NIL)Tree[r].parent=num;
    }
  for(i=0;i<n;i++)
    {if(Tree[i].parent==NIL)
	root=i;}

  printf("Preorder\n");
  preorder(root);
  printf("\n");
  printf("Inorder\n");
  inorder(root);
  printf("\n");
  printf("Postorder\n");
  postorder(root);
  printf("\n");
  
  return 0;
}

void preorder(int s)
{
  if(s==NIL)return;
  printf(" %d",s);
  preorder(Tree[s].left);
  preorder(Tree[s].right);
}

void inorder(int s)
{
if(s==NIL)return;
  inorder(Tree[s].left);
  printf(" %d",s);
  inorder(Tree[s].right);
}

void postorder(int s)
{
if(s==NIL)return;
  postorder(Tree[s].left);
  postorder(Tree[s].right);
  printf(" %d",s);
}



Measured memory_bytes: 2112
#include <iostream>
auto f(const int64_t n, const int64_t k) {
  const int64_t k_wo_hikeru_kaisu = n / k;
  const int64_t hikareta_atono_N_sei = n - (k * k_wo_hikeru_kaisu);
  const int64_t hikareta_atono_N_hu_zettaichi =
      (hikareta_atono_N_sei - k) * (-1);
  return hikareta_atono_N_sei < hikareta_atono_N_hu_zettaichi
             ? hikareta_atono_N_sei
             : hikareta_atono_N_hu_zettaichi;
}

int main(int, char **) {
  int64_t n, k;
  std::cin >> n >> k;
  std::cout << f(n, k) << std::endl;
}


Measured memory_bytes: 256
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(input())

    An = sorted(map(int, input().split()))
    Bn = sorted(map(int, input().split()))
    Cn = sorted(map(int, input().split()))

    ans = 0
    lx = 0
    ux = 0

    for Bi in Bn:
        # 以上
        lx = bisect_left(An, Bi, lx, N)

        # より大きい
        ux = bisect_right(Cn, Bi, ux, N)

        ans += lx * (N - ux)

    print(ans)
    return


main()


Measured memory_bytes: 22720
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    vl a(n+1);
    rep(i,n + 1){
        if(s[i] == '<'){
            a[i+1] = max(a[i+1],a[i] + 1);
        }
    }

    for(int i = n;i >= 0; i--){
        if(s[i] == '>'){
            a[i] = max(a[i],a[i+1]+1);
        }
    }
    ll ans = 0;
    rep(i,n+1){
        //cout << a[i]  << " ";
        ans+= a[i];
    }
    //cout << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7656
#include <stdio.h>

int main(void)
{
	int S,h,m,s;
	scanf("%d",&S);
	h = S / (60 * 60),
	m = (S % (60 * 60)) / 60,
	s = (S % (60 * 60)) % 60;
	printf("%d:%d:%d\n",h,m,s);

	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m;
    cin >> n >> m;
    if(n < m) swap(n, m);
    ll ans;
    if(n == 1 && m == 1) {
        ans = 1;
    }else if(m == 1) {
        ans = n - 2;
    }else{
        ans = (n - 2) * (m - 2);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 3612
#include <stdio.h>

int main(void) {

  int n[100] = {0}, x[100] = {0}, a = 0, i, j, k, l = 0;
  
  for (i = 0; i < 100; i++) {
    scanf("%d %d", &n[i], &x[i]);
    if (n[i] == 0 && x[i] == 0) {
      break;
    }
  }
  
  while (l < 100) {
    if (n[l] == 0) {
      break;
    }
    for (i = 1; i < n[l] - 1; i++) {
      for (j = i + 1; j < n[l]; j++) {
        for (k = j + 1; k <= n[l]; k++) {
          if (i + j + k == x[l]) {
            a++;
          }
        }
      }
    }
    printf("%d\n" ,a);
    a = 0;
    l++;
  }
  
  return 0;
}

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

int main(){
	int n;
	cin>>n;
	int kind[16];
	int unkind[16];
	
	for(int i=0; i<n; i++){
		int kind_p = 0;
		int unkind_p = 0;
		int t;
		cin>>t;
		while(t--){
			int a,b;
			cin>>a>>b;
			if(b) kind_p |=(1<<--a);
			else unkind_p|=(1<<--a);
		}
		kind[i] = kind_p;
		unkind[i] = unkind_p;
	}
	int maxpeople = 0;
	for(int i=0; i<(1<<n); i++){
		int totalkind = 0;
		int totalunkind = 0;
		for(int j=0; j<n; j++){
			if(i&(1<<j)){
				totalkind|=kind[j];
				totalunkind|=unkind[j];
			}
		}
		bool possible = true;
		for(int j=0; j<n; j++){
			if(totalkind&(1<<j) && (i&(1<<j))==0) possible = false;
			if(totalunkind&(1<<j) && i&(1<<j)) possible = false;
		}
		
		if(possible) maxpeople = max(maxpeople,__builtin_popcount(i));
	}
	//for(int i=0; i<n; i++) cout<<kind[i]<<" ";
	cout<<maxpeople;
}

Measured memory_bytes: 3628
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            print("Bad")
            quit()
    print("Good")
    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 40516
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    vector<vector<char>> v(3, vector<char>(3));
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> v[i][j];
        }
    }
    for(int i = 0; i < 3; i++){
        cout << v[i][i];
    }
    cout << endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
S=[list(map(int,input().split())) for i in range(M)]
if N==1 and M==0:
    print(0)
else:    
    A=[1]
    for i in range(1,N):
        A.append(0)

    a=False
    for i in range(M):
        if a==False:
            for j in range(M):
                if S[i][0]==S[j][0] and S[i][1]!=S[j][1]:
                    print(-1)
                    a=True
                    break

    if a==False:
        for i in range(M):
            A[S[i][0]-1]=S[i][1]
        if A[0]!=0:
            B=list(map(str,A))
            print("".join(B))
        elif A[0]==0 and N>=2:
            print(-1)
        elif A[0]==0 and N==1:
            print(0)


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

int main() {
    string s;
    cin >> s;
    int check = 700;
    if (s[0] == 'o') check += 100;
    if (s[1] == 'o') check += 100;
    if (s[2] == 'o') check += 100;
    cout << check << endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
lst = [['*' for i in range(w+2)]]
for i in range(h):
    string = input()
    lsti = ['*']
    for j in range(w):
        lsti.append(string[j])
        if string[j] == 's':
            start = (i+1, j+1)
        elif string[j] == 'g':
            goal = (i+1, j+1)
    lsti.append('*')
    lst.append(lsti)
lst.append(['*' for i in range(w+2)])

lst_cnt = [[300 for i in range(w+2)] for j in range(h+2)]
if lst[1][1] == '#':
    lst_cnt[1][1] = -1
else:
    lst_cnt[1][1] = 0

queue_new = [(1, 1)]
while queue_new != []:
    queue = queue_new
    queue_new = []
    while queue != []:
        zahyo = queue.pop()
        i, j = zahyo[0], zahyo[1]
        if lst[i+1][j] == '#':
            if lst_cnt[i][j] < 0:
                if abs(lst_cnt[i][j]) < abs(lst_cnt[i+1][j]):
                    lst_cnt[i+1][j] = -abs(lst_cnt[i][j])
                    queue_new.append((i+1, j))
            else:
                if abs(lst_cnt[i][j])+1 < abs(lst_cnt[i+1][j]):
                    lst_cnt[i+1][j] = -(abs(lst_cnt[i][j])+1)
                    queue_new.append((i+1, j))
        elif lst[i+1][j] == '.':
            if abs(lst_cnt[i][j]) < abs(lst_cnt[i+1][j]):
                lst_cnt[i+1][j] = abs(lst_cnt[i][j])
                queue_new.append((i+1, j))
        
        if lst[i][j+1] == '#':
            if lst_cnt[i][j] < 0:
                if abs(lst_cnt[i][j]) < abs(lst_cnt[i][j+1]):
                    lst_cnt[i][j+1] = -abs(lst_cnt[i][j])
                    queue_new.append((i, j+1))
            else:
                if abs(lst_cnt[i][j])+1 < abs(lst_cnt[i][j+1]):
                    lst_cnt[i][j+1] = -(abs(lst_cnt[i][j])+1)
                    queue_new.append((i, j+1))
        elif lst[i][j+1] == '.':
            if abs(lst_cnt[i][j]) < abs(lst_cnt[i][j+1]):
                lst_cnt[i][j+1] = abs(lst_cnt[i][j])
                queue_new.append((i, j+1))
print(abs(lst_cnt[h][w]))

Measured memory_bytes: 3432
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1e9 + 7;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    vector<ll> A(5);
    ll k;
    cin >> A[0] >> A[1] >> A[2] >> A[3] >> A[4] >> k;
    rep(i, 5)
    {
        for(int j=i+1; j <5;++j)
        {
            if (i == j)
            {
                continue;
            }
            if (A[j] - A[i] > k)
            {
                cout << ":(";
                return 0;
            }
        }
    }
    //
    cout << "Yay!";
    return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 200000
#define STRLEN 20

int main(void){
    int l,n, count=0;
    scanf("%d", &n);
    char y[n-1];
    for(int i=0;i<n;i++){
        scanf(" %c",&y[i]);
    }
    l = n-1;

    for(int i=0;i<n;i++){
        if(y[i] == 'W' && i < l){
            while(y[l] == 'W'){
                l--;
                if(l == i) break;
            }
            if(l != i){
                y[i] = 'R';
                y[l] = 'W';
                count++;
            }
        }
    }

    printf("%d\n", count);
    return 0;
}


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

int K;

void DFS(string ANS, int P, int& NOW) {
	if (P == 0) {
		NOW++;
		if (NOW == K) cout << ANS << endl;
		return;
	}
	int X = ANS[ANS.size() - 1] - '0';
	for (int i = X - 1; i <= X + 1; i++) {
		if (i < 0 || 9 < i) continue;
		DFS(ANS + (char)(i + '0'), P - 1, NOW);
	}
}

int main() {
	cin >> K;
	int NOW = 0;
	for (int i = 1; ; i++) {
		for (int j = 1; j <= 9; j++) {
			string S = "";
			S += j + '0';
			DFS(S, i - 1, NOW);
			if (NOW > K) return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
typedef long long ll;

int main(){
	int a[26];
	char s;
  	int d, x, y;
  	x = 'A', y = 'a';
  	for (int i = 0; i < 26; i++) a[i] = 0;
  	while( cin >> s ){
      	d = s;
		if ( d >= 'A' && d <= 'Z' ) a[d-'A'] += 1;
      	else if ( d >= 'a' && d <= 'z' ) a[d-'a'] += 1;
    }
    for (int i = 0; i < 26; i++){
      	s = 'a' + i;
    	cout << s << " : " << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std; 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define rep(i,a,b) for(int i=a;i<b;i++)
#define reprev(i,a,b) for(int i=b-1;i>=a;i--)
#define all(c) c.begin(),c.end()
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vin(a,n) vi a(n); rep(i,0,n) cin>>a[i];
#define vout(a,n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl;
#define mapp map<int,int>
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define tr(container, it) \
for(auto it = container.begin(); it != container.end(); it++)
 
bool comps(const pair<int,int> &a, const pair<int,int> &b) {return (a.second<b.second);} 

int fac[100001];
int power(int x, unsigned int y)
{ 
    int temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
}

int powerp(int x, unsigned int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}

int binomialCoeff(int n, int k)
{  
    // Base Cases  
    if (k == 0 || k == n)  
        return 1;  
  
    // Recur  
    return binomialCoeff(n - 1, k - 1) +  
                binomialCoeff(n - 1, k);  
}
void precomp()
{ 
    fac[0] = 1; 
    for (int i=1 ; i<=100000; i++) 
        fac[i] = fac[i-1]*i%mod;
}
int modInverse(int n, int p) {return powerp(n, p-2, p);}
int nCrModPFermat(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r   
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 
signed main()
{
    
    IOS
    int n,k;
    cin>>n>>k;
    vi res(n);
    while(k--)
    {
        int d;
        cin>>d;
        rep(i,0,d) {int temp;cin>>temp; res[temp-1]=1;}
    }
    int count=0;
    rep(i,0,res.size()) if(res[i]==0) count++;
    cout<<count;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

main(){
  int a, b;
  int sum=0, sum2=0;
  double ave;
  int i;
  for(i=0;;i++){
    if(scanf("%d,%d", &a, &b)==EOF) break;
    sum+=a*b;
    sum2+=b;
  }
  ave=(double)sum2/(double)i;
  ave*=10;
  int ans=((int)ave+5)/10;
  printf("%d\n%d\n", sum, ans);
  return 0;
}

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


Measured memory_bytes: 128
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
killed = 0
if n == 1:
  print(min(b[0],a[0]+a[1]))
else:
  for i in range(n):
    if a[i] >= b[i]:
      killed += b[i]
      a[i] -= b[i]
      b[i] = 0
    else:
      killed += a[i]
      b[i] -= a[i]
      if a[i+1] >= b[i]:
        killed += b[i]
        a[i+1] -= b[i]
        b[i] = 0
      else:
        killed += a[i+1]
        a[i+1] = 0
  print(killed)
      

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

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

  vector<ll> X(N, 0);
  vector<ll> L(N, 0);
  vector<pll> A(N, make_pair(0, 0));
  rep(i, N) {
    cin >> X.at(i) >> L.at(i);
    A.at(i).first = X.at(i) - L.at(i);
    A.at(i).second = X.at(i) + L.at(i);
  }
  sort(A.begin(), A.end(), [](pll a, pll b) {return a.second < b.second;});
  int ans = 0;
  int t = -INF;
  rep(i, N) {
    if (t <= A.at(i).first) {
      ans++;
      t = A.at(i).second;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3456
#include<iostream>
#include <string>
using namespace std;
#define ll  long long
int main(){
ll n,k,q;
cin>>n>>k>>q;
ll a[q],score[n];
  for(ll i=0;i<n;i++)score[i]=k;
for(ll i=0;i<q;i++){
	cin>>a[i];
	score[a[i]-1]++;
	}

for(ll i=0;i<n;i++){
 
if((score[i] -q)>0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;


}
	return 0;
}



Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define hashset unordered_set
#define hashmap unordered_map
#define getbit(x, i) (((x) >> (i)) & 1)
using namespace std;
typedef pair<int, int> pii; 
template <typename T>
inline vector<T> readvector(size_t size) {
    vector<T> res(size);
    for (size_t i = 0; i < size; ++i) {
        cin >> res[i];
    }
    return res;
}
template <typename T>
inline void printvector(vector<T>& arr, string sep = " ", string ends = "\n") {
    for (size_t i = 0; i < arr.size(); ++i) {
        cout << arr.at(i) << sep;
    }
    cout << ends;
}
inline int binPow(int x, int deg, int mod) {
    int ans = 1;
    for (int i = sizeof(x) * CHAR_BIT - 1; i >= 0; i--) {
        ans *= ans;
        ans %= mod;
        if (getbit(deg, i)) ans *= x;
        ans %= mod;
    }
    return ans;
}
// ====================== END ======================
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;


int cnt[10][10];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string x = to_string(i);
        cnt[x[0] - '0'][x.back() - '0']++;
    }
    int ans = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;

    return 0;
}   

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

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);

    for(int i = 0; i < N; i++){
        cin >> A[i];
        A[i]--;
    }
    for(int i = 0; i < N; i++){
        cin >> B[i];
    }
    for(int i = 0; i < N-1; i++){
        cin >> C[i];
    }

    int sum = 0;
    for(int i = 0; i < N-1; i++){
        sum += B[A[i]];
        if(A[i] + 1 == A[i+1]){
            sum += C[A[i]];
        }
    }
    sum += B[A[N-1]];

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Char
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as BS

readIntTriplet :: BS.ByteString -> (Int, Int, Int)
readIntTriplet s = let Just (a, s') = BS.readInt s
                       Just (b, s'') = BS.readInt $ BS.dropWhile isSpace s'
                       Just (c, _) = BS.readInt $ BS.dropWhile isSpace s''
                   in (a, b, c)

main = do
  n <- readLn
  happiness <- V.replicateM n (readIntTriplet <$> BS.getLine)
  let (!a,!b,!c) = V.foldl1' (\(!a,!b,!c) (!a',!b',!c') -> (max b c + a', max a c + b', max a b + c')) happiness
  print (max a (max b c))


Measured memory_bytes: 3452
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ulong = unsigned long;
const ll mod = 1000000000000000000;

int main() {
  int n;
  cin >> n;
  ll p = 1;
  bool out = false;
  bool zero = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) zero = true;
    if (a > mod) out = true;
    ll next = p * a;
    if (p > next) out = true;
    p = next;
    if (p > mod) out = true;
  }
  if (out && !zero)
    cout << -1 << endl;
  else
    cout << p << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	int a, b;
	cin >> a >> b;
	cout << (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ? "Possible" : "Impossible") << endl;
	return 0;
}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  map<ll, ll> mp;
  cin >> n;
  rep(i, n) {
    ll d;
    cin >> d;
    mp[d]++;
  }

  ll m;
  cin >> m;
  rep(i, m) { ll t;
    cin >> t;
    if(mp.count(t) == 0 || mp[t] == 0){
      puts("NO");
      return 0;
    }
    mp[t]--;
  }

  puts("YES");

  return 0;
}


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

#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define popcount __builtin_popcountll

const int INF = 1LL<<60;
const int MOD = 1000000007;

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}

template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}

template <typename A>
string to_string(A x[], int n) {
    string result = "{";
    REP(i, 0, n) {
        if (i!=0) result += ", ";
        result += to_string(x[i]); 
    }
    return result + "}";
}

string bin_string(int x) {
    const int d = 64;
    string result(d, ' ');
    RREP(i, d-1, -1) result[d-1-i] = '0'+((x&1LL<<i)!=0);
    return result;
}

vector<int> getZ(string s) {
    int n = s.size();
    vector<int> z(n);
    int x = 0, y = 0;
    REP(i, 1, n) {
        z[i] = max(0LL, min(z[i-x], y-i+1));
        while (i+z[i] < n && s[z[i]] == s[i+z[i]]) {
            x = i;
            y = i+z[i];
            ++z[i];
        }
    }
    return z;
}

int powa(int base, int exp) {
    if (exp<=0) return 1;
    if (base<=0) return 0;
    int val = powa(base, exp>>1);
    val = val*val % MOD;
    if (exp&1) {
        val = val*base % MOD;
    }
    return val;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    const int INNER = 80*160+10;
    const int OUTER = INNER+100;

    int R,C;
    cin >> R >> C;
    int grid[R][C];

    REP(r, 0, R) REP(c, 0, C) cin >> grid[r][c];
    REP(r, 0, R) REP(c, 0, C) {
        int x;
        cin >> x;
        grid[r][c] = abs(grid[r][c]-x);
    }

    bool dp[R][C][2*OUTER];
    dp[0][0][OUTER+grid[0][0]] = dp[0][0][OUTER-grid[0][0]] = 1;
    REP(r, 0, R) REP(c, 0, C) REP(k, OUTER-INNER, OUTER+INNER) {
        if (r == 0 && c == 0) continue;
        dp[r][c][k] = r!=0 && (dp[r-1][c][k-grid[r][c]] || dp[r-1][c][k+grid[r][c]]) || c!=0 && (dp[r][c-1][k-grid[r][c]] || dp[r][c-1][k+grid[r][c]]);
    }
    
    int res=0;
    while (!dp[R-1][C-1][OUTER+res] && !dp[R-1][C-1][OUTER-res]) ++res;
    cout << res;
}

Measured memory_bytes: 161664
n = int(input())

suite = ['S', 'H', 'C', 'D']
ans = set()

for s in suite:
    for i in range(1, 14):
        ans.add('{} {}'.format(s, i))

for i in range(n):
    ll, nn = input().split()
    ans.remove('{} {}'.format(ll, nn))

ans = list(ans)
for i, j in enumerate(ans):
    ans[i] = ans[i].replace('S', 'A')
    ans[i] = ans[i].replace('H', 'B')
    ans[i] = ans[i].replace('10', 'K')
    ans[i] = ans[i].replace('11', 'L')
    ans[i] = ans[i].replace('12', 'M')
    ans[i] = ans[i].replace('13', 'N')


ans.sort()

for i, j in enumerate(ans):
    ans[i] = ans[i].replace('A', 'S')
    ans[i] = ans[i].replace('B', 'H')
    ans[i] = ans[i].replace('K', '10')
    ans[i] = ans[i].replace('L', '11')
    ans[i] = ans[i].replace('M', '12')
    ans[i] = ans[i].replace('N', '13')

if len(ans) != 0:
    print('\n'.join(ans))


Measured memory_bytes: 5616
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
char s[maxn];
int cnt[maxn];
int n;
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	int cnt0=0,cnt1=0;
	for(int i=1;i<=n;i++)
		if(s[i]=='R'){
			if(i&1)++cnt1;
			else ++cnt0;
		}
		else{
			if(i&1)cnt[i]+=cnt1,cnt[i-1]+=cnt0;
			else cnt[i]+=cnt0,cnt[i-1]+=cnt1;
			cnt0=cnt1=0;
		}
	cnt0=cnt1=0;
	for(int i=n;i;i--)
		if(s[i]=='L'){
			if(i&1)++cnt1;
			else ++cnt0;
		}
		else{
			if(i&1)cnt[i]+=cnt1,cnt[i+1]+=cnt0;
			else cnt[i]+=cnt0,cnt[i+1]+=cnt1;
			cnt0=cnt1=0;
		}
	for(int i=1;i<=n;i++)
		writesp(cnt[i]);
	return 0;
}

Measured memory_bytes: 896
def main():
    S = input()
    Q = int(input())
    H = True
    A = ""  #
    B = ""
    for _ in range(Q):  # リストにしない
        q = list(input().split())
        if q[0] == "1": H = not H
        elif q[1] == "1" and H:     A = q[2] + A
        elif q[1] == "1" and not H:     B = B + q[2]
        elif q[1] == "2" and H:     B = B + q[2]
        elif q[1] == "2" and not H:     A = q[2] + A

    ans = A + S + B
    if H:   print(ans)
    else:   print(ans[::-1])

main()

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

int cmpChar(char *pchar){
  
  if(strlen(pchar) == 0) return 0;
  
  int rc = 0;
  if(memcmp(pchar, "dreamer", 7) == 0){
    rc = cmpChar(pchar + 7);
    if(rc == 0) return rc;
  }  
  if(memcmp(pchar, "dream", 5) == 0){
    rc = cmpChar(pchar + 5);
    if(rc == 0) return rc;
  }
  if(memcmp(pchar, "eraser", 6) == 0){
    rc = cmpChar(pchar + 6);
    if(rc == 0) return rc;
  }
  if(memcmp(pchar, "erase", 5) == 0){
    rc = cmpChar(pchar + 5);
    if(rc == 0) return rc;
  }
  
  return -1;
}

int main(void){
  char buf[131072] = { 0 };
  
  fgets(buf, sizeof(buf), stdin);
  // 改行チェック
  char *tok = strtok(buf, "\n"); 
  
  int rc = cmpChar(tok);
  if(rc == 0) printf("YES\n");
  else printf("NO\n");
  
  return 0;
}

Measured memory_bytes: 1884
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
using namespace std;
int main(void) {
    long n, m,a,b,l[100001] = { 0 }, h[100001] = { 0 }, i;
    cin >> n;
    cin >> m;
    for (i = 1; i <= n; i++) {
        cin >> h[i];
    }
    //for (i = 1; i <= n; i++) {
    //    cout << h[i];
    //}
    for (i = 1; i <= m; i++) {
        cin >> a;
        cin >> b;
        if (h[a] > h[b]) l[b] = 1;
        else if (h[a] < h[b]) l[a] = 1;
        else
        {
            l[a] = 1;
            l[b] = 1;
        }
    }
    //for (i = 1; i <= n; i++) {
    //    cout << l[i];
    //}
    m = 0;
    for (i = 1; i <= n; i++) {
        if (l[i] == 0)m++;
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 5188
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main() {

    int N; cin >> N;
    ll ans = 0;
    for (int i = 1; i <= N; ++i) {
        if (i % 3 != 0 && i % 5 != 0) {
            ans += i;
        }
    }
    out(ans);



    return 0;
}






Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int intpow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1)
            ans *= a;
        a *= a;
        ans %= 2019;
        a %= 2019;
        b /= 2;
    }
    return ans;
}

string S;
int d[202020];
int cnt[3000];
int N;
void solve() {
    N = S.size();
    for (int i = N - 1; i >= 0; i--) {
        d[N - i] = d[N - i - 1] + intpow(10, N - i - 1) * S[i];
        d[N - i] %= 2019;
        //cerr << d[N - i] << endl;
    }
    FOR (N + 1)
        cnt[d[i] % 2019]++;
    int ans = 0;
    FOR (2019) {
        ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> S;
    for (auto& c : S)
        c -= '0';


    solve();
    return 0;
}


Measured memory_bytes: 5356
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def BellmanFord(edges, v, source):
    INF = float("inf")
    dist = [INF for _ in range(v)]
    dist[source] = 0
    for i in range(2 * v + 1):
        for now, fol, cost in edges:
            if dist[now] != INF and dist[fol] > dist[now] + cost:
                dist[fol] = dist[now] + cost
                if i >= v:
                    dist[fol] = -INF
    if dist[-1] == -INF:
        return -1
    else:
        return max(0, -dist[-1])


n, m, p = map(int, readline().split())
abc = [list(map(int, readline().split())) for i in range(m)]
edges = []
for a, b, c in abc:
    edges.append((a - 1, b - 1, p - c))
print(BellmanFord(edges, n, 0))


Measured memory_bytes: 44124
// Problem : 
// 			D - Teleporter
// 			Editorial
// 		
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define re(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	ll n,k;
	cin>>n>>k;
	vi a(n),place;
	loop(i,n)
	{
		cin>>a[i];
		a[i]--;
	}
	vector<bool> vis(n);
	int i=0,len=0;
	while(!vis[i])
	{
		vis[i]=true;
		i=a[i];
		len++;
		if(len==k)
		{
			cout<<i+1<<nl;
			return 0;
		}
	}
	int ssz=1,cpy=i;
	vi ans;
	ans.pb(i);
	i=a[i];
	ans.pb(i);
	while(i!=cpy)
	{
		ssz++;
		i=a[i];
		ans.pb(i);
	}
	int val=(k-len)%ssz;
	cout<<ans[val]+1<<nl;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 4624
while True:
    count=0
    n, x=(int(i) for i in input().split())
    if n==x==0:
        break
    for a in range(3, n+1):
        for b in range(2, a):
            for c in range(1, b):
                if a+b+c==x:
                    count+=1
    print(count)


Measured memory_bytes: 5600
#include <iostream>
using namespace std;
#define ll long long
int main() {
	ll a,b,k;
	cin>>a>>b>>k;
	if(k<=a)
	    a = a-k;
	else
	{
	    k = k-a;
	    a = 0;
	    if(k>b)
	   {
	       k = k-b;
	       b=0;
	   }
	   else
	   {
	       b = b-k;
	   }
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}

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

using namespace std;

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

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

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

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

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

int main(void) {
    int N;
    cin >> N;
    vector<int> d(N);
    REP(i, N) {
        cin >> d[i];
    }

    ll sum = 0;
    REP(i, N) {
        SREP(j, i+1, N) {
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$h = array_map('intval', explode(' ', trim(fgets(STDIN))));
$h[0]--;
for ($i = 1; $i < $n; $i++) {
    if ($h[$i - 1] < $h[$i]) {
        $h[$i]--;
    } elseif ($h[$i - 1] > $h[$i]) {
        exit ('No'.PHP_EOL);
    }
}
echo 'Yes'.PHP_EOL;

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

int main(){
    ll R,C,K;
    cin >> R >> C >> K;
    vector<ll> r(K), c(K) , v(K);
    rep(i,K) cin >> r[i] >> c[i] >> v[i];
    vector<vector<ll> > point(R + 2,vector<ll>(C + 2));
    rep(i,R + 2){
        rep(j,C + 2){
            point[i][j] = 0;
        }
    }
    rep(i,K){
        point[r[i]][c[i]] = v[i];
    }
    vector<vector<vector<ll> > > dp(R + 2, vector<vector<ll> >(C + 2, vector<ll>(5)));
    for (ll i = 0; i <= R + 1; i++){
        for (ll j = 0; j <= C + 1; j++){
            for (ll k = 0; k < 5; k++){
                dp[i][j][k] = 0;
            }
        }
    }
    dp[1][1][1] = point[1][1];
    for (ll i = 1; i <= R; i++){
        for (ll j = 1; j <= C; j++){
            for (ll k = 0; k <= 3; k++){
                dp[i][j + 1][k + 1] = max(dp[i][j][k] + point[i][j + 1], max(dp[i][j + 1][k + 1], dp[i][j][k + 1]));
                dp[i][j + 1][k] = max(dp[i][j][k], dp[i][j + 1][k]);
            }
        }
        for (ll j = 1; j <= C; j++){
            for (ll k = 0; k <= 3; k++){
                dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
                dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][k] + point[i + 1][j]);
            }
        }
    }
    ll ans = max(dp[R][C][0], max(dp[R][C][1], max(dp[R][C][2], dp[R][C][3])));
    cout << ans << endl;
}


Measured memory_bytes: 712296