akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<utility>
#include<string.h>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    int n;
    while(1==1)
    {
        scanf("%d\n",&n);
        if(n==0)return 0;
        int dp[1000005]={};
        for(int i=1;i<1000005;i++)dp[i]=-1;
        long long int he[250]={};
        long long int ohe[63]={};
        REP(i,250)he[i]=i*(i+1)*(i+2)/6;
        REP(i,63)ohe[i]=he[i*4+1];
        for(int i=1;i<=5;i++)
        {
            REP(j,n)
            {
                if(dp[j]==i-1)
                {
                    REP(k,250)
                    {
                        if(j+he[k]<=n&&dp[j+he[k]]==-1)
                        {
                            dp[j+he[k]]=i;
                        }
                    }
                }
            }
            if(dp[n]!=-1)break;
        }
        printf("%d ",dp[n]);
        REP(i,1000005)dp[i]=-1;
        dp[0]=0;
        for(int i=1;i<=55;i++)
        {
            REP(j,n)
            {
                if(dp[j]==i-1)
                {
                    REP(k,63)
                    {
                        if(j+ohe[k]<=n&&dp[j+ohe[k]]==-1)
                        {
                            dp[j+ohe[k]]=i;
                        }
                    }
                }
            }
            if(dp[n]!=-1)break;
        }
        printf("%d\n",dp[n]);
    }
    return 0;
}


Measured memory_bytes: 7096
#include <iostream>

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

    if (s == "Sunny") {
        std::cout << "Cloudy";
    } else if (s == "Rainy") {
        std::cout << "Sunny";
    } else {
        std::cout << "Rainy";
    }
}


Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};
use std::collections::HashMap;

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    input
        .split_whitespace()
        .skip(1)
        .map(|x| x.parse::<i32>().unwrap())
        .flat_map(|x| vec![x, x + 1, x - 1])
        .fold(HashMap::new(), |mut map, x| {
            let v = map.get(&x).map(|i| i + 1).unwrap_or(1);
            map.insert(x, v);
            map
        })
        .into_iter()
        .fold(None, |a, (x, y)| match a {
            Option::None => Some((x, y)),
            Option::Some((_, q)) if y > q => Some((x, y)),
            _ => a,
        })
        .unwrap()
        .1
        .to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!(super::run($input.to_string()), $output.to_string());
                }
            )*
        }
    }
}

tests! {
    test1: "7
3 1 4 1 5 9 2" => "4",
    test2: "10
0 1 2 3 4 5 6 7 8 9" => "3",
test3:"1
99999"=>"1",
}


Measured memory_bytes: 10492
#include <stdio.h>
int main(){

  int n,a,h[200],m[200],i,j,blank;

  scanf("%d",&n);

  for(i = 0; i < n; i++) scanf("%d %d",&h[i],&m[i]);

  scanf("%d",&a);

  for(i = n; i < n+a; i++) scanf("%d %d",&h[i],&m[i]);

  for(j = 0; j < n+a-1; j++){

    for(i = 0; i < n+a-1; i++){

      if(h[i] > h[i+1]){

        blank=h[i];
        h[i]=h[i+1];
        h[i+1]=blank;

        blank=m[i];
        m[i]=m[i+1];
        m[i+1]=blank;

      }

      if(h[i] == h[i+1] && m[i] > m[i+1]){

        blank=m[i];
        m[i]=m[i+1];
        m[i+1]=blank;

      }

    }

  }

  if(m[0] < 10) printf("%d:0%d",h[0],m[0]);
  else printf("%d:%d",h[0],m[0]);
  
  for(i = 1; i < n+a; i++){

    if(h[i] == h[i-1] && m[i] == m[i-1]) continue;

    if(m[i] < 10) printf(" %d:0%d",h[i],m[i]);
    else printf(" %d:%d",h[i],m[i]);

  }

  printf("\n");

  return 0;

}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
 
//DEFINE and TYPEDEF--------------------------------------------------------------
 
#define FORG(i,a,n) for(lld i=a;i<n;i++) //for - general
#define FORZ(i,n) for(lld i=0;i<n;i++) //for - zero
#define FORGI(i,a,n,inc) for(lld i=a;i<n;i+=inc) //for - general incremental
#define FORZI(i,n,inc) for(lld i=0;i<n;i+=inc) //for - zero incremental
#define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables
#define ZINDA cerr<<"\nIdhar-ich hai apun!!\n"; //to debug if code reached that point
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
 
#define SORTall(m) sort(m.begin(),m.end());
 
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define mod 1000000007
 
typedef long long int lld;
typedef unsigned long long int ulld;
 
lld power(lld b, lld e)
{
    if(e==0)
        return 1;
    if(e%2==1)
        return b*power(b*b,(e-1)/2);
    else
        return power(b*b,e/2);
}
 
lld power(lld b, lld e, lld m)
{
	if(e==0)
		return 1;
	if(e%2==1)
		return b*power(((b%m)*(b%m))%m,(e-1)/2,m)%m;
	else
		return power(((b%m)*(b%m))%m,e/2,m)%m;
}
 
int nDig(lld n)
{
	if(n==0)
		return 1;

    return floor(log10(n) + 1);
}

//endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------

void swagWaalaFunction()
{
	lld n,ai,ans=0,sum=0;
	cin>>n;

	vector<lld> v;
	map<lld,lld> m,f;
	FORZ(i,n)
	{
		cin>>ai;
		v.pb(ai);
		m[ai]++;
	}

	for(auto i:m)
	{
		if(i.nd>=2)
			f[i.st]=i.nd*(i.nd-1)/2;
		else
			f[i.st]=0;
		//cerr<<f[i.st]<<" ";
		sum+=f[i.st];
	}
	//DEBUG(sum);

	FORZ(i,n)
	{
		//if(!f[i])
			ans=sum-f[v[i]];
		//else

		if(m[v[i]]>2)
			ans+=(m[v[i]]-1)*(m[v[i]]-2)/2;
		
		cout<<ans<<endl;
	}
	return;
}

int main()
{
    SPEEDUP;
 	lld t=1;
 	//cin>>t;

 	while(t--)
 		swagWaalaFunction();

 	return 0;
}

Measured memory_bytes: 18928
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

# solve
# 解説AC
# f(r + 1, c) = f(r, 0) + f(r, 1) + ... + f(r, c)
# 図はこう
# .....147
# .....258
# .....369
# .....ACE
# .....BDF
# 4の通りはf(1)+f(2)+f(3)+f(A)+(B)
# てことはf(1)+f(2)+f(3) = f(4) - f(A) - f(B)
# さらにf(A)+f(B)=f(C)　なんで
# f(1)+f(2)+f(3) = f(4)-f(C)
# これを繰り返すだけ
# easy
def solve():
    def cmb(n, k):
        return fact[n] * invfact[k] * invfact[n-k] % mod
    maxn = int(3e6 + 10)
    r1, c1, r2, c2 = LI()
    ans = 0
    fact = [i for i in range(maxn)]
    fact[0] = 1
    invfact = [i+1 for i in range(maxn)]
    invfact[0] = 1
    for i in range(1, maxn-1):
        fact[i + 1] *= fact[i]
        fact[i + 1] %= mod
    invfact[-1] = pow(fact[-1], mod - 2, mod)
    invr1 = pow(r1, mod - 2, mod)
    for i in range(maxn - 2, -1, -1):
        invfact[i] *= invfact[i + 1]
        invfact[i] %= mod
    acc = list(map(lambda x: x % mod, itertools.accumulate(fact)))
    for c in range(c1, c2 + 1):
        ans += cmb(c + r2 + 1, c + 1) - cmb(c + r1 , c + 1)
        ans %= mod
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 169500
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i =1;i<=n;i++) {
            map.put(i,sc.nextInt());
        }
        System.out.println(map.keySet().stream().sorted(Comparator.comparingInt(map::get)).map(String::valueOf).collect(Collectors.joining(" ")));
    }
}


Measured memory_bytes: 73840
#include <cstdio>
typedef long long int64;
static const int MAXN = 15;
static const int MODULUS = 1e9 + 7;
#define _  %  MODULUS
#define __ %= MODULUS

int n, m;
int out[MAXN] = { 0 };
int64 f[1 << MAXN];

int main()
{
    scanf("%d%d", &n, &m);
    int u, v;
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &u, &v); --u, --v;
        out[u] |= (1 << v);
    }

    f[0] = 1;
    for (int s = 1; s < (1 << n); ++s) if (!!(s & 1) == !!(s & 2)) {
        for (int t = s; t > 0; t = (t - 1) & s) if (!!(t & 1) == !!(t & 2)) {
            int64 cur = f[s ^ t];
            for (int u = 0; u < n; ++u) if (s & (1 << u)) {
                (cur *= (t & (1 << u)) ?
                    (1LL << __builtin_popcount(out[u] & (s ^ t)))_ :
                    ((1LL << __builtin_popcount(out[u] & t)) - 1)_)__;
            }
            (f[s] += cur)__;
        }
    }

    int64 p = 1;
    for (int i = 0; i < m; ++i) (p += p)__;
    printf("%lld\n", (p - f[(1 << n) - 1] + MODULUS)_);
    return 0;
}


Measured memory_bytes: 384
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())))
S = [0]
for i in range(N-P+1):
    S += [S[-1]+A[i]]
a = P-1
for i in range(N-P+1):
    if A[i]+M>=A[N-P] and A[i]*(N-P-i)-(S[-1]-S[i+1])>=M*(V-N):
        a += 1
print(a)

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

using namespace std;

int main(){
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    #endif*/
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;

    int n;cin>>n;
    deque<int> q;
    int a,t=n-1;cin>>a;
    q.push_back(a);
    while(t--){
        cin>>a;
        if(t%2){
            q.push_back(a);
        }
        else {
            q.push_front(a);
        }
    }
    for(auto x:q){
        cout<<x<<" ";
    }

    /*#ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif*/
    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    cout << n * (n-1) / 2 << endl;

}

Measured memory_bytes: 256
import java.text.DecimalFormat;
import java.util.*;

public class Main {
    public static void main(String[] args)  throws java.io.IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] dataset = new int[n];
        for (int i=0;i<n;i++){
            dataset[i] =  sc.nextInt();
        }
        sc.close();
        long sum = 0;

        for (int elem : dataset){
            sum += elem;
        }
        Arrays.sort(dataset);
        System.out.println(dataset[0] + " " +  dataset[dataset.length-1]+ " "+sum);
    }
}

Measured memory_bytes: 34204
n = list(map(int,input()))
cnt = 0
f = n[0]

for i in range(4):
    if cnt == 3:
        break
    if f == n[i]:
        cnt += 1
        f = n[i]
    else:
        cnt = 0
        f = n[i]
if f == n[i]:
    cnt += 1

if cnt >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61888
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
map<int,bool> ps;
#define SZ 2333 
int n,x[SZ];
vector<int> s[2];
#define SZ 233333
int M=1;typedef long long ll;
int fst[SZ],nxt[SZ],vb[SZ],cap[SZ];
void _ad_dl(int a,int b,int c) {++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;cap[M]=c;}
void ad_dl(int a,int b,int c) {_ad_dl(a,b,c); _ad_dl(b,a,0);}
int S,T,q[SZ],d[SZ];
bool bfs()
{
    memset(d,-1,sizeof(d));
    d[S]=0; q[1]=S; int h=1,t=2;
    while(h!=t)
    {
        int cur=q[h++];
        for(int e=fst[cur];e;e=nxt[e])
        {
            int b=vb[e];
            if(d[b]==-1&&cap[e]) d[b]=d[cur]+1, q[t++]=b;
        }
    }
    return d[T]!=-1;
}
int dfs(int x,int f)
{
    if(f<=0) return 0;
    if(x==T) return f;
    int ca=0;
    for(int e=fst[x];e;e=nxt[e])
    {
        int b=vb[e];
        if(d[b]!=d[x]+1) continue;
        int w=dfs(b,min(cap[e],f-ca));
        cap[e]-=w; cap[e^1]+=w; ca+=w;
        if(ca==f) break;
    }
    if(!ca) d[x]=-1;
    return ca;
}
#define inf 1000000000
int dinic()
{
    int ans=0;
    while(bfs()) ans+=dfs(S,inf);
    return ans;
}
int N;
#define SS 12345678
bool npp[SS];
int main()
{
	npp[1]=1;
	for(int i=2;i*i<SS;++i) if(!npp[i])
		for(int j=i*i;j<SS;j+=i) npp[j]=1;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)	
		scanf("%d",x+i),
		ps[x[i]]^=1,ps[x[i]+1]^=1;
	for(auto x:ps)
		if(x.se) s[x.fi&1].pb(x.fi);
	N=0; S=++N; T=++N;
	int a=N+1,b=N+1+s[0].size();
	for(int i=0;i<s[0].size();++i)
		for(int j=0;j<s[1].size();++j)
			if(!npp[abs(s[0][i]-s[1][j])])
				ad_dl(a+i,b+j,1);
	for(int i=0;i<s[0].size();++i)
		ad_dl(S,a+i,1);
	for(int i=0;i<s[1].size();++i)
		ad_dl(b+i,T,1);
	int mx=dinic();
	int ans=mx+2*((s[0].size()-mx)/2+(s[1].size()-mx)/2)
	+3*((s[0].size()-mx)%2);
	printf("%d\n",ans);
}


Measured memory_bytes: 16768
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    ll n, k;
    cin >> n >> k;

    auto mod = n % k;

    cout << min(mod, abs(k - mod)) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int n,k,q;
  cin >> n>>k>>q;
  vector<int> a(q);
  rep(i,q){
    cin>>a.at(i);
    a.at(i)--;
  }
  vector<int>c(n,q);
  rep(i,q){
    c[a.at(i)]--;
  }
  rep(i,n) {
    if(c.at(i)<k){
      cout<<"Yes"<<endl;   
    }
    else{
      cout<<"No"<<endl;   
    }
  }
  cout<<endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define MAXN 2050
#define pii  pair<int, int>
#define ss second
#define ff first
 
using ll = long long;
using namespace std;
const int mod = 1e9 + 7;


int main(){
    set<string> lista;
    string s;
    int n;

    cin >> n;

    while (n--){
        cin >> s;
        lista.insert(s);
    }

    cout << lista.size() << endl;

}

Measured memory_bytes: 19224
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  //printf("n = %d, m = %d\n", n, m);
  int A[100][100];
  int b[100];

  int i, j;
  int k;
  for(i = 0; i < n; i++) {
    j = 0;
	//printf("i = %d\n", i);
    while(cin >> k) {
      //printf("k = %d %d\n", k, j);
      A[i][j] = k;
      j++;
      if(j >= m) break;
    }
  }

  char nl;
  for(i = 0; i < m; i++) {
    scanf("%d%c", &b[i], &nl);
  }

  int c;
  for(i = 0; i < n; i++) {
    c = 0 ;
    for(j = 0; j < m; j++) {
      c += A[i][j] * b[j];
    }
    printf("%d\n", c);
  }
  return 0;
}

Measured memory_bytes: 3232
def q1():
    S = input()
    w = ['Sunny', 'Cloudy', 'Rainy']
    if S == w[0]:
        print(w[1])
    elif S == w[1]:
        print(w[2])
    elif S == w[2]:
        print(w[0])

if __name__ == '__main__':
    q1()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const ll INF = (1LL << 60);
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/**************************************/
/******** User-defined Function *******/




/**************************************/
/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    int k ;cin >> k;

    int cnt = 0;

    while(true){
        for(int i=1; i<3; i++){
            if(a[i-1]>=a[i]){
                 a[i] *= 2;
                 cnt++;
                 break;
            }
        }
        
        if(a[0]<a[1] && a[1]<a[2]) break;
    }

    if(cnt<=k) cout << "Yes" << endl;
    else cout << "No" << endl;

    
    return 0;
}
/********  Main() Ends Here *************/


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

int main(){
	int n, Y, M, D;
	int Yn, Mn, Dn;
	cin >> n;
	int *person = new int[n];

	for(int i = 0; i < n; i++){
		cin >> Y >> M >> D;
		Yn = 0; Mn = 0; Dn = 0;
		for(int j = Y + 1; j < 1000; j++){
			if(j >= 3 && j % 3 == 0){
				Yn += 200;
			}else{
				Yn += 195;
			}
		}

		for(int j = M + 1; j <= 10; j++){
			if(Y >= 3 && Y % 3 == 0){
				Mn += 20;
			}else{
				if(j % 2 == 0){
					Mn += 19;
				}else{
					Mn += 20;
				}
			}
		}

		if(M % 2 != 0){
			Dn = 20 - D;
		}else{
			if(Y >= 3 && Y % 3 == 0){
				Dn = 20 - D;
			}else{
				Dn = 19 - D;
			}
		}
		person[i] = Yn + Mn + Dn + 1;
	}

	for(int i = 0; i < n; i++){
		cout << person[i] << endl;
	}

	return 0;
}

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

int main() {
    while (true) {
        int t;
        cin >> t;
        
        if (t==0) {
            break;
        }
        
        int n;
        cin >> n;
        
        int c = 0;
        
        for (int i=0; i<n; i++) {
            int si, fi;
            cin >> si >> fi;
            c += fi-si;
        }
        
        if (c>=t) {
            cout << "OK" << endl;
        }
        else {
            cout << t-c << endl;
        }
    }
}


Measured memory_bytes: 3088
#include<stdio.h>
#include<stdlib.h>

int acount;
int bcount;
int ccount;
int dec(char, char, int);

void main(int argc, char *argv[]){
    char buf[130];
    char S[3] = "abc";
    int ok;
    int okcount;

    if(scanf("%c %c %c", &buf[0], &buf[1], &buf[2]) < 3){
        exit(1);
    }

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            ok = dec(S[i], buf[j], i);
            if(ok == 1){
                okcount++;
                break;
            }
        }
    }

    if(okcount == 3){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}

int dec(char a,char b, int i){
    if(a == b){
        if(i == 0, acount == 0){
            acount++;
            return 1;
        }else if(i == 1, bcount == 0){
            bcount++;
            return 1;
        }else if(i == 2, ccount == 0){
            ccount++;
            return 1;
        }else{
            return 0;
        }
    }else{
        return 0;
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	int A, L;

	while(true){
		scanf("%d %d\n",&A, &L);
		if(A==0 && L==0){return 0;}

		int* a = new int[22];
		int* num = new int[L];
		int big=0, small=0, cal=0;
		bool flag = true;

		a[0] = A;
		for(int i=1; i<22; i++){
			a[i] = -1;
		}
		for(int i=0; i<21; i++){
			cal = a[i];
			/* 各桁ごとに数字を記憶 */
			for(int j=0; j<L; j++){
				num[j] = cal%10;
				cal = cal/10;
			}
			sort(num, num+L); /* 各桁の数字をソート */
			/* 最大数と最小数を求める */
			for(int j=0; j<L; j++){
				big += num[j] * pow(10,j);
				small += num[j] * pow(10,L-1-j);
			}
			/* 最大数と最小数の差分から数列の次項を求めて記憶 */
			cal = big - small;
			a[i+1]=cal;
			big=0; small=0;
			/* これまで求めた項に一致する数字があるかを調べる */
			for(int j=0; j<i+1; j++){
				if(cal == a[j]){
					printf("%d %d %d\n", j, cal, (i+1)-j);
					flag = false;
					break;
				}
			}
			if(!flag){break;}
		}
		delete[] a;
		delete[] num;
	}

	return 0;
}

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

int main() {
  int N; cin >> N;
  
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++){
    cin >> B.at(i);
  }
  
  int ans=0;
  for(int i=0;i<N;i++){
    if(i == 0){
      ans += B.at(0);
    }else if(0<i && i<N-1){
      ans += min(B.at(i-1), B.at(i));
    }else if(i == N-1){
      ans += B.at(N-2);
    } 
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<cstring>
#include<iostream>
#define _PI acos(-1.0)
#define INF 0x3f3f3f3f
#define esp 1e-9
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define FRE freopen("abc.in", "r", stdin)
#define MEM(X,Y) memset(X,Y,sizeof(X))
typedef long long LL;
typedef unsigned long long ULL;
long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; }
using namespace std;
/*===========================================*/

int main(void)
{
	int n;
	scanf("%d", &n);
	LL ans = 0;
	ans += ((LL)n / 500) * 1000;
	n %= 500;
	ans += n / 5 * 5;
	printf("%lld", ans);
}

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

using namespace std;

const int MOD = 1000000000 + 7;
const int NMAX = 200000 + 5;

typedef long long int lint;
const lint INF = 1.5E18;

lint N, M;

vector <pair <lint, lint> > graph[NMAX];
priority_queue <pair <lint, lint> > q;
bool vis[NMAX];

void dijkstra(int node, lint dist[], lint cnt[]) {
    for (int i = 1; i <= N; ++ i)
        vis[i] = false, dist[i] = INF, cnt[i] = -1;

    q.push({0, node});
    dist[node] = 0;
    cnt[node] = 1;

    while (!q.empty()) {
        node = q.top().second;
        q.pop();
        if (vis[node])
            continue;
        vis[node] = true;

        for (auto it: graph[node]) {
            if (dist[node] + it.second < dist[it.first]) {
                dist[it.first] = dist[node] + it.second;
                cnt[it.first] = cnt[node];
                q.push(make_pair(-dist[it.first], it.first));
            }
            else if (dist[node] + it.second == dist[it.first]) {
                cnt[it.first] += cnt[node];
                if (cnt[it.first] >= MOD)
                    cnt[it.first] -= MOD;
            }
        }
    }
}

int S;
lint distS[NMAX];
lint cntS[NMAX];
int T;
lint distT[NMAX];
lint cntT[NMAX];

int main()
{
    //freopen("data.in", "r", stdin);
    ios_base :: sync_with_stdio(false);

    cin >> N >> M;
    cin >> S >> T;

    for (int i = 1; i <= M; ++ i) {
        int a, b, c;
        cin >> a >> b >> c;
        graph[a].push_back({b, c});
        graph[b].push_back({a, c});
    }

    dijkstra(S, distS, cntS);
    dijkstra(T, distT, cntT);

    const lint D = distS[T];
    lint ans = (1LL * cntS[T] * cntS[T]) % MOD;

    // Meet in node
    for (int i = 1; i <= N; ++ i)
        if (distS[i] + distT[i] == D && distS[i] == distT[i]) {
            const int x = (1LL * cntS[i] * cntT[i]) % MOD;
            ans = (ans - 1LL * x * x) % MOD;
            if (ans < 0)
                ans += MOD;
        }

    // Meet on edge
    for (int i = 1; i <= N; ++ i)
        for (auto it: graph[i]) {
            const lint a = i;
            const lint b = it.first;
            const lint c = it.second;

            if (distS[a] + c + distT[b] == D) {
                const lint lBound = distS[a];
                const lint rBound = distS[b];
                if (2LL * lBound < D && D < 2LL * rBound) {
                    const int x = (1LL * cntS[a] * cntT[b]) % MOD;
                    ans = (ans - 1LL * x * x) % MOD;
                    if (ans < 0)
                        ans += MOD;
                }
            }
        }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 22008
#include<stdio.h>

int func(char c){
	if(c=='J')return 1;//001
	if(c=='O')return 2;//010
	if(c=='I')return 4;//100
}
int dp[1005][9];
char s[1005];
int main(){
	int i,j,k,n,id,ans;
	char c;
	
	scanf("%d",&n);
	scanf("%s",s);
	dp[0][1]=1;
	for(i=0;i<n;i++){
		id=func(s[i]);
		for(j=0;j<8;j++){
			for(k=0;k<8;k++){
				if((j&k)!=0 && (k&id)!=0)dp[i+1][k]+=dp[i][j];
			}
		}
		for(j=0;j<8;j++)dp[i+1][j]=dp[i+1][j]%10007;
	}
	ans=0;
	for(i=0;i<8;i++)ans+=dp[n][i];
	printf("%d\n",ans%10007);
	
	return 0;
}

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

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

    vector<int> low(Q);
    vector<int> high(Q);

    for(int i = 0 ; i < Q ; i++){
        cin >> low.at(i) >> high.at(i);
    }

    vector<bool> flagMap(100001,true);
    flagMap.at(1) = false;

    for(int i = 2 ; i <= 316 ; i++){
        if(flagMap.at(i)){
            for(int j = i * 2 ; j <= 100000 ; j += i){
                flagMap.at(j) = false;
            }
        }
    }

    vector<int> data(100001,0);

    for(int i = 1 ; i <= 100000 ; i++){
        if(flagMap.at(i) && flagMap.at((i + 1) >> 1)){
            data.at(i) = data.at(i - 1) + 1;
        }else{
            data.at(i) = data.at(i - 1);
        }
    }

    for(int i = 0 ; i < Q ; i++){
        cout << data.at(high.at(i)) - data.at(low.at(i) - 1) << endl;
    }
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
using namespace std;
const int nmax=100005;
map<int,int> ap,norm;
vector<int> v[nmax];
int viz[nmax],a[nmax],b[nmax];
int n,i,j,nr,edges,cc;
void dfs(int x)
{
    viz[x]=1;
    for(int i=0;i<v[x].size();i++)
        if(!viz[v[x][i]])
           dfs(v[x][i]);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i],a[0]^=a[i];
    for(j=1;j<=n;j++)
        cin>>b[j],b[0]^=b[j];
    for(i=0;i<=n;i++)
        ap[a[i]]++;
    for(i=0;i<=n;i++)
        ap[b[i]]--;
    for(i=0;i<=n;i++)
        if(ap[a[i]]||ap[b[i]])
    {
        cout<<"-1";
        return 0;
    }
    for(i=0;i<=n;i++)
        if((!norm[a[i]])&&(a[i]!=b[i]||i==0))
          norm[a[i]]=++nr;
    if(!norm[b[0]])
        norm[b[0]]=++nr;
    for(i=1;i<=n;i++)
        if((a[i]!=b[i]))
    {
        a[i]=norm[a[i]];
        b[i]=norm[b[i]];
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
        edges++;
    }
    for(int i=1;i<=nr;i++)
        if((!viz[i]))
          dfs(i),cc++;
    cout<<edges+cc-1<<'\n';
    return 0;
}


Measured memory_bytes: 19456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
const int maxc=3e3+10;
const int N=2e5+10;
typedef pair<int,int> P;
map<ll,ll> mp;
ll n,a,b,c,d,inf;
ll dfs(ll now){
    if(mp[now])
        return mp[now];
    ll ans=inf;
    if((__int128)now*d>inf)
        ans=inf;
    else
        ans=now*d;
    for(int i=0;i<5;i++){
        ll val=now-i;
        if(val==0){
            ans=min(d*i,ans);
            return mp[now]=ans;
        }
        if(val%2==0)
            ans=min(ans,dfs(val/2)+a+d*i);
        if(val%3==0)
            ans=min(ans,dfs(val/3)+b+d*i);
        if(val%5==0)
            ans=min(ans,dfs(val/5)+c+d*i);
    }
    for(int i=1;i<5;i++){
        ll val=now+i;
        if(val%2==0)
            ans=min(ans,dfs(val/2)+a+d*i);
        if(val%3==0)
            ans=min(ans,dfs(val/3)+b+d*i);
        if(val%5==0)
            ans=min(ans,dfs(val/5)+c+d*i);
    }

    return mp[now]=ans;
}

int main()
{
    int t;
    scanf("%d",&t);
    inf=1e18;
    while(t--){
        scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
        mp.clear();
        printf("%lld\n",dfs(n));
    }
    return 0;
}

Measured memory_bytes: 6684
/*
ID: Barry Wang
LANG: C++11
TASK: 
*/
#include <bits/stdc++.h>
using namespace std;
typedef queue<int> qi;
typedef vector<int> vi;
const int inf=(1<<29);
int n,m;
struct node{
	int u,v,w;
}E[2000005];
int p=0;
int f[1000005],ind[1000005];
bool used[1000005];
vi G[1000005];
int dis[1000005]; 
qi q;
bool comp(node a,node b){
	return a.w<b.w;
}

inline int fa(int x){
	if(f[x]!=x){
		f[x]=fa(f[x]);
	}
	return f[x];
}

inline void unite(int l,int r){
	for(int i=l;i<=r;++i){
		f[E[i].u]=E[i].u;used[E[i].u]=0;ind[E[i].u]=-1;
		f[E[i].v]=E[i].v;used[E[i].v]=0;ind[E[i].v]=-1;
	}
	for(int i=l;i<=r;++i){
		if(fa(E[i].u)!=fa(E[i].v)){
			f[fa(E[i].u)]=fa(E[i].v);
		}
	}
	for(int i=l;i<=r;++i){
		int fu=fa(E[i].u),fv=fa(E[i].v);
		if(!used[E[i].u]){
			if(ind[fu]==-1){
				ind[fu]=++p;
			}
			G[E[i].u].push_back(ind[fu]);
			G[ind[fu]].push_back(E[i].u);
			used[E[i].u]=1;
		}
		if(!used[E[i].v]){
			if(ind[fv]==-1){
				ind[fv]=++p;
			}
			G[E[i].v].push_back(ind[fv]);
			G[ind[fv]].push_back(E[i].v);
			used[E[i].v]=1;
		}
	}
} 
int main(){
	cin>>n>>m;
	p=n;
	for(int i=1;i<=m;++i){
		cin>>E[i].u>>E[i].v>>E[i].w;
	}
	sort(E+1,E+m+1,comp);
	int l=1;
	for(int i=1;i<m;++i){
		if(E[i].w!=E[i+1].w){
			unite(l,i);
			l=i+1;
		}
	}
	unite(l,m);
	memset(dis,-1,sizeof(dis));
	dis[1]=0;
	q.push(1);
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int i=0;i<G[x].size();++i){
			int y=G[x][i];
			if(dis[y]==-1){
				dis[y]=dis[x]+1;
				q.push(y);
			} 
		}
	}
	if(dis[n]==-1)
	{
		puts("-1");
		return 0;
	}
	cout<<dis[n]/2<<'\n';
	return 0;
}


Measured memory_bytes: 47360
use strict;
my $n = <>;
my @a = sort { $b <=> $a } glob<>;
$a = 0;
$b = 0;
for (0...$n) {
  $a += @a[$_] if $_ % 2 == 0;
  $b += @a[$_] if $_ % 2 == 1;
}
print $a - $b;

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

int main()
{
    int N;
    cin >> N;
    set<int> s;
    vector<int> A(N);
    rep(i, N)
    {
        cin >> A[i];
        if (s.find(A[i]) == s.end())
        {
            s.insert(A[i]);
        }
        else
        {
            s.erase(A[i]);
        }
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 5248
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

#define mid ((l+r)>>1)
const int N=1e4+9;
const int Inf=1e9+7;

struct node
{
	int x,y;
}p[N];

struct pts
{
	int x,id;
	bool operator < (pts o)const
	{
		return x<o.x;
	}
}pt[N<<1];

int n,ans=0;
vector<int> g[N<<3];
int low[N<<1],pre[N<<1],scc[N<<1],scccnt,dfn;
int rp[N<<1],stk[N<<1],top,ptop;

inline void chkmin(int &a,int b){if(a>b)a=b;}
inline void chkmax(int &a,int b){if(a<b)a=b;}

inline void add(int u,int v)
{
	g[u].push_back(v);
}

inline void dfs(int u)
{
	low[u]=pre[u]=++dfn;
	stk[++top]=u;
	for(int i=0,e=g[u].size(),v;i<e;i++)
		if(!low[(v=g[u][i])])
		{
			dfs(v);
			chkmin(low[u],low[v]);
		}
		else if(!scc[v])
			chkmin(low[u],pre[v]);
	if(low[u]==pre[u])
	{
		scccnt++;
		do
			scc[stk[top]]=scccnt;
		while(stk[top--]!=u);
	}
}	

inline void build(int x,int l,int r)
{
	if(l==r)
		return;
	build(x<<1,l,mid);
	build(x<<1|1,mid+1,r);
	add((x<<1)+ptop,x+ptop);
	add((x<<1|1)+ptop,x+ptop);
}

inline void adds(int x,int l,int r,int dl,int dr,int id)
{
	if(dl==l && r==dr)
	{
		add(id,x+ptop);
		return;
	}
	if(dr<=mid)
		adds(x<<1,l,mid,dl,dr,id);
	else if(mid<dl)
		adds(x<<1|1,mid+1,r,dl,dr,id);
	else
	{
		adds(x<<1,l,mid,dl,mid,id);
		adds(x<<1|1,mid+1,r,mid+1,dr,id);
	}
}

inline bool judge(int k)
{
	dfn=scccnt=0;
	for(int i=0;i<ptop;i++)
		g[i].clear();
	memset(low,0,sizeof(low));
	memset(scc,0,sizeof(scc));

	//build(1,1,ptop);
	//for(int i=0;i<ptop;i++)
	//	adds(1,1,ptop,pt[i].x-k,pt[i].x,pt[i].id);

	
	for(int i=0;i<ptop;i++)
	{
		for(int j=i-1,cnt=1;~j && pt[j].x+k>pt[i].x && cnt<=50;j--,cnt++)
		{
			add(pt[i].id,pt[j].id^1);
			add(pt[j].id,pt[i].id^1);
		}
	}
	

	for(int i=0;i<ptop;i++)
		if(!low[i])
			dfs(i);
	for(int i=0;i<n;i++)
		if(scc[i<<1]==scc[i<<1|1])
			return false;
	return true;
}

int main()
{
	n=read();
	int l=0,r=0,mids,ans=0;
	for(int i=0;i<n;i++)
	{
		p[i].x=read();
		p[i].y=read();
		if(p[i].x>p[i].y)swap(p[i].x,p[i].y);
		chkmax(r,p[i].y);
		pt[i<<1].x=p[i].x;pt[i<<1].id=i<<1;
		pt[i<<1|1].x=p[i].y;pt[i<<1|1].id=i<<1|1;
	}
	ptop=n*2;
	sort(pt,pt+ptop);
	while(l<=r)
	{
		mids=l+r>>1;
		if(judge(mids))
			ans=mids,l=mids+1;
		else
			r=mids-1;
	}

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


Measured memory_bytes: 15744
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vishal Burman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BTripleDots solver = new BTripleDots();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTripleDots {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = Integer.parseInt(in.readLine());
            String str = in.readLine();
            if (str.length() > n) {
                out.println(str.substring(0, n) + "...");
            } else
                out.println(str);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0) {
                s = readLine0();
            }
            return s;
        }

    }
}



Measured memory_bytes: 36108
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
#define endl             "\n"
// -----------------<Container manipulation / traversal macros>------------------
#define mp                 make_pair
#define pb                 push_back
#define ff                 first
#define ss                 second
#define sz(x)             ((int)((x).size()))
#define all(x)             (x).begin(),(x).end()
#define rep(i,n)         for(ll (i)=0;(i)<(n);(i)++)
#define forn(i,a,b)     for(ll (i)=(a);(i)<=(b);(i)++)
#define fill(l,a)        memset((l) , (a) , sizeof(l))
// -----------------<Some common useful functions>------------------
#define maX(a,b)        ( (a) > (b) ? (a) : (b))
#define miN(a,b)        ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)   ( (n >> b) & 1)
#define INDEX(arr,i)      ( lower_bound(all(arr),i)-arr.begin())
#define in(b,a)         ( (b).find(a) != (b).end())
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector< std::vector<ll> > matrix;
typedef map<ll,ll> mii;
typedef vector<pii> vpii;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}
ll lcm(ll a,ll b)
{
    return(a/gcd(a,b)*b);
}
ll power(ll a,ll b,ll p)
{
    ll res=1;
    a%=p;
    while(b>0)
    {
        if(b&1)
        res=res*a%p;
        a=a*a%p;
        b>>=1;
    }
    return(res);
}
/*ll b_search(ll arr[],ll n,ll s)
{
    ll l=0,r=n-1;
    while(l<=r)
    {
        ll mid=l+(r-l)/2;
        if(arr[mid]==s)
        return(mid);
        if(arr[mid]<s)
        l=mid+1;
        else
        r=mid-1;
    }
    return(-1);
}*/
void solve()
{
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    ll n=s.length();
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
        arr[i]=((s[i]-'0')*power(10,i,2019))%2019;
    }
    ll dp[n];
    dp[0]=arr[0];
    for(ll i=1;i<n;i++)
    {
        dp[i]=(dp[i-1]+arr[i])%2019;
    }
    map<ll,ll> mp;
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        if(dp[i]==0)
            ans++;
        ans+=mp[dp[i]];
        mp[dp[i]]++;
    }
    cout<<ans<<endl;
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);
}


Measured memory_bytes: 6896
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        long K = scan.nextLong();
        char[] data = S.toCharArray();
        char current = ' ';
        int count = 0;
        List<Pair> list = new ArrayList<>();
        for (int i = 0; i < data.length; i++) {
            if (current != data[i]) {
                if (0 < count) {
                    Pair p = new Pair();
                    p.x = current;
                    p.count = count;
                    list.add(p);
                }
                current = data[i];
                count = 0;
            }
            count += 1;
            if (i == data.length - 1) {
                Pair p = new Pair();
                p.x = current;
                p.count = count;
                list.add(p);
            }
        }
        if (list.get(0).x != list.get(list.size()-1).x) {
            long ans = 0;
            for (int i = 0; i < list.size(); i++) {
                int cnt = list.get(i).count;
                ans += cnt / 2;
            }
            System.out.println(ans * K);
            return;
        }
        if (list.size() == 1) {
            int first = list.get(0).count;
            long ans = (first*K) / 2;
            System.out.println(ans);
            return;
        }
        long ans = 0;
        for (int i = 1; i < list.size()-1; i++) {
            int cnt = list.get(i).count;
            ans += cnt / 2;
        }
        ans *= K;
        int first = list.get(0).count;
        int last = list.get(list.size()-1).count;
        ans += first/2;
        ans += last/2;
        ans += ((first+last)/2) * (K - 1);
        System.out.println(ans);
    }

    class Pair {
        char x;
        int count;
    }
}


Measured memory_bytes: 21716
# coding: utf-8

import sys
import math

import array
import bisect
import collections
from collections import Counter, defaultdict
import fractions
import heapq
import re

sys.setrecursionlimit(1000000)


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

def argsort(l, reverse=False):
    return sorted(range(len(l)), key=lambda i: l[i], reverse=reverse)

def argmin(l):
    return l.index(min(l))

def YESNO(ans, yes="YES", no="NO"):
    print([no, yes][ans])

II = lambda: int(input())
MI = lambda: map(int, input().split())
MIL = lambda: list(MI())
MIS = lambda: input().split()


def main():
    c = Counter()
    for _ in range(3):
        i, j = MI()
        c[i] += 1
        c[j] += 1
    return c.most_common(1)[0][1] == 2


if __name__ == "__main__":
    YESNO(main())


Measured memory_bytes: 5652
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
int map[15][15];
void floyd(int n)
{
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			for(int k=0;k<n;++k)
			{
				map[j][k]=min(map[j][k],map[j][i]+map[i][k]);
			}
		}
	}
}
void init(int n)
{
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<i;++j)
		{
			map[i][j]=map[j][i]=inf;
		}
		map[i][i]=0;
	}
}
int main()
{
	int n;
	while(scanf("%d",&n),n)
	{
		init(15);int m=0;
		for(int i=0;i<n;++i)
		{
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			map[a][b]=map[b][a]=min(map[a][b],c);
			m=max(max(m,a),b);
		}
		floyd(m+1);
		int ans=inf,res=0;
		for(int i=0;i<=m;++i)
		{
			int p=0;
			for(int j=0;j<=m;++j)
			{
				if(map[i][j]!=inf)
				{
					p+=map[i][j];
				}
			}
			if(p<ans)
			{
				ans=p;res=i;
			}
		}
		printf("%d %d\n",res,ans);
	}
	return 0;
}


Measured memory_bytes: 3208
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    for(int i=0;i<n;i++){
        if(i+1==k){
            cout << (s[i]=='A'?'a':(s[i]=='B'?'b':'c'));
        }else{
            cout << s[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    W = int(input())

    weight = [1]
    pow6 = 6
    while pow6 <= W:
        weight.append(pow6)
        pow6 *= 6
    pow9 = 9
    while pow9 <= W:
        weight.append(pow9)
        pow9 *= 9

    N = len(weight)

    MAX_N = 15
    MAX_W = 100005
    INF = 1000000005
    dp = [[INF for _ in range(MAX_W)] for _ in range(MAX_N)]
    for i in range(N + 1):
        dp[i][0] = 0

    for i in range(N):
        for j in range(W + 1):
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
            if j >= weight[i]:
                dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][j - weight[i]] + 1)

    print(dp[N][W])


if __name__ == '__main__':
    main()


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

int main()
{
	int a,b,c,x; cin>>a>>b>>c>>x;
  int wa=0;
  int count=0;
  for(int i=0;i<=a;i++){
  wa+=500*i;
    for(int j=0;j<=b;j++){
    wa+=100*j;
      for(int k=0;k<=c;k++){
      wa+=50*k;
        if(wa==x){
        count++;
        }
      wa-=50*k;
      }
    wa-=100*j;
    }
  wa-=500*i;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return 1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////

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

vector<ll> vec{};

map<ll, ll> mp;

rep(i, n){
ll t;
cin>>t;
if(!mp.count(t)){
	mp[t]=1;
	vec.push_back(t);
}
else{
	mp[t]++;
}

}
ll ans=0;

for(int i=0;i<vec.size();i++){
	ll p=vec[i];
	ll val=mp[p];
	if(val%2){ans++;}
}

cout<<ans<<endl;
return 0;






}




Measured memory_bytes: 7284
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[5];
	cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
	int ag[5]={a[0]%10,a[1]%10,a[2]%10,a[3]%10,a[4]%10};
	int mn=10000000,mi;
	for(int i=0;i<5;i++)
	{
		if(ag[i]<mn&&ag[i]!=0)
		{
			mn=ag[i];
			mi=i;
		}
	}
	int ans=0;
	for(int i=0;i<5;i++)
	{
		if(mi!=i)
		ans+=(a[i]+10-1)/10*10;
		else
		ans+=a[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256