akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 1000000009
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int main(){
    setIO();
    ll n;
    cin>>n;
    ll res = fpow(10LL,n);
    res+=fpow(8LL,n);
    res%=MOD;
    res-=fpow(9LL,n);
    if(res<0)
      res+=MOD;
    res-=fpow(9LL,n);
    if(res<0)
      res+=MOD;
    cout<<res;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long a[3];
    cin>>a[0]>>a[1]>>a[2];
    if(a[0]%2==0||a[1]%2==0||a[2]%2==0){
        cout<<0<<endl;
    }else{
        sort(a,a+3);
        cout<<a[0]*a[1]<<endl;
    }
    
}


Measured memory_bytes: 256
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    dislike = []
    for _ in range(M):
        a, b = map(int, input().split())
        dislike.append((a, b))

    """
    aについて昇順に貪欲法を考えて破綻しました。。。
    （その後aの昇順にdpすることも考えたけど同じく行き詰まり）
    bについての昇順なら貪欲法がうまく回ります。
    「貪欲法はあらゆる変数に対して考えるべし」ということなのか？
    """
    dislike.sort(key=lambda x: x[1])
    cnt = 0
    last = -1 # 最後に落とした橋
    for a, b in dislike:
        if a <= last: continue
        cnt += 1
        last = b - 1
    print(cnt)



if __name__ == "__main__":
    main()


Measured memory_bytes: 79312
N,u,v = map(int,input().split())
l = []
from collections import defaultdict
from collections import deque
d = defaultdict(list)
for i in range(N-1):
    ta,tb = map(int,input().split())
    d[ta-1].append(tb-1)
    d[tb-1].append(ta-1)

def dfs(x):

    l = deque()
    l.append(x-1)
    dp = [-1] * N
    dp[x-1] = 0
    # print(l)
    while l:
        t = l.pop()
        for i in d[t]:
            # print(i)
            if dp[i] ==-1:
                dp[i] = dp[t]+1
                l.append(i)
        # print(l)
    return dp

distu = dfs(u)
distv = dfs(v)
M = 0
for i , j in zip(distu,distv):
    if i < j:
        M = max(M,j-1)
print(M)


Measured memory_bytes: 37944
#include<bits/stdc++.h>
#define li long int
#include<math.h>
#include<sstream>
#define str string
#define ll long long int
#define con continue

#define rt return 0
#define fr first
#define sec second
#define pb push_back
#define pf push_front
#define vb vct.begin()
#define ve vct.end()
#define ib it.begin()
#define ie it.end()
#define lb lst.begin()
#define le lst.end()
#define mb mp.begin()
#define me mp.end()
#define ms mp.size()
#define sb st.begin()
#define se st.end()
#define strb s.begin()
#define stre s.end() 
#define mxn 1000007
using namespace std;
str s,sub;
int main()
{
  // ll tc;cin>>tc; while(tc--){
     
    ll i,m,j,k,n,ans=0,cnt=0,mn=1e9;
    cin>>s>>sub;
    n=s.size()-1,m=sub.size()-1;
    for(i=0;i+m<=n;i++)
    {
      ans=0,cnt=i;
     for(j=0;j<=m;j++)
      {
        if(s[cnt++]!=sub[j])ans++;
      }
      // cout<<ans<<" ";
       mn=min(mn,ans);
    }
   // cout<<endl;
    cout<<mn<<endl;
    
//}        
      return 0;
}
      

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

int main() {
  int x, y, s;
  cin >> x;
  cin >> y;
  s = y - (2 * x);
  if (y % 2 == 1) {
    cout << "No";
  }
	else if (s < 0) {
		cout << "No";
	}
	else {
		if (4 * x < y ) {
			cout << "No";
		}
		else {
			cout << "Yes";
		}
	}
  return 0;
}

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

#define INF INT_MAX

using namespace std;

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

int k[10];
int s[10][10];
int p[10];
int N,M;
int ans;

void dfs(vector<int> &v){
	if(v.size() == N){
		for(int i = 0;i < M;i++){
			int sum = 0;
			for(int j = 0;j < k[i];j++){
				sum += v[s[i][j]-1];
			}
			if(sum%2 != p[i]){
				return;
			}
		}
		ans++;
		return;
	}
	vector<int> vv = v;
	vv.push_back(0);
	dfs(vv);
	vector<int> vvv = v;
	vvv.push_back(1);
	dfs(vvv);
}

int main(void){
 	cin.tie(0);
    ios::sync_with_stdio(false);
	cin >> N >> M;
	for(int i = 0;i < M;i++){
		cin >> k[i];
		for(int j = 0;j < k[i];j++){
			cin >> s[i][j];
		}
	}
	for(int i = 0;i < M;i++)cin >> p[i];
	vector<int> v;
	dfs(v);

	cout << ans << endl;

	return 0;
}

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

int main(void){
	int tmp, a, b;
	a = b = 0;
	for(int i = 0; i < 8; i++){
		cin >> tmp;
		if(i < 4)
			a += tmp;
		else
			b += tmp;
	}
	cout << ((a >= b)? a : b) << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

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

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
   
    
  int main(){
     lint N,W,Q,R;
     string s;
     cin>>N>>R;
     if(N>=10)cout<<R;
     else cout<<R+100*(10-N);
    }
     
  


Measured memory_bytes: 256
while 1:
    n,m=map(int,input().split())
    if n==m==0:break
    taro=[]
    hana=[]
    for i in range(n):taro.append(int(input()))
    for i in range(m):hana.append(int(input()))
    s_t=sum(taro)
    s_h=sum(hana)
    if (s_t+s_h)%2==1:print(-1)
    else:
        if s_t==s_h:
            taro.sort()
            for i in taro:
                if i in hana:
                    print(i,i)
                    break
            else:print(-1)
        elif s_t>s_h:
            i=(s_t-s_h)//2
            hana.sort()
            for j in hana:
                if i+j in taro:
                    print(i+j,j)
                    break
            else:print(-1)
        elif s_t<s_h:
            i=(s_h-s_t)//2
            taro.sort()
            for j in taro:
                if i+j in hana:
                    print(j,i+j)
                    break
            else:print(-1)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL INF=100000000000;
string u="abcdefghijklmnopqrstuvwxyz";

vector<LL> fact;
vector<LL> inver(200001);

LL combination(int n,int r){
    if(n==0&&r==0) return 1;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}

LL fpow(LL a, LL n){
    int x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}

int main(){
    int H,W;
    cin >> H >> W;
    int A,B;
    cin >> A >> B;
    LL s=1;
    fact.push_back(0);
    for(int i=1;i<=200000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[200000]=fpow(fact[200000],mod-2);
    for(int i=199999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
    LL ans=0;
    for(int i=B;i<W;i++){
        ans+=combination(H-A-1+i,i)%mod*combination(A+W-i-2,W-i-1)%mod;
    }
    cout << ans%mod << endl;
    return 0;
}

Measured memory_bytes: 3956
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;

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

int main()
{
        int n;
        cin >> n;
        vector<ll> wa;
        ll sum = 0;
        for (int i = 1; i <= n; i++) {
                ll now;
                cin >> now;
                if (now != 0) {
                        sum += now;
                } else {
                        wa.push_back(sum);
                        sum = 0;
                }
        }
        if (sum > 0) wa.push_back(sum);

        ll result = 0;
        for (auto x : wa) {
                result += x / 2;
        }
        cout << result << endl;
}


Measured memory_bytes: 4208
s = gets.chop
if s.length > 9
  puts 'NO'
  exit 0
else
  ans = 'AKIHABARA'.chars
  list = s.chars
  loop do
    if list.empty? && (ans - ['A'] ).empty?
      puts 'YES'
      exit 0
    end
    break if list.empty? || ans.empty?

    t = list.shift
    m = ans.shift
    next if t == m

    if m == 'A'
      list.unshift(t)
    else
      puts 'NO'
      exit 0
    end
  end
end
puts 'NO'

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
string a;
  string b;
  string c;
  cin >>a>>b>>c;
  int x=a.size()-1;
  int y=b.size()-1;
  int z=c.size()-1;
  if((a.at(x)==b.at(0)) && (b.at(y)==c.at(0))) {
cout <<"YES" << endl;
  }
else {
cout <<"NO" << endl;
}
}
  


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int n,k,x,y,price;
	scanf("%d",&n);
	scanf("%d",&k);
	scanf("%d",&x);
	scanf("%d",&y);
	if(n<=k){
		price=n*x;
		printf("%d\n",price);
		
		}
	else{
		price=k*x+(n-k)*y;
		printf("%d\n",price);
		}
	
	return 0;	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,arr[200001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x,y;
    cin>>x>>y;
    if (y%2==0 && y>=x*2 && y<=x*4){
        cout<<"Yes";
    }
    else cout<<"No";
    /*
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>arr[i];
    }
    */
}

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

#define rep(i,n) for (int i=0;i<(n);++i)
#define rep2(i,a,b) for (int i=(a);i<(b);++i)
#define rrep(i,n) for (int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;--i)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) cout<<(#_v)<<":";for(auto(_x):(_v)){cout<<" "<<(_x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

// 14:30-15:00

// N, E, S, W
const int dx[4] = {-1, 0,  1,  0};
const int dy[4] = { 0, 1,  0, -1};

int w, h;
int a[30][30];
int c[4];
int d[30][30][4]; // d[i][j][k] = (i, j):pos, k:dir

bool inside(int x, int y) {
    return 0 <= x && x < h && 0 <= y && y < w;
}

int dijkstra() {
    using State = tuple<int, int, int, int>; // cost, i, j, k
    priority_queue<State, vector<State>, greater<State>> pq;
    rep(i, h) rep(j, w) rep(k, 4) d[i][j][k] = inf;
    d[0][0][1] = 0;
    pq.push(State(0, 0, 0, 1));

    while (!pq.empty()) {
        int cost, i, j, k;
        tie(cost, i, j, k) = pq.top(); pq.pop();
        if (d[i][j][k] < cost) continue;
        rep(nk, 4) {
            int ni = i + dx[nk], nj = j + dy[nk];
            if (!inside(ni, nj)) continue;
            int ncost = c[(nk - k + 4) % 4];
            if (a[i][j] != 4 && nk == (k + a[i][j]) % 4) {
                ncost = 0;
            }
            if (d[ni][nj][nk] > cost + ncost) {
                d[ni][nj][nk] = cost + ncost;
                pq.push(State(cost + ncost, ni, nj, nk));
            }
        }
    }

    int ret = inf;
    rep(k, 4) chmin(ret, d[h-1][w-1][k]);
    return ret;
}

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

    int testcase = 0;
    while (cin >> w >> h, w) {
        rep(i, h) rep(j, w) cin >> a[i][j];
        rep(i, 4) cin >> c[i];
        cout << dijkstra() << endl;
    }
}

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

int main(){
	char klasse[25];
	int s,a,i,t;
	
	for(i=0;i<9;i++){
		scanf(" %s %d",klasse,&s);
		scanf("%d",&a);
		t=s*200;
		t+=a*300;
		a+=s;
		printf("%s %d %d\n",klasse,a,t);
	}
	return 0;
}

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

struct mint{
	// 自動的にmodを取ってくれるクラスです。
	ll x;
	mint(ll x = 0):x(x%mod){}

	mint& operator+=(const mint a){
		if((x += a.x >= mod)) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += a.x >= mod)) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res-=a;
	}

	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const {
		if(!t) return 1;
		mint b = pow(t/2);
		b *= b;
		if(t%2 == 1) b *= *this;
		return b;
	}

	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		(*this) *= a.inv();
		return *this;
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}

};

struct combination{
	vector<mint> fact,ifact;
	combination(int n):fact(n+1),ifact(n+1){
		fact.at(0) = mint(1);
		for(int i = 1;i <= n;i++){
			mint mi(i);
		       	fact.at(i) = fact.at(i-1) * mi;
		}
		ifact.at(n) = fact.at(n).inv();
		for(int i = n; i >= 1;i--){
			mint mi(i);
		       	ifact.at(i-1) = ifact.at(i) * mi;
		}

	}
	mint operator()(int n,int k){
		if(k < 0 || k > n) return 0;
		return fact.at(n)*ifact.at(k)*ifact.at(n-k);
	}

};

int main(){

	int n,k;
	cin >> n >> k;
	combination cnk(n-k+1);
	combination ck(k-1);
	
	for(int i = 1;i <= k;i++){
		mint ans = cnk(n-k+1,i)*ck(k-1,i-1);
		cout << ans.x << endl;
	}
	       	
	
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<char> c(N);
  for (int i = 0; i < N; i++){
    cin >> c[i];
  }
  int red = 0;
  for (int i = 0; i < N; i++){
    if (c[i] == 'R'){
      red++;
    }
  }
  int ans = 0;
  for (int i = 0; i < red; i++){
    if (c[i] == 'W'){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
h,w,q=map(int,input().split())
c2=[input() for _ in range(h) ]
ans=0
for i in range(2**w):#縦
  
  for j in range(2**h):#横
    c=c2[:]
    for k in range(w):#ビット
      if i>>k &1:
       
        for l in range(h):
          c[l]=c[l][:k]+"b"+c[l][k+1:]
    for k2 in range(h):
      if j>>k2 &1:
        c[k2]="a"*w
    sm=("".join(c).count("#"))

    if sm==q:
      ans+=1
print(ans)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i,n) cin >> a[i] >> b[i];
  int ok = 0;
  int prev = 0;
  for (int i = 0; i < n; i++) {
    int len = 1;
    if (a[i] != b[i]) continue;
    for (int j = i + 1; j < n; j++) {
      if (a[j] != b[j]) break;
      len++;
    }
    if (len >= 3) ok = 1;
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0; 
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

//B
int main() {
	ll N;
	scanf("%lld", &N);
	vector<ll> A(N);
	ll total = 0;
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		total += A[i];
	}

	ll result = INF;
	ll sum = 0;
	for (ll i = 0; i < N; i++) {
		sum += A[i];

		if (sum * 2 == total) {
			result = 0;
		}
		else if (sum * 2 <= total) {
			result = min(result, abs(total - 2 * sum));
		}
		else {
			result = min(result, abs(2 * sum - total));
		}
	}



	printf("%lld\n", result);
}

//A
/*
int main() {
	ll X;
	scanf("%lld", &X);
	ll Y;
	scanf("%lld", &Y);

	ll result = 0;

	if (X == 3) {
		result += 100000;
	}
	else if (X == 2) {
		result += 200000;
	}
	else if (X == 1) {
		result += 300000;
	}

	if (Y == 3) {
		result += 100000;
	}
	else if (Y == 2) {
		result += 200000;
	}
	else if (Y == 1) {
		result += 300000;
	}

	if (X == 1 && Y == 1) {
		result += 400000;
	}

	printf("%lld\n", result);
}
*/

Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] H = new int[N];
        int ans = 0;

        for (int i = 0; i < N; i++) {
            int h = sc.nextInt();
            if (h >= K)
                ans++;
        }

        System.out.println(ans);
   	}
}

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

int main(){
  string a;
  cin >> a;
  int n= a.size();
  reverse(a.begin(),a.end());
  vi s(2019);
  s[0]++;
  int sum=0,ten=1;
  ll ans=0;
  rep(i,n){
    sum+=(a[i]-'0')*ten;
    sum%=2019;
    ans+=s[sum];
    s[sum]++;
    ten*=10;
    ten%=2019;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
void base_0(vector<pair<int,int> > &vec){
  int base_x,base_y;
  base_x = vec[0].first;
  base_y = vec[0].second;
  vec[0].first = 0;
  vec[0].second = 0;
  for(int i = 1;i < vec.size();i++){
	vec[i].first -= base_x;
	vec[i].second -= base_y;
  }
}
bool check_pair_eq(pair<int,int> &a,pair<int,int> &b){
  if(a.first == b.first && a.second == b.second){
	return true;
  }
  return false;
}
vector<int> cal(vector< vector<pair<int,int> > > &vec){
  vector<int> ans = vector<int>();
  for(int i = 1;i < vec.size();i++){
	int flag = 0;
	for(int j = 0;j < vec[i].size();j++){
	  if(vec[0].size() != vec[i].size() || !check_pair_eq(vec[0][j],vec[i][j])){
		flag = 1;
		break;
	  }
	}
	if(flag == 0){
	  ans.emplace_back(i);
	}
  }
  
  return ans;
}
vector<int>  vectoadd(vector<int> const &a,vector<int> const &b){

  vector<int> res = vector<int>();

  for(int i = 0;i < a.size();i++){
	res.push_back(a[i]);
  }

  for(int i = 0;i < b.size();i++){
	res.push_back(b[i]);
  }

  return res;
}
void rotate_r_90(vector<pair<int,int> > &vec){
  for(int i = 0;i < vec.size();i++){
	int x = vec[i].first;
	int y = vec[i].second;
	vec[i].first = -1*y;
	vec[i].second = x;
  }
}
int main(){
  
  int n;
  while(cin >> n && n != 0){
	
	vector<vector<pair<int,int> > > poly(n+1);
	for(int i = 0;i <= n;i++){
	  int m;
	  cin >> m;
	  poly[i] = vector<pair<int,int> > ();
	  for(int j = 0;j < m;j++){
		int x,y;
		cin >> x >> y;
		poly[i].emplace_back(x,y);
	  }
	}

	vector<int> ans = vector<int>();
	for(int i = 0;i <= n;i++){
	  base_0(poly[i]);
	}
	for(int i = 0;i < 4;i++){
	  for(int j = 1;j <= n;j++){
		rotate_r_90(poly[j]);
	  }
	  ans = vectoadd(ans, cal(poly));
	}

	for(int i = 1;i <= n;i++){
	  reverse(poly[i].begin(),poly[i].end());
	  base_0(poly[i]);
	}
	for(int i = 0;i < 4;i++){
	  for(int j = 1;j <= n;j++){
		rotate_r_90(poly[j]);
	  }
	  ans = vectoadd(ans, cal(poly));
	}
	


	sort(ans.begin(),ans.end());
	if(ans.size())
	  cout << ans[0] << endl;
	for(int i = 1;i < ans.size();i++){
	  if(ans[i-1] != ans[i]){
		cout << ans[i] << endl;
	  }
	}
	cout << "+++++" << endl;
	
	
  }  
  return 0;
}

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

#define MAX_LEN (10)

int main(int argc, char *argv[]) {
  int a;
  char cs[MAX_LEN + 1];
  scanf("%d", &a);
  fgets(cs, MAX_LEN + 1, stdin);
  scanf("%s", cs);

  if (a >= 3200) {
    printf("%s\n", cs);
  } else {
    printf("red\n");
  }
  
  return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		int k = fs.nextInt();
		
		if(k % 2 == 0 || k % 5 == 0) {
			System.out.println(-1);
			return;
		}
		
		long l;
		if(k % 7 == 0) {
			l = 9 * k / 7;
		}else {
			l = 9 * k;
		}
		
		
		long ans = 0;
		long tenPow = 1;
		boolean canMake = false;
		
		for(int i = 0; i < l; i++) {
			ans++;
			tenPow = (tenPow * 10) % l;
			
			if(tenPow - 1 % l == 0) {
				canMake = true;
				break;
			}
		}
		
		if(canMake) {
			System.out.println(ans);
		}else {
			System.out.println(-1);
		}
	}
	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 32612
#include <stdio.h>

int main(){
  int x[5];
  scanf("%d %d %d %d %d", x, x+1, x+2, x+3, x+4);
  
  for(int i = 0; i < 5; i++)
    if(x[i] == 0)
      printf("%d\n", i+1);
  
  return 0;
}

Measured memory_bytes: 1704
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
  char s[100];
  gets(s);
  int flag=0,i,j;
  int x=strlen(s);
  if(x%2==0)
  {
    for(i=0;i<(x/2);i++)
    {
        int y=i+1;
      if(s[i]!=s[x-y])
        flag++;
    }
  }
  else
  {
    int w=x/2-1;
    for(i=0;i<=w;i++)
    {
       int y=i+1;
       if(s[i]!=s[x-y])
        flag++;
    }
  }
  printf("%d",flag);
}


Measured memory_bytes: 128
//
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    int sum = 0;
    //1
    if (a > b)
    {
        sum += a;
        --a;
    }
    else
    {
        sum += b;
        --b;
    }
    //2
    if (a > b)
    {
        sum += a;
        --a;
    }
    else
    {
        sum += b;
        --b;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int cards[] = new int[n];
		for(int i = 0; i < n; i++){
			cards[i] = sc.nextInt();
		}

		Arrays.sort(cards);

		ArrayList<Numbers> list = new ArrayList<Numbers>();

		int count = 0;
		for(int i = 0; i < n; i++){
			if(i >= 1 && cards[i] != cards[i - 1]){
				list.add(new Numbers(cards[i - 1], count));
				count = 1;
			}
			else {
				count++;

			}
			if(i == n - 1){
				list.add(new Numbers(cards[i], count));
			}
		}

//		Numbers changes[] = new Numbers[m];
		for(int i = 0; i < m; i++){
			int b = sc.nextInt();
			int c = sc.nextInt();

//			changes[i] = new Numbers(c, b);
			list.add(new Numbers(c, b));
		}
//		Arrays.sort(changes);
		Collections.sort(list);

		long sum = 0;
		int remain = n;

		for(int i = 0; i < list.size(); i++){
//			System.out.println("value "+list.get(i).value+" count "+list.get(i).num);

			Numbers tmpNum = list.get(i);

			int use = Math.min(remain, tmpNum.num);

			sum += (long)use*tmpNum.value;

			remain -= use;

			if(remain == 0){
				break;
			}
		}

		System.out.println(sum);
	}

}

class Numbers implements Comparable<Numbers>{
	int value;
	int num;

	Numbers(int value, int num){
		this.value = value;
		this.num = num;
	}

	@Override
	public int compareTo(Numbers c1) {
		// TODO 自動生成されたメソッド・スタブ
		return c1.value - this.value;
	}


}


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

using namespace std;
using ll = long long;

int main() {
    vector<int> a(5);
    for(int i = 0;i < 5;++i) {
        int t;
        cin>>t;
        if(t==0)cout<<i+1<<endl;
    }

    return 0;
}


Measured memory_bytes: 3544
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
A,B = [int(i) for i in input().split()]
if A == 1 and B==1:
    print(1)
else:
    ans = 1
    lia = factorization(A)
    lib = factorization(B)
    na = len(lia)
    nb = len(lib)
    a = [0] * na
    b = [0] * nb
    for i in range(na):
        a[i] = lia[i][0]
    for i in range(nb):
        b[i] = lib[i][0]
    a_ = set(a)
    b_ = set(b)
    if na >= nb:
        for i in range(nb):
            if b[i] in a_:
                ans+=1
        print(ans)
        exit()
    else:
        for i in range(na):
            if a[i] in b_:
                ans+=1
        print(ans)
        exit()

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

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

  int a, b;
  a = d / 10; b = d % 10;
  int ans = 0;
  for (int i = 2; i <= a; ++i) {
    for (int j = 2; j <= 9; ++j) {
      if (i * 10 + j > d) continue;
      if (i * j <= m) ++ans;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#define INF 9999999
using namespace std;

int a[100000+5];
vector<int> line[500];

int main(){
    int n;
    scanf("%d",&n);
    int k=floor(sqrt(2*n)+0.5);
    if(k*(k+1)==2*n){
        int cnt=k+1;
        int t=1;
        for(int i=1;i<cnt;i++){
            int s=i*(i-1)/2+1;
            for(int j=0;j<i;j++)line[j].push_back(s++);
            for(int j=0;j<i;j++)line[i].push_back(--s);
        }
        printf("Yes\n%d\n",cnt);
        for(int i=0;i<cnt;i++){
            printf("%d",line[i].size());
            for(int j=0;j<line[i].size();j++)
                printf(" %d",line[i][j]);
            printf("\n");
        }
    }else{
        printf("No\n");
    }
}


Measured memory_bytes: 2304
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#include <map>
#define rep(i,N) for(int (i)=0;(i) < (N); ++(i))
typedef long long ll;
using namespace std;

ll gcd(ll n, ll m){
  ll r = n % m;
  //cout << n << " " << m << "\n";
  while(r != 0){
    n = m;
    m = r;
    r = n % m;
  }
  //cout << m << "\n";
  return m;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  if(d > c){
    int temp;
    temp = c;
    c = d;
    d = temp;
  }
  ll e = (c * d)/gcd(c, d);
  //cout << e << "\n";

  ll num_c = b/c - (a - 1)/c;
  //cout << b/c << " " << (a - 1)/c << "\n";
  ll num_d = b/d - (a - 1)/d;
  //cout << b/d << " " << (a - 1)/d << "\n";
  ll num_e = b/e - (a - 1)/e;
  //cout << b/e << " " << (a - 1)/e << "\n";
  ll divided = num_c + num_d - num_e;

  ll res = b - a + 1 - divided;
  cout << res << "\n";
  return 0;
}


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

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

int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    int l = max(a, c);
    int r = min(b, d);
    if(r - l < 0) cout << 0 << endl;
    else cout << r - l << endl;
}



Measured memory_bytes: 256
/*
    A - Ferris Wheel
    https://atcoder.jp/contests/abc127/tasks/abc127_a
*/
#include <bits/stdc++.h>
using namespace std;

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

    int a, b;
    cin >> a >> b;
    if (a <= 5)
        cout << 0 << endl;
    else if (a <= 12)
        cout << (b / 2) << endl;
    else
        cout << b << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        HashSet<String> set = new HashSet<>();

        String ans = "None";
      String alp = "abcdefghijklmnopqrstuvwxyz";

        for(int i = 0; i < alp.length(); i++) {
            String tmp =  String.valueOf(alp.charAt(i));

                if(s.contains(tmp)) {
                    continue;
                }
                ans=tmp;
               
                break;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25648
#include<stdio.h>

int main(){
  int N, K, i, r;
  
  scanf("%d %d", &N, &K);
  
  r = K;
  for (i = 1; i < N; i++){
    r *= K - 1;
  }
  printf("%d\n", r);
  
  return 0;
}

Measured memory_bytes: 128
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

s = input()
N = len(s)
p = 0
g = 0
ans = 0
for i in range(N):
    if s[i] == "g":
        if p + 1 <= g:
            ans += 1
            p += 1
        else:
            g += 1
    else:
        if p + 1 <= g:
            p += 1
        else:
            ans -= 1
            g += 1
print(ans)


Measured memory_bytes: 5672
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll D;
    cin >> N >> D;
    vector<ll> X(N), Y(N);
    rep(i, 0, N) {
        cin >> X[i] >> Y[i];
    }
    int ans = 0;
    rep(i, 0, N) {
        if (X[i] * X[i] + Y[i] * Y[i] <= D * D) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6364
# encoding: utf-8
n = int(input())
S = [input() for i in range(n)]

table = [[0] * n for i in range(26)]
base = ord("a")

for i, Si in enumerate(S):
    for char in Si:
        table[ord(char) - base][i] += 1

ans = ""
for i, row in enumerate(table):
    if min(row) >= 1:
        for j in range(min(row)): ans += chr(base + i)

print(ans)

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

function main()
	s = readline() |> chomp
	n = length(s)
	k = 0
	for i in 1:n>>1
		if s[i]!=s[n+1-i]
			k += 1
		end
	end
	println(k)
end

main()



Measured memory_bytes: 162820
n=int(input())
ans=0
cnt=[0]*500000
#print(2*10**2)
for i in range(1,2*10**2+1):
    for j in range(1,2*10**2+1):
        for k in range(1,2*10**2+1):
            cnt[((i+j)**2+(j+k)**2+(k+i)**2)//2-1]+=1
for i in range(n):
    print(cnt[i])


Measured memory_bytes: 73060
#include<stdio.h>
#include<string.h>
typedef struct{
  char sign;
  int num;
}Card;


void Bubble(Card k[],int n)
{
  int i,j,flag=0;
 
  while (flag < n-1)
    {
      int last=n-1;
      for(j=n-1; j>flag; j--)
	if(k[j-1].num>k[j].num){//構造体から抜き出した変数
	  Card tmp;//構造体Card内の変数作成
	  tmp=k[j-1];
	  k[j-1]=k[j];
	  k[j]=tmp;
	  
	  last = j;
	}
      flag=last;
    }
  for(i=0; i<n; i++){
    if(i==n-1)
      printf("%c%d",k[i].sign,k[i].num);
    else
      printf("%c%d ",k[i].sign,k[i].num);
  }
}

void Selection(Card k[], int n)
{
  int i,j;
  for(i=0; i<n-1; i++){
       int min=i;
    for(j=i; j<n; j++)
      if(k[j].num<k[min].num)
	min=j;
    Card tmp;
    tmp=k[i];
    k[i]=k[min];
    k[min]=tmp;
  }
  for(i=0; i<n; i++){
    if(i==n-1)
      printf("%c%d",k[i].sign,k[i].num);
    else
      printf("%c%d ",k[i].sign,k[i].num);
  }
}

void read(Card k[],Card k3[], int n)
{
  int i;
  for(i=0; i<n; i++)
    k3[i]=k[i];
}

void judge(Card k[], Card k3[], int n)
{
  int i,a=0;
  for(i=0; i<n; i++)
    if(k[i].num!=k3[i].num||k[i].sign!=k3[i].sign)
      a++;
  if(a==0)
    printf("Stable");
  else
    printf("Not stable");
 
}  
int main()
{
  int i,n;
  scanf("%d",&n);
  Card k[n];
  Card k2[n];//初期の値を仮代入
  Card k3[n];//Bubbleソートを入れる
  for(i=0; i<n; i++){
    scanf("\t%c%d",&k[i].sign,&k[i].num);//構造体の内部の変数に読み込み
    k2[i]=k[i];
  }
  
  Bubble(k,n);
  read(k,k3,n);
  putchar('\n');
  puts("Stable");//バブルソートは安定
  
  for(i=0; i<n; i++)
    k[i]=k2[i];

  Selection(k,n);
  putchar('\n');
  judge(k,k3,n);
  putchar('\n');
    return 0;
}



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

int main() {
 int n;
 cin >> n;
 double a;
 double b;
 b = 0;
 for (int i = 0; i < n; i++) {
  cin >> a;
  a = 1 / a;
  b = b + a;
 }
 b = 1 / b;
 cout << b << endl;
}

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

using namespace std;

int main() {
  long long l, r;
  scanf("%lld %lld", &l, &r);
  int ans = 1;
  while (l * 2 <= r) {
    l *= 2;
    ++ans;
  }
  printf("%d\n", ans);
}


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

int i,j,k,h,w,min,ans,mat[700][700];
char c[600];

int main(){
	while(scanf("%d %d",&h,&w)*h*w){
		for(i=0;i<h;i++){
			k=0;
			scanf("%s",c);
			for(j=0;j<w;j++){
				if(c[j]=='.')k++; else k=0;
				mat[i][j]=k;
			}
		}

		ans=0;
		for(j=w-1;j>=0 && (j+1)*h>ans ;j--){
			for(k=h-1;k>=0;k--){
				min=mat[k][j];
				if(min*(h-k)<=ans)continue;
				for(i=1;i+k<h;i++){
					if(min>mat[i+k][j])min=mat[i+k][j];
					if(min*(h-k)<=ans)break;
					if(min*(i+1)>ans)ans=min*(i+1);
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1968
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,T;
    cin>>n>>T;
    vector<int> c(n),t(n);
    priority_queue<int> min;
    for(int i=0;i<n;i++){
        cin>>c.at(i)>>t.at(i);
        if(t.at(i)<=T)
        min.push(c.at(i));
    }
    if(min.size()==0){
        cout<<"TLE"<<endl;
        return 0;
    }
    while(min.size()>1){
        min.pop();
    }
    cout<<min.top()<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF =1001001001;
using P = pair<int,int>;

int main(void) 
{
   string s, t;
   cin >> s >> t;

   rep(i, s.size()){
      if(s[i] != t[i])
      {
         cout << "No" << endl;
         return 0;
      }
   }
   if(s.size() + 1 == t.size())  cout << "Yes" << endl;
   else  cout << "No" << endl;
   return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main(){
	int N;
  	char S[50];
  	int count=0;
  	int i;
  	scanf("%d",&N);
  	scanf(" %c",&S[0]);
  	for(i=1;i<N;i++){
      scanf("%c",&S[i]);
  	}
  	for(i=0;i<=N-3;i++){
    	if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
        	count++;
        }
    }
  	printf("%d\n",count);
  	return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const int MOD = 1000000007;

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

    ll N;
    cin >> N;
    vector<ll> C(N);
    Rep (i, N) {
        cin >> C[i];
    }

    vec pre(2e5+1, -1);
    vec check(N, -1);
    Rep (i, N) {
        check[i] = pre[C[i]];
        pre[C[i]] = i;
    }

    // Rep (i, N) {
    //     cout << check[i] << " ";
    // }
    // cout << "\n";

    vec dp(N+1);
    dp[0] = 1;
    Rep (i, N) {
        dp[i+1] = dp[i];
        ll j = check[i];
        if (j == i-1) {
            continue;
        }
        if (j != -1) {
            dp[i+1] += dp[j+1];
            dp[i+1] %= MOD;
        }
    }

    cout << dp[N] << "\n";
}

Measured memory_bytes: 6528
let n = stdin.ReadLine() |> int
let ls = stdin.ReadLine().Split() |> Array.map int

let sorted = ls |> Array.sort

//メモ化
let memoize fn =
    let cache = new System.Collections.Generic.Dictionary<_,_>()
    (fun x ->
        match cache.TryGetValue x with
        | true, v -> v
        | false, _ -> 
            let v = fn (x)
            cache.Add(x,v)
            v)

let searchC sum = 
    sorted |>Array.tryFindIndex (fun x -> x >= sum ) 
    |> fun i -> match i with
    |None -> n-1
    |Some(i) -> i - 1

let memSearchC = memoize searchC

[
    for i in 0..n-3 do
        for j in i+1..n-2 do
            yield sorted.[i], sorted.[j],j
]
|> List.map (fun (a,b,i) -> (memSearchC (a+b), i))
|> List.map (fun (x, y) -> x - y)
|> List.sum
|> stdout.WriteLine

Measured memory_bytes: 318400
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
using namespace std;
typedef long long ll;
#define N (1000000000+7)
typedef pair<int, int> P;

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



int main(void) {
	int s;
	cin >> s;
	set<int>x;
	x.insert(s);
	int num = 1;
	while (true) {
		if (s % 2 == 0) {
			s /= 2;
			if (x.count(s)) {
				num++;
				break;
			}
			else {
				x.insert(s);
				num++;
			}
		}
		else {
			s = 3 * s + 1;
			if (x.count(s)) {
				num++;
				break;
			}
			else {
				x.insert(s);
				num++;
			}
		}
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define rfor(i, n) for (int i = n-1; i>=0; --i)
#define rmod(x, y) (((x%y)+y)%y)
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
const int MAXN = 1024;

//OPERATORS


//GLOBALS


//FUNCTIONS


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,k; cin >> n >> k;
	vector<int> fu(n);
	for(int i = 0; i < n; i++){
		cin >> fu[i];
	}
	vector<bool> depe(k+1,0);
	for(int i = 0; i <= k; i++){
		for(auto ra: fu){
			if(i  >= ra and !depe[i-ra])
				depe[i] = true;	
		}
	}
	if(depe[k] == true) cout << "First"  << endl;
	else cout << "Second" << endl;
	return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i];

    ll ans = 1e18;
    rep(bit, 1 << N) {
        if (__builtin_popcount(bit) < K)
            continue;
        B = A;

        ll now = 0, ma = A[0];
        for (int i = 1; i < N; i++) {
            if (bit & (1 << i)) {
                B[i] = max(ma + 1, B[i]);
                now += B[i] - A[i];
            }
            ma = max(ma, B[i]);
        }
        ans = min(ans, now);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int num[5];
    int i, key, key2, key3;
    int sum=0;

    for(i=0; i<5; i++){
        scanf("%d", &num[i]);
    }

    key = num[0] % 10;
    for(i=1; i<5; i++){
        key2 = num[i] % 10;
        if(key2 > key || key2 == 0){
            key3 = num[i];
            num[i] = num[i-1];
            num[i-1] = key3;
        }else{
            key = key2;
        }
    }
    for(i=0; i<5-1; i++){
        key2 = num[i] % 10;
        if(key2 > 0){
            num[i] += 10 - key2;
        }
        sum += num[i];
    }
    sum += num[4];
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String str[] = br.readLine().split(" ");
			int n = Integer.parseInt(str[0]);
			int k = Integer.parseInt(str[1]);

			if (n == 0 && k == 0)
				break;

			int a[] = new int[n];

			for (int i = 0; i < n; i++) {
				a[i] = Integer.parseInt(br.readLine());
			}
			int s[] = new int[n + 1];
			for (int i = 0; i < n; i++) {
				s[i + 1] = s[i] + a[i];
			}

			long max = Long.MIN_VALUE;
			for (int i = 0; i < n - k; i++) {
				long value = s[k + i] - s[i];
				max = Math.max(max, value);
			}
			System.out.println(max);
		}
	}
}


Measured memory_bytes: 35948
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val s: List<Set<Int>> = (1..m).map {
        val k = sc.nextInt()
        sc.asSequence().take(k).map(String::toInt).map { it - 1 }.toSet()
    }
    val p = sc.asSequence().take(m).map(String::toInt).toList()

    val ret = (0 until (1 shl n)).asSequence().count { bits ->
        s.withIndex().all { e ->
            val (idx, ss) = e
            val onCnt = (0 until n).filter { ss.contains(it) }.count { b -> (1 shl b) and bits != 0 }
            onCnt % 2 == p[idx]
        }
    }
    println(ret)
}


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

int main()
{
  int n;
  cin >> n;
  
  int a[2][n];
  for(int i = 0; i < 2; i++){
    for(int j = 0; j < n; j++){
      cin >> a[i][j];
    }
  }
  
  int o[n] = {0};
  o[0] = a[0][0]; 
  int t[n] = {0};
  t[0] = a[1][0];
  for(int i = 1; i < n; i++){
    o[i] = a[0][i] + o[i-1];
  }
  for(int i = 1; i < n; i++){
    t[i] = a[1][i] + t[i-1];
  }
  
  int cmax = o[0] + t[n-1];
  for(int i = 1; i < n; i++){
    int max = o[i] + t[n-1] - t[i-1];
    if(max > cmax){
      cmax = max;
    }
  }
  
  cout << cmax << endl;
    
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b,c,x;
  while(cin >> n >> a >> b >> c >> x && n + a + b + c + x){
    vector<ll> v(n);
    rep(i,n){
      cin >> v[i];
    }
    ll ans = 0,cnt = 0;
    while(ans < 10001){
      if(v[cnt] == x) ++cnt;
      if(cnt == n) break;
      x = (a * x + b) % c;
      ++ans;
    }
    if(ans == 10001){
      cout << -1 << endl;
    }
    else
      cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

const int MAX_N = 100000;
const int64_t M = 1000000007;
int n;
int64_t pr_psum[MAX_N+1];

int64_t mod_pow(int64_t a, int64_t b)
{
  if (b == 0) return 1;
  int64_t ret = mod_pow(a, b/2);
  ret = ret * ret % M;
  if (b % 2 == 1) ret = a * ret % M;
  return ret;
}

int main()
{
  cin >> n;
  pr_psum[0] = 0;
  for (int i = 1; i <= n; i++) {
    pr_psum[i] = (pr_psum[i-1] + mod_pow(i, M-2)) % M;
  }

  int64_t fn = 1;
  for (int i = n; i >= 1; i--) {
    fn = (fn * i) % M;
  }

  int a;
  int64_t cost = 0;
  for (int j = 1; j <= n; j++) {
    cin >> a;
    int64_t pr = (pr_psum[n-j+1] - pr_psum[1] + pr_psum[j] - pr_psum[0]) % M;
    cost = (cost + pr * a % M) % M;
  }
  cout << fn * cost % M << endl;

  return 0;
}


Measured memory_bytes: 1024
s = input()
t = s[2:-1]
count = 0
q = [s[1]]
for i in range(len(t)):
    if t[i] == "C":
        count += 1
    else:
        q.append(t[i])
q.append(s[-1])
q =''.join(q)
if s[0] == "A" and count == 1 and str(q).lower() ==str(q):
    print("AC")
else:
    print("WA")
    

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

int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >>  h2 >> m2 >> k;
    int diffHrs = h2 - h1;
    int diffMins = m2 - m1;
    int duration = diffHrs * 60 + diffMins;
    cout << duration - k  << endl;
    return 0;
}

Measured memory_bytes: 3640