akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n); ++i)
typedef long long ll;

const int mod = 1e9+7;
const int INF = 2000000;
const double PI = acos(-1.0);

int main() {
    
    int X;
    cin >> X;
    int K = 1;
    while(X*K%360 != 0) K++;
    cout << K << endl;
}

Measured memory_bytes: 3560
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int[] num = new int[6];
		for(int i=0;i<6;i++){
			num[i]=sc.nextInt();
		}
		Dice1 d = new Dice1(num);
		int q=sc.nextInt();
		int un=0,fn=0;
		for(int i=0;i<q;i++){
			int u=sc.nextInt();
			for(int j=0;j<6;j++){
				if(num[j]==u){
					un=j;
					break;
				}
			}
			int f=sc.nextInt();
			for(int j=0;j<6;j++){
				if(num[j]==f){
					fn=j;
					break;
				}
			}
			System.out.println(num[d.rcheck(un, fn)]);
		}
	}
}

class Dice1{
	static int[] label=new int[6];
	Dice1(int[] a){
		for(int i=0;i<6;i++){
			label[i]=a[i];
		}
	}
	int rcheck(int up,int fr){
		int a=0;
		if(up==0){
			if(fr==1){
				a=2;
			}else if(fr==2){
				a=4;
			}else if(fr==3){
				a=1;
			}else if(fr==4){
				a=3;
			}
		}else if(up==1){
			if(fr==0){
				a=3;
			}else if(fr==2){
				a=0;
			}else if(fr==3){
				a=5;
			}else if(fr==5){
				a=2;
			}
		}else if(up==2){
			if(fr==0){
				a=1;
			}else if(fr==1){
				a=5;
			}else if(fr==4){
				a=0;
			}else if(fr==5){
				a=4;
			}
		}else if(up==3){
			if(fr==0){
				a=4;
			}else if(fr==1){
				a=0;
			}else if(fr==4){
				a=5;
			}else if(fr==5){
				a=1;
			}
		}else if(up==4){
			if(fr==0){
				a=2;
			}else if(fr==2){
				a=5;
			}else if(fr==3){
				a=0;
			}else if(fr==5){
				a=3;
			}
		}else if(up==5){
			if(fr==1){
				a=3;
			}else if(fr==2){
				a=1;
			}else if(fr==3){
				a=4;
			}else if(fr==4){
				a=2;
			}
		}
		return a;
	}
}

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

int main() {
    long N, L;
    cin >> N >> L;

    long ans;
    if (L >= 0) {
        ans = N * (L - 1) + N * (N + 1) / 2 - L;
    }
    else {
        if (L + N - 1 >= 0) {
            ans = N * (L - 1) + N * (N + 1) / 2;
        }
        else {
            ans = (N - 1) * (L - 1) + (N - 1) * N / 2;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
// Gaurav Aggarwal

/*
useful stl
array<ll,size> ar;         //size(),front(),back(),fill(),empty()
deque<ll> d                //push_back(),push_front(),pop_front(),pop_back()
vector<ll> v(size,val);    //push_back(),*max_element(v.begin(),v.end()),accumulate(v.begin(),v.end(),0)
stack<ll> g;               //push(),pop(),top(),size(),empty()         LIFO
queue<ll> q;               //push(),size(),front(),back(),empty()      FIFO
priority_queue<ll> pq
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ipair;
typedef pair<long,long> lpair;
typedef pair<double,double> pdd;
#define scan(x) do{while((x=getchar_unlocked())<'0'); for(x-='0'; '0'<=(_=getchar_unlocked()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884 
#define debug1(a) cout<<a<<"\n";
#define debug2(a,b) cout<<a<<" "<<b<<"\n";
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define debug_arr(a,n) {for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}}
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define beg_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {a[i] = 0;}

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}


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


    string s;
    cin>>s;
    int n = s.size();
    if(n == 1) {
        cout<<0;
        return 0;
    }
    int count = 1;
    int ans = 0;
    for(int i=1;i<n;++i) {
         // cout<<ans<<"\n";

        if(s[i] == s[i-1]) {
            ++count;
        }
        else {
            if(count &1 ) {
                ans += count/2;
                count = 1;
            }
            else {
                ans += count/2;
                count = 2;
            }
        }

    }
    if(s[n-1] == s[n-2]) {
        if(count &1 ) {
                ans += count/2;
                count = 1;
            }
            else {
                ans += count/2;
                count = 2;
            }
    }

    cout<<ans;


    return 0;
}

Measured memory_bytes: 512
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    now_t, now_x, now_y = 0, 0, 0
    for i in range(N):
        t, x, y = map(int, input().split())

        a = abs(now_x - x) + abs(now_y - y)
        b = t - now_t
        if a > b or a % 2 != b % 2:
            print(No)
            return

        now_t, now_x, now_y = t, x, y

    print(Yes)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

N = 10000
def tokey(i, j, k):
    return i*N*N + j*N + k
def dekey(n):
    i = int(n / N / N)
    j = int(n / N) % N
    k = n % N
    return i, j, k

def main():
    X, Y, Z, K = i2nn()
    A = i2nn()
    B = i2nn()
    C = i2nn()
    A.sort()
    A.reverse()
    B.sort()
    B.reverse()
    C.sort()
    C.reverse()
    Q = [(A[0] + B[0] + C[0], 0, 0, 0)]
    loop = 0
    stored = set()
    def next(i, j, k):
        if i >= X or j >= Y or k >= Z:
            return
        key = tokey(i, j, k)
        if key not in stored:
            stored.add(key)
            n = A[i] + B[j] + C[k]
            Q.append((n, i, j, k))
    while True:
        Q.sort(key=lambda v: v[0])
        v = Q.pop()
        print(v[0])
        loop += 1
        if loop >= K:
            break
        next(v[1]+1, v[2], v[3])
        next(v[1], v[2]+1, v[3])
        next(v[1], v[2], v[3]+1)

main()


Measured memory_bytes: 58844
# coding:utf-8

import sys
from collections import defaultdict

sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, k = LI()
    A = LI_()

    D = defaultdict(list)
    for i in range(1, n):
        D[A[i]].append(i)

    # 首都は必ず自己ループでなければならない
    global res
    res = 0 if A[0] == 0 else 1

    def DFS(v, par):
        global res
        h = 0
        for to in D[v]:
            # print('dfs {} -> {}'.format(v+1, to+1))
            # h: 葉からの距離の最大値
            h = max(h, DFS(to, v))

        # 根が首都ではなく，高さがk - 1の場合は首都につなぎ直す
        if h == k - 1 and par != 0:
            res += 1
            h = -1
        # print('Finish {} <- {}'.format(par+1, v+1))
        return h + 1

    DFS(0, 0)

    return res


print(main())


Measured memory_bytes: 141852
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
int n,m;
signed main()
{
	scanf("%d%d",&n,&m);
	printf("%d",((m*2)-n));
	return putchar(10),0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int dp[n];
    dp[0] = 0;
    REP(i,1,n)
    {
        if(s[i-1]=='A' && s[i]=='C')
        {
            dp[i] = dp[i-1]+1;
        }
        else
        {
            dp[i] = dp[i-1];
        }
    }
    REP(i,0,q)
    {
        int l, r;
        cin >> l >> r;
        cout << dp[r-1]-dp[l-1] << endl;
    }
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

typedef vector<ll> Edges;
typedef vector<Edges> Graph;

const ll V_MAX = 1010101;
vector<ll> ts(V_MAX, -1);
int topologicalSort(Graph &G){
	ll V = G.size();
	vector<ll> indeg(V, 0);
	queue<ll> qu;

	REP(i, V){
		REP(j, G[i].size()){
			indeg[G[i][j]]++;
		}
	}
	REP(i, V){
		if(!indeg[i]) qu.push(i);
	}

	ll depth = 0;
	while(!qu.empty()){
		ll s = qu.size();
		REP(i, s){
			ll now = qu.front();qu.pop();
			ts[now] = depth;
			REP(j, G[now].size()){
				ll next = G[now][j];
				indeg[next]--;
				if(!indeg[next]) qu.push(next);
			}
		}
		depth++;
	}

	REP(i, V){
		if(ts[i] == -1) return -1;
	}
	return depth;
}

struct battle{
	ll x, y;
	bool operator<(const battle &right)const{
		return (x != right.x ? x < right.x : y < right.y);
	}
};

vector<battle> id2b(1010101);
map<battle, ll> b2id;
ll V;

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

    ll N;
    cin >> N;


    ll now = 0;
    REP(i, N){
    	REP(j, N){
    		if(i>=j) continue;
    		battle b = {i, j};
    		id2b[now] = b;
    		now++;
    	}
    }
    V = N*(N-1)/2;
    REP(i, V){
    	b2id[id2b[i]] = i;
    }

    Graph G(V);

    REP(i, N){
    	vector<ll> tmp(N-1);
    	REP(j, N-1) cin >> tmp[j], tmp[j]--;
    	REP(j, N-2){
    		ll x1, y1, x2, y2;
    		x1 = i;
    		y1 = tmp[j];
    		x2 = i;
    		y2 = tmp[j+1];
    		if(x1>y1) swap(x1, y1);
    		if(x2>y2) swap(x2, y2);
    		battle b1 = {x1, y1}, b2 = {x2, y2};
    		G[b2id[b1]].push_back(b2id[b2]);
    	}
    }

    int res = topologicalSort(G);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 86400
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			for(int i = 0;i < n;i++){
				System.out.println("Case " + (i+1) + ":");
				int s = scan.nextInt();
				String ts = "";
				for(int j = 0;j < 10;j++){
					s *= s;
					ts = String.valueOf(s);
					if(ts.length() < 8){
						ts = addZero(ts);
					}
					ts = ts.substring(2,6);
					s = Integer.parseInt(ts);
					System.out.println(s);
				}
			}
		}
	}
	
	public static String addZero(String str){
		String t = "";
		for(int i = 0;i < 8-str.length();i++){
			t += "0";
		}
		return t+str;
	}
}

Measured memory_bytes: 17228
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int k, n;
vector< pair<ll, int> > v;

bool used[100010];

int
main(void){  
  ios_base::sync_with_stdio(false);

  cin >> n >> k;
  REP(i, n) {
    ll d, t;
    cin >> t >> d;
    v.push_back(make_pair(d, t));
  }
  //sort(v.begin(), v.end(), greater<pair<ll, int>>());
  sort(v.begin(), v.end());
  
  priority_queue<ll> q;
  ll sum = 0LL;
  ll var = 0;
  REP(i, k){
    n--;    
    ll t = v[n].second;
    ll d = v[n].first;
    sum += d;
    if(used[t]){
      q.push(-d);
    }
    else{
      used[t] = true;
      var++;
    }
    //cout << "t:" << t << " d:" << d << endl;
  }
  ll ans = sum + var * var;

  while(n>0 && !q.empty()){
    sum += q.top();
    q.pop();
    while(n--){
      ll t = v[n].second;
      ll d = v[n].first;
      if(used[t]) continue; // おんなじネタはいらない
      used[t] = true;
      var++;
      sum += d;
      break;
    }
    ans = max(ans, sum + var * var);
  }

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


Measured memory_bytes: 2672
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    string s, t; cin >> s >> t;
    cout << t+s << endl;

return 0;
}

Measured memory_bytes: 3620
//
//AtCoder Beginner Contest 169
//D - Div Game
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <numeric>
#include <iostream>
#include <array>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main()
{
    ll n;

    cin >> n;

    int ans = 0;

    for(auto p : prime_factor(n)) {
        int c = p.second;
        FOR(i, 1, c){
            p.second-=i;
            if (p.second>=0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


mod = 998244353
n,k = readints()
s = [readints() for i in range(k)]

a = [0] * (n+1)
a[1] = 1

b = [0] * k

for i in range(2,n+1):
    for j in range(k):
        l,r = s[j]
        if i-l>0:
            b[j] += a[i-l]
        if i-r-1>0:
            b[j] -= a[i-r-1]
        a[i] += b[j]
        a[i] %= mod

print(a[-1])









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

int main() {
    int n, q; cin >> n >> q;
    priority_queue<     // 優先順位付きキュー
        int,            //  要素の型は int
        vector<int>,    //  内部コンテナは std::vector（デフォルト）
        less<int>       //  降順 std::less<T>（デフォルト）
    > pq[n];            //  昇順 std::greater<T>
    while (q--) {
        int com; cin >> com;
        if (com == 0) {
            int t, x; cin >> t >> x; pq[t].emplace(x);
        } else if (com == 1) {
            int t; cin >> t;
            if (!pq[t].empty()) cout << pq[t].top() << endl;    // 大きい方から
        } else if (com == 2) {
            int t; cin >> t;
            if (!pq[t].empty()) pq[t].pop();
        }
    }
    return 0;
}


Measured memory_bytes: 4048
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int w = sc.nextInt();
        for (int i = 0; i < s.length(); i++) {
            if (i % w == 0) {
                System.out.print(s.charAt(i));
            }
        }
        System.out.println();
    }    
}


Measured memory_bytes: 21716
n = int(input())
a = list(map(int, input().split()))
res = [0]*n
ans = []
for i in range(n-1, -1, -1):
    if sum(res[i::i+1])%2!=a[i]:
        res[i] = 1
        ans.append(i+1)
a.sort()
print(len(ans))
print(*ans)

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

int main() {
	int n;
	int p[25];
	int res;

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

	res = 0;

	for (int i=1; i<n-1; i++){
		if ( (p[i-1] < p[i] && p[i] < p[i+1])
			 || (p[i+1] < p[i] && p[i] < p[i-1]))
			res++;
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<58;
 
int main(){
    ll A,B,C,K; cin >> A >> B >> C >> K;
  	ll ans;
    if(K % 2 == 0) ans = A - B;
  	else ans = B - A;
    cout << ans << endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	x,y = readline() |> split |> parseMap
	if x*y<0
		println(abs(x+y)+1)
	elseif x<=y
		println(y-x)
	elseif y == 0 || x == 0
		println(x-y+1)
	else
		println(x-y+2)
	end
end

main()

Measured memory_bytes: 110156
#include <iostream>
#include <vector>
#include <tuple>
#include <set>

using namespace std;

int countDigit(int number) {
    int count = 0;

    if (number == 0) {
        return 1;
    }

    while (number != 0) {
        number = number / 10;
        count++;
    }

    return count;
}

int calculateFrontNumber(int number) {
    int tmp = 0;
    tmp = number;
    for (int i = 0;i < countDigit(number) - 1;i++) {
        tmp = tmp / 10;
    }
    return tmp;
}

int calculateEndNumber(int number) {
    return number % 10;
}


int main()
{
    int N;
    cin >> N;
    vector<pair<pair<int, int>,set<int>>> V;
    for (int i = 0;i <= 9;i++) {
        for (int j = 0;j <= 9;j++) {
            set<int> tmpset;
            V.push_back(make_pair(make_pair(i,j), tmpset));
        }
    }

    //全ての数値を最初と最後の値で(1,1),...,(9,9)といった
    //集合群に分け、Nが(1,2)なら(2,1)のNまでの要素数を出力すればよい。
    for (int i = 1;i <= N;i++) {
        V[10 * calculateFrontNumber(i) + calculateEndNumber(i)].second.insert(i);
    }
    vector<int> count(N+1,0);
    for (int i = 1;i <= N;i++) {
        count[i] = count[i-1] + V[10 * calculateEndNumber(i) + calculateFrontNumber(i)].second.size();
    }
    cout << count[N] << endl;

    return 0;
}

Measured memory_bytes: 10368
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
    long long n;
    cin>>n;
    long long t=n%50;
    long long c=n/50;
    c+=49;
    cout<<"50"<<endl;
    for(int i=1;i<=50;i++){
        if(i<=(50-t)){
            cout<<c-t<<" ";
        } else {
            cout<<c+51-t<<" ";
        }
    }
    return 0;
}


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

int main() {
  string N = "1000";
  bool flag = false;
  string target_num = "";
  cin >> N;

  for (int i = 0; i < 4; i++){
    target_num = "";
    for (int j = 0; j < 3; j++){
      target_num += N[i];
    }
    if (N.find(target_num) != string::npos){
      flag = true;
      break;
    }
  }
  if (flag == true){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
def countingSort(a,n):
    count = [0]*(max(a)+1)
    for k in a:
      count[k] += 1
    for i in range(len(count)-1):
      count[i+1] += count[i]
    
    sorted_a = [0]*n

    for k in a[::-1]:
        sorted_a[count[k]-1] = k
        count[k] -= 1
    return sorted_a

n = int(input())
a = list(map(int,input().split()))
print(*countingSort(a,n))

Measured memory_bytes: 233592
#pragma comment(linker, "/STACK:60777216")  

#include <cassert>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<cstdlib>
#include<memory.h>
#include<ctime>
#include<bitset>
#include<fstream>
#include<queue>
#include<stack>
#include<unordered_map>
#include<unordered_set>

using namespace std;

typedef long double ld;

typedef long long ll;
typedef pair<int,int>	pii;
typedef pair<ld,ld>	pdd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef pair<ll,ll> pl;

#define FOR(i,a,b)		for(int i=(a);i<(b);i++)
#define REP(i,n)		FOR(i,0,n)
#define SORT(v)			sort((v).begin(),(v).end())
#define UN(v)			SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a,b)			memset(a,b,sizeof a)
#define pb				push_back

int n;
int a[2222];

int d[2222][2222];
int d1[2222];
int d2[2222];

int solve(int p1,int p2);

int solve1(int p1){
	if(d1[p1]!=-1)return d1[p1];
	int res = 2e9;
	for(int i=p1+1;i<n;i++)res=min(res,solve(p1,i));
	return d1[p1]=res;
}

int solve2(int p2){
	if(d2[p2]!=-1)return d2[p2];
	int res = 0;
	for(int i=p2+1;i<n;i++)res=max(res,solve(i, p2));
	return d2[p2]=res;
}

int solve(int p1,int p2){
	if(p1==n-1 || p2==n-1)return abs(a[p1]-a[p2]);
	if(d[p1][p2]!=-1)return d[p1][p2];
	int res = 0;
	if(p1>p2){
		res=solve1(p1);
	}else{
		res=solve2(p2);
	}
	return d[p1][p2]=res;
}

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

	CL(d,-1);
	CL(d1,-1);
	CL(d2,-1);

	cin>>n;n+=2;
	REP(i,n)cin>>a[i];
	cout<<solve(0,1)<<endl;

	
#ifdef LocalHost
	printf("TIME: %.3lf\n",ld(clock())/CLOCKS_PER_SEC);
#endif
	return 0;
}

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

ll cnt;
ll n;
ll l;
vector<ll> win,lose;
vector<vector<ll>> h;

void dfs(){
   for(ll i=1;i<=n;i++){
       for(ll j=1;j<=n;j++){
           if(i==n&&j==n){
               for(ll k=1;k<=n;k++){
                   if(win[k]!=l||lose[k]!=l)return;
               }
               cnt++;
           }
           if(i<=j)continue;
           if(h[i][j]==0){
               h[i][j]=1;h[j][i]=-1;
               win[j]++;lose[i]++;
               if(win[j]<=l&&lose[j]<=l){
                   dfs();
               }
               win[j]--;lose[i]--;
               h[i][j]=-1;h[j][i]=1;
               win[i]++;lose[j]++;
               if(win[j]<=l&&lose[j]<=l){
                   dfs();
               }
               h[i][j]=0;h[j][i]=0;
               win[i]--;lose[j]--;
               return;
           }
       }
   }
}

int main() {
   ll m;
   while(true){
       cin>>n;
       if(n==0)return 0;
       cin>>m;
       l=(n-1)/2;
       h.assign(n+1,vector<ll>(n+1,0));
       win.assign(n+1,0);
       lose.assign(n+1,0);
       rep(i,m){
           ll p,q;
           cin>>p>>q;
           h[p][q]=-1;
           h[q][p]=1;
           lose[q]++;
           win[p]++;
       }
       cnt=0;
       dfs();
       cout<<cnt<<endl;
   }
}


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

long long int bord[502][502];
long long int ans[100000][4];

int main() {
  long long int h, w;
  cin >> h >> w;

  for (long long int k = 1; k < h+1; k++) {
    for (long long int l = 1; l < w+1; l++) {
      cin >> bord[k][l];
    }
  }

  long long int count = 0;
  for (long long int k = 1; k < h+1; k++) {
    for (long long int l = 1; l < w+1; l++) {
      if (bord[k][l] % 2 != 0) {
        if (l != w) {
          ans[count][0] = k;
          ans[count][1] = l;
          ans[count][2] = k;
          ans[count][3] = l+1;
          bord[k][l]--;
          bord[k][l+1]++;
          count++;
        }
        else {
          if (h >= 2) {
            if (k != h) {
              ans[count][0] = k;
              ans[count][1] = l;
              ans[count][2] = k+1;
              ans[count][3] = l;
              bord[k][l]--;
              bord[k+1][l]++;
              count++;
            }
            else {
              ans[count][0] = k;
              ans[count][1] = l;
              ans[count][2] = k-1;
              ans[count][3] = l;
              bord[k][l]--;
              bord[k-1][l]++;
              count++;
            }
          }
        }
      }
    }
  }

  cout << count << endl;
  for (long long int k = 0; k < count; k++) {
    for (long long int l = 0; l < 4; l++) { 
      cout << ans[k][l];
      if (l != 3) cout << ' ';
    }
    cout << endl;
  } 
  return 0;
}

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

int main() {

  int a[] = {23,1,12,1,2,1,2,1,1,2,1,2,1};
  
  int x,y;
    cin>>x>>y;
    
    if(a[x]==a[y])
    cout<<"Yes";
    
    else
    cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=500;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}int n,ans[505][505];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read();
	if(n<=MAXN){cout<<n<<'\n';Rep(i,1,n){Rep(j,1,n)cout<<i<<" ";cout<<"\n";}}
	else{
		cout<<MAXN<<"\n";
		Rep(i,0,MAXN-1)Rep(j,0,MAXN-1){
			if(i+MAXN+1>n)ans[j][(i+j)%MAXN]=i+1;
			else ans[j][(i+j)%MAXN]=(j&1)?i+MAXN+1:i+1;
		}Rep(i,0,MAXN-1){Rep(j,0,MAXN-1)cout<<ans[i][j]<<" ";cout<<"\n";}
	}
	return 0;
}




Measured memory_bytes: 4588
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
using namespace std;


int main(){

  int n, m;
  while(cin >> n >> m){
    if( n == 0 && m == 0 ) break;

    vector<int> a(n);
    vector<int> b(m);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<m; i++) cin >> b[i];

    int asum = accumulate(a.begin(), a.end(), 0);
    int bsum = accumulate(b.begin(), b.end(), 0);

    int aans = 10000;
    int bans = 10000;
    for(int i=0; i<n; i++){
      for(int j=0; j<m; j++){
        if( asum - bsum == (a[i] - b[j]) * 2 ){
          if( aans + bans > a[i] + b[j] ){
            aans = a[i];
            bans = b[j];
          }
        }
      }
    }
    if( aans == 10000 && bans == 10000 ) cout << -1 << endl;
    else cout << aans << " " << bans << endl;

  }

  return 0;
}








// EOF

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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if((x - r >= 0 && x + r <= W) && (y - r >= 0 && y + r <= H)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[1e9]*(n+k)
dp[0]=0
for i in range(n):
    for j in range(1,k+1):
        if i+j<n:
                dp[i+j]=min(dp[i+j],abs(a[i]-a[i+j])+dp[i])
print(dp[n-1])

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

int main()
{
  int n;
  int k;
  std::cin >> n >> k;

  std::vector<int> v(n);

  for (int i = 0; i < k; ++i)
  {
    int d;
    std::cin >> d;

    for (int j = 0; j < d; ++j)
    {
      int a;
      std::cin >> a;
      ++v[a - 1];
    }
  }

  int x = 0;
  for (int i = 0; i < n; ++i)
  {
    if (!v[i])
    {
      ++x;
    }
  }
  std::cout << x << std::endl;
}


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

int main() {
    int X[5] = {};
    int Y[5] = {};
    int mx = 0;int flag = 0;
    for (int i = 0;i < 5;i++){
        cin >> X[i];
        Y[i] = (10 - (X[i] % 10)) % 10;
        if (Y[i] > mx) {
            mx = Y[i];
            flag = i;
        }
    }
    int res = 0;
    for (int i = 0;i < 5;i++){
        if (i == flag) continue;
        res += X[i] + Y[i];
    }
    res += X[flag];
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
typedef pair<int,int>pii;
typedef vector<int> vi;
typedef vector<vi> vii;
const int mxN=2e5+5,M=1e9+7;
//did u check when n=1?
//is mxN correct?
int mod(int a){int ret=a%M;if(ret<0)ret+=M;return ret;}
int exp(int a,int b){
    if(b==0LL)return 1LL;
    if(b==1LL)return mod(a);
    int t=exp(a,b/2);
    if(b&1)return mod(a*mod(t*t));
    return mod(t*t);
}
int h,w,n;
int fat[mxN],inv[mxN],dp[mxN];
vector<pii> aux;
bool comp(pii a,pii b){
    return a.first+a.second<b.first+b.second;
}
int add(int a,int b){
    return (a+b)%M;
}
int mul(int a,int b){
    return (a*b)%M;
}
int sub(int a,int b){
    return (a-b+M)%M;
}
int solve(int a,int b){
    return mul(fat[a+b],mul(inv[a],inv[b]));
}
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    fat[0]=inv[0]=1;
    for(int i=1;i<mxN;i++){
        fat[i]=(fat[i-1]*i)%M;
    }
    inv[mxN-1]=exp(fat[mxN-1],M-2);
    for(int i=mxN-2;i>=1;i--)inv[i]=(inv[i+1]*(i+1))%M;
    cin>>h>>w>>n;
    for(int i=0;i<n;i++){
        int x,y;cin>>x>>y;
        aux.pb({x,y});
    }
    sort(aux.begin(),aux.end(),comp);
    aux.pb({h,w});
    for(int i=0;i<=n;i++){
        int cur=solve(aux[i].first-1,aux[i].second-1);
        for(int j=0;j<i;j++){
            if(aux[j].first<=aux[i].first && aux[j].second<=aux[i].second){
                cur=sub(cur,mul(dp[j],solve(aux[i].first-aux[j].first,aux[i].second-aux[j].second)));
            }
        }
        dp[i]=cur;
    }
    cout<<dp[n];
    
}

Measured memory_bytes: 6884
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){


    string s;
    cin >> s;
    cout << s[0] << s.length()-2 << s[s.length()-1] << endl;






    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <array>

int main()
{
	int ans = 0;

	std::array<int, 3> arr;
	int k;
	std::cin >> arr[0] >> arr[1] >> arr[2];
	std::cin >> k;

	std::sort(arr.begin(), arr.end());

	for (size_t i = 0; i < k; ++i)
	{
		arr[2] *= 2;
	}

	ans = arr[0] + arr[1] + arr[2];
	std::cout << ans << std::endl;

	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int ans;
  if(s == "SUN") ans = 7;
  else if(s == "MON") ans = 6;
  else if(s == "TUE") ans = 5;
  else if(s == "WED") ans = 4;
  else if(s == "THU") ans = 3;
  else if(s == "FRI") ans = 2;
  else ans = 1;
  cout << ans << endl;
}

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


def make_sorted_pairs(a_list, b_list):
    return list(sorted(
        tuple(sorted((a, b))) 
        for a, b in zip(a_list, b_list)
    ))


def is_in_range(bridges_range, west):
    b_west, b_east = bridges_range
    if b_east <= west:
        return False
    return True


def update_range(bridges_range, west, east):
    b_west, b_east = bridges_range
    return max(b_west, west), min(b_east, east)


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    pairs = make_sorted_pairs(a, b)
    bridges_range = (-1, -1)
    n_broken = 0
    for west, east in pairs:
        if is_in_range(bridges_range, west):
            bridges_range = update_range(bridges_range, west, east)
            continue
        bridges_range = west, east
        n_broken += 1
    print(n_broken)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
#define pb push_back

/*int pare(int en,int start,int par[])
{
	if(par[en]==start)
	{
		return en;
	}
	pare(par[en],start,par);
}*/


int main()
{
    int t=1;
	//scanf("%d",&t);
    while(t--)
    {
		string s;
		cin >> s;
		ll sz=s.size(),i;
		for(i=0;i<sz;i++)
		{
			if(s[i]=='?')
			{
				s[i]='D';
			}
		}
		cout << s << endl;
    }
    return 0;
}


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

using namespace std;

int main(void){
  long long A, B, K;
  cin >> A >> B >> K;
  for(int i = 0; i < K; i++){
    if(i % 2 == 0){
      A /= 2;
      B += A;
    }else{
      B /= 2;
      A += B;
    }
  }
  cout << A << " " << B << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

s = str(input().rstrip())
ans = deque(list(s))

f = True
q = int(input())
for i in range(q):
    q = list(map(str, input().split()))
    if int(q[0]) == 1:
        if f:
            f = False
        else:
            f = True
    else:
        f_i = int(q[1])
        if f_i == 1:
            if f:
                ans.appendleft(q[2])
            else:
                ans.append(q[2])
        else:
            if f:
                ans.append(q[2])
            else:
                ans.appendleft(q[2])
ans = list(ans)
if f:
    print("".join(ans))
else:
    print("".join(ans[::-1]))

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

int32_t main(){
    string s;
    int k;
    cin>>k;
    cin>>s;
    if(k>=s.size()){
        cout<<s<<endl;
    }
    else{
        for(int i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int H, W;
    cin >> H >> W;
    char c;
    int ans=0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> c;
            if (c == '#') {
                ans++;
            }
        }
    }

    if (ans == H+W-1) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 2e18;
const ll fact_table = 1200008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
const ll mod = 998244353ll;
// const ll mod = 1000000007ll;
  
ll mypow(ll number1,ll number2, ll mod){
    if(number2 == 0){
        return 1ll;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n,m,num,a,b,c,d,e,h,q;
ll w, k;
ll x[50005];

void solve(){
    string s;
    cin >> s;
    ll cnt = 1, sum = 0;
    n = s.size();
    ll ans = 0;
    x[0]++;
    for(ll i=n-1;i>=0;i--){
        sum += cnt * (s[i] - '0');
        sum %= 2019;
        cnt *= 10;
        cnt %= 2019;
        ans += x[sum];
        x[sum] ++;
    }

    
    p(ans);
    return;
}


int main(){
    // init();
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if(multicase){
        cin >> q;
    }else{
        q = 1; 
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    
    // solve();
    return 0;
}
















Measured memory_bytes: 3768
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int N;
int a[100];
int b, c, d;
int main()
{
	cin >> N;
	for(int i=0; i<N; i++)
	{
		cin >> a[i];
	}
	d=0;
	for(int k=0; k<N-1; k++)
	{
		b=k;
		for(int i=k; i<N; i++)
		{
			if(a[i]<a[b])
			{
				b=i;
			}
		}
		if(k!=b)
		{
			c=a[b];
			a[b]=a[k];
			a[k]=c;
			d+=1;
		}
	}
	cout << a[0];
	for(int i=1; i<N; i++)
	{
		cout << " " << a[i];
	}
	cout << endl << d << endl;
	return 0;
}

Measured memory_bytes: 1160
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    sort(a+1, a+n+1);
    ll res = a[n];
    int vt = n-1, cnt = 0;
    FOR(i,1,n-2) {
        res += a[vt];
        cnt++;
        if (cnt == 2) {
            vt--;
            cnt = 0;
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 4424
#include <stdio.h>
#include <string.h>

int main(void) {
	int x;
	char s[101];
	
	scanf("%d", &x);
	memset(s, 0, sizeof(s));
	
	if(x >= 0 && x < 1200){
		strcat(s, "ABC");
	}else if(x >= 1200){
		strcat(s, "ARC");
	}
	
	printf("%s\n", s);
	
	return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
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; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	rep(i, s.size()) {
		if (s[i] == ',') cout << " ";
		else cout << s[i];
	}
	cout << endl;
}


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

void solve()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (c >= a && c <= b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main()
{
    solve();
    return 0;
}

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

const int N = 123;
const int INF = 2e9;
const int mod = 1e9+7;

int ans, n, m, k;
int a[N];

int main() {
  scanf("%d", &n);
  ans = 24+(24-n);
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 256