akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc046/tasks/arc062_a

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

def div(a, b):
    if a % b == 0:
        return a // b
    else:
        return (a // b) + 1

def main():
    n = int(input())
    t, a = 1, 1
    for _ in range(n):
        tt, at = map(int, input().split())

        temp_t = div(t, tt)
        temp_a = div(a, at)
        co = max(temp_t, temp_a)

        t = co * tt
        a = co * at

    print(t + a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38896
#include<bits/stdc++.h>
using namespace std;
const int inf=1000000009;

int L,R,d;

int main(){
	scanf("%d%d%d",&L,&R,&d);
	int ret=0;
	for(int i=d;i<=R;i+=d){
		if(i>=L)++ret;
	}
	printf("%d\n",ret);
	return 0;
}

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

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

  string S;
  cin >> S;

  bool ans = false;
  for (int i = 0; i < S.size(); ++i) {
    if (i % 2 == 0) {
      if (S.at(i) == 'R' || S.at(i) == 'U' || S.at(i) == 'D') {
        ans = true;
      }
      else {
        ans = false;
        cout << "No" << endl;
        break;
      }
    }
    else {
      if (S.at(i) == 'L' || S.at(i) == 'U' || S.at(i) == 'D') {
        ans = true;
      }
      else {
        ans = false;
        cout << "No" << endl;
        break;
      }
    }
  }

  if (ans) {
    cout << "Yes" << endl;
  }
  return 0;
}


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


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

int main(){
    int N,result=0,memo=0;
    cin >> N;
    for (int i=1;i<N+1;i++){
        for (int j=1;j<N+1;j++){
            for(int k=1;k<N+1;k++){
                long long int A[2];
                A[0] = gcd(i,j);
                A[1] = gcd(A[0],k);
                result += A[1];
            }
        }
    }
    cout << result;
}



Measured memory_bytes: 3620
for _ in range(10000):
    h, w = map(int, input().split())

    if h == 0:
        if w == 0:
            break

    for i in range(h):
        l = ""
        for j in range(w):
            if i == 0:
                l += '#'
            elif i == (h - 1):
                l += '#'
            else:
                if j == 0:
                    l += '#'
                elif j == (w - 1):
                    l += '#'
                else:
                    l += '.'
        print(l)
    print()



Measured memory_bytes: 5612
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>//小数点以下表示
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main(){
    int n;
    cin>>n;
    char a[n];
    cin>>a;
    if(n%2==1){
        cout<<"No"<<endl;
    }
    else{
        bool b=true;
        rep(i,n/2){
            if(a[i]!=a[i+n/2]){
                b=false;
            }
        }
        if(b){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  ll ans = 0;
  int tmp = 0;
  rep(i,N) {
    cin >> A[i];
    if(A[i] == 0) {
      tmp = 0;
      continue;
    }
    A[i] += tmp;
    ans += (ll)(A[i] / 2);
    A[i] %= 2;
    tmp = A[i];
  }
  cout << ans << endl;

  return 0;
}

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

const int maxn = 100+10;

int x[maxn];

int main() {
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        scanf("%d", &x[i]);
    int ans = 1e9;
    for(int i=1; i<=100; i++) {
        int cur = 0;
        for(int j=1; j<=n; j++)
            cur += (i-x[j])*(i-x[j]);
        ans = min(ans, cur);
    }
    printf("%d\n", ans);
    return 0;
}


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

int N, K;
int R, S, P;
int res = 0;
string T;


int rsp(char h, char& ch, int r, int s, int p){
    if(h == ch){ ch = '.'; return 0; }
    if(h == 's'){ ch = 's'; return r; }  //グーで勝ち
    else if(h == 'p'){ ch = 'p'; return s; }  //チョキで勝ち
    else if(h == 'r'){ ch = 'r'; return p; } //パーで勝ち
}


int main(){
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    for(int i = 0; i < K; i++){
        int head = i;
        char c = '.';  //K回後の相手の手
        while(head < N){ 
            res += rsp(T[head], c, R, S, P);
            head += K;
        }
    }

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


Measured memory_bytes: 3772
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
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; }
const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long D){
    while(1){
        C -= B;
        if(C <= 0) {
            cout<<YES<<endl;
            return;
        }
        A -= D;
        if(A <= 0){
            cout<<NO<<endl;
            return;
        }
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 3192
while True:
    H,W = list(map(int,input().split()))
    
    if H == 0 and W == 0:
        break
    for i in range(H):
        if i % 2 == 0:
            for j in range(W):
                if j % 2 == 0:
                    print("#",end="")
                else:
                    print(".",end="")
            print()
        else:
            for j in range(W):
                if j % 2 == 0:
                    print(".",end="")
                else:
                    print("#",end="")
            print()
    print()


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll H, W;
    cin >> H >> W;

    vector<string> S(H);

    REP(i, H){
        cin >> S[i];
    }

    // cout << S[2][2] << endl;

    vector<vector<ll>> HC(H, vector<ll>(W,0));
    vector<vector<ll>> WC(H, vector<ll>(W,0));

    REP(i, H){
        REP(j, W){
            if(j == 0){
                if(S[i][j] == '#'){
                    HC[i][j] = 0;
                } 
                else{
                    HC[i][j] = 1;
                }
                continue;
            }
            // cout << S[i][j] << endl;
            if(S[i][j] == '#'){
                HC[i][j] = 0;
                // cout << "hello2";
            } 
            else{
                HC[i][j] = HC[i][j-1] + 1;
                // cout << "hello";
            }
        }
        for(ll j= W-1; j>=0; j--){
            // cout << HC[i][j] << endl;
            if(j == W-1) continue;
            if(HC[i][j] == 0) continue;

            HC[i][j] = max(HC[i][j], HC[i][j+1]);
        }
    }

    REP(i, W){
        REP(j, H){
            if(j == 0){
                if(S[j][i] == '#'){
                    WC[j][i] = 0;
                } 
                else{
                    WC[j][i] = 1;
                }
                continue;
            }
            if(S[j][i] == '#'){
                WC[j][i] = 0;
            } 
            else{
                WC[j][i] = WC[j-1][i] + 1;
            }
        }
        for(ll j= H-1; j>=0; j--){
            if(j == H-1) continue;
            if(WC[j][i] == 0) continue;

            WC[j][i] = max(WC[j][i], WC[j+1][i]);
        }
    }
    
    // デバッグ用
    // REP(i, H){
    //     REP(j, W){
    //         cout << WC[i][j];
    //     }
    //     cout << endl;
    // }

    ll ans = 0;

    REP(i, H){
        REP(j, W){
            ans = max(ans, HC[i][j] + WC[i][j]-1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 67072
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

using namespace std;


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

   ll e=lcm(c,d);

   ll la=(a-1)/c,ra=b/c;
   ll lb=(a-1)/d,rb=b/d;

   ll le=(a-1)/e,re=b/e;

   ll ans=(b-a)+1;
   ans-=(ra-la);
   ans-=(rb-lb);
   ans+=(re-le);

   cout<<ans;


return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
  
int main(){
        char st[3][101];
        int n,i,c1=0,c2;

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

        for(i = 0; i < n; i++){
                c2=0;
                if(st[0][i]!=st[1][i])c2++;
                if(st[0][i]!=st[2][i])c2++;
                if(c2!=0 && st[1][i]==st[2][i])c2--;
                c1+=c2;
        }

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

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

#define ll     long long
#define fr     first
#define sec    second
#define rep(i,n)  for(i=0;i<n;i++)
#define vi     vector <int>
#define vc     vector <char>
#define vl     vector <ll>
#define vb     vector <bool>
#define pb     push_back
#define M      1000000007
#define ios    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open   freopen("input.txt","r",stdin);
#define close  freopen("output.txt","w",stdout);
#define M_PI   3.14159265358979323846
#define pp     pair<int,int>
#define nn 100003

int main()
{
    ios;
    ll x,n,i,a;
    cin>>x>>n;
    set <ll> s;
    rep(i,n)
    {
        cin>>a;
        s.insert(a);
    }
    rep(i,x+1)
    {
        for(ll j=-1;j<=1;j++)
        {
            ll ans=x+i*j;
            if(s.find(ans)==s.end())
            {
                cout<<ans;
                i=x+1;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>

int main(){
	int p[3];
	int J[2];
	int i, j;
	for(i=0;i<3;i++){
		scanf("%d", &p[i]);
	}
	for(i=0;i<2;i++){
		scanf("%d", &J[i]);
	}
	int min=p[0]+J[0];
	for(i=0;i<3;i++){
		for(j=0;j<2;j++){
			if(min>p[i]+J[j]){
				min=p[i]+J[j];
			}
		}
	}
	printf("%d\n", min-50);
	return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
int N;
long long K,Q;
long long a[500005]={0};
cin>>N;
cin>>K;
cin>>Q;
for(int i=1;i<=N;i++)
{a[i]+=K; a[i]-=Q; }
for(int i=1;i<=Q;i++)
{
    int op;
    cin>>op;
    a[op]++;
}
for(int j=1;j<=N;j++)
{
    if(a[j]>0)
        printf("Yes\n");
    else
        printf("No\n");
}
return 0;
}


Measured memory_bytes: 4608
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

//??°?????????????????°

void function()
{
	//??¢??°
}

int main()
{
	int r, c;
	int a[101][101];
	cin >> r >> c;
	for (int i = 0; i < r; i++)
	{
		a[i][c] = 0;
		for (int j = 0; j < c; j++)
		{
			cin >> a[i][j];
			a[i][c] += a[i][j];
		}
	}

	for (int i = 0; i < c + 1; i++)
	{
		a[r][i] = 0;
		for (int j = 0; j < r; j++)
		{
			a[r][i] += a[j][i];
		}
	}

	for (int i = 0; i < r + 1; i++)
	{
		for (int j = 0; j < c + 1; j++)
		{
			cout << a[i][j];

			if (j == c)
			{
				cout << endl;
			}
			else
			{
				cout << " ";
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1200
import Control.Monad
import Data.List

getLineRepeat :: Int -> IO [String]
getLineRepeat times = replicateM times getLine

main = do
    n <- read <$> getLine :: IO Int
    d <- getLineRepeat n
    let ts = map read d :: [Integer]
    let ans = foldl lcm 1 ts
    putStrLn . show $ ans


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;


signed main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(v[0] - v[1]);
    for (int j = 2; j < n; j++) {
        dp[j] = min(dp[j - 1] + abs(v[j] - v[j - 1]), dp[j - 2] + abs(v[j] - v[j - 2]));
    }
    cout << dp[n - 1] << "\n";
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    map<int,int> mp;
    rep(i,0,N)mp[V[i]]++;
    for(auto p:mp)if(p.second > 2 || p.first == 0){
        cout << 0 << endl;
        return 0;
    }
    int maxi = 0;
    set<int> st;
    vector<int> vec;
    rep(i,0,N){
        if(mp[V[i]] == 1){
            vec.push_back(V[i]);
        }else{
            st.insert(V[i]);
            st.insert(24 - V[i]);
        }
    }
    int M = vec.size();
    
    if(V[0] == 0 && N == 1){
        cout << 0 << endl;
        return 0;
    }
    st.insert(0);
    rep(i,0,1 << M){
        rep(j,0,M){
            if(i & (1 << j)){
                st.insert(vec[j]);
            }else{
                st.insert(24 - vec[j]);
            }
        }
        vector<int> tmp;
        for(auto itr:st)tmp.push_back(itr);
        int mini = INF;
        rep(ii,0,tmp.size())rep(jj,ii+1,tmp.size()){
            int dif = abs(tmp[ii] - tmp[jj]);
            mini = min({mini, dif, 24 - dif});
        }
        rep(j,0,M){
            if(i & (1 << j)){
                st.erase(vec[j]);
            }else{
                st.erase(24 - vec[j]);
            }
        }
        maxi = max(maxi, mini);
    }
    //assert(false);
    cout << maxi << endl;
}

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

const int md = 998244353;

inline int add(int a, int b) 
{
	a += b;
	if (a >= md) a -= md;
	return a;
}
inline int sub(int a, int b) 
{
	a -= b;
	if (a < 0) a += md;
	return a;
}
inline int mul(int a, int b) 
{
	return (int)((long long)a * b % md);
}

const int N = 3000;

int dp[N + 1][N + 1];

int main() 
{
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	dp[a][b] = 1;
	for (int i = a; i <= c; ++i) {
		for (int j = b; j <= d; ++j) {
			if (i - 1 >= a) {
				if (j - 1 >= b) dp[i][j] = sub(add(mul(dp[i][j - 1], i), mul(dp[i - 1][j], j)), mul(dp[i - 1][j - 1], (i - 1) * (j - 1)));
				else dp[i][j] = mul(dp[i - 1][j], j);
			}
			else {
				if (j - 1 >= b) dp[i][j] = mul(dp[i][j - 1], i);
			}
		}
	}
	printf("%d\n", dp[c][d]);
	return 0;
}


Measured memory_bytes: 36828
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, T; 
  cin >> N >> T;

  vector<int> A(N), B(N);
  REP(i, N) cin >> A[i] >> B[i];

  vector<int> o(N);
  iota(ALL(o), 0);
  sort(ALL(o), [&](int const & l, int const & r){
      return A[l] < A[r];
      });

  vector<vector<int>> dp(N+1, vector<int>(T+1, -INF));
  dp[0][0] = 0;

  REP(i, N) REP(j, T+1){
    int I = o[i];
    chmax(dp[i+1][j], dp[i][j]);
    if(j < T) chmax(dp[i+1][min(T, j+A[I])], dp[i][j]+B[I]);
  }

  int ans = 0;
  REP(j, T+1) chmax(ans, dp[N][j]);

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 70784
a, b, c, d = map(int, input().split())

if a % d == 0:
    mons_a = a // d
else:
    mons_a = a // d + 1

if c % b == 0:
    mons_b = c // b
else:
    mons_b = c // b + 1

if mons_a >= mons_b:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61720
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

vector<int> v[300];
int main()
{
	string t, s;
	cin >> t >> s;
	for(int i = 0; i < t.size(); i ++)
		v[t[i]].push_back(i);
	ll cur = -1;
	ll n = (ll)t.size();
	ll ans = 0;
	for(int i = 0; i < s.size(); i ++)
	{
		if(v[s[i]].empty())
			return cout << -1, 0;
//		cerr << cur << '\n';
		int id = upper_bound(v[s[i]].begin(), v[s[i]].end(), cur)-v[s[i]].begin();
//		cerr << id << '\n';
		if(id == v[s[i]].size())
		{
			ans += n;
			cur = v[s[i]][0];
		}
		else
			cur = v[s[i]][id];
	}
	cout << ans + cur+1;



	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

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

#define PB          push_back
#define PF          push_front
#define MP          make_pair
#define FI          first
#define SE          second
#define SIZE( A )   int( ( A ).size( ) )
#define ALL( A )    ( A ).begin( ), ( A ).end( )
#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )

using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lf;
typedef pair< int, int >    pii;
typedef pair< ll, ll >      pll;
typedef vector< bool >      vb;
typedef vector< lf >        vd;
typedef vector< ll >        vll;
typedef vector< int >       vi;
typedef vector< pii >       vpii;

const int MAXN = int( 1e5 )+10;
const int MOD  = int( 1e9 )+7;
const int oo   = INT_MAX;

int n;

int main( ) {

  #ifdef LOCAL
    freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
  #else
    //freopen( ".in", "r", stdin );
    //freopen( ".out", "w", stdout );
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );
  #endif

  while( cin >> n ) {
    int d1 = n%10;
    int d2 = n/100;
    cout << ( d1 == d2 ? "Yes" : "No" ) << '\n';
  }

  return 0;
}

Measured memory_bytes: 256
if __name__=="__main__":
    s = input()
    count = 0
    for i in range(0,2):
        if count>=3:
            break
        else:
            count = 1
            for j in range(i+1,i+3):
                if s[i]==s[j]:
                    count=count+1

    if count>=3:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	s := nextString()
	t := nextString()

	for i := 0; i < len(s); i++ {
		if t == s[i:]+s[:i] {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


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

class UnionFind {
 private:
  std::vector<size_t> parents;
  std::vector<size_t> ranks;
  std::vector<size_t> sizes;

 public:
  UnionFind(size_t n) : parents(n), ranks(n), sizes(n, 1) {
    for (size_t i = 0; i < n; i++) parents[i] = i;
  }
  void Unite(size_t a, size_t b) {
    a = Find(a);
    b = Find(b);
    if (a == b) return;
    if (ranks[a] < ranks[b]) {
      parents[a] = b;
    } else {
      parents[b] = a;
      if (ranks[a] == ranks[b]) ranks[a]++;
    }
    sizes[Find(a)] = sizes[a] + sizes[b];
  }
  int Find(size_t a) { return parents[a] == a ? a : parents[a] = Find(parents[a]); }
  int Size(size_t a) { return sizes[Find(a)]; }
};

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

  UnionFind uf(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    uf.Unite(a - 1, b - 1);
  }

  int r = 0;
  for (int i = 0; i < n; i++) r = max(r, uf.Size(i));
  cout << r << endl;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

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

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vll A(N);
	bool f = false;
	for (int i = 0; i < N; i++) {
		ll d; cin >> d;
		if (d < 0) f ^= true;
		A[i] = abs(d);
	}
	sort(begin(A), end(A));
	cout << (accumulate(begin(A), end(A), 0ll) - (f ? 2*A[0] : 0)) << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

int main(){
  int i,j,tmp,N,K;
  int R,S,P,ans;
  char pre;
  cin >> N >> K;
  cin >> R >> S >> P;
  string A;
  vector<vector<char>> T(K,vector<char>());
  cin >> A;
  for(i=0; i<N; i++){
    T.at(i%K).push_back(A[i]);
  }
  ans =0;
  for(i=0; i<K; i++){
    tmp = 0;
    pre ='x';
    for(j=0; j<T.at(i).size(); j++){
      if(T.at(i).at(j) == 'r' && pre != 'p'){
        pre = 'p'; tmp += P;
      }
      else if(T.at(i).at(j) == 's' && pre != 'r'){
        pre = 'r'; tmp += R;
      }
      else if(T.at(i).at(j) == 'p' && pre != 's'){
        pre = 's'; tmp += S;
      }
      else{
        pre = 'x';
      }
    }
    ans += tmp;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h> 
using namespace std; 
int main(){ 
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  
  if(A>=K){
  cout << K << endl;
  }
  
  else if(A+B>=K){
  cout << A << endl;
  }
  
  else if(A+B+C>=K){
    cout << A-1*(K-A-B) << endl;
  }
}


Measured memory_bytes: 3612
#include<stdio.h>
int a[1111],b[1111],c[1111],d[1111],p[1111],i,j,x,y,z;
main(){
  for(;scanf("%d%d%d",a,b,c)&&(*a+=*b+*c);){
    for(i=0,scanf("%d",p);i++<*p;scanf("%d%d%d%d",a+i,b+i,c+i,d+i),p[i]=2);
    for(i=0;i++<4;)
      for(j=0;j++<*p;d[j]?p[a[j]]=p[b[j]]=p[c[j]]=1:(x=p[a[j]]&1)&(y=p[b[j]]&1)?p[c[j]]=0:x&(z=p[c[j]])?p[b[j]]=0:y&z?p[a[j]]=0:0);
    for(i=0;i<*a;printf("%d\n",p[++i]));
  }return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ios>
#include <iomanip>
#include <bitset>

#define INF 200000000
#define MOD 1000000007
//#define int long long int
#define ll long long int
#define _tilde_ ~

using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k-1] = tolower(s[k-1]);
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
program hrn;
 var
  n,i,a,x,v:longint;
  function co(s:longint):longint;
   begin
    repeat
     if s mod 2=0 then begin
      s:=s div 2;inc(v);end;
    until s mod 2=1;
    co:=v;v:=0;
   end;
 begin
  read(n);x:=maxlongint;
  for i:=1 to n do begin
   read(a);
   if co(a)<x then x:=co(a);
  end;
  writeln(x);
 end.


Measured memory_bytes: 128
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

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

using namespace std;

typedef long long ll;

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

  int n, m;
  char a[100][100];
  char b[100][100];

  cin >> n >> m;

  rep(i, n) { cin >> a[i]; }
  rep(i, m) { cin >> b[i]; }

  rep(sy, n-m+1) {
    rep(sx, n-m+1) {
      bool is_ok = true;
      for (int y = sy; y < sy+m; y++) {
        for (int x = sx; x < sx+m; x++) {
          if ( a[y][x] != b[y-sy][x-sx] ) { is_ok = false; }
        }
      }
      if (is_ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
n=int(input())
mod=(1e+9)+7
x=1
if n>=2:
  ans=1
else:
  ans=0
for i in range(n):
  x*=10
  ans*=8
  ans%=mod
  x%=mod
nin=1

for i in range(n):
  nin*=9
  nin%=mod
x+=ans
x%=mod
x-=(nin*2)%mod
if x<0:
  x+=mod
if n==1:
  print(0)
else:
  print(int(x%mod))

Measured memory_bytes: 9204
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]


S = input()

if S[2] == S[3] and S[4] == S[5]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 43376
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int N,K; cin >> N >> K;

  map<int, int> mp;
  rep(i,N) {
    int a; cin >> a;
    mp[a]++;
  }

  vec v;
  for(auto x : mp) v.push_back(x.second);
  sort(ALL(v));

  int num = v.size() - K;
  int res = 0;
  if(num) rep(i, num) res+=v[i];

  cout << res << endl;

  return 0;
}


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

using namespace std;

typedef long long llint;

int main() {
  int n;
  cin >> n;
  vector<llint> v(100001, 0);
  llint sum = 0;
  for (int i = 0; i < n; i++) {
    llint a;
    cin >> a;
    v[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  while (q--) {
    llint b, c;
    cin >> b >> c;
    sum -= b * v[b];
    sum += c * v[b];
    v[c] += v[b];
    v[b] = 0;
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 4028
import heapq


def dijkstra(start_v, G):
    n = len(G)
    dist = [0 if i == start_v else float("inf") for i in range(n)]

    que = []
    heapq.heappush(que, (0, start_v))

    while que:
        cur_d, cur_v = heapq.heappop(que)
        if dist[cur_v] < cur_d:
            continue
        for adj in G[cur_v]:
            nxt_v, cost = adj
            if dist[cur_v] + cost < dist[nxt_v]:
                dist[nxt_v] = dist[cur_v] + cost
                heapq.heappush(que, (dist[nxt_v], nxt_v))

    return dist


v, e, r = map(int, input().split())
g = [[] for _ in range(v)]

for _ in range(e):
    s, t, d = map(int, input().split())
    g[s].append((t, d))

dist = dijkstra(r, g)
for i in range(v):
    if dist[i] != float("inf"):
        print(dist[i])
    else:
        print("INF")



Measured memory_bytes: 91596
#include <iostream>
using namespace std;
int main(){
  int n, i, s;
  int a[10000];
  a[0]=2;
  for(i=1; i<10000;i++){
    a[i]=a[i-1]+i+1;  
  }
  while(cin>>n){
  cout<<a[n-1]<<endl;
  }
  return 0;  
}

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

int iabs(int a) {
    if (a >= 0) return a;
    else return -a;
}

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

int main(void) {
    int n;
    scanf("%d", &n);
    int h[n+1];
    h[0] = 0;
    for (int i = 1; i < n+1; i++) scanf("%d", &h[i]);

    int dp[n+1];
    for (int i = 0; i < n+1; i++) dp[i] = 0;
    dp[2] = iabs(h[1]-h[2]);
    for (int i = 3; i < n+1; i++) {
        dp[i] = min(dp[i-2]+iabs(h[i-2]-h[i]), dp[i-1]+iabs(h[i-1]-h[i]));
    }

    printf("%d\n", dp[n]);

    return 0;
}


Measured memory_bytes: 896
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ans = 0
for _ in range(n):
    x,y = input().split()
    if y == 'BTC':
        ans += 380000*float(x)
    else:
        ans += int(x)
print(ans)


Measured memory_bytes: 38384
S = input()

MAE = int(S[:2])
USIRO = int(S[2:])

MMYY_Flag = False
YYMM_Flag = False


if 1 <= MAE and 12 >= MAE:
    MMYY_Flag = True

if 1 <= USIRO and 12 >= USIRO:
    YYMM_Flag = True


if MMYY_Flag and YYMM_Flag:
    print ("AMBIGUOUS")

elif MMYY_Flag:
    print ("MMYY")

elif YYMM_Flag:
    print ("YYMM")

else:
    print ("NA")


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    /*int n;
    cin>>n;
    ll ans=0;
    rep(i,0,n){
        int x;cin>>x;
        while(x%2==0){
            ans++;
            x/=2;
        }
    }
    cout<<ans<<endl;
*/
    int d,n;
    cin>>d>>n;
    if(n==100)n++;
    cout<<n;
    rep(i,0,d)cout<<"00";
    cout<<endl;
    

    /*int n,m;
    cin>>n>>m;
    vector<vector<ll> > dp(n+1,vector<ll>(m+1,0));

    rep(i,0,n){
        int a,b,c;
        cin>>a>>b>>c;
        rep(j,0,m){
            dp[i+1][j+1]=max(abs(dp[i][j]+a+b+c),abs(dp[i][j]));
        }
    }
    ll ans=0;
    rep(i,0,n+1){
        ans=max(ans,dp[i][m]);
    }
    cout<<ans<<endl;*/

    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;

signed main(){
	
	int n,a[111111];
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=n%2;i<n;i+=2){
	    if(a[i]!=a[i+1]){
	        cout<<0<<endl;
	        return 0;
	    }
	}
	if(n%2==1)n-=1;
	int ans=1;
	for(int i=0;i<n/2;i++){
	    ans*=2;
	    ans%=1000000007;
	}
	cout<<ans<<endl;

}

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

int main() {
  char a, b;
  cin >> a >> b;
  if(a == 'H') {
    cout << b << endl;
  } else if(b == 'H') {
    cout << 'D' << endl;
  } else {
    cout << 'H' << endl;
  }
}

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

#define ll long long

int main() {
    int n;
    vector<int> v;
    vector<int> ans;

    cin >> n;
    // Load
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        v.push_back(x);
    }
    // Sort
    sort(v.begin(), v.end());

    int h1 = 0, h2 = 0;
    bool f1 = false, f2 = false;
    for (int i = v.size() - 1; i >= 0; i--) {
        if (v[i] == v[i-1]) {
            if (!f1) {
                h1 = v[i];
                f1 = true;
                i--;
            } else if (!f2){
                h2 = v[i];
                f2 = true;
                break;
            }
        }
    }
    printf("%lld\n", (ll)h1 * h2);
}

Measured memory_bytes: 892
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    int[] AS;
    foreach (_; 0..N) AS ~= readln.chomp.to!int;

    int[] lis;
    foreach (a; AS) {
        if (lis.empty || lis[$-1] < a) {
            lis ~= a;
            continue;
        } else if (lis[0] >= a) {
            lis[0] = a;
            continue;
        }

        size_t l, r = lis.length-1;
        while (l+1 < r) {
            auto m = (l+r)/2;
            if (lis[m] >= a) {
                r = m;
            } else {
                l = m;
            }
        }
        lis[r] = a;
    }
    writeln(lis.length);
}


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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool prime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

ll addmod(ll a,ll b)
{
    return (a+b)%mod;
}
ll mulmod(ll a,ll b)
{
    a %=mod;
    b%=mod;
    return (a*b)%mod;
}
ll submod(ll a,ll b)
{
    ll x  = a-b;
    if(x<0)x+=mod;
    x%=mod;
    return x;
}
bool comp(pair<pi,ll>a,pair<pi,ll>b)
{
    if(a.fi.fi==b.fi.fi)return a.fi.se<b.fi.se;
    return a.fi.fi<b.fi.fi;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s; cin>>s;
    reverse(all(s));
    ll n = s.size();
    vi arr(n);

    for(ll i=0;i<n;i++)
    {
        arr[i] = ((s[i]-'0')*modexp(10,i,2019))%2019;
    }
    vi pref(n);
    pref[0] = arr[0];
    rep(i,1,n)pref[i]= (pref[i-1]+arr[i])%2019;
    map<ll,ll>mp;
    mp[0] = 1;
    ll ans = 0;
    for(ll i=0;i<n;i++)
    {
        //if(pref[i]==0)ans++;
        ans+=mp[pref[i]];
        mp[pref[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}
/*
5 10 10
22 23
17 19
13 17
8 12
2 6
*/


Measured memory_bytes: 6740
<?php

$rdx = explode(' ', trim(fgets(STDIN)));
$r = $rdx[0];
$d = $rdx[1];
$x = $rdx[2];

for($i=0; $i<10; $i++){
  if ($i !== 0) echo "\n";
  $x = $x*$r-$d;
  echo $x;
}

?>

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    int answer=-1;
    for(int i=1; i<500000; i++) {
        double a=i*1.08;
        if(N<=a&&a<N+1) answer=i;
    }
    if(answer==-1) cout<<":("<<endl;
    else cout<<answer<<endl;
}

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

using namespace std;

int main(){
    string s; cin >> s;
    int diff = 0;
    for(int i=0;i<s.size();i++){
        if(i%2==0 && s[i] == '1'){
            diff++;
        }
        if(i%2==1 && s[i] == '0'){
            diff++;
        }
    }
    int other = s.size()-diff;
    int ans;
    ans = diff > other ? other : diff;
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  string str;
  cin >> str;
  int ans=0;
  
  for(int i=0;i<n-2;i++){
  	if(str[i]=='A' && str[i+1]=='B' && str[i+2]=='C') ans++;
  }
  
  cout << ans;
 return 0; 
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    string a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sort(a[i].begin(),a[i].end());
    }
    long long int br=0;
    long long int kolku=1;
    sort(a,a+n);
    for(int i=0;i<(n-1);i++)
    {
        if(a[i]==a[i+1])
        {
            kolku++;
            //cout<<"here "<<kolku<<" "<<a[i]<<" "<<a[i+1]<<endl;
        }
        if(a[i]!=a[i+1] || ((i+1)==(n-1) && a[i]==a[i+1]) )
        {
            //cout<<kolku<<" "<<a[i]<<" "<<a[i+1]<<endl;
            br=br+kolku*(kolku-1)/2;
            kolku=1;
        }
    }
    cout<<br<<endl;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int64_t l0=2;
  int64_t l1=1;
  int64_t ans=1;
  for(int i=2; i<n+1; i++){
    ans = l0 + l1;
    l0=l1;
    l1=ans;
  }
  
  cout << ans <<endl;
}

Measured memory_bytes: 256
import collections
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
cs = collections.Counter(s)
ct = collections.Counter(t)
points = 0
for key in cs.keys():
    points = max(points, cs[key] - ct[key])
print(points)

Measured memory_bytes: 3316
let change n m d =
  let t = Array.make (n + 1) max_int in
  t.(0) <- 0;
  let rec doit i x =
    if i = m then t.(n)
    else
      let v = x + d.(i) in
      if v > n then doit (i + 1) 0
      else begin
        t.(v) <- if t.(v) < t.(x) + 1 then t.(v) else t.(x) + 1;
        doit i (x + 1)
      end in
  doit 0 0

let () =
  let (n, m) = Scanf.scanf "%d %d " (fun n m -> (n, m)) in
  let d = Array.init m (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  change n m d |> Printf.printf "%d\n"

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

long long GCD(long long A, long long B) {
	if (B == 0) return A;
	return GCD(B, A % B);
}

int main() {
	long long N, X;
	cin >> N >> X;
	long long G = GCD(N, X);
	N /= G, N--;
	cout << N * G * 3 << endl;
}

Measured memory_bytes: 256
use std::io;
use std::cmp;

fn enough(h: &Vec<i64>, t: i64, A: i64, B: i64) -> bool {
    let adtnl = A - B;

    let sum = h.iter().fold(0, |acc, &x| acc + (cmp::max(0i64, x - t * B ) as f64 / adtnl as f64).ceil() as i64) ;
    sum <= t
}

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line);
    let mut line = line.split_whitespace();
    let N = line.next().unwrap().parse::<i64>().unwrap();
    let A = line.next().unwrap().parse::<i64>().unwrap();
    let B = line.next().unwrap().parse::<i64>().unwrap();
    let mut h = Vec::<i64>::with_capacity(100_000usize);

    for i in 0..N {
        let mut input = String::new();
        io::stdin().read_line(&mut input);

        h.push(input.trim().parse::<i64>().unwrap());
    }

    let hmax = h.iter().fold(std::i64::MIN, |max, &x| cmp::max(max, x));
    let mut upper = (hmax as f64 / B as f64).ceil() as i64;
    let mut lower = 1i64;
    
    let ans: i64;
    loop {
        
        if upper == lower {
            ans = upper;
            break;
        }
        let mid = lower + (upper - lower) / 2i64;
        if enough(&h, mid, A, B) {
            upper = mid;
        } else {
            lower = mid + 1i64;
        }

    }

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

Measured memory_bytes: 4476
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i,n) rep2(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int n,k;
    string s;
    cin >> n >> k >> s;
    int side_unhappy=(s[0]=='L'?1:0)+(s[n-1]=='R'?1:0);
    int middle_unhappy=0;
    rep2(i,1,n){
        if(s[i-1]=='R'&&s[i]=='L')middle_unhappy++;
    }
    while(k>0){
        if(middle_unhappy>1||(middle_unhappy==1&&side_unhappy>0)){
            --middle_unhappy;
            --k;
        }else if(middle_unhappy==1&&side_unhappy==0){
            --middle_unhappy;
            ++side_unhappy;
            --k;
        }else if(side_unhappy>1){
            --side_unhappy;
            --k;
        }else{
            break;
        }
    }
    cout << n-middle_unhappy*2-side_unhappy << endl;
    return 0;
}

Measured memory_bytes: 512
q = int(input())
LR = [0]*q
for i in range(q):
    LR[i] = list(map(int,input().split()))
lis = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317]

p_lis = [0]*(1+10**5)
for i in range(3,10**5+1):
    sw1 = 1
    sw2 = 1
    for P in lis:
        if P > i**0.5:
            break
        if i%P == 0:
            sw1 = 0
            break
        
    if sw1 == 1:
        for P in lis:
            if P > ((i+1)//2)**0.5:
                break
            if (i+1)//2%P == 0:
                sw2 = 0
                break
            
    if sw1 == 1 and sw2 == 1:
        p_lis[i] = 1
s_lis = [0]*(1+10**5)
for i in range(1,len(p_lis)):
    if p_lis[i] == 1:
        s_lis[i] = s_lis[i-1] + 1
    else:
        s_lis[i] = s_lis[i-1]
for L,R in LR:
    print(s_lis[R]-s_lis[L-1])


Measured memory_bytes: 29832
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<set>
#include<iomanip>
using namespace std;
using ll=long long int ;



int main() {

	int n;
	cin >> n;
	
	vector < pair<int, int>> s(n);
	for (int i = 0; i < n; i++) {
		int a,b;
		cin >> a >> b;
		s[i] = make_pair(b, a);
	}
	
	sort(s.begin(), s.end());

	int sum = 0;
	bool can = true;
	for (int i = 0; i < n; i++) {
		sum += s[i].second;
		if (s[i].first < sum) {
			can = false;
		}
	}

	if (can) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 1792