akhauriyash/Code-Regression huggingface dataset:
n = int(raw_input())

def count(sc):
    c3 = 0
    c5 = 0
    c7 = 0
    for c in sc:
        if c == "3":
            c3 += 1
        elif c == "5":
            c5 += 1
        elif c == "7":
            c7 += 1
        else:
            raise ValueError("error!")
    return c3 > 0 and c5 > 0 and c7 > 0
            

def up(tsc):
    res = ['0']*(len(tsc)+1)
    done = False
    i = len(tsc) - 1
    while not done and i >= -1:
        if tsc[i] == '7':
            carry = True
            res[i+1] = '3'
        elif tsc[i] == '5':
            res[i+1] = "7"
            done = True
        elif tsc[i] == '3':
            res[i+1] = "5"
            done = True
        elif i == -1:
            res[i+1] == '3'
            done = True
        i -= 1
    for i in range(i, -1, -1):
        res[i+1] = tsc[i]
    if res[0] == "0":
        return "".join(res[1:])
    else:
        return "".join(res)
        
def solve(n):
    tsc = "357"
    res = 0
    while int(tsc) <= n:
        if count(tsc):
            res += 1
        tsc = up(tsc)
    return res
print solve(n)
        
        
        
    
        

Measured memory_bytes: 34536
#import<bits/stdc++.h>
#define L long
#define t first
#define u second
#define M push_back(make_pair(c(
using namespace std;L R,C,N,a[9<<14],b,i;vector<pair<L,L>> p;L s(L x,L y){return!(x^0&&x^R&&y^0&&y^C);}L c(L x,L y){return L(atan2(x-R/2,y-C/2)*(1<<30));}main(){for(cin>>R>>C>>N;i<N;++i){cin>>*a>>a[1]>>a[2]>>a[3];if(s(*a,a[1])&&s(a[2],a[3])){p.M*a,a[1]),i));p.M a[2],a[3]),i));}}sort(p.begin(),p.end());fill(a,a+114514,0);stack<L>s;for(auto P:p){if(s.empty()||s.top()^P.u)s.push(P.u);else s.pop();}puts(s.size()?"NO":"YES");}

Measured memory_bytes: 6256
inf = float('inf')
# ベルマンフォード法
# 計算量O(VE) V:頂点数, E:辺の数
# [引数]   n:頂点数, edges:辺集合, start:始点, end:終点
# [返り値] dist:startからの最短距離, exists_negative_cycle: 負閉路が存在するかどうか
def bellmanford(n : int, edges : list, start : int, goal : int) -> (list, bool):
    dist = [inf] * n
    dist[start] = 0
    exist_negative_cycle = True

    # 負閉路を含まないとき、頂点数nなら更新は高々n-1回で済む
    for _ in range(N-1):
        for v, nv, w in edges:
            if dist[nv] > dist[v] + w:
                dist[nv] = dist[v] + w


    # (1)グラフに負閉路が含まれるときの検出
    # N回目で更新があったとき、グラフは負閉路を含む
    # for v, nv, w in edges:
    #     if dist[nv] > dist[v] + w:
    #         is_cycle = False

    # (2)startとendのパスに負閉路が含まれるときの検出
    is_updated = [False] * n
    for _ in range(N):
        for v, nv, w in edges:
            if dist[nv] > dist[v] + w:
                dist[nv] = dist[v] + w
                is_updated[nv] = True
            if is_updated[v] is True:
                is_updated[nv] = True

    exist_negative_cycle = is_updated[goal]

    return dist, exist_negative_cycle

N, M = map(int,input().split())
edges = []
for _ in range(M):
    a, b, c = map(int,input().split())
    a -= 1; b -= 1
    edges.append((a, b, -c))

dist, exist_negative_cycle = bellmanford(N, edges, 0, N-1)

if exist_negative_cycle is True:
    ans = "inf"
else:
    ans = -dist[N-1]

print(ans)

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

int main(){
	//cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>a(n);
	for(auto&i:a)cin>>i;
	sort(a.begin(),a.end(),[](auto a,auto b){return a>b;});
	int tmp=a.front(),place=0;
	while(tmp){
		++place;
		tmp/=2;
	}
	vector<int>cnt(place+1,0);
	for(auto&i:a){
		int j=1,p=1;
		while(j<=place){
			if(p&i)++cnt.at(j);
			++j;
			p=p<<1;
		}
	}
	bool yes=true;
	for(int i=1;i<cnt.size();++i){
		if(cnt.at(i)%2!=0)yes=false;
	}
	cout<<(yes?"Yes"s:"No"s)<<"\n"s;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	int x,y,z;
	cin >> x >> y >> z;
	swap(x,y);
	swap(x,z);
	cout << x << " " << y << " " << z << endl;

  return 0;
}


Measured memory_bytes: 256
/*
    Flowers, wake up like the sea!
*/
#include <bits/stdc++.h>
#define PB push_back
#define FT first
#define SD second
#define MP make_pair
#define INF 0x7fffffff
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>  P;
typedef vector<int> VI;
typedef map<int,int> MII;
const int N = 2e5 + 10, MOD = 7+1e9;
int n, a[N];
LL s[N];
int main()
{
#ifdef YUUKILP
    freopen("in.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> a[i], a[i] -= i;
    sort(a + 1, a + 1 + n);
    for(int i = 1;i <= n;i ++) s[i] = s[i-1] + a[i];
    LL ans = -1;
    for(int i = 1;i <= n;i ++)
    {
        int b = -1 * a[i];
        LL now = s[n] - s[i] + 1ll * b * (n - i - i + 1) - s[i-1];
        if(ans == -1) ans = now;
        else ans = min(ans, now);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<math.h>

using namespace std;

int main(){
    int n,x;
    int ans=0;
    cin>>n;
    int count=0;
    int k;
    while(count<n){
        count++;
        cin>>x;
        k=1;
        
        for(int i=2; i<=sqrt(x); i++){
            if(x%i==0) {
                k=0;
                break;
            }
        }
        ans+=k;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

class DisjointSet{
public:
  int N;
  vector<int> rank,p;
  vector<int> sz;
 
  DisjointSet(){}
  DisjointSet(int n):N(n),rank(n),p(n),sz(n){
    for(int i=0;i<N;i++) makeSet(i);
  }
 
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
    sz[x]=1;
  }
 
  bool same(int x,int y){
    return leader(x)==leader(y);
  }
 
  void unite(int x,int y){
    if(same(x,y)) return;
    link(leader(x),leader(y));
  }
 
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      sz[x]+=sz[y];
    }else{
      p[x]=y;
      sz[y]+=sz[x];
      if(rank[x]==rank[y]){
        ++rank[y];
      }
    }
  }
 
  int leader(int x){
    if(x!=p[x]) p[x]=leader(p[x]);
    return p[x];
  }
 
  int size(int x){
    return sz[leader(x)];
  }
};

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

  int N;
  cin>>N;
  vector<int> X(N),Y(N);
  rep(i,N) cin>>X[i]>>Y[i];

  rep(i,N){
    X[i]--;Y[i]--;
  }

  DisjointSet us(N);
  {
      vector<int> ord(N,0);
      rep(i,N) ord[i]=i;
      sort(all(ord),[&](int a,int b){
          return X[a]<X[b];
      });
      set<pair<int,int>> se;
      rep(i,N) se.insert(mkp(Y[i],i));
      set<pair<int,int>> te;

      for(auto i:ord){
          auto itr=se.lower_bound(mkp(Y[i],i+1));
          if(itr!=se.end()){
              int tar=(*itr).second;
              us.unite(i,tar);
          }
          se.erase(mkp(Y[i],i));

          {
            auto itr=te.lower_bound(mkp(Y[i],i));
            if(te.size()>0&&itr!=te.begin()){
                --itr;
                int tar=(*itr).second;
                us.unite(i,tar);
            }
              te.insert(mkp(Y[i],i)); 
          }
      }
  }
  {
      vector<int> ord(N,0);
      rep(i,N) ord[i]=i;
      sort(all(ord),[&](int a,int b){
          return Y[a]<Y[b];
      });
      set<pair<int,int>> se;
      rep(i,N) se.insert(mkp(X[i],i));
      set<pair<int,int>> te;

      for(auto i:ord){
          auto itr=se.lower_bound(mkp(X[i],i+1));
          if(itr!=se.end()){
              int tar=(*itr).second;
              us.unite(i,tar);
          }
          se.erase(mkp(X[i],i));

          {
            auto itr=te.lower_bound(mkp(X[i],i));
            if(te.size()>0&&itr!=te.begin()){
                --itr;
                int tar=(*itr).second;
                us.unite(i,tar);
            }
              te.insert(mkp(X[i],i)); 
          }
      }
      
  }

  vector<int> ans(N,0);
  rep(i,N) ans[i]=us.size(i);

  rep(i,N) cout<<ans[i]<<"\n";

  return 0;
}


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


int main() {
    string s,t;
    cin>>s>>t;
    bool ans =false;
    rep(i,s.size()){
        if(s==t){
            ans = true;
            break;
        }
        s = s.back() + s.substr(0,s.size()-1);
    }
    cout << (ans? "Yes" :"No") <<endl;
    
    return 0;
}


Measured memory_bytes: 256
def is_available_yymm(s: str) -> bool:
    return 12 >= int(s[2] + s[3]) >= 1


def is_available_mmyy(s: str) -> bool:
    return 12 >= int(s[0] + s[1]) >= 1


def main():
    s = input()
    yymm = is_available_yymm(s)
    mmyy = is_available_mmyy(s)
    if yymm and mmyy:
        print("AMBIGUOUS")
    elif yymm:
        print("YYMM")
    elif mmyy:
        print("MMYY")
    else:
        print("NA")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define DIM 300007
long long n,c,minc,W[DIM],E[DIM];
string s;
int main()
{
    //freopen("input.txt","r",stdin);
    cin>>n>>s;
    for(int i=0;i<n;i++){
     if(s[i]=='W')W[i]++;
     else if(s[i]=='E')E[i]++;
     W[i]+=W[i-1];
     E[i]+=E[i-1];
    }
    minc=100000007;
    for(int i1=0;i1<n;i1++){
     c=0;
     c+=W[i1-1];
     c+=E[n-1]-E[i1];
     if(c<minc)minc=c;
    }
    cout<<minc<<endl;
}


Measured memory_bytes: 5380
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
 
int main() {
 
    int n; cin >> n;
    string s; cin >> s;
 
    map<char, int> ma;
    ma['R'] = 0;
    ma['G'] = 0;
    ma['B'] = 0;
 
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') ma['R']++;
        if (s[i] == 'G') ma['G']++;
        if (s[i] == 'B') ma['B']++;
    }
 
    ll ans = (ll)ma['R'] * (ll)ma['G'] * (ll)ma['B'];
 
    for (int t = 1; t <= n; ++t) {
        for (int i = 0; i < n; ++i) {
            set<char> se;
            se.insert(s[i]);
 
            if (i + t >= n) continue;
            se.insert(s[i + t]);
 
            if (i + t + t >= n) continue;
            se.insert(s[i + t + t]);
 
            if (se.size() == 3) ans--;
        }
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 3632
N = int(input())
L = list(map(int,input().split()))
ans = 0
def zero_spliter(L):
    cnt = 1
    for x in L:
        if x == 0:
            cnt += 1
    M = [[] for _ in range(cnt)]
    i = 0
    for x in L:
        if x != 0:
            M[i].append(x)
        else:
            i += 1
    for x in M:
        if x != []:
            yield x
ans = 0
def counter(L):
    global ans
    if L == []:
        pass
    if 0 in L:
        l = list(zero_spliter(L))
        for x in l:
            counter(x)
    else:
        M = [x-1 for x in L]
        ans += 1
        counter(M)
counter(L)
print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

int ruisekiwa[100005];
int main()
{
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		int c, d; scanf("%d%d", &c, &d);
		ruisekiwa[c]++; ruisekiwa[d + 1]--;
	}
	int k = 1;
	int MAX = 0;
	for (int i = 0; i < 100005; i++) {
		k += ruisekiwa[i];
		if (k >= i)MAX = max(MAX, min(k, i));
	}
	cout << MAX-1 << endl;
}

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

int main(){
    string s[3];
    for(int i=0;i<3;i++){
        cin>>s[i];
    }
    cout<<s[0][0]<<s[1][1]<<s[2][2]<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
//#include <boost/functional/hash.hpp>
//example: unordered_set< pair<int,int>,boost::hash< std::pair<int, int> > > used;
//priority_queue< pair<int,pair<int,int> >, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int> > > > pqueue;    //cost, vertex(行き先)
using namespace std;

#define MODULE 1000000007
#define MP make_pair
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
template<typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val){ //usage: int dp[10][10]; Fill(dp,INF);
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef pair<int, int> P;
typedef long long LL;
const int INF = INT_MAX / 2;    //int_max->2*e+9 LLの時はLLONG_MAX
/*const int MAXN = 100001;

struct edge {
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<edge> graph[MAXN];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};*/

//-----Template---------
LL n,t;
LL a[100001];
LL maxA=INF;
LL maxDiff=1;
LL ycount=0;
int main(){
    ios::sync_with_stdio(false); //cout<< fixed << setprecision(10);
    cin>>n>>t;
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    maxA=a[n-1];
    for (int i = n-2; i >=0 ; --i) {
        if(maxDiff<(maxA-a[i])){
            ycount=1;
            maxDiff=maxA-a[i];
        }else if(maxDiff==(maxA-a[i])){
            ycount++;
        }

        if(maxA<a[i]){
            maxA=a[i];
        }
    }
    cout<<ycount<<endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main()
{
 ll N,sum,i,K,p,ans;
  p=1000000007;
  cin >> N >> K;
  ans=((K-1)*K%p*(2*K-1)%p-(N+1)*(N+2)%p*(2*N+3)%p)*modinv(6,p)%p+(N+2-K)+(N+2-K)*(N+1)%p*(N+1+K)%p*modinv(2,p);
  ans=ans%p;
  if(ans<0)
    ans+=p;
  cout << ans << endl;
  
  
  

}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int h,a; cin >> h >> a;
  int n=0;
  while(h > 0){
    h -= a;
    n++;
  }
  cout << n << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack> 
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
//const int MAX_V=105;

int main(){
  
  int N,c=1;
  int sum=0;
  cin >> N;
  long long A[N+1];
  rep(i,N){
    cin >> A[i];
  }
  sort(A,A+N);
  A[N]=0;
  rep(i,N){
    if(A[i]==A[i+1]){
      c+=1;
    }else{
      sum += c%2;
      c=1;
    }
  }
  cout << sum << endl;

    return 0;
}
 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int ans=0,t=0;
    for(int i=0;i<n-1;i++){
        if(h[i]>=h[i+1]){
            ++t;
            ans=max(ans,t);
        }
        else{
            t=0;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
<?php

fscanf(STDIN, "%d", $n);
$a_list = explode(' ', trim(fgets(STDIN)));

$ng_a_list = array_filter($a_list, function ($a) {
    if ($a % 2 === 1) {
        return false;
    }

    return ($a % 3 !== 0 && $a % 5 !== 0);
});

echo empty($ng_a_list) ? 'APPROVED' : 'DENIED';


Measured memory_bytes: 15940
import java.util.*;
public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int A, B ,M;
		A = sc.nextInt();
		B = sc.nextInt();
		M = sc.nextInt();
		int dataA[] = new int[A];
		int dataB[] = new int[B];
		int minA = Integer.MAX_VALUE;
		int minB = Integer.MAX_VALUE;
		
		for(int i = 0; i < A; i++) {
			dataA[i] = sc.nextInt();
			minA = Math.min(minA,dataA[i]);
		}
		for(int i = 0; i < B; i++) {
			dataB[i] = sc.nextInt();
			minB = Math.min(minB,dataB[i]);
		}
		int ans = minA+minB;
		for(int i = 0; i<M; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int c = sc.nextInt();
			ans = Math.min(ans, dataA[x-1] + dataB[y-1] - c);
		}
		System.out.println(ans);
		
		
	}
}



Measured memory_bytes: 134720
#include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,int> dp[32][32][32][32];
int m[32][32];
int S[33][33];
int p;
pair<int,int> solve(int a,int b,int c,int d){
	if(~(dp[a][b][c][d].first))return dp[a][b][c][d];
	pair<int,int> q=make_pair(-99999999,0);
	if(S[b+1][d+1]-S[b+1][c]-S[a][d+1]+S[a][c]>=p){
		q=make_pair(1,S[b+1][d+1]-S[b+1][c]-S[a][d+1]+S[a][c]-p);
	}
	for(int i=a;i<b;i++){
		pair<int,int> L=solve(a,i,c,d);
		pair<int,int> R=solve(i+1,b,c,d);
		R.first+=L.first;
		R.second=min(L.second,R.second);
		q=max(q,R);
	}
	for(int i=c;i<d;i++){
		pair<int,int> L=solve(a,b,c,i);
		pair<int,int> R=solve(a,b,i+1,d);
		R.first+=L.first;
		R.second=min(L.second,R.second);
		q=max(q,R);
	}
	return dp[a][b][c][d]=q;
}
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		for(int i=0;i<a;i++)
			for(int j=i;j<a;j++)
				for(int k=0;k<b;k++)
					for(int l=k;l<b;l++)
						dp[i][j][k][l]=make_pair(-1,-1);
		int s=0;
		for(int i=0;i<a;i++)
			for(int j=0;j<b;j++){
				scanf("%d",&m[i][j]);
				s+=m[i][j];
			}
		p=s-c;
		for(int i=0;i<a;i++)
			for(int j=0;j<b;j++)
				S[i+1][j+1]=m[i][j];
		for(int i=1;i<=a;i++)
			for(int j=1;j<=b;j++)
				S[i][j]+=S[i-1][j];
		for(int i=1;i<=a;i++)
			for(int j=1;j<=b;j++)
				S[i][j]+=S[i][j-1];
		pair<int,int> ret=solve(0,a-1,0,b-1);
		printf("%d %d\n",ret.first,ret.second);
	}
}

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


int main(){
  string  a, b,c;
  cin >> a >> b >>c;
  if(a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1) == c.at(0)){
    cout <<"YES" << endl;
  }
  else{
    cout <<"NO" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
#define MAX_N 100001



int main()
{
	map<ll,ll> numList;
	ll n;
	cin>>n;
	ll sum = 0;
	rep(i,n){
		ll num;
		cin>>num;
		sum += num;
		if(numList.count(num) == 0){
			numList.insert(make_pair(num,1));
		}else{
			numList[num]++;
		}
	}
	ll Q;
	cin>>Q;
	rep(i,Q){
		ll b,c;
		cin>>b>>c;
		ll x;
		if( numList.count(b) == 0){
			cout<<sum<<endl;
			continue;
		}else{
			x = numList[b];
			sum = sum - x*b + x*c;
			numList.erase(b);
			if( numList.count(c) != 0){
				numList[c] += x;
			}else{
				numList.insert(make_pair(c,x));	
			}
			cout<<sum<<endl;
		}
		/*for(auto iter = numList.begin(); iter != numList.end(); iter++){
			cout<<iter->first<<":"<<iter->second<<endl;
		}*/
		
	}
	return 0;
}


Measured memory_bytes: 7124
from collections import Counter

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

c = Counter(a)

dp = [[[0]*(N+1) for _ in range(N+1)] for _ in range(N+1)]

# メモ化再帰ではpypy3でもTLEするのでforループを使う
# j==k==0の場合を計算 → k==0の場合を計算 → 一般の場合を計算
# dp[i][j][k]の順だとTLEなのでdp[k][j][i]の順で
for k in range(c[3]+1):
    for j in range(c[3]+c[2]-k+1):
        for i in range(N-j-k+1):
            if i == j == k == 0:
                continue
            else:
                tmp = N
                if i > 0: # IndexError防止
                    tmp += dp[k][j][i-1]*i
                if j > 0:
                    tmp += dp[k][j-1][i+1]*j
                if k > 0:
                    tmp += dp[k-1][j+1][i]*k
                dp[k][j][i] = tmp/(i+j+k) # 割り算をまとめた方が速い

print(dp[c[3]][c[2]][c[1]])

Measured memory_bytes: 500488
import java.util.*;
public class Main {
	public static void main(String[] args){
		int mod = 1000000007;

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();

		long g = 0;
		for ( int i=k; i<=n+1; i++ ) {
			long l = (long)(i-1)*(long)i/2l;
			long r = (long)n*(long)i-l;
			g = modadd(g, r-l+1, mod);
		}

		System.out.println(g);
	}

	private static long modadd( long a, long b, int m) {
		long c = (a + b)%(long)m;
		return c;
	}
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (300006)
int main()
{
	FAST
	ll h, a; cin>>h>>a;
	cout<<ll(ceill((h/ld(a))));
}


Measured memory_bytes: 256
package main

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

func main() {
	nextReader = newScanner()
	N := nextInt()
	Ls := nextInts(N)
	sort.Ints(Ls)

	ans := 0
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			v := Ls[i] + Ls[j]
			for k := j + 1; k < N; k++ {
				if v > Ls[k] {
					ans++
				} else {
					break
				}
			}
		}
	}
	fmt.Println(ans)
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


Measured memory_bytes: 640
n = int(input())
H = list(map(int, input().split()))

ans = 0
H_r = H[::-1]
cnt = 0

for i in range(n - 1):
    now = H_r[i]
    nex = H_r[i + 1]
    if now <= nex:
        cnt += 1
        ans = max(ans, cnt)
    else:
        cnt = 0
    nex = now
print(ans)


Measured memory_bytes: 85124
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int min = 1000000;
        int ans = 0;
        for(int i = 0; i < n; i++) {
            int p = Integer.parseInt(sc.next());
            if(p < min) ans++;
            min = Math.min(min, p);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 49292
// use proconio::marker::Chars;
use proconio::{fastout, input};
// use std::cmp::{max, min};

#[fastout]
fn main() {
    input! {
        n: usize,
        d: [usize; n]
    };

    let mut d: Vec<usize> = d;
    d.sort();

    let mut result = 0;
    for i in 0..n - 1 {
        result += d[i];
    }

    result += d[n - 1] / 2;

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


Measured memory_bytes: 2168
n=int(input())
l=[0 for i in range(2*10**5+1)]
r=[0 for i in range(2*10**5+1)]
c=1
a=0
if n!=0:
  k=[int(i) for i in input().split()]
for i in range(n):
  if k[i]+c<=2*10**5:
    l[k[i]+c]+=1 
  if -k[i]+c>=0 and -k[i]+c<=2*10**5:
    r[-k[i]+c]+=1
  c+=1
for i in range(n):
  a+=l[i]*r[i]
print(a)


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

int main(){
    ll n; //カードの枚数
    ll m; //操作の回数
    cin >> n >> m;

    deque<ll> A; //カードに書かれている番号
    for(int i=0; i<n; i++){
        ll a; cin >> a;
        A.push_back(a);
    }

    ll b,c;
    vector<pair<ll,ll>> pair(m);
    for(int i=0; i<m; i++){
        cin >> b >> c;
        pair[i].first = c;
        pair[i].second = b;
    }

    sort(A.begin(),A.end());
    sort(pair.begin(),pair.end());

    ll ans = 0;
    int j=m-1;
    int count = 0;
    int i = 0;
    while(j >= 0 && i<n && count < 2){
        if(A[i] < pair[j].first && pair[j].second > 0){
            A[i] = pair[j].first;
            pair[j].second--;
            i++;
            count = 0;
        }else{
            j--;
            count++;
        }
    }

    for(int i=0; i<n; i++) ans += A[i];

    cout << ans << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x; 
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x; 
        return true;
    }
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    int n; cin >> n;
    auto tmp = n % 1000;
    if (tmp) {
        cout << 1000 - tmp << endl;
    } else {
        cout << 0 << endl;
    }
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define li long ll
#define pp pair<ll, ll> 
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i, x, n) for (ll i = x; i < n; i++)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fr first
#define ss second
using namespace std;
int main()
{
	fast;
	int x;
	cin>>x;
	if(x==0)
	cout<<"1"<<endl;
	else if(x==1)
	cout<<"0"<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    vector<int> A(N);
    int ans = 1e9;
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = -100; i < 101; ++i){
        int sum = 0;
        for(int j = 0; j < N; ++j){
            sum += (i-A[j])*(i-A[j]);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int s=0;
  for(int i=0;i<=100;i++){
    if(a<=i&&i<b && c<=i&&i<d) s++;
  }
cout<<s<<endl;
}


Measured memory_bytes: 256
import collections


def main():
    from sys import stdin, stdout

    read = iter(stdin.read().splitlines()).next
    #def read():
    #    return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    N, Q = read_int_array()
    updates1 = []
    updates2 = []
    for i in range(N):
        S, T, X = read_int_array()
        updates1.append((S - X, X))
        updates2.append((T - X, X))

    active = []
    to_delete = collections.defaultdict(int)
    import heapq
    heapq.heapify(updates1)
    heapq.heapify(updates2)
    for _ in range(Q):
        x = read_int()
        while updates1 and updates1[0][0] <= x:
            coord, val = heapq.heappop(updates1)
            heapq.heappush(active, val)

        while updates2 and updates2[0][0] <= x:
            coord, val = heapq.heappop(updates2)
            to_delete[val] += 1

        while active and to_delete[active[0]] > 0:
            to_delete[active[0]] -= 1
            heapq.heappop(active)
        write(active[0] if active else -1)

main()


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

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  
  for(int i=0;i<N;i++){
    cin >> X.at(i);
  }
  int A=0;
  int B=0;
  
  sort(X.begin(),X.end());
  reverse(X.begin(),X.end());
  
  for(int j=0;j<N;j+=2){
    A+=X.at(j);
  }
  for(int k=1;k<N;k+=2){
    B+=X.at(k);
  }
  cout << A - B << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int x,y,l=0;
    scanf("%d%d",&x,&y);
    if(x==1&&y==1)l+=400000;
    if(x==1)l+=300000;
    else if(x==2)l+=200000;
    else if(x==3)l+=100000;
    if(y==1)l+=300000;
    else if(y==2)l+=200000;
    else if(y==3)l+=100000;
    printf("%d",l);
    return 0;
}

Measured memory_bytes: 1712
def LI(): return list(map(int, input().split()))
def LS(): return input().split()
def I(): return int(input())
def S(): return input()

n = I()
a = LI()
b = LI()
plus = 0
minus = 0
for i in range(n):
    c = a[i] - b[i]
    if c > 0:
        plus += c
    else:
        minus -= abs(c)//2
if minus + plus <= 0 :
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4596
def main():
    N, W = map(int, input().split())
    w1 = [0, 0]
    w2 = [0, 0]
    w3 = [0, 0]
    w4 = [0, 0]
    v1 = []
    v2 = []
    v3 = []
    v4 = []
    i = 0
    while i < N:
        w, v = map(int, input().split())
        if i == 0 or w == w1[0]:
            w1[0] = w
            w1[1] += 1
            v1.append(v)
        elif w == w1[0] + 1:
            w2[0] = w
            w2[1] += 1
            v2.append(v)
        elif w == w1[0] + 2:
            w3[0] = w
            w3[1] += 1
            v3.append(v)
        elif w == w1[0] + 3:
            w4[0] = w
            w4[1] += 1
            v4.append(v)
        i += 1

    v1.sort(reverse=True)
    v2.sort(reverse=True)
    v3.sort(reverse=True)
    v4.sort(reverse=True)

    ans = []
    for i in range(w1[1] + 1):
        for j in range(w2[1] + 1):
            for k in range(w3[1] + 1):
                for l in range(w4[1] + 1):
                    w = w1[0] * i + w2[0] * j + w3[0] * k + w4[0] * l
                    v = sum(v1[:i] + v2[:j] + v3[:k] + v4[:l])
                    if w <= W:
                        ans.append(v)

    print(max(ans))

main()


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

static const ll NIL = -1;

int N, M;
vector<vector<int>> G;
int s, t;

ll bfs(void) {
    vector<vector<ll>> distance(N, vector<ll>(3, NIL));
    distance[s][0] = 0;
    queue<pair<int, int>> Q;
    Q.push({s, 0});
    
    while(!Q.empty()) {
        pair<int, int> current = Q.front(); Q.pop();
        int v = current.first;
        int parity = current.second;
        for(auto nv : G[v]) {
            int np = (parity+1) % 3;
            if(distance[nv][np]==NIL) {
                distance[nv][np] = distance[v][parity] + 1;
                Q.push({nv, np});
            }
        }
    }
    if(distance[t][0]==NIL) return -1;
    else return distance[t][0]/3;
}

int main(void) {
    cin >> N >> M;
    G.assign(N, vector<int>());
    
    int u, v;
    for (int i=0; i<M; i++) {
        cin >> u >> v; --u; --v;
        G.at(u).push_back(v);
    }

    cin >> s >> t; --s; --t;
    cout << bfs() << endl;

    return (0);
}


Measured memory_bytes: 11136
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a;
    cin >> b;
    cin >> c;
    if (a<=b && b<=c) cout << a << " " << b << " " << c << endl;
    else if (b<=c && c<=a) cout << b << " " << c << " " << a << endl;
    else if (c<=a && a<=b) cout << c << " " << a << " " << b << endl;
    else if (c<=b && b<=a) cout << c << " " << b << " " << a << endl;
    else if (b<=a && a<=c) cout << b << " " << a << " " << c << endl;
    else if (a<=c && c<=b) cout << a << " " << c << " " << b << endl;
    else cout << a << " " << b << " " << c << endl;
    return 0;
    
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <string.h>
int main() {
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if (A < C && C < B) {
    printf("Yes\n");
  } else if (A > C && C > B) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
N = int(input())
ls = [[0 for i in range(3)] for i in range(N)]
for i in range(N):
    ls[i] = list(map(int,input().split()))
# dp[i][j] -> i-1日目にjの仕事をしたときの i 日目の幸福度の総和
dp = [ [0 for i in range(3)] for i in range(N)]
for i in range(3):
    dp[0][i] = ls[0][i]
for i in range(1,N):
    for j in range(3):
        w = [0,1,2]
        w.remove(j)
        x,y = w[0],w[1]
        dp[i][j] = max(dp[i-1][x],dp[i-1][y]) + ls[i][j]
            
print(max(dp[N-1]))


Measured memory_bytes: 104924
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
#define CEIL(A,B) ((A)+(B)-1)/(B)
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}


ll N;
string S;

int z_algorithm(int offset) {
    vector<int> prefix(N - offset, 0);
    for(int i = 1, j = 0; i + offset < N; i++) {
        if(i + prefix[i - j] < j + prefix[j]) {
            prefix[i] = prefix[i - j];
        } else {
            int k = max(0, j + prefix[j] - i);
            while(i + k + offset < N && S[k + offset] == S[i + k + offset]) ++k;
            prefix[i] = k;
            j = i;
        }
    }
    REP(i, N - offset) prefix[i] = min(i, prefix[i]);
    return *max_element(ALL(prefix));
}

int main() {
    fastio();
    cin >> N;
    cin >> S;
    int ans = 0;
    REP(offset, N) ans = max(ans, z_algorithm(offset));
    cout << ans << endl;
    return 0;
}

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

using namespace std;
long long x[100001], y[100001];
int sx[100001], sy[100001], wx[100001], wy[100001];
char done[100001] = {};
int N;

priority_queue<pair<long long, int> > q;

int sortx(int a, int b) {
  return x[a] < x[b];
}

int sorty(int a, int b) {
  return y[a] < y[b];
}

int visit(int pos) {
  if (done[pos] == 1) return 0;

  done[pos] = 1;
  if (wx[pos] >= 1) {
    int next_city = sx[wx[pos] - 1];
    int cost = abs(x[pos] - x[next_city]);
    //    printf("edge1 %d to %d cost %d\n", pos, next_city, cost);
    q.push(make_pair(-cost, next_city));
  }
  if (wy[pos] >= 1) {
    int next_city = sy[wy[pos] - 1];
    int cost = abs(y[pos] - y[next_city]);
    //    printf("edge2 %d to %d cost %d\n", pos, next_city, cost);
    q.push(make_pair(-cost, next_city));
  }
  if (wx[pos] <= N - 2) {
    int next_city = sx[wx[pos] + 1];
    int cost = abs(x[pos] - x[next_city]);
    //    printf("edge3 %d to %d cost %d\n", pos, next_city, cost);
    q.push(make_pair(-cost, next_city));
  }
  if (wy[pos] <= N - 2) {
    int next_city = sy[wy[pos] + 1];
    int cost = abs(y[pos] - y[next_city]);
    //    printf("edge4 %d to %d cost %d\n", pos, next_city, cost);
    q.push(make_pair(-cost, next_city));
  }

  return 1;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%lld %lld", x + i, y + i);
    sx[i] = sy[i] = i;
  }
  sort(sx, sx + N, sortx);
  sort(sy, sy + N, sorty);
  for (int i = 0; i < N; i++) {
    wx[sx[i]] = i; // id to pos in sx
    wy[sy[i]] = i;
  }

  long long ans = 0;
  visit(0);
  int finished = 1;
  while (finished < N) {
    long long cost = -q.top().first;
    int pos = q.top().second;
    q.pop();

    //    printf("visiting %d\n", pos);
    if (visit(pos) == 1) {
      //      printf("accepted\n");
      finished++;
      ans += cost;
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 9584
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define dep(i, s, t) for(i = s; i >= t; --i)

using namespace std;

const int N = 2e4 + 10;
int n, cnt;
int ans[N];

void print(int x) {
	int i;
	rep(i, 0, cnt)
	if(ans[i] != x) printf("%d ", ans[i]);
	puts("");
}

int main() {
	int i, p = 0;
	scanf("%d", &n); cnt = n;
	if(n == 3) puts("2 5 63"); else
	if(n == 4) puts("2 5 20 63"); else
	if(n == 5) puts("2 5 20 30 63"); else {
		for(i = 1; n; ++i)
		if(i%6 == 0 || i%6 == 2 || i%6 == 3 || i%6 == 4) {
			ans[n--] = i;
			p = (p+i) % 6;
		}
		if(p == 0) print(0); else
		if(p == 2) {
			for(; ; ++i)
			if(i%6 == 0) {ans[0] = i; break;}
			print(8);
		} else
		if(p == 3) {
			for(; ; ++i)
			if(i%6 == 0) {ans[0] = i; break;}
			print(9);
		} else
		if(p == 5) {
			for(; ; ++i)
			if(i%6 == 4) {ans[0] = i; break;}
			print(9);
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1; i<=n; i++){
        if((i%3)!=0&&(i%5)!=0) sum+=i;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3632
n = int(input())
H = list(map(int, input().split()))
A = []
m = H[0]
c = 0
for i in H[1:]:
    if m >= i:
        c += 1
        m = i
    else:
        m = i
        A.append(c)
        c = 0
A.append(c)
print(max(A))

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

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

    int N;
    cin >> N;
    int cnt0 = 0, cnt4 = 0;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if (a % 2) {
            cnt0++;
        } else if (a % 4 == 0) {
            cnt4++;
        }
    }

    if (cnt0 + cnt4 == N) {
        cout << ((cnt0 > cnt4 + 1) ? "No" : "Yes") << endl;
    } else {
        cout << ((cnt0 > cnt4) ? "No" : "Yes") << endl;
    }

    return 0;
}

Measured memory_bytes: 256
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 li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

##moji利用したらTLE
S = input()
T = input()
ls = len(S)+1
lt = len(T)+1
dp = dp2(0, ls, lt)

#moji = [['']*ls for i in range(lt)]

for i in range(1, lt):
    for j in range(1, ls):
        if S[j-1]==T[i-1]:
            dp[i][j] = dp[i-1][j-1]+1
            #moji[i][j] = moji[i-1][j-1] + S[j-1]
        else:
            if dp[i-1][j] >= dp[i][j-1]:
                dp[i][j] = dp[i-1][j]
                #moji[i][j] = moji[i-1][j]
            else:
                dp[i][j] = dp[i][j-1]
                #moji[i][j] = moji[i][j-1]

#print(moji[lt-1][ls-1])
ans = ''
i = lt-1
j = ls-1
while i > 0 and j > 0:
    if dp[i][j] > dp[i-1][j-1] and S[j-1]==T[i-1]:
        ans += S[j-1]
        i -= 1
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        j -= 1

print(ans[::-1])

Measured memory_bytes: 112220
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC049_C();
        }

        static void ABC049_C()
        {
            // dreameraser
            var str = new List<string>
            {
                "dream",
                "dreamer",
                "erase",
                "eraser",
            };

            var S = Console.ReadLine();
            var T = new List<string>();
            var i = S.Length - 1;
            while (i >= 0)
            {
                var count = 0;
                foreach (var s in str)
                {
                    var l = i+1 - s.Length;
                    if (l >= 0 && s == S.Substring(l, s.Length))
                    {
                        T.Add(s);
                        count++;
                    }
                }
                if (count == 0)
                {
                    Console.WriteLine("NO");
                    return;
                }
                i -= T.Last().Length;
            }
            Console.WriteLine("YES");
        }
    }
}

Measured memory_bytes: 15968
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int n, m, a, h, **ary;
	
	while(1){
		cin >> n >> m >> a;
		if(n == 0){
			break;
		} else if(n == 1){
			m++;
		}
		h = 0;
		ary = (int **)calloc(m, sizeof(int));
		if(n == 1){
			m--;
		}
		for(int i = 0; i < m; i++){
			ary[i] = (int *)calloc(3, sizeof(int));
			cin >> ary[i][0] >> ary[i][1] >> ary[i][2];
			if(h < ary[i][0]){
				h = ary[i][0];
			}
		}
		
		for(int i = h; i > 0; i--){
			for(int j = 0; j < m; j++){
				if(i == ary[j][0]){
					if(ary[j][1] == a){
						a = ary[j][2];
					} else if(ary[j][2] == a){
						a = ary[j][1];
					} else {
						continue;
					}
					break;
				}
			}
		}
		cout << a << endl;
		
		for(int i = 0; i < m; i++){
			free(ary[i]);
		}
		free(ary);
	}
	
	return 0;
}

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

const int MAXW = 1e5 + 10;

long long knapsack[MAXW];
int N,W;

int main(){

	cin >> N >> W;

	for(int item = 1;item<=N;item++){
		int w,v;
		cin >> w >> v;
		for(int i = W;i>=w;i--) knapsack[i] = max(knapsack[i-w] + v,knapsack[i]);
	}

	long long best = 0;
	for(int i = 0;i<=W;i++) best = max(best,knapsack[i]);
	cout << best << endl;

	return 0;

}

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

using namespace std;

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <iostream>
#include <stdio.h>

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pairll;

#define sll(x) scanf("%lld",&x);
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout)

#define ff first
#define ss second

inline ll readInt()
{
    ll in; scanf("%lld",&in); return in;
}

inline ll ADD(ll a, ll b, ll mod)
{
    return (a + b + mod + mod)%mod;
}

inline ll SUBS(ll a, ll b, ll mod)
{
    return (a-b+mod + mod) %mod;
}

inline ll MUL(ll a, ll b, ll mod)
{
    return (a*b + mod)%mod;
}

ll bigMod(ll base, ll power, ll mod)
{
    if(!power) return 1;
    if(!base) return 0;

    ll temp = bigMod(base, power/2, mod);

    if(power%2 == 0)
    {
        return (temp*temp)%mod;
    }
    else return (((temp*temp)%mod)*base)%mod;
}

inline ll modInverse(ll a, ll modp)
{
    return bigMod(a, modp -2, modp);
}

inline ll modInverseExtended(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        ll q = a / m; 
        ll t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
  

void autoinput()
{
    #ifndef ONLINE_JUDGE
    READ; 
    //WRITE;

    #endif
}

int main()
{
    autoinput();
    ll a, b, c, d, k;
    sll(a); sll(b); sll(c); sll(d); sll(k);

    ll t1 = a*60+b;
    ll t2 = c*60+d;

    ll dif = t2 - t1;

    dif -= k;
    if(dif < 0) dif = 0;

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



Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,x,y,P=0;
  cin>>N;
  vector<int>A(N);
  vector<vector<pair<int,int>>>s(N,vector<pair<int,int>>(N));
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    for(int j=0;j<A.at(i);j++){
      cin>>x>>y;
      s.at(i).at(j)=make_pair(x,y);
    }
  }
  for(int i=0;i<(1<<16);i++){
    bitset<16>x(i);
    if(x.test(N))break;
    int j;
    for(j=0;j<N;j++){
      int k;
      if(x.test(j)){
        for(k=0;k<A.at(j);k++)if(x[s.at(j).at(k).first-1]!=s.at(j).at(k).second)break;
        if(k!=A.at(j))break;
      }
    }
    if(j==N){
      int p=x.count();
      P=max(P,p);
    }
  }
  cout<<P<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repin(Array,n) for(int i=0;i<n;i++){cin>>Array[i];}
using namespace std;

using ll = long long;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;

int main() {

	ll a, b, x;
	cin >> a >> b >> x;

	if (a == 0)
		cout << b / x + 1 << endl;
	else
		cout << b / x - (a - 1) / x << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    string s;cin>>s;
    rep(i,s.size())cout<<'x';
    cout<<endl;
}

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():
    k = II()

    amari = 0
    for i in range(k):
        amari = (amari * 10 + 7) % k
        if amari == 0:
            print(i + 1)
            return
    print(-1)


main()


Measured memory_bytes: 65884