akhauriyash/Code-Regression huggingface dataset:
N,M = map(int,input().split())

memo = [1]*M

for _ in range(N):
  items = tuple(map(int,input().split()))
  
  s = set(items[1:])
  for i in range(1,M+1):
    if i not in s:
      memo[i-1] = 0

print(sum(memo))


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	bitset<60> bi(n);
	vector<vector<ll>> dp(60, vector<ll>(5, 0));
	REP(i, 60) REP(j, 5) {
		ll rem = j;
		if(bi[i]) rem++;
		if(i == 0) {
			dp[i][j] = 1;
			if(rem > 0) dp[i][j]++;
			if(rem > 1) dp[i][j]++;
		} else {
			dp[i][j] = dp[i - 1][min(4ll, 2 * rem)];
			if(rem > 0) dp[i][j] += dp[i - 1][min(4ll, 2 * (rem - 1))];
			if(rem > 1) dp[i][j] += dp[i - 1][min(4ll, 2 * (rem - 2))];
		}
		dp[i][j] %= MOD;
	}
	cout << dp[59][0] << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)

using namespace std;

int x[100010];
int y[100010]; 
int par[100010];


int root(int x){
	if (par[x]==x) return x;
	return par[x]=root(par[x]);
}

int same(int x, int y){
	return root(x)==root(y);
}

void unite(int x, int y){
	x=root(x);
	y=root(y);
	if (x==y) return;
	par[x]=y;
}


int main(){
	int N;
	long long ans = 0;
	vector <pair<int, int> > v, w;
	vector <pair<int, pair<int, int> > > z;
	
	cin >> N;
	
	rep(i,N) cin >> x[i] >> y[i];
		
	rep(i,N) {
		v.push_back(make_pair(x[i], i));
		w.push_back(make_pair(y[i], i));
	}
	
	sort(v.begin(), v.end());
	sort(w.begin(), w.end());
	
	rep(i,N-1) {
		z.push_back(make_pair(v[i + 1].first - v[i].first, make_pair(v[i].second, v[i + 1].second)));
		z.push_back(make_pair(w[i + 1].first - w[i].first, make_pair(w[i].second, w[i + 1].second)));
	}

	
	sort(z.begin(), z.end());
	

	for (int i = 0; i < N+1; i++)  par[i]=i;
	
	for (int i =0; i < z.size(); i++) {
		
		int x = z[i].second.first;
		int y = z[i].second.second;
		int cost=z[i].first;
		
		if ( !same(x,y) ) {
			unite(x,y);
			ans+=cost;
		}	
	}
	
	cout << ans <<endl;

}



Measured memory_bytes: 7784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15



int main() {
	int x, y, z;
	cin >> x >> y >> z;
	if(abs(x - x/(y+z)*(y+z)) >= z){
		cout << x/(y+z) << endl;
	}else
		cout << x/(y+z) -1 << endl;
	return 0;
}






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

int main()
{
    int n;
    cin>>n;
    int ar[n+3];
    for(int i=1;i<=n;i++)
        cin>>ar[i];
    int cnt=0,temp=0,flag=0;
    for(int i=n;i>1;i--)
    {
        if(ar[i]<=ar[i-1])
        {
            cnt++;
        }
        else
        {
            if(cnt>temp)
                temp=cnt;
            cnt=0;
        }
    }
    if(cnt>temp)
        cout<<cnt<<endl;
    else
        cout<<temp<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;

	int sum = 0;

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}

	int nm = 0;
	for (int i = 1; i <= n; i++)nm += i;
	
	if (sum % nm) {
		cout << "NO" << endl;
		return 0;
	}

	int m = sum / nm;
	dump(m);

	bool ok = true;
	int count = 0;

	for (int i = 0; i < n; i++) {
		int d = a[(i + 1) % n] - a[i] - m;
		if (d > 0)ok = false;
		if (-d % n)ok = false;
		count += -d / n;
	}

	if (count != m) ok = false;
	
	if (ok) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 1024
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	int tmp;
	int h, w, n;
	cin >> h >> w >> n;
	int sr, rc;
	cin >> sr >> rc;
	string s,t;
	cin>> s >> t;
	int tu = 0, td=h+1, tr=w+1, tl=0;
	bool ch = true;
	for(int i = n-1; i >= 0; i--){
		if(t[i] == 'U') td = min(td + 1, h + 1);
		if(t[i] == 'D') tu = max(tu - 1, 0);
		if(t[i] == 'R') tl = max(tl - 1, 0);
		if(t[i] == 'L') tr = min(tr + 1, w + 1);
		if(s[i] == 'U') tu = min(tu + 1, h);
		if(s[i] == 'D') td = max(td - 1, 1);
		if(s[i] == 'R') tr = max(tr - 1, 0);
		if(s[i] == 'L') tl = min(tl + 1, w);
		if(tl == w || tr == 1 || tu == h || td == 1) ch = false;
		//cout << tl << " " << tu << " " << td << " " << tr << endl;
	}
	if (tu < sr && sr < td && tl < rc && rc < tr && ch) cout << "YES" << endl;
	else cout << "NO" << endl;
	//cout << ans << endl;
}

Measured memory_bytes: 3916
s = input()
if s == 'SUN':
  print(7)
elif s == 'MON':
  print(6)
elif s == 'TUE':
  print(5)
elif s == 'WED':
  print(4)
elif s == 'THU':
  print(3)
elif s == 'FRI':
  print(2)
elif s == 'SAT':
  print(1)

Measured memory_bytes: 3060
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val set = mutableSetOf<String>()
    for (i in 0 until n) {
        val s = sc.nextLine()
        set.add(s)
    }
    println(set.count())
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 68364
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define name (i++?" ":"")
int main(){

  int n;
  cin>>n;

  vector <int> a(n);
  REP(i,n) cin>>a[i];

  int q;
  cin>>q;
  \
  REP(i,q){

    int b,e,t;
    cin>>b>>e>>t;

    swap_ranges(a.begin()+b,a.begin()+e,a.begin()+t);

  }

  int i=0;
  for(int e:a) cout<<name<<e;
  cout<<endl;

  return 0;

}



Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n,k,x,ans = 0;
    cin >>n>>k;
    vector<int> V(n);
    for(int i=0;i<n;i++){ 
        cin >> x; 
        V[i] = x;
    }
    sort(V.begin(),V.end(),greater<int>());
    for(int i = 0;i<k;i++ ) ans += V[i];
    cout<<ans;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range, std.algorithm;
void main() {
	long n, m, l;
	"%d %d %d\n".readf(&n, &m, &l);
	long[][] a, b;
	foreach (_n; 0..n) a ~= readln.split.to!(long[]);
	foreach (_m; 0..m) b ~= readln.split.to!(long[]);
	foreach (_a; a) {
		long[] c = [];
		foreach (_l; 0..l) c ~= iota(m).map!(_m => _a[_m] * b[_m][_l]).sum;
		c.to!(string[]).join(" ").writeln;
	}
}

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

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define mst(a,v) memset(a,v,sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;

const int N=100010;
const int mod=1e9+7;
const ld PI=acos(-1.0);
const int inf=0x3f3f3f3f;

int n,m;
vpi a;

int main()
{
#ifdef local
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    a.resize(m);
    for(int i=0; i<m; i++)
        cin>>a[i].f>>a[i].s;
    sort(all(a));
    int ans=1,t=a[0].s;
    for(int i=1; i<m; i++)
    {
        if(a[i].f>=t) ans++,t=a[i].s;
        else t=min(t,a[i].s);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

using Edge = pair<int,ll>;
using Graph = vector<vector<Edge>>;

void rec(const Graph &G, int v, int p, ll sum, vector<ll> &dist){
  dist[v] = sum;
  for(auto e: G[v]){
    if(e.first == p) continue;
    rec(G, e.first, v, sum+e.second, dist);
  }
}

int main(){
  int N; cin >> N;
  Graph G(N);
  rep(i,N-1){
    int a,b; ll c; cin >> a >> b >> c;
    a--;b--;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }
  int Q, K; cin >> Q >> K; K--;
  vector<ll> dist(N,0);
  rec(G,K,-1,0,dist);
  
  rep(q,Q){
    int x,y; cin >> x >> y; x--; y--;
    cout << dist[x]+dist[y] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 17408
/*
*
*Problem Link : https://atcoder.jp/contests/dp/tasks/dp_c
*Platform: atcoder
*Status: correct
*Author: Mayukh Chakrabarti
*
*/

#include<bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false)
#define boost cin.tie(NULL)
#define booster cout.tie(NULL)
#define endl "\n"
typedef long long int lld;

#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;

using namespace std;

int main(){
	
	int N;
	cin>>N;
	
	vector<vector<int>> ar(N,vector<int>(3));
	NF(ar,N,3);
	
	vector<vector<int>> dp(N,vector<int>(3,-1));
	
	dp[0][0]= ar[0][0];
	dp[0][1]= ar[0][1];
	dp[0][2]= ar[0][2];
	
	for(int i=1; i<N; i++){
		for(int j=0; j<3; j++){
			
			for(int k=0; k<3; k++){
				if(k==j)continue;
				
				dp[i][j]= max(dp[i][j] , ar[i][j]+dp[i-1][k]);
			}
		}
	}
	
	cout<<max(dp[N-1][0], max(dp[N-1][1] , dp[N-1][2]) );
	
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    string S[N];
    map<string, int> num_kind;
    for (int i = 0; i < N; i++)
    {
        cin >> S[i];
        num_kind[S[i]]++;
    }
    cout << num_kind.size() << endl;
}


Measured memory_bytes: 25508
import itertools

N = int(input())

se = set([0])
for _ in range(10):
  se |= set(10*x+y for x,y in itertools.product(se,[7,5,3]))
  
se = set(str(x) for x in se if 1 <= x <= N)
se = set(x for x in se if set(x) == set('753'))
answer = len(se)
print(answer)

Measured memory_bytes: 20444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	vector<ll>a;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	ll ans=0;
	vector<ll>b;
	for(int i=0;i<n;i++){
		b.push_back(a[i]);
		if(i!=n-1-i){
		b.push_back(a[n-1-i]);
		}
		if(i==n-1-i||i>n-1-i){
			break;
		}
	}
	//cout << b.size()<<endl;
	ll now=b[0];
	for(int i=1;i<n-1;i++){
		ans+=abs(now-b[i]);
		now=b[i];
	}
	ans+=abs(b[n-1]-b[0]);
	ll ans2=ans;
	reverse(a.begin(),a.end());
	ans=0;
	vector<ll>c;
	for(int i=0;i<n;i++){
		c.push_back(a[i]);
		if(i!=n-1-i){
		c.push_back(a[n-1-i]);
		}
		if(i==n-1-i||i>n-1-i){
			break;
		}
	}
	//cout << b.size()<<endl;
	now=c[0];
	for(int i=1;i<n-1;i++){
		ans+=abs(now-c[i]);
		now=c[i];
	}
	ans+=abs(c[n-1]-c[0]);	
	cout << max(ans,ans2);
	// your code goes here
	return 0;
}

Measured memory_bytes: 3316
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1)*18;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	int i,n,j,K;cin>>n>>K;
	vector<int>card(n);
		for(i=0;i<n;i++){cin>>card[i];mineq(card[i],K);}
	SO(card);REV(card);
	bitset<10001> bit;bit[0]=true;
	bitset<10001> Kika;
	bitset<10001> Kizyo;
	for(j=0;j<K;j++){Kika[j]=true;}
	for(j=K;j<=10000;j++){Kizyo[j]=true;}
	int use=0;
	for(i=0;i<n;i++){
		bit|=(bit<<card[i]);
		if((bit&Kizyo).any()){use=i+1;}
		bit&=Kika;
	}
	cout<<n-use<<endl;RE;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<climits>
using namespace std;
int main() 
{
    int n,k;
    cin>>n>>k;
    vector<int>v;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        v.push_back(x);
    }
    int dp[100000];
    dp[0]=0;
    dp[1]=abs(v[0]-v[1]);
    for(int i=2;i<n;i++)
    {
        int ans=INT_MAX;
        for(int j=1;j<=k;j++)
        {
            if(i-j>=0)
            {
                ans=min(ans, abs(v[i]-v[i-j]) +dp[i-j] );
            }
             else
             {
                 break;
             }
        }
        dp[i]=ans;
    }
    
    cout<<dp[n-1];
}

Measured memory_bytes: 3688
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let D: i32 = read();
    println!("{}", match D {
        25 => "Christmas",
        24 => "Christmas Eve",
        23 => "Christmas Eve Eve",
        22 => "Christmas Eve Eve Eve",
        _ => panic!(),
    });
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(x, a, b) for(int x = (a); x <= (b); ++x)
#define rop(x, a, b) for(int x = (a); x < (b); ++x)
#define per(x, a, b) for(int x = (a); x >= (b); --x)
using namespace std;
typedef long long LL;
typedef double DB;
const int mod = 1000000007;
LL f[4005][2005][2], S[2005], as;
inline LL MOD(LL x) {
	return (x % mod + mod) % mod;
}
int n, m, K; 
int main() {
	scanf("%d%d%d", &n, &m, &K);
	if(n > m) swap(n, m);
	int lm = n + m;
	f[0][0][1] = 1;
	rep(i, 1, lm) {
		S[0] = MOD(f[i - 1][0][0] + f[i - 1][0][1]);
		rep(k, 1, n) S[k] = MOD(S[k - 1] + f[i - 1][k][0] + f[i - 1][k][1]);
		rep(k, 0, n) {
			f[i][k][1] = MOD(f[i - 1][k][0] + f[i - 1][k][1]);
			f[i][k][0] = MOD(S[k - 1] - (k >= K ? S[k - K] : 0));
		}
		rep(k, 0, n) {
			if(k % (K - 1) == n % (K - 1)) {
				int lsbl = i * (K - 1) - k + 1;
				if(lsbl <= m && lsbl % (K - 1) == m % (K - 1)) as = MOD(as + f[i][k][0]);
			}
		}
	}
	cout << as << endl;
	return 0;
}


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

using namespace std;

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

    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    int min = *min_element(A.begin(), A.end());
    int max = *max_element(A.begin(), A.end());
    
    cout << max - min << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
#define SIZE 100005
char arr[SIZE];
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll N,K,R,S,P;
	cin>>N>>K>>R>>S>>P;
	map<char,ll> m;
	m['r']=P;
	m['p']=S;
	m['s']=R;
	string str;
	cin>>str;
	ll ans=0;
	for(ll i=0;i<N;++i){
		if(arr[i%K]==str[i]){
			arr[i%K]='a';
			continue;
		}
		else{
			ans+=m[str[i]];
			arr[i%K]=str[i];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 592
// Made by Luis Miguel Baez
// es.luismiguelbaez@gmail.com

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

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

#define pii   pair<int, int>
#define piii  pair<int, pair<int, int>>
#define pll   pair<ll, ll>

#define F  first
#define S  second
#define PB push_back
#define MP make_pair

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename T>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const T &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string((T)x);
    }
    res += "}";
    return res;
}

// add templates here

template<class T>
void println(const vector<T> &data) {
    cout << to_string<vector<T>, T>(data) <<endl;
}

template<class T>
void println(const T &data) {
    cout << to_string((T)data) << endl;
}

const int MOD = int(1e9+7);
const int oo  = int(1e9 + 20);
const ll lloo  = (ll)(1e18 + 10);

bool isInteger(double number) {
    return number == int(number);
}

double distance(vector<int> &X, vector<int> &Y) {
    double answer = 0.0;
    int n = min(X.size(), Y.size());
    for(int i = 0; i < n; ++i) {
        answer += pow( (X[i] - Y[i]) ,2);
    }
    
    return sqrt(answer);
}

    
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int N, D;
    cin >> N >> D;
    vector<vector<int>> grid(N+1, vector<int>(D+1));
    
    for(int i = 1; i <= N; ++i) {
        for(int j = 1; j <= D; ++j) {
            cin >> grid[i][j];
        }
    }
    
    int answer = 0;
    for(int i = 1; i <= N; ++i) {
        for(int j = i + 1; j <= N; ++j) {
            if(i == j) continue;
            double dist = distance(grid[i], grid[j]);
            if(isInteger(dist)) answer++;
        }
    }
    
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define JN ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#define mod 1000000007

#define pb push_back
#define mp make_pair

using namespace std;
typedef unsigned long long int ull;
typedef long long int          ll;

int n, m;

int w[105], value[105];

ll dp[105][100005];





int main()
{
    JN;

    cin >> n >> m;

    for(int i=1; i<=n; i++)
        cin >> w[i] >> value[i];

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(w[i] <= j)
                dp[i][j] = max(dp[i-1][j-w[i]]+value[i], dp[i-1][j]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }


    cout << dp[n][m] << "\n";






    

    
    
    return 0;

}

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

int main() {
  int n;
  cin >> n;
  int num = n / 2;
  if(n % 2 == 0){
    cout << num * num << endl;
  }else{
    cout << num * (num + 1) << endl;
  }
}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  return __gcd(a,b);
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}


int main() {
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL a,b,c;
  cin >> a >> b >> c;
  
  LL k = 4* a*b, l = (c-a-b)*(c-a-b);
  LL j = c-a-b;
  if(j < 0){
    cout << "No" << endl;
    return 0;
  }
  if(k < l) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
N, A, B = list(map(int, input().split()))

if B < A:
    print(0)
else:
    max_sum = A + B * (N - 1)
    min_sum = A * (N - 1) + B
    ans = max_sum - min_sum + 1
    if ans < 0:
        print(0)
    else:
        print(ans)


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

typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin>>n;
    ll i;
    vector<ll>v(n),v2(n);
    for(i=0;i<n;++i){
        cin>>v[i];
    }
    v2=v;
    sort(v2.begin(),v2.end());
    ll count=0;
    for(i=0;i<n;++i){
        if(v[i]!=v2[i])
            count++;
    }
    if(count<=2)
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, p;
  cin >> s >> p;
  s += s;
  auto res = s.find(p);
  if (res != string::npos) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3208
// 2010/12/22 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int p_max = 0;
		int d_max = -1;
		for(int i=0; i<n; i++){
			int p, d1, d2;
			cin >> p >> d1 >> d2;
			if(d1+d2>d_max){
				p_max = p;
				d_max = d1+d2;
			}
		}

		cout << p_max << ' ' << d_max << endl;
	}

	return 0;
}

Measured memory_bytes: 868
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    return N,

def standalize(N):

    q = list()
    alphabets = "abcdefghijklmnopqrstuvwxyz"
    
    s = []

    def dfs(i):
        """i種類の文字から選んで、sの末尾に追加する
        """
        if len(s) == N:
            q.append(''.join(s))
        else:
            for j, a in enumerate(alphabets[:i-1]):
                s.append(a)
                dfs(i)
                s.pop()
            a = alphabets[i-1]
            s.append(a)
            dfs(i+1)
            s.pop()
    
    dfs(1)
    return q

def solve(N):
    for s in standalize(N):
        print(s)

if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % outputs)


Measured memory_bytes: 12664
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

//using Graph = vector<vector<pair<int, int>>>;
using Graph = vector<vector<int>>;

int n;
vector<bool> seen(n,false);
vector<int> cost(n);
Graph G(n);

void dfs(int v){
    seen[v] = true;
    for(auto next_v : G[v]){
        if(seen[next_v]) continue;
        cost[next_v]+=cost[v];
        dfs(next_v);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int q;
    cin>>n>>q;
    //Graph G(n);
    //vector<int> cost(n);
    //vector<bool> seen(n,false);
    G.resize(n);
    cost.resize(n);
    seen.resize(n,false);
    int a,b;
    rep(i,n-1){
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    int p,x;
    rep(i,q){
        cin>>p>>x;
        p--;
        cost[p]+=x;
    }

    seen[0]=true;
    dfs(0);

    rep(i,n){
        cout<<cost[i]<<endl;
    }   
}

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

int main(){

    int n;

    cin >> n;
    ll ans=0;

    rep(i,n){
        ll l,r;
        cin >> l >> r;
        ans+=(r-l+1);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

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

const int mod=1e9+7;

int main(){
    int n,k;
    string s;
    cin >> n >> k >> s;
    int ans=0;
    int right=0;
    int cnt=0;
    vector<int> p;
    int tmp=0;
    for(int left=0;left<s.size();left++){
        while(right<s.size()&&cnt<k){
            if(s[right]=='0'){
                while(right<s.size()&&s[right]=='0')    right++;
                if(right==s.size()) right--;
//                cout << right << endl;
                p.push_back(right);
                cnt++;
            }
            right++;
        }
        while(right<s.size()&&s[right]=='1'){
            right++;
        }
//        cout << right << endl;
        ans=max(right-left,ans);
//        cout << "cnt=" << cnt << endl;
//        cout << "left=" << left << ", right=" << right << endl;
//        cout << "right-left=" << right-left << endl;
        if(right==s.size())   break;
        if(right==left){
            right++;
        }else{
            left=p[tmp]-1;
            tmp++;
            right--;
            cnt--;
        }
    }
    cout << ans << endl;
}







Measured memory_bytes: 768
#include <stdio.h>

int main()
{
	char A1, A2, A3;
	scanf("%c %c %c", &A1, &A2, &A3);
	if(A1, A2 != A3){
		printf("Yes\n");
	}
	else if (A1, A3 != A2){
		printf("Yes\n");
	}
	else if (A2, A3 != A1){
		printf("Yes\n");
	}
	else if (A1 == A2, A2 == A3){
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 2040
A,B,C,D,E,F = list(map(int, input().split()))


# 水が入る量をリストアップ
W = set()
for a in range(0, F+1, A*100):
  for b in range(0, F+1, B*100):
    w = a+b
    if w==0 or w>F:
      continue
    W.add(w)
    
# 砂糖が入る量をリストアップ
Suger = set()
for c in range(0, F+1, C):
  for d in range(0, F+1, D):
    s = c+d
    if s>F:
      continue
    Suger.add(s)
    
d_max = -1
ans = None
for w in W:
  for s in Suger:
    # 砂糖が溶けない or ビーカーの容量を超えたらcontinue
    if w*E//100 < s or w+s > F:
      continue
    d = 100*s / (w+s) # 濃度
    if d > d_max:
      d_max = d
      ans = (w+s, s)
print(*ans)

Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
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<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }
 
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
 
int main() {
    int a, b;
    cin >> a >> b;
    int ans = max(max(a+b, a-b), a*b);
    cout << ans << endl;
    return 0;
}

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

#define Mod 1000000007

using namespace std;


typedef long long ll;


inline int read() {
	int out = 0;
	bool flag = false;
	register char cc = getchar();
	while (cc < '0' || cc > '9') {
		if (cc == '-') flag = true;
		cc = getchar();
	}
	while (cc >= '0' && cc <= '9') {
		out = (out << 3) + (out << 1) + (cc ^ 48);
		cc = getchar();
	}
	return flag ? -out : out;
} 

int N, x, y, rt;


int head[200010], nxt[400010], to[400010], cnt;

void add_edge(int u, int v) {
	to[++cnt] = v;
	nxt[cnt] = head[u];
	head[u] = cnt;
}


ll fac[200010], inv[200010];

int ksm(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y & 1) res = res * x % Mod;
		x = x * x % Mod;
		y >>= 1;
	}
	return res;
}
 
ll com(int x, int y) {
	return 1ll * fac[x] * inv[y] % Mod * inv[x - y] % Mod;
}



int f[200010], siz[200010], dp[200010];

void dfs(int u, int fa) {
	f[u] = 1;
	for (int i = head[u]; i; i = nxt[i]) {
		int v = to[i];
		if (v == fa) continue;
		dfs(v, u);
		siz[u] += siz[v];
		f[u] = com(siz[u], siz[v]) * f[u] % Mod * f[v] % Mod;
	}
	siz[u]++;
}

void change(int u, int fa) {
	for (int i = head[u]; i; i = nxt[i]) {
		int v = to[i];
		if (v == fa) continue;
		dp[v] = dp[u] * fac[siz[v]] % Mod * fac[N - 1 - siz[v]] % Mod * inv[siz[v] - 1] % Mod * inv[N - siz[v]] % Mod;
		change(v, u);
	}
}

int main() {
	N = read();
	fac[0] = inv[0] = 1;
	for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % Mod;
	inv[N] = ksm(fac[N], Mod - 2);
	for (int i = N - 1; i; i--) inv[i] = inv[i + 1] * (i + 1) % Mod;
	for (int i = 1; i < N; i++) {
		x = read(), y = read();
		add_edge(x, y);
		add_edge(y, x);
	}
	rt = 1;
	dfs(rt, 0);
	dp[rt] = f[rt];
	change(rt, 0);
	for (int i = 1; i <= N; i++) printf("%d\n", dp[i]);
	return 0;
}


Measured memory_bytes: 13116
#include <iostream>
#include <vector>
#include <set>

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

const int MAX_N = 1e5+5;

int parent[MAX_N], size[MAX_N];
int root(int x) {
  if (parent[x] == x) return x;
  return parent[x] = root(parent[x]);
}
int get_size(int x) {
  return size[root(x)];
}
void unite(int x, int y) {
  if (root(x) == root(y))
    return;
  x = root(x); y = root(y);
  parent[x] = y;
  size[y] += size[x];
  return;
}
bool same(int x, int y) {
  return root(x) == root(y);
}

int main() {
  int N, M, K; cin >> N >> M >> K;

  int h[N];
  rep(i, N) {
    parent[i] = i;
    size[i] = 1;
    h[i] = 0;
  }

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    ++h[a]; ++h[b];
    unite(a, b);
  }
  int ans[N];
  rep(i, N)
    ans[i] = get_size(i) - 1 - h[i];

  rep(i, K) {
    int c, d;
    cin >> c >> d;
    --c, --d;
    if (same(c, d)) {
      --ans[c]; --ans[d];
    }
  }
  rep(i, N) {
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    while(1){
        ll n,x;cin>>n>>x;
        if(n==0)return;

        ll ans=0;
        fore(i,1,n){
            fore(j,i+1,n){
                fore(k,j+1,n){
                    if(i+j+k==x)ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
}

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



Measured memory_bytes: 3204
fun main(arr:Array<String>) {
    var (a,b,k) = readLine()!!.split(" ").map { it.toInt() }
    for(i in (0 until k)) {
        if(i % 2 == 0) {
            if(a%2!=0) {
                a--
            }
            b += a/2
            a /= 2
        } else {
            if(b%2!=0) {
                b--
            }
            a += b/2
            b /= 2
        }
    }
    println("%d %d".format(a,b))
}


Measured memory_bytes: 37932
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long N;
    long long ans=0;

    cin >> N;

    vector<long long>a(N);

    rep(i,N){
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    for(long long i=0; i<N; i++){
        long long kosuu=0;
        long long ope=a[i];

        long long j=i;
        while(j<N && a[j]==ope){
            kosuu++;
            j++;
            i=j-1;
        }
        if(kosuu > ope){
            ans+=kosuu-ope;
        }else if(kosuu < ope){
            ans+=kosuu;
        }
    }
    cout << ans << endl;

    return 0;
}



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

# 連続する場合は無視できるので圧縮
tmp = list(map(int, input().split()))
arr = [tmp[0]]
for i in range(1, n):
    if arr[-1] != tmp[i]:
        arr.append(tmp[i])

# 株価が上がる前に全力で買って、上がったら全力で売る。を貪欲にやる
money, stock = 1000, 0
for i in range(1, len(arr)):
    if arr[i - 1] < arr[i]:
        # 全力買い
        buy, money = divmod(money, arr[i - 1])
        stock += buy
        # 全力売り
        money += stock * arr[i]
        stock = 0

print(money)

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

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    long mod = 1000000000+7;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    long solve(){
        // it's all about implementation
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxD = 100000;
        int[] cnt = new int[maxD+1];
        for(int i=0;i<n;i++){
            int d = sc.nextInt();
            cnt[d] += 1;
        }
        int smaller = 0, ans = 0;
        for(int i=1;i<=maxD;i++){
            smaller += cnt[i-1];
            if(smaller*2==n) ans += 1;
        }
        return ans;
    }
}



Measured memory_bytes: 50876
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
         static void Main(string[] args)
        {
            var firstLine = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();

            WriteLine(firstLine[0] + firstLine[1] < 10 ? $"{firstLine[0] + firstLine[1]}" : "error");
        }
    }
}


Measured memory_bytes: 11348
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
void showDanish (void);

int main(int argc, char const *argv[])
{
    //initialise
    int t = 0;
    int k = 0;
    scanf("%d %d\n", &k, &t);
    int A[t];
    for(int i = 0; i<t; i++){
        scanf("%d", &A[i]);
    }
    int max = A[0];
 
    for (int c = 1; c < t; c++) {
        if (A[c] > max){
           max  = A[c];
        }
    }
    int diff = 0;
    int min = 0;
    if(k%2 != 0){ //odd
        if(max < (k+1)/2){
            printf("0\n");
            return 0;
        }
        diff = max - (k+1)/2;
        min = 2*diff;
    } else {
        if(max < (k/2 + 1)){
            printf("0\n");
            return 0;
        }
        diff = max - k/2;
        min = 2*diff-1;
    } 

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



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io

    int n,k;
    cin>>n>>k;
    vector<ll> h(n);
    rep(i,n) cin>>h[i];
    sort(h.begin(), h.end());
    ll ans=100100100100;
    rep(i,n-k+1){
        ans=min(ans, h[i+k-1]-h[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,n;
  cin>>h>>w>>n;
  if(h>w){
    int ans=ceil((double)n/h);
    cout<<ans<<endl;}
    else{
      int ans=ceil((double)n/w);
      cout<<ans<<endl;
    }
}
 

Measured memory_bytes: 256
a = input().split()
N,A,B = int(a[0]),int(a[1]),int(a[2])

ylist = []
for i in range(1,N+1):
  tot = sum(map(int,list(str(i))))
  if tot >= A and tot <=B:
    ylist.append(i)
print(sum(ylist))

Measured memory_bytes: 3296
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
using namespace std;

int W[10001];
int H[10001];

int main() {
    int n;
    while ( cin >> n && n ) {
        for ( int i = 0; i < n; i++ ) {
            cin >> W[i];
        }
        for ( int i = 0; i < n; i++ ) {
            cin >> H[i];
        }
        sort( H, H+n, greater<int>() );

        for ( int i = 0; i < n; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                if ( W[j] > 0 ) {
                    W[j]--;
                    H[i]--;
                }
            }
        }

        bool flag = true;
        for ( int i = 0; i < n; i++ ) {
            if ( H[i] != 0 ) flag = false;
        }
        cout << ( flag ? "Yes" : "No" ) << endl;
    }
    return 0;
}

Measured memory_bytes: 928
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    List<String> list = new ArrayList<>();
    int count1 = 0;
    int count2 = 0;
    int count3 = 0;
    int count4 = 0;

    for(int i = 0; i < n ; i++){
        list.add(sc.next());
    }

    for(int i = 0; i < n ; i++){
        if(list.get(i).equals("AC")){
            count1++;
        }else if(list.get(i).equals("WA")){
            count2++;
        }else if(list.get(i).equals("TLE")){
            count3++;
        }else{
            count4++;
        }
    }

    System.out.println("AC x "+ count1);
    System.out.println("WA x "+ count2);
    System.out.println("TLE x "+ count3);
    System.out.println("RE x "+ count4);

    

    




    





    
    


    
	}
}

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

#define INF 1000050000

int dp[3002][3002];

int main()
{
	string s, t;
	cin >> s >> t;
	int fl[3003];
	memset(fl, 0, sizeof(fl));
	// vector<char> v(3001);
	stack<char> st;
	for(int i = 0; i < s.size(); i++) {
		for(int j = 0; j < t.size(); j++) {
			if(s[i] == t[j]) {
				dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j]);
			} else {
				dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
			}
		}
	}
	int len = dp[s.size()][t.size()];
	for(int i = s.size(); i > 0; i--) {
		for(int j = t.size(); j > 0; j--) {
			if(dp[i][j] == len && dp[i][j] == dp[i-1][j-1]+1 && s[i-1] == t[j-1]) {
				len--;
				st.push(t[j-1]);
				break;
			}
		}
	}
	while(!st.empty()) {
		printf("%c", st.top());
		st.pop();
	}
	printf("\n");
}


Measured memory_bytes: 35584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		StringBuffer sb = new StringBuffer();
		for (int i = 0; i <= 2; i++){
			String s = sc.next();
			sb.append(s.substring(0, 1).toUpperCase());
		}
		System.out.println(sb.toString());
	}

}


Measured memory_bytes: 21972
n=int(input())
p=[]
for i in range(n):
    p.append(list(map(int,input().split())))
a=[]
b=[]
for i in range(n):
    a.append(p[i][0]+p[i][1])
    b.append(p[i][0]-p[i][1])
a.sort()
b.sort()
print(max(a[n-1]-a[0],b[n-1]-b[0]))

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

int main() {
int n;
cin >> n;
vector<double> vec(n);
for(int i = 0; i < n; i++){
    cin >> vec.at(i);
}
sort(vec.begin(), vec.end());
double avg = (vec.at(0) + vec.at(1)) / 2;
for(int i = 2; i < n; i++){
    avg = (avg + vec.at(i))/2;
}
  cout << avg << endl;
}


Measured memory_bytes: 256
import math
A = int(input())
p = int(math.sqrt(A)) + 1
all_lis = []
ans_lis = []

for i in range(1,p,1):
    if A % i == 0:
        kumi = [i,int(A/i)]
        all_lis.append(kumi)

for j in all_lis:
    ans_lis.append(j[0]+j[1])
    
print(int(min(ans_lis)-2))

Measured memory_bytes: 40300