akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, start, stop) for (ll i = start; i < stop; i++)
#define FORR(i, start, stop) for (ll i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<ll>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<ll>());
#define REMOVE(v,n) remove(vector<ll> v,v+v.size(),ll n)
#define ERASE(v,n) v.erase(v.begin()+n);
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }
//string al="abcdefghijklmnopqrstuvwxyz";
//vector< vector<int> > v (size1, vector<int>(size2) );



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    string S;
    cin>>N>>S;
    vector< vector<ll> > dp (N+1, vector<ll>(N+1) );

    FOR(i,0,N+1){
        dp[0][i]=0;
        dp[i][0]=0;
    }

    ll ans=0;
    ll tem=0;
    FOR(i,0,N){
        FOR(j,0,N){
            if(S[i]==S[j])dp[i+1][j+1]=dp[i][j]+1;
            else dp[i+1][j+1]=0;
            tem=0;
            if(i<=j-dp[i+1][j+1] || j<=i-dp[i+1][j+1])tem=dp[i+1][j+1];
            ans=max(ans,tem);
        }
    }

    cout<<ans<<endl;
    
}
//601

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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;


int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   int n; cin >>n;
   ll l1 = 2, l2= 1;
   ll ans;
   if(n == 0)
   {
      cout << 2 << nl;
      return 0;
   }
   if(n==1)
   {
      cout << 1 << nl;
      return 0;
   }
   for(int i = 2; i <= n; i++ )
   {
      ans = l2 + l1;
      l1 = l2;
      l2 = ans;
   }
   cout << ans << nl;

   return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<char> t(q), d(q);
  rep(i, q) cin >> t[i] >> d[i];

  int l, r;
  // left side
  l = -1;
  r = n;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    int pos = mid;

    bool f = false;
    rep(i, q) {
      if (t[i] != s[pos]) continue;
      pos = pos + (d[i] == 'L' ? -1 : 1);
      if (pos < 0) f = true;
      if (!(0 <= pos && pos < n)) break;
    }

    if (f)
      l = mid;
    else
      r = mid;
  }
  int lcnt = l + 1;

  // right side
  l = -1;
  r = n;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    int pos = mid;

    bool f = false;
    rep(i, q) {
      if (t[i] != s[pos]) continue;
      pos = pos + (d[i] == 'L' ? -1 : 1);
      if (pos >= n) f = true;
      if (!(0 <= pos && pos < n)) break;
    }

    if (f)
      r = mid;
    else
      l = mid;
  }
  int rcnt = (n - r);

  cout << n - lcnt - rcnt << endl;
}


Measured memory_bytes: 900
/*********** Template Starts Here ***********/

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

#define MAX 500
#define ll long long
#define ull unsigned long long
#define ___   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = b; i >= a; i--)
#define debug(x) cout << #x << " " << x << endl;
#define in(x) cin>>x;
#define out(x) cout<<x;
#define gap cout<<" ";
#define nl cout<<endl;
#define cs(x) cout<<"Case "<<x<<": ";
/*********** Template Ends Here ***********/
/** ################################## Code starts here ################################### **/

int main()
{
    ___
    int K,cnt=0;
    ll N;
    in(N) in(K)
    while(N!=0)
    {
    N/=K;
    cnt++;
    }
    out(cnt)
    return 0;
}

/** ################################## Happy Coding ################################### **/


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int a, b, i;
	scanf("%d %d", &a, &b);
	
	if (a <= b) {
		for (i = 0; i < b; i++)
			printf("%d", a);
	}
	else {
		for (i = 0; i < a; i++)
			printf("%d", b);
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define MAX 500000

int H, A[MAX];
void maxHeapify(int i) {
  int l, r, largest, ch;
  l = 2*i;
  r = 2*i + 1;
  if (l <= H && A[l] > A[i]) largest = l;
  else largest = i;

  if (r <= H && A[r] > A[largest]) largest = r;

  if (largest != i) {
    ch = A[i]; A[i] = A[largest]; A[largest] = ch;
    maxHeapify(largest);
  }
}

void buildMaxHeap() {
  int i;
  for (i = H/2; i> 0; i--) maxHeapify(i);
}

int main() {
  int i;
  scanf("%d", &H);
  for (i =1; i < H+1; i++) scanf("%d", &A[i]);
  buildMaxHeap();

  for (i = 1; i < H+1; i++){
    printf(" %d", A[i]);
  }
    printf("\n");
  return 0;
}



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

using namespace std;
// using Graph = vector<vector<ll>>;

typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

const ll MOD = 1000000007;
const ll INF = 1e18; //1*10^18
const double PI = 3.14159265;

int ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}

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

ll powll(ll a, ll n)
{ //O(log n)
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a;
    }
    a = a * a;
    n >>= 1; //(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a, ll n, ll mod) //O(log n)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1; //(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number = to_string(num);
  return number.length();
}

const ll MAX = 1e6;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() //MODは素数じゃないとだよ！！
{
  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;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind
{
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N)
  { //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x)
  { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y)
  {                   // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry)
      return;     //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y)
  { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

string s[500000];
int main()
{
  // COMinit();
  // srand((unsigned int)time(NULL));//--> rand()
  ll i, j, k, l, ans = 0;
  ll n, count = 1, saidai = 0;
  cin >> n;
  for (i = 0; i < n; i++)
  {
    cin >> s[i];
  }
  sort(s + 0, s + n);

  count = 1;
  for (i = 1; i < n; i++)
  {
    if (s[i] == s[i - 1])
    {
      count++;
    }
    else
    {
      saidai = max(saidai, count);
      count = 1;
    }
  }
  saidai = max(saidai, count);

  count = 1;
  for (i = 1; i < n; i++)
  {
    if (s[i] == s[i - 1])
    {
      count++;
    }
    else
    {
      if (count == saidai)
      {
        cout << s[i - 1] << endl;
      }
      count = 1;
    }
  }
  if (count == saidai)
  {
    cout << s[i - 1] << endl;
  }

  // cout << saidai << endl;
  // cout << ans << endl;
}


Measured memory_bytes: 16768
import math

def conbination(n, r): #nCrを求める
    # nCr = n! //(r! * (n-r)!)
    return math.factorial(n) //(math.factorial(r) * math.factorial(n-r))

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse = True)
ave = (sum(v[:A]))/A
print (ave)

tmp_count = 1 #最初のA個の中にA番目と同じものが何個あるか
tmp = v[0]
for i in range(1, A):
    if v[i] == tmp:
        tmp_count += 1
    else:
        tmp = v[i]
        tmp_count = 1

total_count = tmp_count #全体でA番目と同じものが何個あるか
for i in range(A, N):
    if tmp == v[i]:
        total_count += 1
    else:
        break

ans = 0
if ave == tmp: #ここまで全て同じとき
    # print ('A')
    # for i in range(A, total_count + 1):
    for i in range(A, min(total_count + 1, B + 1)):
        ans += conbination(total_count, i)
else:
    ans += conbination(total_count, tmp_count)

print (ans)


Measured memory_bytes: 3064
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto a = readNum!int;

  writeln(a^^3);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;
using llong = long long;
const int MOD=1000000007;


int main(int argc, char**argv){
    string s;
    cin >> s;

    int ans = 99999;
    for (int i = 0; i < s.size() - 2; i++){
        int diff = abs(753 - stoi(s.substr(i, 3)));
        ans = min(ans, diff);
    }
    cout << ans << endl;

    return 0;
}















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

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

    int time = 0;
    for (int i = 0; i < N; i++){
        time += job[i].second;
        if(time > job[i].first){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <unordered_map>
using namespace std;

constexpr int NUMBER_OF_CELL = 9;
constexpr array<int, 4> d{1, 3, 8, 6};

typedef array<int, NUMBER_OF_CELL> field;
typedef pair<int, unsigned> state;

unsigned encode(const field &f) {
	unsigned res = 0;
	for(const auto &cell : f) {
		res = res * NUMBER_OF_CELL + cell;
	}
	return res;
}

field decode(unsigned code) {
	field res;
	for(auto &cell : res) {
		cell = code % NUMBER_OF_CELL;
		code /= NUMBER_OF_CELL;
	}
	reverse(res.begin(), res.end());
	return res;
}

int ch, cv;

int dijkstra(const unsigned s, const unsigned g) {
	priority_queue<state, vector<state>, greater<state>> que;
	unordered_map<unsigned, int> dist;
	que.emplace(0, s);
	dist[s] = 0;

	while(!que.empty()) {
		const int current_dist = que.top().first;
		const unsigned code = que.top().second;
		que.pop();

		if(dist[code] < current_dist) continue;
		if(code == g) return current_dist;

		const field current = decode(code);
		const int current_empty = find(current.begin(), current.end(), 0) - current.begin();

		for(int i = 0; i < 4; ++i) {
			field next(current);
			const int next_empty = (current_empty + d[i]) % NUMBER_OF_CELL;
			swap(next[current_empty], next[next_empty]);
			const unsigned next_code = encode(next);
			const int next_dist = current_dist + (i & 1 ? cv : ch);
			if(!dist.count(next_code) || dist[next_code] > next_dist) {
				dist[next_code] = next_dist;
				que.emplace(next_dist, next_code);
			}
		}
	}
	assert(false);
}

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

	while(cin >> ch >> cv && ch) {
		field start, goal;
		for(auto &cell : start) cin >> cell;
		for(auto &cell : goal)  cin >> cell;
		cout << dijkstra(encode(start), encode(goal)) << endl;
	}
	return EXIT_SUCCESS;
}

Measured memory_bytes: 19700
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d,e;
  cin>>a>>b;
  c=a-b;
  e=b-1;
  if(c==0){
    d=1;
  }else{
    d=1;
  while(c>0){
    c-=e;
    d++;
  }
  }
    cout<<d<<endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
  int x,prime[1000000];
long long int i,j;

  for(i=0;i<1000000;i++)
    prime[i]=0;
  
  prime[0]=1;
  prime[1]=1;
  for(i=2;i*i<100000;i++){
    if(prime[i]==0){
      for(j=i*2;j<100000;j+=i){
	prime[j]=1;
      }
    }
  }

  while(scanf("%d",&x)!=EOF){
    int count=0;

      for(i=1;i<=x;i++){
      if(prime[i]==0 && prime[x+1-i]==0){
	count++;
      }
    }
      cout << count << endl;
  }
  
  return 0;
}

Measured memory_bytes: 0
import java.util.*;


public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int size = a*b;
		int lap = a*2 + b*2;
		System.out.println(size + " " + lap);
    }
}


Measured memory_bytes: 26144
#include<bits/stdc++.h>
#define mo 1000000007
#define add(a,b) (a+b>=mo)?(a+=b-mo):(a+=b)
using namespace std;
int f[2][22][1<<19],a[22][22];
int lowbit(int s){return s&(-s);}
int main()
{
	int n,m,q;scanf("%d%d%d",&n,&m,&q);
	memset(a,255,sizeof(a));
	while (q--)
	{
		int u,v,w;scanf("%d%d%d",&u,&v,&w);
		a[u][v]=w;
	}
	f[1][0][0]=1;
	for (int i=1;i<=m;i++)
	{
		memset(f[(i&1)^1],0,sizeof(f[(i&1)^1]));
		for (int j=0;j<n;j++)
		for (int s=0;s<(1<<(n-1));s++) if (f[i&1][j][s])
		{
			if (j==n-1)
			{
				add(f[(i&1)^1][0][s],f[i&1][j][s]);
			}
			else
			{
				if ((a[i][j+1]!=1)&&((s&(1<<j))==0)) add(f[i&1][j+1][s],f[i&1][j][s]);
				if (a[i][j+1]!=0)
				{
					if (s&(1<<j)) add(f[i&1][j+1][s],f[i&1][j][s]);
					else add(f[i&1][j+1][s-(lowbit(s>>j)<<j)+(1<<j)],f[i&1][j][s]);
				}
			}
		}
	}
	int ans=0;
	for (int s=0;s<(1<<(n-1));s++) add(ans,f[m&1][n-1][s]);
	printf("%d\n",ans);
}

Measured memory_bytes: 90496
def isValid(List):
    for num in List:
        if num % 2 != 0:
            return False
    return True

n = int(input())
list_x = list(map(int, input().split(' ')))
count = 0
while  (isValid(list_x)):
    count += 1
    for i in range(n):
        list_x[i] /= 2

print(count)



Measured memory_bytes: 2940
#%%
import bisect

#%%
a,b,q = map(int, input().split())
INF = 10**18
shrines = [-INF] + [int(input()) for _ in range(a)] + [INF]
temples = [-INF] + [int(input()) for _ in range(b)] + [INF]

for _ in range(q):

    start = int(input())

    # スタート位置より右にある神社のうち、もっともスタート位置に近いもの
    shrine_east = shrines[bisect.bisect_right(shrines, start)]
    # スタート位置より右にある寺のうち、もっともスタート位置に近いもの
    temple_east = temples[bisect.bisect_right(temples, start)]

    # スタート位置より左にある神社のうち、もっともスタート位置に近いもの
    shrine_west = shrines[bisect.bisect_right(shrines, start) - 1]
    # スタート位置より左にある寺のうち、もっともスタート位置に近いもの
    temple_west = temples[bisect.bisect_right(temples, start) - 1]

    ans = INF

    for shrine in [shrine_east, shrine_west]:
        for temple in [temple_east,temple_west]:
            cur = min(abs(shrine-start), abs(temple-start)) + abs(shrine-temple)
            ans = min(ans,cur)

    print(ans)



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

int x, sum=0;

int main() {
	cin >> x;
 	int a[x], b[x];
 	for (int i=0; i<x-1; i++) cin>>b[i];
	
	a[0]=b[0];
	a[x-1]=b[x-2];
	
	for (int i=1; i<x-1; i++) {
		a[i]=min(b[i], b[i-1]);
 	}
	 
	for (int i=0; i<x; i++) sum+=a[i];
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
ll n,m,r;
vector<bool>check;
vector<ll>rr;
vector<vector<ll>>w(205,vector<ll>(205,10e6));
ll res=10e9;
ll kari=0;
ll ha=0;
void dfs(ll v){
  check[v]=true;
  ll count=0;
  for(int i=0; i<r; i++){
    if(check[rr[i]]) count++;
  }
  if(count==r){
    //cout << ha << "  " << kari << endl;
    res=min(res,kari);
  }
  
  for(int i=0; i<r; i++){
    ll u=rr[i];
    if(check[u])continue;
    kari+=w[v][u];
    dfs(u);
    kari-=w[v][u];
  }
  
  check[v]=false;
  
}

int main(){
  cin >> n >> m >> r;
  check.resize(n);
  rr.resize(r);
  
  for(int i=0; i<r; i++){
    cin >> rr[i];
    rr[i]--;
    //cout << rr[i] << endl;
  }
  
  for(int i=0; i<m; i++){
    ll a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    w[a][b]=c;
    w[b][a]=c;
  }
  
  //for(int i=0; i<n; i++) w[i][i]=0;
  
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
     for(int j=0; j<n; j++){
       w[i][j]=min(w[i][j],w[i][k]+w[k][j]);
     }
    }
  }
  
  ll ans=10e9;
  for(int i=0; i<r; i++){
    for(int j=0; j<r; j++){
      check[rr[j]]=false;
    }
    res=10e9;
    kari=0;
    dfs(rr[i]);
    ans=min(ans,res);
    ha++;
  }
  
  cout << ans << endl;
  
}
  
  
  


Measured memory_bytes: 640
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 200002;

int n;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++)
        ans += 1LL * (n - i + 1) * (n - i + 2) / 2;
    for(int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        ans -= 1LL * min(u, v) * (n - max(u, v) + 1);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	int x, t;
	cin >> x >> t;

	cout << max(0, x - t) << endl;

	return 0;
}


Measured memory_bytes: 256
"""
WA出したやつ、例えば[1, 2, 2, 3, 3, 2]は4,5番目の3を2に減らせばYesになるが、
前から見ていって減少しているときだけ縮めるアルゴリズムでは[1, 2, 2, 3, 2, 2]となりNoになってしまう。
なので、後ろから見ていく。
"""
import sys

N = input()
H = list(map(int, input().split()))

for i in range(len(H)-1, 0, -1):
    if H[i-1] > H[i]:
        H[i-1] -= 1
    if H[i-1] > H[i]:
        print('No')
        sys.exit()

print('Yes')

Measured memory_bytes: 14224
#include <cstdio>
#include <algorithm>

namespace Polyspace {
	template<int Mod, int G, int iG, int MS>
	struct Polyclass {
		typedef long long LL;
		
		inline int qPow(int b, int e) {
			int a = 1;
			for (; e; e >>= 1, b = (LL)b * b % Mod)
				if (e & 1) a = (LL)a * b % Mod;
			return a;
		}
		
		int Sz, InvSz, R[MS];
		inline int getB(int N) { int Bt = 0; while (1 << Bt < N) ++Bt; return Bt; }
		inline void InitFNTT(int N) {
			int Bt = getB(N);
			if (Sz == (1 << Bt)) return ;
			Sz = 1 << Bt, InvSz = Mod - (Mod - 1) / Sz;
			for (int i = 1; i < Sz; ++i) R[i] = R[i >> 1] >> 1 | (i & 1) << (Bt - 1);
		}
		
		inline void FNTT(int *A, int Ty) {
			for (int i = 0; i < Sz; ++i) if (R[i] < i) std::swap(A[R[i]], A[i]);
			for (int j = 1, j2 = 2; j < Sz; j <<= 1, j2 <<= 1) {
				int wn = qPow(~Ty ? G : iG, (Mod - 1) / j2), w, X, Y;
				for (int i = 0, k; i < Sz; i += j2) {
					for (k = 0, w = 1; k < j; ++k, w = (LL)w * wn % Mod) {
						X = A[i + k], Y = (LL)w * A[i + j + k] % Mod;
						A[i + k] -= (A[i + k] = X + Y) >= Mod ? Mod : 0;
						A[i + j + k] += (A[i + j + k] = X - Y) < 0 ? Mod : 0;
					}
				}
			}
			if (!~Ty) for (int i = 0; i < Sz; ++i) A[i] = (LL)A[i] * InvSz % Mod;
		}
		
		inline void PolyConv(int *_A, int N, int *_B, int M, int *_C, int tN = -1) {
			if (tN == -1) tN = N + M - 1;
			static int A[MS], B[MS];
			InitFNTT(N + M - 1);
			for (int i = 0; i < N; ++i) A[i] = _A[i];
			for (int i = N; i < Sz; ++i) A[i] = 0;
			for (int i = 0; i < M; ++i) B[i] = _B[i];
			for (int i = M; i < Sz; ++i) B[i] = 0;
			FNTT(A, 1), FNTT(B, 1);
			for (int i = 0; i < Sz; ++i) A[i] = (LL)A[i] * B[i] % Mod;
			FNTT(A, -1);
			for (int i = 0; i < tN; ++i) _C[i] = A[i];
		}
	};
	Polyclass<998244353, 3, 332748118, 1 << 19> Poly1;
	Polyclass<1004535809, 3, 334845270, 1 << 19> Poly2;
}

namespace WTFisThis {
	typedef long long LL;
	const int Mod = 200003, Phi = Mod - 1;
	const int G = 2, iG = (Mod + 1) / G;
	
	int A[Mod], iA[Mod];
	void Init() {
		A[0] = 1;
		for (int i = 1; i <= Phi; ++i) A[i] = (LL)A[i - 1] * G % Mod;
		for (int i = 0; i < Phi; ++i) iA[A[i]] = i;
	}
}
using namespace WTFisThis;

typedef __int128 LLL;

int buk[Phi];
int ret1[Phi * 2];
int ret2[Phi * 2];

int main() {
	Init();
	for (int N, x = scanf("%d", &N); N; --N) {
		scanf("%d", &x);
		if (x) ++buk[iA[x]];
	}
	Polyspace::Poly1.PolyConv(buk, Phi, buk, Phi, ret1);
	Polyspace::Poly2.PolyConv(buk, Phi, buk, Phi, ret2);
	for (int i = Phi; i <= 2 * (Phi - 1); ++i) {
		ret1[i - Phi] = (ret1[i - Phi] + ret1[i]) % 998244353;
		ret2[i - Phi] = (ret2[i - Phi] + ret2[i]) % 1004535809;
	}
	for (int i = 0; i < Phi; ++i) if (buk[i]) {
		int j = 2 * i % Phi;
		ret1[j] -= buk[i], ret2[j] -= buk[i];
		if (ret1[j] < 0) ret1[j] += 998244353;
		if (ret2[j] < 0) ret2[j] += 1004535809;
	}
	for (int i = 0; i < Phi; ++i) {
		ret1[i] = ret1[i] * 499122177ll % 998244353;
		ret2[i] = ret2[i] * 502267905ll % 1004535809;
	}
	LL Ans = 0;
	for (int i = 0; i < Phi; ++i) {
		LLL val = 0;
		val += (LLL)ret1[i] * 334257240187163831ll;
		val += (LLL)ret2[i] * 668514958533372747ll;
		val %= 1002772198720536577ll;
		Ans += val * A[i];
	}
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 19592
#include <iostream>
#include <cmath>
#include<iomanip>
#include<limits>
#include<math.h>
using namespace std;
int main(void){
   int A,B,H,M;
   cin>>A>>B>>H>>M;
    double pi = 3.141592653589793;
   int t=H*60+M;
   double d=5.5*t;
   for(int i=0;i<100;i++){
       if(d-360*i<=360){
           cout<<setprecision(12)<<sqrt(A*A+B*B-2*A*B*cos((d-360*i)*pi/180))<<endl;
           return 0;
       }
   }
}


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

int main(){
  ll A;
  vector<char> c(4);
  cin>>A;
  for(int i=0;i<4;i++){
    cin>>c.at(i);
  }
  int b=100*(c.at(0)-'0')+10*(c.at(2)-'0')+(c.at(3)-'0');
  ll B=(ll)b;

  cout<<A*B/100<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
	}
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
lli solve(){
	// lli m, n;
	// cin>>m>>n;
	// if(m == n)
	// 	cout<<"Yes\n";
	// else
	// 	cout<<"No\n";
	lli a, b;
	cin>>a>>b;
	lli x = 0, y = 0;
	loop(i, 0, a)
		x = x*10+b;
	loop(i, 0, b)
		y = y*10 + a;
	string q = to_string(x);
	string z = to_string(y);
	cout<<min(q, z);
}
int main(){
	fastio;
	lli t;
	// cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <iomanip>
#include<cmath>
#include<stdio.h>
#include<map>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
#define please return
constexpr auto AC = 0;
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	vector<int> s(b, 1),dp(a+2,1);
	dp[a+1] = 0;
	rep(i, b) {
		cin >> s[i];
		dp[s[i]] = 0;
	}
	for (int i = a - 2; i >= 0; i--) {
		if (dp[i] != 0)dp[i] = (dp[i + 1] + dp[i + 2])%1000000007;
	}

	cout << dp[0] << endl;
	please AC;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
  string a,b,c;
   cin >> a >> b>> c;
   char aa=char(a[0]-32);
   char bb=char(b[0]-32);
   char cc=char(c[0]-32);
   cout << aa << bb << cc << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))a<=5



int main(){
    ll ans,a,b;
    cin >>a>>b;
    ans=b;
    if(a<=5)ans=0;
    if(a<=12)ans/=2;

    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 300010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-6
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, a, d, ans;
struct Node {
	ll x, h;
}p[SIZE];
int main() {
	io(); cin >> n >> d >> a;
	rep(i, 1, n) cin >> p[i].x >> p[i].h;
	rep(i, 1, n) p[i].h = ceil(1.0 * p[i].h / a);
	sort(p + 1, p + 1 + n, [](Node a, Node b) {
		return a.x < b.x;
	});
	vector<int> dif(n + 10, 0);
	vector<int> vec;
	rep(i, 1, n) vec.emplace_back(p[i].x);
	rep(i, 1, n) {
		dif[i] += dif[i - 1];
		p[i].h += dif[i];
		if (p[i].h < 0) continue;
		ans += p[i].h;
		int ps = upper_bound(vec.begin(), vec.end(), p[i].x + 2 * d) - vec.begin() + 1;
		dif[i] -= p[i].h;
		dif[ps] += p[i].h;
	}
	cout << ans;
}

Measured memory_bytes: 6264
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ;i++)

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

int main() {
  int l,r,d;
  cin >> l >> r >> d;
  int a=0;
  
  if(l%d==0){
    a++;
  }
  a+=r/d-l/d;
  cout << a << endl;
  return 0;

}

Measured memory_bytes: 3628
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	x, a, b := intScanner(), intScanner(), intScanner()
	if abs(a-x) < abs(b-x) {
		fmt.Println("A")
	} else {
		fmt.Println("B")
	}
}


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


def factor(n):
    res=set()
    for i in range(2,int(n**(1/2))+10):
        if n%i == 0:
            res.add(i)
            res.add(n//i)

    res.add(n)
    res.discard(1)
    return list(res)

ans = 0

ans += len(factor(n-1))


for k in factor(n):
    n2=n
    if k==1:
        continue
    while n2%k==0:
        n2//=k
    if n2%k == 1:
        ans +=1
        

print(ans)


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int table[11][11];

int main(){
    int n;
    while(cin >> n, n){
    rep(i, n)rep(j, n) cin >> table[i][j];
    rep(i, n){
        int total =0;
        rep(j, n) total += table[i][j];
        table[i][n] = total;
    }
    rep(i, n+1){
        int total =0;
        rep(j, n) total += table[j][i];
        table[n][i] = total;
    }

    rep(i, n+1){
        rep(j, n+1) printf("%5d", table[i][j]);
        cout << endl;
    }
    }
}

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

using namespace std;

long long A, B, C, D, A1, B1, Q1, Q2, ans;
int cnt = 0;

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

int main()
{
	cin >> A >> B >> C >> D;
	A1 = B / C - (A - 1) / C;
	B1 = B / D - (A - 1) / D;
	Q1 = C * D / gcd(C, D);
	Q2 = B / Q1 - (A - 1) / Q1;
	ans = B - A +  1 - A1 - B1 + Q2;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
n,m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
    
def bfs(graph, N):
    que = deque([0])
    dist = [-1]*N
    dist[0]=0
    while que:
        i = que.popleft()
        for j in graph[i]:
            if dist[j] < 0:
                que.append(j)
                dist[j]=i+1
    return dist

dist = bfs(graph, n)[1:]

if all([x>=0 for x in dist]):
    print("Yes")
    for i in dist:
        print(i)
else:
    print("No")

Measured memory_bytes: 37676
using System;

    class Program
    {
        static void Main()
        {
            string result = null;
            while (true)
            {
                string card;
                if ((card = Console.ReadLine()) == "-")
                    break;
                int num = int.Parse(Console.ReadLine());
                for (int i = 0; i < num; i++)
                {
                    int index = int.Parse(Console.ReadLine());
                    card = card.Substring(index) + card.Substring(0, index);
                }
                result += ((result == null) ? "" : " ") + card;
            }
            foreach(string res in result.Split(' '))
            {
                Console.WriteLine(res);
            }
        }
    }

Measured memory_bytes: 5404
#include<cstdio>

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

using namespace std;

int main(){
	for(int p,q;scanf("%d%d",&p,&q),p;){
		static int vis[1000000];
		rep(i,q) vis[i]=-1;

		for(int i=0;;i++){
			if(p==0){
				printf("%d 0\n",i);
				break;
			}
			if(vis[p]!=-1){
				printf("%d %d\n",vis[p],i-vis[p]);
				break;
			}
			vis[p]=i;
			p=10*p%q;
		}
	}

	return 0;
}

Measured memory_bytes: 4664
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

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

    bool flag = false;
    for(int x = 0; x <= N /4; x++){
        for(int y = 0; y <= N/7; y++){
            if(4 * x + 7 * y == N) flag = true;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}



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

int main() {
  int N, cnt=0, max=0;
  vector<int> A(26), B(26);
  string S;
  cin >> N >> S;
  for(int i=1; i<N-1; i++){
    for(int j=0; j<i; j++){
      A.at(S.at(j)-'a')++;
    }
    for(int k=i; k<S.size(); k++){
      B.at(S.at(k)-'a')++;
    }
    for(int l=0; l<26; l++){
      if(A.at(l)>0 && B.at(l)>0){
        cnt++;
      }
    }
    if(max<cnt) max=cnt;
    cnt=0;
    for(int m=0; m<26; m++){
      A.at(m)=0;
      B.at(m)=0;
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 256
let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let bs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun b -> b in
  let acc = Array.fold_left ( lxor ) 0 bs in
  Array.init 29 (fun i -> i)
  |> Array.fold_left (fun (ans, bs) i ->
      let mask = (1 lsl i) - 1 in
      let bs' =
        List.filter (fun b -> 1 lsl (i - 1) <= (b land mask)) bs @
        List.filter (fun b -> (b land mask) < 1 lsl (i - 1)) bs in
      let bs = Array.of_list bs' in
      (ans lor (Array.fold_left ( lxor ) 0 @@ 
      Array.map (fun a ->
        if
          ((a land (1 lsl i)) <> 0 && n mod 2 <> 0) <>
          (acc land (1 lsl i) <> 0) <>
          match 
            upper_bound 0 n (fun j ->
              (1 lsl i) - (a land mask) <= (bs.(j) land mask))
          with
          | 0 -> (1 lsl i) - (a land mask) <= (bs.(0) land mask)
          | i -> i mod 2 = 0
        then 1 lsl i
        else 0) as_), bs')) (0, Array.to_list bs) 
  |> fst
  |> Printf.printf "%d\n"


Measured memory_bytes: 54012
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    if N < 1000:
        print('ABC')
    else:
        print('ABD')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9156
#include <stdio.h>
 
int num(int i, int n, int s)
{
    int cnt = 0;
     
    if (n == 0){
        return (!s);
    }
     
    if (i == 10 || s < 0){
        return (0);
    }
     
    cnt += num(i + 1, n - 1, s - i);
    cnt += num(i + 1, n, s);
     
    return (cnt);
}
 
int main(void)
{
    int n, s;
     
    while (1){
        scanf("%d %d", &n, &s);
         
        if (n == 0 && s == 0){
            break;
        }
         
        printf("%d\n", num(0, n, s));
    }
     
    return (0);
}


Measured memory_bytes: 1972
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string S;
  cin>>S;

  const Int mod = 2019;
  Int N = S.size();
  map<Int, Int> cnt;
  Int num = 0;
  vector<Int> A;
  Int t = 1;
  for(Int i=0;i<N;i++){
    num = num + (S[N - i - 1] - '0') * t;
    num %= mod;
    cnt[num]++;
    A.push_back(num);
    t = t * 10 % mod;
  }

  Int ans = 0;
  t = 1;
  Int ofset = 0;
  for(Int i=0;i<N;i++){
    ans += cnt[ofset];
    Int num = S[N - 1 - i] - '0';
    ofset +=num * t % mod;
    ofset %= mod;
    t = t * 10 % mod;
    cnt[A[i]]--;

  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 5564
import java.util.*;
import java.io.*;

public class Main {
	private static final boolean local = false;
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter output;
	//char c = line.nextToken().charAt(0);

	private static void openFile() throws IOException {
		if (local) {
			String inp = "C:/Users/ztrong/Desktop/AndroidStudioProjects/Java/src/main/java/input.txt";
			String out = "C:/Users/ztrong/Desktop/AndroidStudioProjects/Java/src/main/java/output.txt";
			br = new BufferedReader(new InputStreamReader(new FileInputStream(inp)));
			output = new PrintWriter(new FileOutputStream(out));
		}
		else {
			br = new BufferedReader(new InputStreamReader(System.in));
			output = new PrintWriter(System.out);
		}
	}

	private static String _next() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());
			}
			catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	private static int nextInt() {
		return Integer.parseInt(_next());
	}

	private static long nextLong() {
		return Long.parseLong(_next());
	}

	private static double nextDouble() {
		return Double.parseDouble(_next());
	}

	private static String nextLine() {
		String str = "";
		try {
			str = br.readLine();
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		return str;
	}

	private static final int maxN = (int) 1e5 + 5;
	private static final int maxM = (int) 1e6 + 5;
	private static final int inf = (int) 1e9 + 7;

	private static int N;
	private static int[] A = new int[maxN];

	private static void init() {

	}

	private static void enter() throws IOException {
		N = nextInt();
		for (int i = 1; i <= N; ++i) {
			A[i] = nextInt();
		}
	}

	private static void solve() throws IOException {
		Arrays.sort(A, 1, N + 1);
		int a = 0, cnta = 0, b = 0, cntb = 0;
		for (int i = N; i >= 1; --i) {
			if (a == A[i]) {
				++cnta;
			}
			else if (a == 0 || cnta < 2) {
				a = A[i];
				cnta = 1;
			}
			else if (b == A[i]) {
				++cntb;
			}
			else if (b == 0 || cntb < 2) {
				b = A[i];
				cntb = 1;
			}
			if (cnta >= 4) {
				output.println((long) a * a);
				return;
			}
			if (cnta >= 2 && cntb >= 2) {
				output.println((long) a * b);
				return;
			}
		}
		output.println(0);
	}

	public static void main(String[] args) throws IOException {
		openFile();
		init();
		enter();
		solve();
		output.close();
	}
}

Measured memory_bytes: 37840
#include<bits/stdc++.h>
using namespace std;
#define maxP 100005
#define FOR(a,b,c) for(a=b;a<c;a++)
#define EPS 1e-9
typedef struct {
    double x, y;
} Point;
Point P[maxP], CH[maxP],pivot;
int cmp(const void *i, const void *j) {
    Point *a, *b;
    a = (Point *)i, b = (Point *)j;
    if(a->y != b->y)
        return a->y - b->y > 0 ? 1 : -1;
    return a->x - b->x > 0 ? 1 : -1;
}
bool myComparison(const Point &a,const Point &b)
{
	if(a.y!=b.y)
       return a.y<b.y;
    else return a.x<b.x;
}
double cross(Point *o, Point *a, Point *b) {  		// cross product
    return (a->x - o->x)*(b->y - o->y) -
        (a->y - o->y)*(b->x - o->x);
}

double dist(Point p1, Point p2) {                // Euclidean distance
  return hypot(p1.x - p2.x, p1.y - p2.y); }           // return double. jika Precision error, hilangkan saja hypot

bool angleCmp(Point &a, Point &b) {                 // angle-sorting function
  if (fabs(cross(&pivot, &a, &b)) < EPS)                               // special case
    return dist(pivot, a) < dist(pivot, b);    // check which one is closer
  double d1x = a.x - pivot.x, d1y = a.y - pivot.y;
  double d2x = b.x - pivot.x, d2y = b.y - pivot.y;
  return (atan2(d1y, d1x) - atan2(d2y, d2x)) < 0; }   // compare two angles
	/* TLE? coba ubah jadi ini 
	bool angle_comp(const point &a, const point &b) {
  int isccw = isCCW(pivot, a, b);
  if (isccw == 0) { //special case, coliear
    return dist(pivot, a) < dist(pivot, b);
  }
  return (isccw == -1); 
}*/
void convexHull(int n) {
    int P0 = 0;
  for (int i = 1; i < n; i++)
  if (P[i].y < P[P0].y || (P[i].y == P[P0].y && P[i].x < P[P0].x)) //Diurutkan dari y terkecil, jika y sama maka diutamakan x yang paling kecil.
      {P0 = i;}
  Point temp; 
  temp = P[0]; 
  P[0] = P[P0]; 
  P[P0] = temp;  //swap pivot
  pivot=P[0];
  sort(P+1,P+n,angleCmp); // sort berdasarkan angle
  int i, m = 0, t;
    for(i = 0; i < n; i++) {
        while(m >= 2 && ((cross(&CH[m-2], &CH[m-1], &P[i]) < 0) || !(dist(CH[m-1],P[i])>0)))  // mengecek apakah belok ke kanan atau ke kiri. jika collinear tidak dimasukkan, ditambahkan =.
        		m--;
        CH[m++] = P[i];
    }
    for(i = n-2, t = m+1; i >= 0; i--) {		
        while(m >= t && ((cross(&CH[m-2], &CH[m-1], &P[i]) < 0) || !(dist(CH[m-1],P[i])>0))) //mengikuti aturan diatas. jika collinear dimasukkan, n-1 diubah menjadi n-2.
            m--;
        CH[m++] = P[i];
    }
    printf("%d\n",m-1);
    for(i = 0; i < m-1; i++) {
       
        printf("%.lf %.lf\n", CH[i].x, CH[i].y);
    }
}int main()
{	
	int t,tc,i,n;
	double x,y;
	int k;
	Point contoh;
	char dummy[5];
	tc=1;
	FOR(t,0,tc)
	{
		scanf("%d",&n);
		k=0;
		FOR(i,0,n)
		{
			scanf("%lf %lf",&contoh.x,&contoh.y);
			
				P[k]=contoh;
				k+=1;
			
		}
		convexHull(k);
	}
}

Measured memory_bytes: 5992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

const int MAX = 1200000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

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


// テーブルを作る前処理
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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

int main() {
   COMinit();
   ll n,a,b;

   cin >> n >> a >>b;
   ll ans =  mod_pow(2*(1LL),n,MOD);
   ll x = 1 , y = 1;
   rep(i,a)
   {
      x = (x*(n-i))%MOD;
   }
   x=(x*finv[a])%MOD;
   rep(i,b)
   {
      y = (y*(n-i))%MOD;
   }
   
   y=(y*finv[b])%MOD;
   //cout<<ans<<endl;
   //cout<<x<<endl;
   //cout<<y<<endl;
   ans = (ans - x + MOD)%MOD;
   ans = (ans - y + MOD)%MOD;
   ans = (ans - 1 + MOD)%MOD;
   cout<<ans<<endl;
}

Measured memory_bytes: 28416
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		int R = stdIn.nextInt();
		int G = stdIn.nextInt();
		
		System.out.println(G + (G-R));

	}

}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	string s;
	cin >> s;

	if (s[0] == s[1] && s[1] == s[2]) {
		out("No");
	}
	else {
		out("Yes");
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 10000000000
#define rep(i,n) for(i=0;i<n;i++)

typedef pair<int,int> pii;


int main() {
    while(1){
        int m,t,p,r;
        cin>>m>>t>>p>>r;
        if(m==0 && t==0 && p==0 && r==0)break;
        int i;
        pair<pii,int> team[50]; //solved_num, time, team_num
        int v[50][10]={};//team_num, problem_num, wrong_num
        int time,tnum,pnum,j;
        rep(i,t)
            team[i].second=i+1;
        rep(i,r){
            cin>>time>>tnum>>pnum>>j;
            tnum--;
            pnum--;
            if(j){//WA
                v[tnum][pnum]++;
            }else{//AC
                team[tnum].first.first++;
                team[tnum].first.second-=time+v[tnum][pnum]*20;
            }
        }
        rep(i,t)
            if(team[i].first.second==0)team[i].first.second=-1000000;
        
        sort(team,team+t);
        for(i=t-1;i>0;i--){
            cout<<team[i].second;
            if(team[i].first.first==team[i-1].first.first &&
               team[i].first.second==team[i-1].first.second)
                cout<<"=";
            else
                cout<<",";
            
        }
        cout<<team[0].second<<endl;
    
    }
    return 0;
}

Measured memory_bytes: 3088