akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

#define for(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((int)(x).size())
#define inf          1<<25

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; }

//typedef vector<int> vi;
//typedef vector<long long> vl;
//typedef vector<double> vd;
//typedef pair<int,int> pii;
//typedef pair<long,long> pll;
//typedef long long ll;

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

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    
    x -= a;
    x -= (x / b) * b;
    cout << x << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstring>

int abs (int n) {
    return n >= 0 ? n : -n;
}

const int maxn = 100005;

int main() {
    // freopen("data.in", "r", stdin);
    // freopen("data.out", "w", stdout);
    char str[maxn];
    scanf("%s", str);
    int len = strlen(str);
    int cnt = 0;
    for (int i = 0; i < len; ++i) {
        if (str[i] == '0') {
            cnt--;
        } else {
            cnt++;
        }
    }
    cnt = abs(cnt);
    // printf("%d, %d\n", cnt, len);
    printf("%d\n", len - cnt);
    return 0;
}


Measured memory_bytes: 256
using System;

namespace CA {
	class Prg {
		static void Main() {
			string[] str = new string[2];
			while(true){
				str = Console.ReadLine().Split(' ');
				if (int.Parse(str[0]) < int.Parse(str[1])) Console.WriteLine(str[0] + " " + str[1]);
				else if (str[0] == "0" && str[1] == "0") break;
				else Console.WriteLine(str[1] + " " + str[0]);
			}
		}
	}
}

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

int main(){
    string S;
    cin>>S;
    char ans = '*';
    map<char,int> mp;
    for(int i=0;i<26;++i) mp['a'+i]++;
    for(int i=0;i<S.size();++i) mp[S[i]]++;
    for(auto itr=mp.rbegin(); itr != mp.rend();++itr){
        if(itr->second < 2) ans = itr->first;
    }
    if(ans!='*') cout<<ans<<endl;
    else cout<<"None\n";
}

Measured memory_bytes: 512
#include <iostream>
#include <random>
#include <fstream> //iostreamのファイル入出力をサポート
#include <vector>
#include <algorithm>
#include <string>
#include <math.h> 
#include <time.h>
#define FOR(i,k,n) for((i)=(k);(i)<(n);(i)++)
#define rep(i,n) for (int i=0;i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define pb push_back
#define all(a) (a).begin(),(a).end()  //greater<int>()
#define ll long long
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define vs vector<string>
#define VI vector<int>
#define vi vector<int>
#define vll vector<long long>
using namespace std;

int main(){
	int N,i,a,num;
	ll ans=1000000000000000000LL;
	cin>>N;

	vll A,B,C;
	
	rep(i,N){
		cin>>a;
		A.pb(a);
	}

	B.pb(A[0]);
	FOR(i,1,N){
		B.pb(A[i]+B[i-1]);
	}

	rep(i,N-1){
		C.pb(abs(B[N-1]-2*B[i]));
		ans=min(ans,C[i]);
	}

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


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int q;
    cin >> q;
    while (q--) {
        ll a, b;
        cin >> a >> b;
        ll rt = sqrt((long double)(a * b));
        rt = max(1LL, rt - 2);
        ll z = a * b - 1;
        while (z / rt != z / (rt + 1)) {
            ++rt;
        }
        int kek = 1;
        if (a == b) {
            --kek;
        }
        cout << z / rt - 1 + rt - kek << '\n';
    }
    return 0;
}

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

const int N = 4005;

int a, b, n;
bool chk[N], rem[N];
vector<int> adj[N];
vector<int> ve;

int ask(int u, int v) {
    cout << "? " << u << " " << v << endl;
    char c; cin >> c;
    return c == 'Y';
}

void DFS(int u) {
    for (int &v : adj[u]) {
        chk[v] = chk[u];
        DFS(v);
    }
}

int solve(vector<int> ve) {
    if (ve.size() == 1) {
        rem[ve.back()] = true;
        return ve.back();
    }
    int odd = -1;
    if (ve.size() & 1) {
        odd = ve.back();
        ve.pop_back();
    }
    vector<int> nxt;
    for (int i = 0; i < ve.size(); i += 2) {
        int u = ve[i], v = ve[i + 1];
        if (ask(u, v) && ask(v, u)) {
            rem[v] = true;
            adj[u].push_back(v);
            nxt.push_back(u);
        }
    }
    if (!(nxt.size() & 1) && odd != -1) {
        nxt.push_back(odd);
    }
    return solve(nxt);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> a >> b;
    if (b >= a) {
        return cout << "Impossible", 0;
    }
    n = a + b;
    for (int i = 0; i < n; i++) {
        ve.push_back(i);
    }
    int rt = solve(ve);
    chk[rt] = true; DFS(rt);
    for (int i = 0; i < n; i++) {
        if (!rem[i]) {
            chk[i] = ask(rt, i);
            DFS(i);
        }
    }
    cout << "! ";
    for (int i = 0; i < n; i++) {
        cout << chk[i];
    }
    cout << endl;
}


Measured memory_bytes: 980
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

char S[101] = {0};
char s[101] = {0};

int main()
{
	int K = 0, len = 0;
	scanf("%d", &K);
	scanf("%s", S);
	len = strlen(S);
	if (len <= K) {
		printf("%s\n",S);
	} else {
		strncpy(s, S, K);
		printf("%s...\n",s);
	}

	//yesno(ans);
	//okng(ans);
	return 0;
}


Measured memory_bytes: 1728
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;
	REP(i,N){
		string s;
		cin >> s;
		if(s[0] == 'Y'){
			cout << "Four" << endl;
			return 0;
		}
	}

	
	cout << "Three" << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;

int n;
vector<int> e[150000];
vector<double> val[150000];
double ans[150000];

double dfs(int x, int y){
    if(val[x][y] > -0.5) return val[x][y];
    int to = e[x][y];
    if(e[to].size() == 1){
        ans[x] += 1.0;
        return val[x][y] = 1.0;
    }
    double ret = 0.0;
    rep(i,e[to].size()){
        if(e[to][i] == x) continue;
        ret += dfs(to, i)+1.0;
    }
    ret /= (double)(e[to].size()-1);
    ans[x] += ret;
    return val[x][y] = ret;
}

void dfs2(int v, int p, double value){
    if(v != 0){
        if(e[p].size() == 1) ans[v] += 1.0;
        else ans[v] += 1.0 + (ans[p]-value)/(double)(e[p].size()-1);
    }
    rep(i,e[v].size()){
        if(e[v][i] == p) continue;
        dfs2(e[v][i], v, val[v][i]);
    }
}

int main(){
    I(n);
    rep(i,n-1){
        int u,v; I(u,v);
        u--; v--;
        e[u].push_back(v);
        val[u].push_back(-1.0);
        e[v].push_back(u);
        val[v].push_back(-1.0);
    }
    rep(i,e[0].size()){
        dfs(0,i);
    }
    dfs2(0, 0, 0.0);
    rep(i,n){
        printf("%.9f\n",ans[i]/(double)e[i].size());
    }
}
































Measured memory_bytes: 29824
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))

s = []
for i in range(N):
  if N == i + 1:
    s.append(A[0] + abs(K - A[i]))
  else:
    s.append(abs(A[i+1] - A[i]))

total = 0
srtd = sorted(s)
for i in range(len(srtd) - 1):
  total += srtd[i]

print(total)

Measured memory_bytes: 26444
#include<bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define CS
using namespace std;
int main(){
   speed;
   double  n;
   cin >> n;
   double sm=0;
   vector<int>vc(n);
   for (int i = 0 ;i < n;i++){
        cin >> vc[i];
        double a = 1;
        a /= vc[i];
        sm += a;
    }
    double b = 1;
    b /= sm;
    cout << b;

}






Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
fact=[1,1,2,6,24,120,720,5040]
ans=0
for i in range(n-1):
    p0,q0=sorted(p[i:]),sorted(q[i:])
    ans+=(p0.index(p[i])-q0.index(q[i]))*fact[n-i-1]
print(abs(ans))

Measured memory_bytes: 3064
n = gets.to_i
cities = Array.new(n){gets.split.map(&:to_i)}
routes = cities.permutation.to_a
sum = 0
routes.each do |r|
  (r.size-1).times do |i|
    a = r[i]
    b = r[i+1]
    sum += Math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
  end
end
p sum / routes.size


Measured memory_bytes: 20084
#include<iostream>
#include<vector>
#include<algorithm>
using ll = long long;
using namespace std;
ll gcd(ll a,ll b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
int main(){
    ll x,n,y=1;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x;
        y = lcm(x,y);
    }
    cout << y << endl;
    return 0;
}

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

struct edge {
  int fr, to, cost;
  edge(int in_f=0, int in_t=0, int in_c=0):
    fr(in_f), to(in_t), cost(in_c) {}
  friend std::ostream& operator << (std::ostream& o, edge const& e) {
    o << e.fr << " " << e.to << " " << e.cost;
    return o;
  }
};

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int L; std::cin >> L;
  if(L == 2) {
    std::cout <<"2 2\n1 2 0\n1 2 1\n";
    return 0;
  }
  std::vector<edge> ans;
  ans.reserve(60);
  int k = 1, m = 0;
  while(k*3 <= L) { k *= 3; ++m; }
  for(int i = 0, l=1; i < m; ++i) {
    ans.emplace_back(i+1, i+2, 0);
    ans.emplace_back(i+1, i+2, l);
    ans.emplace_back(i+1, i+2, l*2);
    l *= 3;
  }
  if(L >= k*2) {
    ans.emplace_back(m+1, m+2, 0);
    ans.emplace_back(m+1, m+2, k);
    k += k;
    ++m;
  }

  while(L > k) {
    int r = L-k;
    int t = 3, l = 1;
    while(r%t == 0) { t*= 3; ++l; }
    r %= t; t/=3;
    ans.emplace_back(l, m+1, k);
    k += t;
    if(r <= t) continue;
    ans.emplace_back(l, m+1, k);
    k += t;
  }
  std::cout << (m+1) << " " << ans.size() << "\n";
  for(auto const& e: ans) std::cout << e << "\n";
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps=1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.answer"

int main() {
	
	ld N;
	vector<ld>nums;
	while (cin>>N) {
		nums.emplace_back(N);
	}
	cout <<setprecision(22)<<fixed<< *max_element(nums.begin(), nums.end()) - *min_element(nums.begin(), nums.end()) << endl;
	return 0;
}

Measured memory_bytes: 3184
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#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>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;

struct edge{int to,cost;};
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号

int main(){
	int n,p;
	int cnt[50];
	
	while(cin>>n>>p){
		if(n==0&&p==0)break;
		CLR(cnt);
		int wan=p;
		int num=0;
		while(1){
			
			if(wan!=0){
				cnt[num]++;
				wan--;
			}else{
				wan=cnt[num];
				cnt[num]=0;
			}
			//cout<<"!"<<num<<" "<<cnt[num]<<endl;
			if(cnt[num]==p)break;
			num++;
			num%=n;
			
		}
		cout<<num<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readc(n, m, x);
	int a[n + 1][m + 1], c[n + 1];
	FOR (i, 1, n)
	{
	    cin >> c[i];
	    FOR (j, 1, m) cin >> a[i][j];
	}
	
	int mn = inf;
	
	FOR (i, 0, (1LL << n) - 1)
	{
	    int sk[m + 1] = {}, money = 0;
	    FOR (j, 0, n - 1)
	    {
	        if ((i >> j) & 1)
	        {
	            money += c[j + 1];
	            FOR (k, 1, m) sk[k] += a[j + 1][k];
	        }
	    }
	    
	    bool ch = 1;
	    FOR (k, 1, m) if (sk[k] < x) ch = 0;
	    
	    if (ch) mn = min(mn, money);
	}
	
	if (mn < inf) cout << mn;
	else cout << -1;
}



















Measured memory_bytes: 3652
#include <iostream>
#include <queue>
#include <string>
#include <cstdlib>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    const int MAX = 100000;
    int n, q, time=0;
    cin >> n >> q;
    pair<string, int> S[MAX], A[MAX];
    queue<int> q_num;
    queue<string> q_str;

    for(int i=0; i<n; i++){
            cin >> S[i].first >> S[i].second;
            q_str.push(S[i].first);
            q_num.push(S[i].second);
    }

    while(! q_str.empty()){
        int a = q_num.front();
        string s = q_str.front();
        q_num.pop();
        q_str.pop();
        if(a <= q){
            time = time + a;
            cout << s << " " << time << endl;
        }
        else{
            time = time + q;
            q_num.push(a - q);
            q_str.push(s);
        }
    }
   return 0;
}

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

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

int t;
cin>>t;
set<string>S;
while(t--){
	
string s;
cin>>s;
S.insert(s);




}

cout<<S.size();




}




Measured memory_bytes: 19212
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int n; cin >> n;
    std::vector<int> v(n);
    rep(i,n) cin >> v[i];

    sort(v.begin(), v.end());
        
    double x = v[0]+0.0;
    rep(i,n-1){
        x = (x+v[i+1])/2.0;
    }

    cout << x << endl;

    

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string o, e;
	cin >> o >> e;
	rep(i,o.size()+e.size()){
		if(i%2 == 0) cout << o[i/2];
		else cout << e[i/2];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3588
n = int(input())
p = list(map(int,input().split()))

cnt = 0
for i in range(1,n-1):
    if p[i-1] > p[i] and p[i] > p[i+1]:
        cnt += 1
    if p[i-1] < p[i] and p[i] < p[i+1]:
        cnt += 1
print(cnt)

Measured memory_bytes: 9068
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read


s = input()

MOD = 2019
d = [0]*MOD
d[0] = 1
r = 0
t = 1
for i in reversed(s):
    r += int(i)*t
    r %= MOD
    t *= 10
    t %= MOD
    d[r] += 1
    
print(sum(i*(i-1)//2 for i in d))

    





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

int main() {
    
    int min,count;
    string A,B;
    cin >> A >> B;
    min=B.size();
    for(size_t t = 0; t <= A.size()-B.size(); t++) 
    { 
        count = 0;
        for (size_t i = 0; i < B.size(); i++) {
            if(A[t+i]!=B[i])
                count++;
            if(count>=min)
                break;
        }
        if(min>count)
            min=count;
    }

    cout<<min;
    
    return 0;
}

Measured memory_bytes: 3580
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
x=0
dp=[0]*40
for i in a:
    for j in range(40):
        if i&(1<<j):
            dp[j]+=1

for i in range(39,-1,-1):
    if x+ (1<<i) >k:
        continue
    if dp[i]<(n+1)//2:
        x+=(1<<i)





for  i in a:
    ans+=x^i
print(ans)

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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	ll n, m;
	ll k;
	ll h, w;
	//ll x;
	//ll a;
	string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;
	
	cin >> n;
	V a(n);
	rep(i, n) {
		cin >> a[i];
	}

	deque<ll> b;
	rep(i, n) {
		if (i % 2 == 0) {
			b.push_back(a[i]);
		}
		else {
			b.push_front(a[i]);
		}
	}

	if (n % 2 == 1) {
		rep(i, n) {
			cout << b[n-1-i] << " ";
		}
	}
	else {
		rep(i, n) {
			cout << b[i] << " ";
		}
	}

	cout << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(15);

	solve_abc_c();

	return 0;
}


Measured memory_bytes: 6312
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int MAX = 305;
const int NIL = -1;
const ll LINF = 1LL << 50;
const int mod = 1e+9 + 7;
/* global variables */
/* funciton */
/* main */
int main() {
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    vector<vector<ll>> dp(N+1, vector<ll>(K+1));
    vector<ll> cum(K+2);
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        cum[0] = 0;
        for (int j = 0; j <= K; j++) cum[j+1] = cum[j] + dp[i-1][j];
        for (int j = 0; j <= K; j++) {
            ll sum = (cum[j+1] - cum[max(0, j-a[i-1])] + mod) % mod;
            dp[i][j] = max(dp[i][j], sum);
        }
    }
    cout << dp[N][K] << '\n';
}

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

using namespace std;

const int maxn = 2e5 + 5;

int n, a[maxn], b;
ll ans;

int main()
{
	scanf("%d", &n);
	for (R int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[i] -= i;
	sort(a + 1, a + 1 + n);
	b = a[n / 2 + 1];
	for (R int i = 1; i <= n; ++i)
		ans += abs(a[i] - b);
	printf("%lld\n", ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

int main() {
    int a,b,c;
    cin>>a>>b>>c;

    cout<<c<<" "<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll N; cin >> N;
  cout << N/3 << endl;
  return 0;
}


Measured memory_bytes: 256
N=int(raw_input())
ary = map(int, raw_input().split())
c_num = 0

for i in range(N):
    if ary[i] != (i+1):
        c_num += 1

if (c_num == 0) or (c_num == 2):
    print 'YES'
else:
    print 'NO'


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb push_back
#define ll long long
#define fi first
#define se second
#define ii  pair<int, int>
#define vi  vector <int>
#define vii vector <pair <int, int > >
#define all(cont)  cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")


int main(){

   // freopen("input.txt","r",stdin);
    IOS;
    clock_t clk = clock();

    int a; cin >> a;
    forn1(i, 9) {
        if(a % i == 0) {
            int x2 =  a / i;
            if(x2 < 10) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout <<"No" << endl;
    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
}


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

int main()
{
  int ans = 0;
  string N;
  cin >> N;
  bool flag = false;
  int sum = 0;
  for (int i = 0; i < N.length() - 1; i++)
  {
    if (N[i] == 'h' && N[i + 1] == 'i')
    {
      flag = true;
      sum++;
    }
    else
    {
      flag = false;
    }
  }
  //cout << N.length() << endl;
  if (flag && sum == N.length() / 2 && N.length() >= 2 && N.length() % 2 == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='o'){
      ans++;  
    }
  }
  int kai=15-s.size();
  if(ans+kai>=8){
    cout<<"YES"<<endl;  
  }
  else{
    cout<<"NO"<<endl;  
  }
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
typedef long long ll;

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

ll n, p[100], q[100], r[100], b[100], used[100];

ll search(ll i) {
  ll right = 1, left = 1;
  if (r[i] != 0) right = search(r[i]-1);
  if (b[i] != 0) left = search(b[i]-1);
  ll g = gcd(p[i], q[i]);
  ll rt = q[i] / g;
  ll lt = p[i] / g;
  ll r2 = (right / gcd(right, rt));
  ll l2 = (left / gcd(left, lt));
  ll g2 = (r2 / gcd(r2, l2)) * l2;
  return rt * g2 + lt * g2;
}

int main() {
  while (scanf("%lld", &n), n) {
    for (ll i = 0; i < n; i++) used[i] = 0;
    for (ll i = 0; i < n; i++) {
      scanf("%lld%lld%lld%lld", &p[i], &q[i], &r[i], &b[i]);
      if (r[i] != 0) used[r[i]-1] = 1;
      if (b[i] != 0) used[b[i]-1] = 1;
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) if (used[i] == 0) ans = i;
    printf("%lld\n", search(ans));
  }
}



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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < n; i++)
#define REP(n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using INT64 = long long;
using UINT64 = unsigned long long;
constexpr int MOD = 1000000007;

int mod(int x) {
    return x % MOD;
}
int modm(int x,int m) {
    int z = 0;
    REP(m) z = mod(z + x);
    return z;
}

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

    int l = s.size();

    vector<int> dp1(l,0);
    vector<int> dp2(l,0);

    REP(l){
        if (i == 0) {
            dp1[0] = 1;
            dp2[0] = 2;
        } else {
            if (s[i] == '1') {
                dp1[i] = mod(modm(dp1[i-1],3) + dp2[i-1]);
                dp2[i] = mod(modm(dp2[i-1],2));
            } else {
                dp1[i] = mod(modm(dp1[i-1],3));
                dp2[i] = dp2[i-1];
            }
        }
    }

    cout << mod(dp1[l-1] + dp2[l-1])<< endl;


    return 0;
}


Measured memory_bytes: 1232
/* - - - - - - - - - - - - - - -
	User : 		VanishD
	problem :	[abc101D]
	Points : 	
- - - - - - - - - - - - - - - */
# include <bits/stdc++.h>
# define 	ll 		long long
using namespace std;
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
int read(){
	int tmp = 0, fh = 1; char ch = getchar();
	while (ch < '0' || ch > '9'){ if (ch == '-') fh = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9'){ tmp = tmp * 10 + ch - '0'; ch = getchar(); }
	return tmp * fh;
}
ll ow10[20], sum[20];
int n;
struct Num{
	ll num;
};
bool operator < (Num x, Num y){
	ll tmpx = x.num, tmpy = y.num, numx = 0, numy = 0;
	while (tmpx > 0){
		numx += tmpx % 10;
		tmpx /= 10;
	}
	while (tmpy > 0){
		numy += tmpy % 10;
		tmpy /= 10;
	}
	ll deata = x.num * numy - y.num * numx;
	return deata > 0 || (deata == 0 && x.num > y.num); 
}
priority_queue <Num> hp;
int main(){
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read();
	for (int i = 1; i <= 9; i++) hp.push((Num){i});
	ow10[0] = 1;
	for (int i = 1; i <= 18; i++) ow10[i] = ow10[i - 1] * 10;
	ll now = 0;
//	printf("%d\n", (Num){11}<(Num){19});
	while (n){
		ll tmp = hp.top().num;
		hp.pop();
		if (tmp <= now) continue;
		printf("%lld\n", tmp); n--;
		now = tmp;
		int len = 0;
		while (tmp > 0){
			sum[++len] = tmp % 10;
			tmp /= 10;
		}
	//	sum[len + 1] = 0;
		for (int i = 1; i <= 15; i++)
			if (sum[i] != 9){
				sum[i]++;
				ll nex = 0;
				for (int j = 1; j <= len; j++) nex = nex + sum[j] * ow10[j - 1];
				if (i > len) nex = nex + ow10[i - 1];
				hp.push((Num){nex});
				sum[i]--;
			}
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
#include<algorithm>
int main(void)
{
	int n,a,b,c,v,i,va,vb,vc;
	int costA[30], costB[30], costC[30];
	for(i=0;i*200<=5000;++i)
		costA[i] = i%5*380 + i/5*1520;
	for(i=0;i*300<=5000;++i)
		costB[i] = i%4*550 + i/4*1870;
	for(i=0;i*500<=5000;++i)
		costC[i] = i%3*850 + i/3*2244;
	while(scanf("%d",&n),n)
	{
		v=INT_MAX;
		for(a=0;(va=a*200)<=n;++a)
		{
			for(b=0;va+(vb=b*300) <= n; ++b)
			{
				for(c=0; va+vb+(vc=c*500) <= n; ++c)
				{
					if(va+vb+vc==n)
						v = std::min(v, costA[a] + costB[b] + costC[c]);
				}
			}
		}
		printf("%d\n", v);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll A,B,K;
  cin >> A >> B >> K;
  if(A + B <= K){
    cout << "0 0" << endl;
  }
  else if(A < K){
    cout << 0 << ' ' << B - K + A << endl;
  }
  else{
    cout << A - K << ' ' << B << endl;
  }
}

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

using ll = long long;

int main() {
  ll X, K, D;
  cin >> X >> K >> D;
  X = abs(X);

  ll straight = min(K, X / D);
  K -= straight;
  X -= straight * D;

  if (K % 2 == 0) {
    cout << X << endl;
  } else {
    cout << D - X << endl;
  }

  return 0;
}


Measured memory_bytes: 3572
#if 0

#endif
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <queue>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
using ll = long long;
ll ll_max = numeric_limits<ll>::max();
ll ll_min = numeric_limits<ll>::min();
int int_max = numeric_limits<int>::max();
int int_min = numeric_limits<int>::min();
double vertices[20][2];
string xy;
double x, y;
typedef complex<double> xy_t;
double cross_product(xy_t a, xy_t b) { 
    return (conj(a) * b).imag(); 
}
double distance(double a[], double b[]) {
    return sqrt(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2));
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    double sum = 0;
    int cnt = 0;
    while (cin >> xy) {
        stringstream ss(xy);
        ss >> x;
        ss.ignore();
        ss >> y;

        vertices[cnt][0] = x;
        vertices[cnt][1] = y;
        if (cnt > 1) {
            xy_t o(vertices[0][0], vertices[0][1]);
            xy_t vect1(vertices[cnt - 1][0], vertices[cnt - 1][1]);
            xy_t vect2(x, y);
            vect1 = vect1 - o;
            vect2 = vect2 - o;
            sum += cross_product(vect1, vect2) / 2;
        }
        ++cnt;
    }

    cout << fabs(sum) << endl;

    return 0;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;
const int mod = 1000000007;

vector<int> f;
void g(int n) {
  f.resize(n+1);
  f = {0};
  for(int i = 1; i<=n ;i++){
    for(int j = i; j<=n; j += i){
      f[j]++;
    }
  }
  return;
}


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

  g(n);
  ll ans = 0;
  for(ll i = 1; i <=n; i++){
    ans += i*f[i];
  }
  cout << ans << endl;
}


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

using namespace std;
using uint = unsigned int;
using int64 = long long;
using uint64 = unsigned long long;
using vint = vector<int>;
using vint64 = vector<int64>;
#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rep1(i,N) for(int i=1;i<=(int)(N);++i)
#define fs first
#define sc second
#define eb emplace_back
#define all(x) x.begin(),x.end()

template<typename T>
vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}

template<class T, class U> ostream& operator<<(ostream& os, const vector<pair<T, U>> p) {
	os << "P(" << p.first << ", " << p.second << endl;
}

/*
template<class T, class U> ostream& operator<<(ostream& os, const map<T, U>& mp) {
	os << "{";
	for (auto& e : mp) os << P << " ";
	return os << "}";
}
*/

void Main();
signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
}

/* Insert from here! */
/* Cut from here! */

void Main() {
	vector<int> ans(7);
	rep(i, 7) {
		int a, b; cin >> a >> b;
		ans[i] = a - b;
	}
	rep(i, 7) {
		cout << ans[i]<<endl;
	}
}


Measured memory_bytes: 3220
#include <stdio.h>
#include <inttypes.h>

#define SATI UINT64_C(1111111111111111111)

uint64_t add(uint64_t a, uint64_t b) {
	uint64_t r = a + b;
	return r > SATI ? SATI : r;
}

int main(void) {
	uint64_t N, K;
	uint64_t ok, ng;
	if (scanf("%" SCNu64 "%" SCNu64, &N, &K) != 2) return 1;
	ok = 0;
	ng = K + 1;
	while (ok + 1 < ng) {
		uint64_t mid = ok + (ng - ok) / 2;
		uint64_t required = 0;
		uint64_t current = mid;
		uint64_t i;
		for (i = 0; i < N && current > 0; i++, current >>= 1) {
			required = add(required, current);
		}
		if (required <= K) ok = mid; else ng = mid;
	}
	printf("%" PRIu64 "\n", ok);
	return 0;
}



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

#define HEAP_MAX  2000000

#define left(x)   (2*x+1)
#define right(x)  (2*x+2)
#define parent(x) ((x-1)/2)

typedef struct _priorityQueue
{
  int heap_size;
  int queue[HEAP_MAX];
} priorityQueue;

void swap(int *a, int *b)
{
  int temp = *a;
  *a = *b;
  *b = temp;
}

void initPriorityQueue(priorityQueue *pq)
{
  pq->heap_size = 0;
}

int insert(priorityQueue *pq, int key)
{
  int i = pq->heap_size;

  if (pq->heap_size == HEAP_MAX) {
    printf("heap full.\n");
    exit(-1);
  }

  pq->queue[(pq->heap_size)++] = key;
  
  //   j      j
  //  /   or   \
  // i          i
  // gurantees that i <= j.
  while (i > 0 && pq->queue[i] > pq->queue[parent(i)]) {
    swap(&pq->queue[i], &pq->queue[parent(i)]);
    i = parent(i);
  }

  return 0;
}

void printPriorityQueue(priorityQueue *pq)
{
  int i;
  printf("%d\n", pq->heap_size);
  for (i=0; i<pq->heap_size; i++)
    printf("%d\n", pq->queue[i]);
}

// maxHeapify gurantees that heap structure is stil valid.
//     i
//    / \
//   l   r
// i >= l && i >= r.
void maxHeapify(priorityQueue *pq, int i, int l, int r)
{
  int max, maxi;

  //  This is when i is a leaf.
  if (r > pq->heap_size)
    return;

  // swap i and the larger of l or r, then call maxHeapify recursively.
  if (pq->queue[i] < pq->queue[l] && pq->queue[i] < pq->queue[r]) {
    max = (pq->queue[l] > pq->queue[r] ? pq->queue[l] : pq->queue[r]);
    maxi = (max == pq->queue[l] ? l : r);
    swap(&pq->queue[i], &pq->queue[maxi]);
    maxHeapify(pq, maxi, left(maxi), right(maxi));
  } else if (pq->queue[i] < pq->queue[l]) {
    swap(&pq->queue[i], &pq->queue[l]);
    maxHeapify(pq, l, left(l), right(l));
  } else if (pq->queue[i] < pq->queue[r]) {
    swap(&pq->queue[i], &pq->queue[r]);
    maxHeapify(pq, r, left(r), right(r));
  }
}

int extractMax(priorityQueue *pq)
{
  int max;

  if (pq->heap_size < 1) {
    perror("heap is empty.");
    return -1;
  }

  max = pq->queue[0];
  pq->queue[0] = pq->queue[--(pq->heap_size)];

  // call maxHeapify from the root.
  maxHeapify(pq, 0, 1, 2);

  return max;
}

int main(int argc, char const *argv[])
{
  char input[10];
  int n;
  priorityQueue pq;
  initPriorityQueue(&pq);
  
  while (1) {
    scanf("%s", input);
    if (!strcmp(input, "insert")) {
      scanf("%d", &n);
      insert(&pq, n);
    } else if (!strcmp(input, "extract")) {           
      n = extractMax(&pq);
      printf("%d\n", n);
    } else {
      break;
    }  
  }

//  printPriorityQueue(&pq);
  return 0;
}

Measured memory_bytes: 4968
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> t(n), x(n), y(n);

    for (int i = 0; i < n; i++)
    {
        cin >> t[i] >> x[i] >> y[i];
    }
    
    int ntime = 0, nx = 0, ny = 0;
    string ans = "Yes";
    for (int i = 0; i < n; i++)
    {
        int time = t[i] - ntime;
        int distance = abs(x[i] - nx) + abs(y[i] - ny);
        if(time < distance)
        {
            ans = "No";
        }
        else
        {
            if((time - distance) % 2 != 0)ans = "No";
        }
        ntime = t[i];
        nx = x[i];
        ny = y[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    string s;
    cin>>s;
    ll ss =s.size();
    vector<int> a(ss);
    ll sum=0;
    rep(i,ss){
        a[i]=s.at(i) - '0';
    }
    rep(i,pow(2,ss-1)){
        sum += a[ss-1];
        ll dig=0;
        rep(j,ss-1){
            if(i&(1<<j)){
                dig = 0;
                sum += a[ss-2-j];
            }else{
                dig++;
                sum += a[ss-2-j]*pow(10,dig);
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back


int main()
{
  long long n,k;
  cin>>n>>k;
  vector<long long> a(n+1);
  for(long long i=1;i<=n;i++){
    cin>>a[i];
  }
  vector<long long> next(n+1,-1);
  long long cur = 1;
  vector<long long> steps;
  while(next[cur] == -1){
    steps.pb(cur);
    next[cur] =  a[cur];
    cur = next[cur];
  }
  //now cur contains starting polong long of the loop
  //finding cycle length
  long long cycle = cur; //starting polong long
  long long length = 1;
  cur = next[cur];
  while(cycle != cur){
    cur = next[cur];
    length++;
  }
  long long done  = steps.size() - length; // length of path before cycle starts
  if( k <= done){
    cout<<steps[k];
  }
  else{

    long long rem = (k - done) % length;
    long long cur  = cycle;
    while(rem -- ){
      cur = next[cur];
    }
    cout<<cur<<endl;
  }
}


Measured memory_bytes: 8424
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int ans=0;
    string a;
    cin>>a;
    if(a[0]=='1')ans++;
    if(a[1]=='1')ans++;
    if(a[2]=='1')ans++;
    printf("%d\n",ans);
    return 0;
}

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

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

    map<char,int> cnt;

    for(int i=0; i<s.size(); i++){
        cnt[s[i]]++;
    }

    bool flag = true;

    for(auto a : cnt){
        if(a.second % 2 != 0) flag = false;
    }

    cout<<(flag ? "Yes" : "No")<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll N, M, ac=0, penalty=0; cin >> N >> M;
    vector<bool> A(N, false);
    vector<ll> B(N, 0);
    ll p; string S;
    for (int i=0; i<M; ++i){
        cin >> p >> S; p--;
        if (S=="WA") B[p]++;
        else {
            if (A[p]) continue;
            ac++;
            penalty += B[p];
            A[p] = true;
        }
    }
    cout << ac << " " << penalty << endl;
    return 0;
}

Measured memory_bytes: 4032
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){

  int a, b, c, x, y;

  cin >> a >> b >> c >> x >> y;
  int sum;


  int min1 = a * x + b * y;
  if (x > y){
    min1 = min(min1, y * c * 2+ (x - y) * a);
  }else{
    min1 = min(min1, x * c * 2 + (y - x) * b);
  }
  min1 = min(min1, max(x, y) * c * 2);

  cout << min1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string s; cin >> s;
  int n = (int)(s.size());
  int pos = 0;
  for(int i=0;i<n;++i) {
    if(s[i] == '*') {
      pos = i;
      break;
    }
  }
  stack<char> st;
  for(int i=pos+1;i<n;++i) {
    if(st.empty()) {
      st.push(s[i]);
    } else if(st.top() == '(') {
      if(s[i] == '(') st.push(s[i]);
      else st.pop();
    } else {
      st.push(s[i]);
    }
  }
  cout << (int)(st.size()) << endl;
}



Measured memory_bytes: 3236
import math

N = int(input())

min_f = len(str(N))
for a in range(1, int(math.sqrt(N)) + 1):
  if N % a != 0:
    continue
  b = int(N / a)
  f = max(len(str(a)), len(str(b)))
  if min_f > f:
    min_f = f

print(min_f)

Measured memory_bytes: 64988
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
#include <functional>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(),greater<char>());
	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
map<int,int>v1,v2;
int main()
{
    int n;
    cin>>n;
    int tmp;
    for(int i=0;i<n/2;i++)
    {
	cin>>tmp;
	v1[tmp]++;
	cin>>tmp;
	v2[tmp]++;
    }
//    map<int, int>::iterator itera,iterb;
    int a1=0,a2=0,b1=0,b2=0;
    map<int, int>::iterator it;

//cout<<"***************"<<endl;
    for(it=v1.begin();it!=v1.end();it++)
    {

	if(it->second > a2)
	{
	    a1=it->first;
	    a2=it->second;
	}
	if(a2>b2)
	{
	    int t=a1;
	    a1=b1;
	    b1=t;
	    t=a2;
	    a2=b2;
	    b2=t;
	}
    }

//cout<<"***************"<<endl;
//    map<int, int>::iterator iter1a,iter1b;
    int c1=0,c2=0,d1=0,d2=0;
    for(it=v2.begin();it!=v2.end();it++)
    {
        if(it->second > c2)
        {
            c1=it->first;
            c2=it->second;

        }
	if(c2 > d2)
        {
            int t=c1;
	    c1=d1;
	    d1=t;
	    t=d2;
	    d2=c2;
	    c2=t;
        }

    }
//cout<<"***************"<<endl;
    int sum=0;
    if(b1==d1)
    {
	sum=a2;
	if(c2>a2) sum=c2;
	sum=sum+b2;
    }
    else
    {
	sum=b2+d2;
    }
    cout<<n-sum<<endl;
    
}

Measured memory_bytes: 4992
#![allow(unused)]

use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};
use std::{cmp, collections, fmt, io, iter, ops, str};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($fmt: expr) => { eprintln!($fmt) };
    ($fmt: expr, $($args: tt)*) => { eprintln!($fmt, $($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($fmt:expr) => {};
    ($fmt:expr, $($args:tt)*) => {};
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if buf.len() > 0 {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}

fn main() {
    let (n, m) = {
        let mut v = parse_vec::<usize>();
        v.sort();
        (v[0], v[1])
    };

    let ans = match n {
        1 => match m {
            1 => 1,
            _ => m - 2,
        },
        _ => (n - 2) * (m - 2),
    };

    println!("{}", ans);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

long func(long num, long div) {
	long i=0, n=1;
	while(1) {
		n*=div;
		if ( (num%n) != 0 ) break;
		i++;
	}
	return i;
}

long min(long a, long b) {
	return (a<b) ? a : b;
}

int main() {
	long num, j , s, t;

	while(1) {
		s = 0; t = 0;
		scanf("%ld",&num);
		if (num==0) break;
		for(j=0; j<num; j++) {
			s+=func(j+1,2);
			t+=func(j+1,5);
		}
		
		printf("%ld\n",min(s,t));
	}
	return 0;
}

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

int main(void){
  int n;
  cin >> n;
  int a[n+10];
  for(int i=1;i<=n;i++) cin >> a[i];
  int friends=0;
  for(int i=1;i<=n;i++){
    if(a[a[i]]==i) friends++;
  }
  cout << friends/2 << endl;
  return 0;
}


Measured memory_bytes: 640