akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

/**
 * Peaks.
 */
public class Main {
    public static void main(String[] args) {
        var scanner = new Scanner(System.in);
        var n = scanner.nextInt();
        var m = scanner.nextInt();
        var heights = new int[n];
        for (int i = 0; i < n; i++) {
            heights[i] = scanner.nextInt();
        }

        var maxHeight = new int[n];
        for (int i = 0; i < m; i++) {
            var a = scanner.nextInt();
            var b = scanner.nextInt();
            maxHeight[a - 1] = Math.max(maxHeight[a - 1], heights[b - 1]);
            maxHeight[b - 1] = Math.max(maxHeight[b - 1], heights[a - 1]);
        }
        var count = 0;
        for (int i = 0; i < n; i++) {
            if (heights[i] > maxHeight[i]) {
                count++;
            }
        }
        System.out.println(count);
    }
}


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

double ax,ay,bx,by;
double cx,cy,dx,dy;

bool check(double L1,double R1,double L2,double R2){
  if(R1<L2||R2<L1)return false;
  else return true;
}

int main(){
  while(cin>>ax>>ay>>bx>>by>>cx>>cy>>dx>>dy){
    if(check(ax,bx,cx,dx)&&check(ay,by,cy,dy)){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<vector<pair<int,int>>> fri(N);
  for(int i=0;i<N;i++){
  int u,v;
  long long w;
  cin>>u>>v>>w;
    fri[u-1].push_back(make_pair(v-1,w%2));
    fri[v-1].push_back(make_pair(u-1,w%2));
  }
  int color[100000];
  for(int i=0;i<N;i++){
    color[i]=-1;
  }
  queue<int> que;
  que.push(0);
  color[0]=0;
  while(!que.empty()){
    int x=que.front();
    que.pop();
    for(int i=0;i<fri[x].size();i++){
      if(color[fri[x][i].first]==-1){
        que.push(fri[x][i].first);
        color[fri[x][i].first]=(color[x]+fri[x][i].second)%2;
      }
    }
  }
  for(int i=0;i<N;i++){
    cout<<color[i]<<endl;
  }
  
 return 0; 
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int (i) = 0; i < (n); (i)++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    bool C = 0;
    rep(i,s.size()){
        if(s[i] == 'C'){
            C = 1;
        }
        if(s[i] == 'F' && C){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_7 1000003
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

struct point{
    ll x,y;
};


int main(){fastio
    
    ll n;cin>>n;
    point p[n];
    rep(i,0,n-1)cin>>p[i].x>>p[i].y;
    ll ans=n;
    rep(i,0,n-1){
        rep(j,0,n-1){
            if(i==j)continue;
            ll cou=0;
            ll dx=p[i].x-p[j].x;
            ll dy=p[i].y-p[j].y;
            
            bool used[n];memset(used,false,sizeof(used));
            rep(k,0,n-1){
                if(used[k])continue;
                cou++;
                point now=p[k];
                bool flag=true;
                while(flag){
                    flag=false;
                    rep(l,k+1,n-1){
                        if(used[l])continue;
                        if(p[l].x+dx==now.x&&p[l].y+dy==now.y){
                            used[l]=true;
                            flag=true;
                            now=p[l];
                            break;
                        }
                    }
                }
                now=p[k];
                flag=true;
                while(flag){
                    flag=false;
                    rep(l,k+1,n-1){
                        if(used[l])continue;
                        if(p[l].x-dx==now.x&&p[l].y-dy==now.y){
                            used[l]=true;
                            flag=true;
                            now=p[l];
                            break;
                        }
                    }
                }
            }
            Min(ans,cou);
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define pb push_back
#define mp make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<int>;
using vii=vector<vi>;
using pii=pair<int,int>;
const ll MOD=1e9+7;
const int MAX=1e5+1;
const ll INF=(1ll<<62)-1;
ll digit_sum(ll b,ll n){
    if(n<b) return n;
    else return digit_sum(b,n/b)+n%b;
}
signed main(){
    ll n,s; cin>>n>>s;
    ll ans=INF;
    REP(i,2,sqrt(n)){
        ll X=digit_sum(i,n);
        if(X==s) ans=std::min(ans,(ll)i);
    }
    REP(i,1,sqrt(n)){
        ll mod=s-i;
        if(mod<0) break;
        if(mod>n) continue;
        ll quo=n-mod;
        if(quo%i==0&&quo/i>1&&digit_sum(quo/i,n)==s) ans=std::min(ans,quo/i);
    }
    if(n%s==0&&n/s>1&&digit_sum(n/s,n)==s) ans=std::min(ans,n/s);
    if(n==s) ans=std::min(ans,n+1);
    if(ans==INF) ans=-1;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define REP(type,i,n) for(type i=0;i<(n);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> Pi;

const int INF=100000000;
const long long int INF_=1000000000000000000;

int main(){
	int N;
	while(cin >> N&&N){
		int ans=0;
		REP(int,i,N/4){
			int tmp;
			cin >> tmp;
			ans+=tmp;
		}
		cout << ans << endl; 
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void)
{
    int height[10];
    int i, temp;
    int flag;


    for(i=0; i<10; i++)
        scanf("%d", &height[i]);

    do{
        flag=0;
        for(i=0; i<10; i++){
            if(height[i]<height[i+1]){
                flag=1;
                temp=height[i];
                height[i]=height[i+1];
                height[i+1]=temp;
            }
        }
    }while(flag);

    printf("%d\n%d\n%d\n", height[0], height[1], height[2]);

    return 0;
        
}

Measured memory_bytes: 600
from collections import deque

N, M = map(int, input().split())

d = {}

for i in range(N):
    d[i+1] = set()

for i in range(M):
    a, b = map(int,input().split())
    d[a].add(b)
    d[b].add(a)

que = deque([1])
checked = set()
ans = {1:-1}

while que:
    now = que.popleft()
    for h in d[now]:
        if not h in ans:
            ans[h] = now
            que.append(h)
    if len(ans) == N:
        break
    
if len(ans) == N:
    print('Yes')
    for i in range(N-1):
        print(ans[i+2]) 
else:
    print('No')



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

const int N=1e2+5;
typedef long long ll;

int main()
{
    string a,b;
    cin >> a;
    cin >> b;
    bool ans=false;
    for(int i=0; i<a.length(); i++)
    {
        if(a.length()!=b.length()) break;
        for(int j=0; j<a.length() ; j++)
        {
            int k=(i+j)%a.length();
            if(a[k]!=b[j]) break;
            if(j==a.length()-1) ans=true;
        }
        if(ans) break;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> lP;

ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

/*
全探索の場合
 p,qの全探索でout
 差分の数ならN^2よ？

一次元なら座標の差分をとって最大公約数とればpが定まる

次元圧縮してset?
 qx - pyのパターン数を探す
  1,1 3,3, 5,5 6,6 を1としてカウントしてしまうぞ

選んだ物に対して、同一グループを探索

木を生成する解法も解くぞ
*/
void dfs(int v, vector<bool>& b, vector<vector<int>>& root);
int main()
{
    int n;
    cin >> n;
    vector<lP> ball(n);
    rep(i, n){
        cin >> ball[i].first >> ball[i].second;
    }

    vector<lP> diff;
    for (int i = 0; i < n; i++)
    {
        for (int j = i+1; j < n; j++)
        {
            if (i == j) continue;
            ll dx = ball[i].first - ball[j].first;
            ll dy = ball[i].second - ball[j].second;
            diff.push_back({dx, dy});
        }
    }
    
    int ans = n;
    for (int d = 0; d < diff.size(); d++)
    {
        vector<vector<int>> root(n);
        vector<bool> visited(n);
        int tans = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = i+1; j < n; j++)
            {
                if (i==j) continue;
                ll dx = ball[i].first - ball[j].first;
                ll dy = ball[i].second - ball[j].second;
                if ((diff[d].first == dx && diff[d].second == dy) ||
                (diff[d].first == -dx && diff[d].second == -dy))
                {
                    root[i].push_back(j);
                    root[j].push_back(i);
                }
            }   
        }
        for (int i = 0; i < n; i++)
        {
            if (visited[i] == false){
                dfs(i, visited, root);
                tans++;
            }
        }
        ans = min(tans, ans);
    }
    cout << ans << endl;
}

void dfs(int v, vector<bool>& b, vector<vector<int>>& root){
    b[v] = true;
    for (auto next: root[v])
    {
        if(b[next] == true) continue;
        dfs(next,b,root);        
    }
    
}


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

template<typename weight_type = int>
class union_find {
    static_assert(
        std::is_arithmetic<weight_type>::value,
        "Invalid weight type");
private:
    std::vector<int> uni;
    
    std::vector<weight_type> weights;
    int size_;
    const void check(const int n) const {
        if (this->group_size() < 0) {
            assert(false);
        }
        if (!(0 <= n && n < this->all_size())) {
            assert(false);
        }
    }
public:
    std::vector<int> edge_count_;
    union_find() : uni(0), edge_count_(0), weights(0), size_(-1) {}
    union_find(const int n)
        : uni(n, -1), edge_count_(n), weights(n), size_(n) {
        this->check(n - 1);
    }
    union_find(const std::vector<weight_type> &_weights)
        : uni(_weights.size(), -1), edge_count_(_weights.size()),
        weights(_weights), size_(_weights.size()) {
        this->check((int)_weights.size() - 1);
    }
    bool same(const int a, const int b) {
        this->check(a);
        this->check(b);
        return this->find(a) == this->find(b);
    }
    int find(const int a) {
        this->check(a);
        return this->uni[a] < 0 ?
                a :
            this->uni[a] = this->find(this->uni[a]);
    }
    bool unite(int a, int b) {
        a = this->find(a);
        b = this->find(b);
        this->edge_count_[a]++;
        if (a == b) {
            return false;
        }
        this->size_--;
        if (this->uni[a] > this->uni[b]) {
            std::swap(a, b);
        }
        this->uni[a] += this->uni[b];
        this->weights[a] += this->weights[b];
        this->edge_count_[a] += this->edge_count_[b];
        this->uni[b] = a;
        return true;
    }
    const int group_size() const {
        return this->size_;
    }
    const int all_size() const {
        return this->uni.size();
    }
    const int size(const int a) {
        this->check(a);
        return -this->uni[this->find(a)];
    }
    const int edge_count(const int a) {
        this->check(a);
        return this->edge_count_[this->find(a)];
    }
    const weight_type weight(const int a) {
        this->check(a);
        return this->weights[this->find(a)];
    }
};

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  union_find<long long> uf(X);
  vector<tuple<long long, int, int>> edges;
  for (int i = 0; i < M; i++) {
    int a, b;
    long long y;
    cin >> a >> b >> y;
    a--;
    b--;
    edges.emplace_back(y, a, b);
  }
  sort(begin(edges), end(edges));
  int live = 0;
  for (auto e : edges) {
    int a, b;
    long long w;
    tie(w, a, b) = e;
    uf.unite(a, b);
    const int par = uf.find(a);
    if (uf.weight(par) >= w) {
      live += uf.edge_count_[par];
      uf.edge_count_[par] = 0;
    }
  }
  cout << M - live << endl;
}

Measured memory_bytes: 4724
#include <iostream>

using namespace std ;

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

    int zero_cnt = 0 , other_cnt = 0 ;

    for(int i = 0 ; i < n ; i++){
        cin >> x ;

        if(x % 4 == 0)
            zero_cnt++ ;

        else if((x % 4) % 2 == 1)
            other_cnt++ ;
    }

    if(zero_cnt >= other_cnt)
        cout << "Yes" << endl ;

    else{
        if(n - (zero_cnt + other_cnt) > 0)
            other_cnt++ ;

        if(zero_cnt == other_cnt - 1)
            cout << "Yes" << endl ;

        else
            cout << "No" << endl ;
    }

	return 0 ;
}


Measured memory_bytes: 256
# Reference: https://betrue12.hateblo.jp/entry/2020/09/15/180849

import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))

    C = [0] * (N + 1)
    D = [0] * (N + 1)

    for i in range(N):
        C[A[i]] += 1
        D[B[i]] += 1

    for i in range(1, N + 1):
        if C[i] + D[i] > N:
            print('No')
            return

    print('Yes')

    C = list(accumulate(C))
    D = list(accumulate(D))

    B.reverse()

    i = 0
    while i < N and A[i] != B[i]:
        i += 1

    if i == N:
        print(*B)
        return

    n = A[i]

    idx_ng = []
    idx_ok = []

    for i in range(N):
        if A[i] == n and B[i] == n:
            idx_ng.append(i)
        elif A[i] != n and B[i] != n:
            idx_ok.append(i)

    for ng, ok in zip(idx_ng, idx_ok):
        B[ng], B[ok] = B[ok], B[ng]

    print(*B)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 53184
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    H,W,A,B=map(int,input().split())
    def COMinit(n,MOD):
        fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
        fac[0]=fac[1]=1
        finv[0]=finv[1]=1
        inv[1]=1
        for i in range(2,(n+1)):
            fac[i]=fac[i-1]*i%MOD
            inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
            finv[i]=finv[i-1]*inv[i]%MOD
        return fac,finv,inv
    
    fac,finv,inv=COMinit(H+W,MOD)
    
    def COM(n, k, MOD=MOD):
        if n<k or n<0 or k<0:
            return 0
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
    
    ans=0
    for i in range(B,W):
        ans+=COM(H-A-1+i,i)*COM(A-2+W-i,A-1)
        ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()


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

int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  int ans = 2 * n;
  for (int i = 0; i < n; i++) {
    string sres = s.substr(i);
    string tres = t.substr(0, n - i);
    if (sres == tres) {
      cout << n + i << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
    int x, a, b;
    std::cin >> x >> a >> b;
    int past = b - a;
    std::string res;
    if (past <= 0) res = "delicious";
    else if (past > x)res = "dangerous";
    else res = "safe";
    std::cout << res << std::endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> C(n), S(n), F(n);
  rep(i, 0, n-1) cin >> C[i] >> S[i] >> F[i];

  rep(i, 0, n-1) {
    int ans = 0;
    rep(j, i+1, n) {
      if (ans < S[j-1]) ans = S[j-1];
      else if (ans % F[j-1] == 0);
      else ans = ans + F[j-1] - ans%F[j-1];
      ans += C[j-1];
    }
    cout << ans << endl;
  }
  cout << 0 << endl;
}


Measured memory_bytes: 256
def insertionSort(a, N, g, count):
    for i in range(g, N):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j -= g
            count += 1
        a[j+g] = v
    return count

def shellSort(a, N):
    count = 0
    G = []
    G.append(1)
    i = 0
    while G[i] <= N:
        G.append(3*G[i] + 1)
        i += 1
    del G[-1]
    m = len(G)
    for i in range(m):
        count = insertionSort(a, N, G[m-1-i], count)
    return G, count


if __name__ == "__main__":
    N = int(input())
    a = [int(input()) for _ in range(N)]
    answer = shellSort(a, N)
    print(len(answer[0]))
    print(*answer[0][::-1])
    print(answer[1])
    for x in a: print(x)



Measured memory_bytes: 45520
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define A a
#define B b
#define C c
#define D d
#define N n
#define M m
#define H h
#define W w
#define S s
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
int main(){
	int n;cin>>N;
	int p[n];int a,b,c;
	int count=0;
	rep(i,0,n){
		cin>>p[i];
		if(i>=2){
			a=p[i-2];b=p[i-1];c=p[i];
			if((a<b&&b<c)||(a>b&&b>c)){
				count++;
			}
		}
	}cout<<count<<endl;
}

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

int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int A[101];

int main() {
  int N, M, i;
  int sum;
  scanf("%d %d", &N, &M);
  for(i=0; i<N; i++) scanf("%d", &A[i]);

  sum = 0;
  for(i=0; i<N; i++) sum += A[i];
  qsort(A, sizeof(A)/sizeof(*A), sizeof(*A), desc);
  if(A[M-1]*4*M>=sum){
    printf("Yes");
  }else{
    printf("No");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n,m; cin >> n >> m;
    vl cnt(m);
    rep(i,n){
        ll k; cin >> k;
        rep(j,k){
            ll a; cin >> a; a--;
            cnt[a]++;
        }
    }
    ll ans = 0;
    rep(i,m){
        if(cnt[i] == n) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine();
            Console.WriteLine(s.Count(x => x == '1'));
        }
    }
}


Measured memory_bytes: 26268
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7, M = 100010;
ll dp[101][M];

int main() {
    int n, k;
    cin >> n >> k;
    VI a(n);
    REP(i,n) a[i] = in();
    FOR(j,k+1,M-1) dp[0][j] = 1;
    REP(i,n){
        REP(j,k+1){
            dp[i+1][j+1] = (dp[i][min(k+1,j+a[i]+1)] - dp[i][j] + mod) % mod;
        }
        REP(j,M-2){
            dp[i+1][j+1] = (dp[i+1][j+1] + dp[i+1][j]) % mod;
        }
    }
    cout << dp[n][1] << endl;
    return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

map<long long, long long>Map[64];
long long N, mod = 1000000007;

long long solve(int bit, long long rem) {
	if (bit >= 0) rem = min(rem, (4LL << bit) - 2LL);
	if (rem < 0) return 0;
	if (bit == -1) return 1;
	if (Map[bit][rem] >= 1) return Map[bit][rem] - 1;

	long long v1 = solve(bit - 1, rem);
	long long v2 = solve(bit - 1, rem - (1LL << bit));
	long long v3 = solve(bit - 1, rem - (2LL << bit));
	long long D = (v1 + v2 + v3) % mod;
	Map[bit][rem] = D + 1;
	return D;
}

int main() {
	cin >> N;
	cout << solve(60, N) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,c,count7=0;
  
  	scanf("%d %d %d",&a,&b,&c);
  	
  	if(a==7){
    	count7++;
    }
  	if(b==7){
    	count7++;
    }
  	if(c==7){
    	count7++;
    }
  
  	if(count7==1){
    	printf("YES\n");
    }else{
    	printf("NO\n");
    }
  	
  
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    l, r = MI()

    if r - l >= 2018:
        print(0)
        return

    mod_l = l % 2019
    mod_r = r % 2019

    candidates = []

    if mod_l < mod_r:
        candidates.extend(range(mod_l, mod_r + 1))
    else:
        candidates.extend(range(0, mod_r + 1))
        candidates.extend(range(mod_l, 2019))
    min_ans = 2019

    for i in range(len(candidates)):
        for j in range(i + 1, len(candidates)):
            tmp = (candidates[i] * candidates[j]) % 2019
            if tmp < min_ans:
                min_ans = tmp

    print(min_ans)


main()


Measured memory_bytes: 83776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100 + 10, M = 1e5 + 10;
ll n, m, w, v, dp[M];
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> w >> v;
		for (int j = m - w; j >= 0; j--)
			dp[j + w] = max (dp[j + w], dp[j] + v);	
	} 
	cout << *max_element (dp, dp + m + 1) << endl;
	return 0;
}

Measured memory_bytes: 1024
// https://atcoder.jp/contests/abc151/tasks/abc151_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    string S;
    cin >> S;
    cout << ++S[0] << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3640
#include<stdio.h>

int main(){

int ans=0,max=0,sum = 0;
int N;
scanf("%d",&N);
int a[N];
for (int i = 0; i < N; i++){
    scanf("%d",&a[i]);
    ans += a[i]-1; 
}

printf("%d",ans);

return 0;

}

Measured memory_bytes: 1736
c1=list(map(int,input().split()))
c2=list(map(int,input().split()))
c3=list(map(int,input().split()))

b1,b2,b3=c1[0],c1[1],c1[2]
if c2[0]-b1==c2[1]-b2==c2[2]-b3 and c3[0]-b1==c3[1]-b2==c3[2]-b3: print('Yes')
else: print('No')

Measured memory_bytes: 38384
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			char[] a = scanner.next().toCharArray();
			char[] b = scanner.next().toCharArray();
			if (String.valueOf(a).equals("0"))
				break;
			int[] num = new int[10];
			for (int i = 0; i < 4; i++) {
				num[a[i] - '0']++;
				num[b[i] - '0']++;

			}
			int sum = 0;
			for (int i = 0; i < 10; i++) {
				if (num[i] == 2)
					sum++;
			}
			int ans = 0;
			for (int i = 0; i < 4; i++) {
				if (a[i] == b[i]) {
					ans++;
					sum--;
				}
			}
			System.out.println(ans + " " + sum);
		}
	}
}

Measured memory_bytes: 43996
def test():

	n = int(input())
	A = list(map(int,input().split()))

	swap_count = 0
	for i in range(n):
		for j in range(n-1,i,-1):
			if A[j] < A[j-1]:
				swap_count += 1
				tmp = A[j]
				A[j] = A[j-1]
				A[j-1] = tmp

	for i in range(n-1):
		print(f"{A[i]} ",end = '')
	print(f"{A[n-1]}")
	print(swap_count)


if __name__ == "__main__":
	test()



Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

int s[105], a[205];

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  LL n; cin >> n;
  int tot = 0;
  while (n) s[++tot] = n & 1, n >>= 1;
  int L = 100, R = 99, tmp = 0;
  while (tot) {
    --tot;
    int cnt = 1;
    while (!s[tot] && tot > 0) --tot, ++cnt;
    if (!tot) --cnt;
    while (cnt > 0) a[++R] = ++tmp, --cnt;
    a[--L] = ++tmp;
  }
  printf("%d\n", 100 + (R - L + 1));
  for (RI i = L; i <= R; ++i) printf("%d ", a[i]);
  for (RI i = 1; i <= 100; ++i) printf("%d ", i);

  return 0;
}

// created by Daniel yuan


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

int main(void)
{
  int A, B, C, K, k = 0;
  scanf("%d%d%d%d", &A, &B, &C, &K);
  while (A >= B)
  {
    B = B * 2;
    k++;
  }
  while (B >= C)
  {
    C = C * 2;
    k++;
  }
  if (K >= k)
  {
    printf("Yes");
  }
  else
  {
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

struct Card { char suit, value; };

void printArray(struct Card c[], int n) {
  for (int i = 0; i < n; ++i) {
    cout << c[i].suit << c[i].value;
    if (i == n - 1) break;
    cout << " ";
  }
  cout << endl;
}

void bubbleSort(struct Card c[], int n) {
  for (int i = 0; i < n; ++i) {
    for (int j = n - 1; j > i; --j) {
      if (c[j].value < c[j - 1].value) {
        swap(c[j], c[j - 1]);
      }
    }
  }
  printArray(c, n);
  cout << "Stable" << endl;
}

void selectionSort(struct Card c[], int n) {
  for (int i = 0; i < n; ++i) {
    int minj = i;
    for (int j = i; j < n; ++j) {
      if (c[j].value < c[minj].value) {
        minj = j;
      }
    }
    swap(c[i], c[minj]);
  }
  printArray(c, n);
}

bool isStable(struct Card c1[], struct Card c2[], int n) {
  for (int i = 0; i < n; ++i) {
    if (c1[i].suit != c2[i].suit) return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  Card c1[n], c2[n];
  for (int i = 0; i < n; ++i) {
    cin >> c1[i].suit >> c1[i].value;
    c2[i].suit = c1[i].suit;
    c2[i].value = c1[i].value;
  }

  bubbleSort(c1, n);
  selectionSort(c2, n);
  bool res = isStable(c1, c2, n);
  if (res) cout << "Stable" << endl;
  else cout << "Not stable" << endl;

  return 0;
}



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

typedef pair<int, int> ii;

long long dp[110][100010];
int main(){
    int n, w;
    cin >> n >> w;

    for(int i = 0; i <= n; i++){
        for(int j = 0; j < 100010; j++){
            dp[i][j] = 2000000000;
        }
    }
    dp[0][0] = 0;


    vector<ii> a(n);
    for(auto &x : a ){
        cin >> x.first >> x.second;
    }

    for(int i = 1; i <= n; i++){
        int ww = a[i-1].first;
        int v = a[i-1].second;
        for(int j = 0; j < 100010; j++){
            if(j>=v){
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v] + ww);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    int ans = 0;

    for(int i = 1; i <=n; i++){
        for(int j = 0; j < 100010; j++){
            if(dp[i][j] <= w){
                ans = max(ans, j);
            }
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 80128
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b=mod-2,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int n, res;
pair<int,int> a[55];

signed main() {
    cin >> n;
    res = n;
    rep(i,n) cin >> a[i].first >> a[i].second;
    sort(a, a+n);
    rep(i,n) reps(j,i+1,n) {
        int p = a[j].first-a[i].first, q = a[j].second-a[i].second;
        int t = n;
        rep(l,n) {
            int lx = a[l].first, ly = a[l].second;
            reps(r,l+1,n) if (lx==a[r].first-p && ly==a[r].second-q) t--;
            chmin(res, t);
        }
    }
    cout << res << endl;
}


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


public class Main{ 

	public static void main(String args[]){
		
		Scanner scan = new Scanner(System.in);
		Dice d = new Dice(scan.nextLine());
		int qnum = scan.nextInt();
		for(int i=0; i< qnum;i++){
			d.rollSet(scan.nextInt(),scan.nextInt());
		}

	}

}
class Dice{
	int top;
	int back;
	int right;
	int left;
	int front;
	int bottom;
	public Dice(String line){
		String[] face = line.split(" ");
		top = Integer.parseInt(face[0]);
		back = Integer.parseInt(face[1]);
		right = Integer.parseInt(face[2]);		
		left = Integer.parseInt(face[3]);
		front = Integer.parseInt(face[4]);
		bottom = Integer.parseInt(face[5]);
	}
	void rotate(){
		int tmp = front;
		front = right;
		right=back;
		back = left;
		left = tmp;
	}
	public void roll(char c){
		int tmp = top;
		switch(c){
			case 'N':
				top = back;
				back=bottom;
				bottom = front;
				front = tmp;
				break;
			case 'E':
				top = left;
				left = bottom;
				bottom = right;
				right = tmp;
				break;
			case 'S':
				top = front;
				front = bottom;
				bottom = back;
				back = tmp;
				break;
			case 'W':
				top = right;
				right = bottom;
				bottom = left;
				left = tmp;
				break;
		}
	}
	public void printTop(){
		System.out.println(this.top);
	}
	public void rollSet(int t, int b){
		if(!frontRoll(t)){
			while(top!=t)
				roll('W');
		}
		while(back!=b)
				rotate();
		System.out.println(this.right);
	}
	boolean frontRoll(int t){
		for(int i=0;i<4;i++){
			roll('N');
			if(top==t)
				return true;
		}
		return false;
	}

}

Measured memory_bytes: 17356
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	double r; cin >> r;
	double pi = 22.0 / 7.0;

	pi *= 2.0;
	pi *= r;

	cout << ps(pi, 3) << '\n';
	return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    int sum = 1;
    for (int i = 0; i < N; ++i) {
        if (sum * 2 < sum + K) {
            sum *= 2;
        } else {
            sum += K;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 45
int A[N];

int fibonacci(int n)
{
  if(n==0 || n==1) return 1;
  if(A[n] !=-1) return A[n];
  return A[n] = fibonacci(n-2)+fibonacci(n-1);
}
int main()
{
  int i,n;

  for(i=0; i<N; i++) A[i] =-1;
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));

  return 0;
}



Measured memory_bytes: 2104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main{
	
	static long mod = (int)1e9 + 7;
	

	public static void main(String[] args) throws Exception{

		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int n = fs.nextInt();
		int m = fs.nextInt();
		
		Node[] nodes = new Node[n];
		for(int i=0;i<n;i++) nodes[i] = new Node();
		
		for(int i=0;i<m;i++) {
			int a = fs.nextInt()-1, b = fs.nextInt()-1;
			nodes[a].set.add(b);
			nodes[b].set.add(a);
		}
		
		int ans = 0;
		
		for(int i=0;i<n;i++) {
			ans = Math.max(ans, dfs(nodes,nodes[i]));
		}
		
		out.println(ans);
		
		out.close();
		
		

		
	}
	
	static int dfs(Node[] nodes, Node node) {
		if(node.visited) return 0;
		int count = 1;
		node.visited = true;
		for(int i: node.set) {
			if(!nodes[i].visited) {
				count += dfs(nodes,nodes[i]);
			}
		}
		return count;
	}
	
	static class Node{
		HashSet<Integer> set = new HashSet<Integer>();
		boolean visited = false;
		
	}
	
	
	
	
	
	static class FastScanner{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		public String next(){
			while(!st.hasMoreElements()){
				try{
					st = new StringTokenizer(br.readLine());
				} catch(IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		
		public String nextLine() throws IOException {
			return br.readLine();
		}
		
		public int nextInt(){
			return Integer.parseInt(next());
		}

		public int[] readArray(int n){
			int[] a = new int[n];
			for(int i=0;i<n;i++)
				a[i] = nextInt();
			return a;
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	


}

Measured memory_bytes: 130100
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define ll long long int
using namespace std;
void Solve()
{
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i] == '7')
        {
            cout << "Yes";
            return;
        }
    }
    cout << "No";
}

int main()
{
    ios_base::sync_with_stdio( false );
    cin.tie( nullptr );
   // int t;
    //cin >> t;
    //while (t--)
    {
        Solve();
        cout << '\n';
    }
    return 0;
}



Measured memory_bytes: 3660
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

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

	string s;
	cin >> s;

	vector<int> g;
	vector<int> h;
	bool b = true;
	int cnt = 0;
	for (int i = 0; i < s.length(); i++)
	{
		string c = s.substr(i, 1);

		if (c == "0")
		{
			if (b)
			{
				g.push_back(cnt);
				cnt = 0;
			}
			b = false;
		}
		else
		{
			if (!b)
			{
				g.push_back(-cnt);
				cnt = 0;
			}
			b = true;
		}

		cnt++;
	}
	g.push_back(cnt);

	int m = 0;
	for (int i = 0; i < g.size(); i++)
	{
		int x = 0;
		if (g.at(i) >= 0)
		{
			int i0 = i;
			for (int j = 2*k + 1; j > 0; j--)
			{
				x += abs(g.at(i0));
				i0++;
				if (i0 >= g.size())
				{
					break;
				}
			}
		}
		m = max(m, x);
	}

	cout << m << endl;
}

Measured memory_bytes: 1020
from collections import Counter

N, K = map(int, input().split())
a = list(map(int, input().split()))

sum = 0
c = Counter(a).most_common()
if K > len(c):
    print(0)
    exit()
for i in range(K):
    sum += c[i][1]
print(len(a) - sum)


Measured memory_bytes: 129876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define loop(i, a, b) for(ll i = a; i < b; i++)
#define rloop(i, e, s) for(ll i = e; i >= s; i--)
const ll mod = 1e9 + 7;
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr);

int main()
{
  //Anti Division
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = b-a+1;
    ans -=  b/c - (a-1)/c;
    ans -= b/d - (a-1)/d;
    ll x = (c*d)/__gcd(c, d);
    ans +=  b/x - (a-1)/x;
    cout << ans << endl;

}

Measured memory_bytes: 256
import math
n,m=map(int,input().split())
s=input()
t=input()
g = n * m // math.gcd(n, m)

'''if n<m:
    s,t=t,s
    snum,tnum=tnum,snum'''

for i in range(math.gcd(n,m)):
    #print(i, i*(g//m), s[i*(g//m)], i*(g//n), t[i*(g//n)])
    if s[i*(g//m)]!=t[i*(g//n)]:
        print(-1)
        exit()
print(g)

Measured memory_bytes: 9236
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
char s[112345];

int main() {
  scanf("%s", s);
  vector<int64_t> d(13);
  d[0] = 1;
  int64_t base = 1;
  for (int i = int(strlen(s)) - 1; i >= 0; --i) {
    vector<int64_t> d2(13);
    char c = s[i];
    if (c == '?') {
      for (int x = 0; x <= 9; ++x) {
        for (int y = 0; y < 13; ++y) {
          int t = (x * base + y) % 13;
          d2[t] = (d2[t] + d[y]) % mod;
        }
      }
    } else {
      int x = c - '0';
      for (int y = 0; y < 13; ++y) {
        int t = (x * base + y) % 13;
        d2[t] = (d2[t] + d[y]) % mod;
      }
    }
    d = d2;
    base = base * 10 % 13;
  }
  printf("%lld\n", d[5]);
  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

typedef long long LL;

LL a[200010], f[200010], sum[200010];
LL n;

int main() {
    read(n);
    for (int i = 1; i <= n; ++i)    read(a[i]);
    sum[1] = a[1];
    for (int i = 2; i <= n; ++i)    sum[i] = sum[i - 2] + a[i];
    for (int i = 2; i <= n; ++i) {
        if (i & 1) {
            f[i] = std::max(f[i - 1], f[i - 2] + a[i]);
        } else {
            f[i] = std::max(f[i - 2] + a[i], sum[i - 1]);
        }
    }
    printf("%lld\n", f[n]);
    return 0;
}

Measured memory_bytes: 8416
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 10000;
const int MAX_P = 10000;

/* typedef */

typedef vector<int> vi;

/* global variables */

bool primes[MAX_P + 1];
vi pnums;

/* subroutines */

void gen_primes(int maxp, vi &pnums) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  int p;
  for (p = 2; p * p <= maxp; p++)
    if (primes[p]) {
      pnums.push_back(p);
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
    }
  for (; p <= maxp; p++)
    if (primes[p]) pnums.push_back(p);
}

bool is_prime(int a) {
  if (a <= MAX_P) return primes[a];

  for (vi::iterator vit = pnums.begin(); vit != pnums.end(); vit++) {
    int &pi = *vit;
    if (pi * pi > a) break;
    if (a % pi == 0) return false;
  }
  return true;
}

/* main */

int main() {
  gen_primes(MAX_P, pnums);

  int n;
  cin >> n;

  int cnt = 0;
  
  for (int i = 0; i < n; i++) {
    int ai;
    cin >> ai;
    if (is_prime(ai)) cnt++;
  }

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

Measured memory_bytes: 1224
#include<cstdio>
using namespace std;
int main()
{
	int n,c=0;
	while(scanf("%d",&n)!=EOF){
		c=0;
	for(int i=0;i<10;i++){
		for(int i2=0;i2<10;i2++){
			for(int i3=0;i3<10;i3++){
				for(int i4=0;i4<10;i4++){
					if(i+i4+i2+i3==n)c++;
				}
			}
		}
	}
	printf("%d\n",c);}
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define RREP1(i, n) for (ll i = n; i >= 1; i--)
#define FOR(i, a, b, c) for (ll i = a; i <= b; i += c)
#define RFOR(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define INF 1145141919
typedef long long ll;
 
int main() {
    ll h, w;
    scanf("%lld %lld", &h, &w);
    
    if (h % 3 == 0 || w % 3 == 0) {
        puts("0");
        return 0;
    }
    ll min = (ll)INF * INF;
    {
        ll t1 = h * (w / 3);
        ll t2 = h * ((w - (w / 3)) / 2);
        ll t3 = (h * w) - t1 - t2;
        ll tmax = MAX(MAX(t1, t2), t3);
        ll tmin = MIN(MIN(t1, t2), t3);
        min = MIN(min, tmax - tmin);
    }
    {
        ll t1 = w * (h / 3);
        ll t2 = w * ((h - (h / 3)) / 2);
        ll t3 = (h * w) - t1 - t2;
        ll tmax = MAX(MAX(t1, t2), t3);
        ll tmin = MIN(MIN(t1, t2), t3);
        min = MIN(min, tmax - tmin);
    }
    REP(i, h + 1) {
        ll t1 = w * i;
        ll t2 = (h - i) * (w / 2);
        ll t3 = w % 2 == 0 ? t2 : t2 + (h - i);
        ll tmax = MAX(MAX(t1, t2), t3);
        ll tmin = MIN(MIN(t1, t2), t3);
        min = MIN(min, tmax - tmin);
    }
    REP(i, w + 1) {
        ll t1 = h * i;
        ll t2 = (w - i) * (h / 2);
        ll t3 = h % 2 == 0 ? t2 : t2 + (w - i);
        ll tmax = MAX(MAX(t1, t2), t3);
        ll tmin = MIN(MIN(t1, t2), t3);
        min = MIN(min, tmax - tmin);
    }
    printf("%lld\n", min);
    return 0;
}

Measured memory_bytes: 128