akhauriyash/Code-Regression huggingface dataset:
process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const length = Number(inputs[0]);
  const str = inputs[1];
  let rejectCount = 0;
  let sum = 0;

  if (str.includes('R') && str.includes('G') && str.includes('B')) {
    sum += (str.split('R').length - 1) * (str.split('G').length - 1) * (str.split('B').length - 1);
  } else {
    console.log(sum);
    return;
  }

  for (let i = 0; i < length; i++) {
    for (let j = 1; j < length; j++) {
      if (i + j >= length || i + j * 2 >= length) {
        break;
      }

      if (str[i] !== str[i + j] && str[i] !== str[i + j * 2] && str[i + j] !== str[i + j * 2]) {
        rejectCount++;
      }
    }
  }

  sum -= rejectCount;

  console.log(sum);
}


Measured memory_bytes: 33988
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)


def main():

    V, E = map(int, input().split())

    # need sorted
    edge_q = sorted([tuple(map(int, input().split())) for _ in range(E)], key=lambda x: x[2])

    # kruskal
    ans = 0
    forest = UnionFind(V)
    for s, t, w in edge_q:
        if forest.same(s, t):
            continue
        forest.unite(s, t)
        ans += w
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 25020
#include<stdio.h>
int main(){
  int a[10],n,i,j,tmp;
  for(n=0;n<10;n++){
    scanf("%d",&a[n]);
  }
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(a[j]>a[j-1]){
	tmp=a[j];
	a[j]=a[j-1];
	a[j-1]=tmp;
      }
    }
  }
  for(i=0;i<3;i++){
    printf("%d\n",a[i]);
  }
  return (0);
}

Measured memory_bytes: 600
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,x,k=map(int, readline().rstrip().split())
    s=n//x
    if n%x > 0:
        s+=1
    print(s*k)
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 16164
h,w=map(int,input().split())
tmp=[]
jg=[0 for _ in range(0,w)]
s=""
for i in range(0, h):
    s = input()
    if s != '.'*w:
        tmp.append(s)
    for j in range(0,len(s)):
        if s[j] == '#':
            jg[j] = 1
rs=[]
for i in range(0, len(tmp)):
    s=list(tmp[i])
    for k in range(0,w):
        if jg[k] == 0:
            s[k] = ''
    rs.append(s)
for _ in rs:
    print(''.join(_))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FOREACH(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SIZE(v) ((int)(v).size())
#define zero(v) memset(v, 0, sizeof(v))
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define pii pair<int, int>

const int MAX = 100100;
ll L[MAX], R[MAX];

int main() {
    int N; scanf("%d", &N);


    REP(i, N) scanf("%lld %lld", L + i, R + i);

    
    if(N == 2) printf("%lld\n", R[0] - L[0] + 1 + R[1] - L[1] + 1);
    else {
        ll mn = 0, mx = 0, cntMn = 1, cntMx = 1;

        for(int i = 1; i < N; i++) {
            if(R[i] < R[mn]) mn = i, cntMn = 1;
            else if(R[i] == R[mn]) cntMn++;

            if(L[i] > L[mx]) mx = i, cntMx = 1;
            else if(L[i] == L[mx]) cntMx++;
        }

        ll ans = 0;

        ll tmp = 0;

        REP(i, N) if((i != mn || cntMn > 1) && (i != mx || cntMx > 1)) tmp = max(tmp, R[i] - L[i] + 1);

        ans = max(ans, tmp + max(0ll, R[mn] - L[mx] + 1));

        vector<pair<ll, ll> > vc;

        set<pair<ll, ll> > l, r, lll;

        REP(i, N) {
            if(L[i] == L[mx]) r.insert(mp(R[i], L[i]));
            else {
                l.insert(mp(R[i], L[i]));
                lll.insert(mp(L[i], R[i]));
            }
        }

        if(!l.empty() && l.begin()->st == R[mn]) {
            ans = max(ans,  max(0ll, r.begin()->st - L[mx] + 1) + max(0ll, R[mn] - lll.rbegin()->st + 1));
            while(true) {
                pair<ll, ll> t = *l.rbegin();
                l.erase(t);
                lll.erase(mp(t.nd, t.st));
                r.insert(t);
                if( t.st == R[mn] ) break;
                ans = max(ans,  max(0ll, r.begin()->st - L[mx] + 1) + max(0ll, R[mn] - lll.rbegin()->st + 1));
            }
        }

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


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  rep(i,n+1){
    if((int)(i*1.08)==n){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 101
#define WHITE -1
#define GRAY 0
#define BRACK 1
int G[N][N] = {}, n, time;
int d[N] = {}, f[N] = {}, color[N];

void DFSvisit(int u){
  int i;
  color[u] = GRAY;
  d[u] = ++time;
  for(i = 1; i <= n; i++){
      if(G[u][i] == 1){
        if(color[i] == WHITE) DFSvisit(i);
      }
  }
  color[u] = BRACK;
  f[u] = ++time;
}

void DFS(void){
  int i, j;
  for(i = 1; i <= n; i++){
        color[i] = WHITE;
        time = 0;
  }
  for(i = 1; i <= n; i++){
        if(color[i] == WHITE) DFSvisit(i);
  }
}

int main(){
  int u, k, v, i, j;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d%d", &u, &k);
    for(j = 0; j < k; j++){
      scanf("%d", &v);
      G[u][v] = 1;
    }
  }
  DFS();
  for(i = 1; i <= n; i++){
    printf("%d %d %d\n", i, d[i], f[i]);
  }
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

int main(void){
	int r,d,x;
	cin>>r>>d>>x;
	rep(i,10){
		x = r*x-d;
		cout<<x<<endl;
	}
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long k,a;
string s;
int main(){
	cin>>s;
	for(int i=0;s[i];i++){
		if(s[i]=='A')k++;
		else if(s[i]=='B'&&s[i+1]=='C')a+=k,i++;
		else k=0;
	}
	cout<<a;
	return 0;
}


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

int main() {
  long long N, M, MOD = 1e9+7;
  cin >> N >> M;
  if (abs(N - M) > 1) {
    cout << 0 << "\n";
    return 0;
  }
  int b = 0;
  if (N == M) b = 1;
  long long X = 1, Y = 1;
  while (N > 0) X = X * N % MOD, N--;
  while (M > 0) Y = Y * M % MOD, M--;
  cout << ((b) ? X * Y % MOD * 2 % MOD : X * Y % MOD)<< "\n";
}

Measured memory_bytes: 256
// Problem : F - Knapsack for All Segments
// Contest : AtCoder - AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 998244353
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int n,s;

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n>>s;
    vi a(n+1);
    vi dp(s+1);
    for(int i=0;i<n;i++) cin>>a[i];
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=s;j>=0;j--){
            int prev = dp[s];
            if((dp[j] || j==0) && j+a[i] <= s){
                dp[j+a[i]] += j==0 ? i+1 : dp[j];
                dp[j+a[i]] %= mod;
            }
            ans += (dp[s]+mod-prev)*(n-i);
            ans %= mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (r, c) = readLine()?.split(" ")?.map { it.toInt() } ?: return
    val matrix = Array(r, { intArrayOf() })
    val rowList = arrayListOf<Int>()
    for (i in 0 until r) {
        val elements = readLine()?.split(" ")?.map { it.toInt() }?.toMutableList() ?: return
        rowList.add(elements.sum())
        matrix[i] = elements.toIntArray()
    }
    val builder = StringBuilder()
    val colSumList = arrayListOf<Int>()
    for ((i, row) in matrix.withIndex()) {
        row.forEachIndexed { j, element ->
            if (colSumList.size < c) {
                colSumList.add(element)
            } else {
                colSumList[j] += element
            }
        }
        builder.append(row.joinToString(" "))
                .append(" ${rowList.get(i)}")
                .appendln()
    }
    builder.append(colSumList.joinToString(" "))
            .append(" ${colSumList.filterNotNull().sum()}")
    println(builder.toString())
}


Measured memory_bytes: 36928
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main(){
	set<int>::iterator it;
	int n,m,t;

	while(cin >> n ,n){
		vector<int> info[31];
		set<int> data[50][31];
		
		for(int i=0;i<50;i++){
			for(int j=0;j<31;j++){
				data[i][j].insert(i);
			}
		}
		for(int i=0;i<n;i++){
			cin >> m;
			for(int j=0;j<m;j++){
				cin >> t;
				info[t].push_back(i);
			}
		}
		for(int i=1;i<31;i++){
			for(int j=0;j<n;j++){
				it = data[j][i-1].begin();
				while(it != data[j][i-1].end()){
					data[j][i].insert(*it); 
					++it;
				}
			}
			for(int j=0;j<info[i].size();j++){
				for(int k=0;k<info[i].size();k++){
					it = data[info[i][k]][i-1].begin();
					while(it != data[info[i][k]][i-1].end()){
						data[info[i][j]][i].insert(*it);
						++it;
					}
				}
				if(data[info[i][j]][i].size() == n){
					cout << i << endl;
					goto end;
				}
			}
		}
		cout << -1 << endl;
		end:0;
		/*for(int i=0;i<31;i++){
			cout << ":::::[ " << i << " ]::::::" << endl;
			for(int j=0;j<n;j++){
				cout << j << " : ";
				it = data[j][i].begin();
				while(it != data[j][i].end() ){
					cout << *it << " ";
					++it;
				}
				cout << endl;
			}
		}
		for(int i=0;i<31;i++){
			cout << "~~~~~~~ " << i << " :  :::::" << endl;
			for(int j=0;j<info[i].size();j++)
				cout << info[i][j] << " ";
			cout << endl;
		}*/
	}
}

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

int main() {
  int x;
  cin >> x;
  int happy = 0;
  int i, j;
  int y;

  i = 0;
  while (500 * i <= x) {
    i++;
  }
  i--;

  y = x % 500;

  j = 0;
  while (5 * j <= y) {
    j++;
  }
  j--;

  happy = 1000 * i + 5 * j;
  cout << happy << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <functional>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif

// 二乗を計算する。
ll sq(ll x) { return x * x; }

// 領域内にいるか。
bool within(ll x, ll min, ll max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T& container, typename T::key_type& key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
ll modpow(ll b, ll e, ll m) {
	ll result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}


// ここから解法

const int MOD = 1'000'000'007;

// xCy を計算する。
// X= max x
//    0 1 2 3
// 0: 1
// 1: 1 1
// 2: 1 2 1
// 3: 1 3 3 1
const int MAX_X = 2100;
ll C[MAX_X + 1][MAX_X + 1];

void init_comb() {
	for (int i = 0; i < MAX_X; i++) {
		C[i][0] = C[i][i] = 1;
	}
	for (int i = 1; i < MAX_X; ++i) {
		for (int j = 1; j < i; ++j) {
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
		}
	}
}

int main(void) {
	init_comb();

	int N, K;
	cin >> N >> K;

	for (int i = 1; i <= K; ++i) {
		if (i == 1) {
			cout << C[N - K + 1][1] << endl;
			continue;
		}
		int ans = 0;
		for (int k = 1; k <= N - K; ++k) {
			if (k < i - 1) continue;
			int rest = N - K - k;
			if (rest < 0) continue;
			ans += (((C[K - 1][i - 1] * C[k - 1][i - 2]) % MOD) * C[rest + 1][1]) % MOD;
			ans %= MOD;
		}
		cout << ans << endl;
	}

	return 0;
}



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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n, m;
    cin >> n >> m;

    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}


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

int main(){
    string a, b;
    cin >> a >> b;
    a += b;
    rep(i, 330){
        if(stoi(a) == i*i){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define in inline
#define reg register
#define int long long
#define MAX 20030813
#define f(i,l,r) for(reg int i=l;i<=r;++i)
#define F(i,l,r) for(reg int i=l;i>=r;--i)
using namespace std;
namespace qwq{
	in void read(int &o)
	{
		o=0;
		int w=1;
		char c=getchar();
		while(c<'0'||c>'9')
		{
			if(c=='-')w*=-1;
			c=getchar();
		}
		while(c>='0'&&c<='9')
		{
			o=(o<<3)+(o<<1)+(c^48);
			c=getchar();
		}
		o*=w;
	}
	in void write(int x)
	{
	   	if(x<0)putchar('-'),x=-x;
    	if(x>9)write(x/10);
    	putchar(x%10+48);
	}
	in int max(int x,int y)
	{
		return x>y?x:y;
	}
	in int min(int x,int y)
	{
		return x<y?x:y;
	}
}
using namespace qwq;
int N,ans;
signed main()
{
	string s;cin>>s;
	for(reg int i=0;i<s.length();++i)
	{
		if((i+1)&1 &&(s[i]=='R'||s[i]=='U'||s[i]=='D'))++ans;
		if(!((i+1)&1) &&(s[i]=='L'||s[i]=='U'||s[i]=='D'))++ans;
	}
	if(ans==s.length())puts("Yes");
	else  puts("No");
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <bitset>
using namespace std;
typedef long long int ll;

const int N=550;

char fi[N][N],red[N][N],blue[N][N];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin >> fi[i][j];
			red[i][j]=blue[i][j]='.';
		}
	}
	for(int i=0;i<n;i++){
		red[i][0]='#';
		blue[i][m-1]='#';
	}
	for(int i=0;i<n;i++){
		for(int j=1;j<m-1;j++){
			if(i%2){
				red[i][j]='#';
			}else{
				blue[i][j]='#';
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(fi[i][j]=='#'){
				red[i][j]='#';
				blue[i][j]='#';
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cout << red[i][j];
		}
		cout << endl;
	}
	cout << endl;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cout << blue[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n); rep (i, n) cin >> a[i];
    sort(all(a));
    ll ai = a.back();
    sort(all(a), [&](ll a, ll b) {return abs(ai - 2 * a) < abs(ai - 2 * b);});
    cout << ai << " " << a[0] << "\n";
    return 0;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
X = list(map(int, input().split()))

X.sort()

x = X[:]
p = x.pop(0)
a = []
for b in x:
    a.append(b - p)
    p = b

if a:
    a.sort(reverse=True)
    print(sum(a[N-1:]))
else:
    print(0)


Measured memory_bytes: 13960
#pragma GCC optimize(2)
#include<bits/stdc++.h>
typedef long long ll;
const int maxn=1e6+5;
using namespace std;
const ll INF=1e13+7;
ll n,m;
char str[maxn];
ll dp[maxn];
ll q[maxn];
int pre[maxn];
void TraceBack(int x)
{
    if(pre[x]==-1)
    {
        printf("%d",x);
        return;
    }
    TraceBack(pre[x]);
    printf(" %d",x-pre[x]);
}
int main()
{
    memset(pre,-1,sizeof(pre));
    scanf("%lld%lld",&n,&m);
    scanf("%s",str);
    //数有n+1个
    int s=1,e=0;
    for(int i=0;i<=m;i++)
    {
        if(str[i]=='0')
            dp[i]=1;
        else
            dp[i]=INF;
        while(s<=e&&dp[i]<dp[q[e]]) e--;
        q[++e]=i;
    }
    s++;
    for(int i=m+1; i<=n; i++)
    {
        dp[i]=INF;
        if(str[i]=='0')
        {
            dp[i]=min(dp[q[s]]+1,dp[i]);
            if(!dp[i]!=INF)
                pre[i]=q[s];
        }
        while(s<=e&&dp[i]<dp[q[e]]) e--;
        q[++e]=i;
        while(s<=e&&q[s]<i+1-m)
            s++;
    }
    if(dp[n]==INF) printf("-1\n");
    else TraceBack(n);
    return 0;
}

/**

**/


Measured memory_bytes: 15872
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> d;
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    d.push_back(k);
  }
  sort(d.begin(), d.end());
  int q = 0;
  int qi;
  for (int i = 0; i < n - 1; i++) {
    int u = min(d[i], d[n-1] - d[i]);
    q = max(q, u);
    if (q == u) {
      qi = i;
    }
  }
  printf("%d %d\n", d[n-1], d[qi]);
  return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll H, A;
  IN(H,A);

  ll ans = H/A;
  if(ans*A!=H) ans++;
  OUT(ans);

  return 0;
}

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

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    a.push_back(0);

    vector<pair<ll, int>> more_than2;
    int cnt = 0;
    rep(i, n) {
        cnt++;
        if (a[i] != a[i + 1]) {
            if (cnt >= 2) more_than2.emplace_back(a[i], cnt);
            cnt = 0;
        }
    }

    if (more_than2.empty() || more_than2.size() == 1 && more_than2[0].second < 4) cout << 0 << endl;
    else {
        auto p = more_than2[more_than2.size() - 1];
        if (p.second >= 4) {
            cout << p.first * p.first << endl;
        } else {
            cout << more_than2[more_than2.size() - 1].first * more_than2[more_than2.size() - 2].first;
        }
    }

    return 0;
}

Measured memory_bytes: 5552
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            String str = sc.next();

            if(str.length() % 2 == 0){
                while(str.length() >= 2){
                    str = str.substring(0, str.length() - 2);
                    String str1 = str.substring(0, str.length()/2);
                    String str2 = str.substring(str.length()/2);
                    if(str1.equals(str2)){
                        System.out.println(str.length());
                        break;
                    }
                }
            } else{
                str = str.substring(0, str.length() - 2);
                String str1 = str.substring(0, str.length()/2);
                String str2 = str.substring(str.length()/2);
                if(str1.equals(str2)){
                    System.out.println(str.length());
                }else{
                    while(str.length() >= 2){
                        str = str.substring(0, str.length() - 2);
                        str1 = str.substring(0, str.length()/2);
                        str2 = str.substring(str.length()/2);
                        if(str1.equals(str2)){
                            System.out.println(str.length());
                            break;
                        }
                    }
                }
            }

 
        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

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

int main() {
    int n;
    map<string,int> cards;
    string suit[] = {"S","H","C","D"};

    cin >> n;cin.ignore();

    for(int i=0;i<n;i++) {
        string str;
        getline(cin,str);
        cards[str] = 1;
    }

    for(int i=0;i<4;i++)
    {
        for(int j=0;j<13;j++)
        {
            string str = suit[i] + " " + to_string(j+1);
            if(cards[str] == 0)
                cout << str << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3204
from collections import defaultdict
n = int(input())
dic = defaultdict(lambda : 0)
def decomp(num, dic):
    sqrt = round(num **0.5) + 1
    z = num
    for i in range(2, sqrt + 1):
        if not z % i:
            count = 0
            while z % i == 0:
                count += 1
                z //= i
            dic[i] += count
    if z > 1:
        dic[z] += 1
for i in range(2, n + 1):
    decomp(i, dic)
ans = 1
for i in dic.values():
    ans *= i + 1
print(ans % (10 ** 9 + 7))

Measured memory_bytes: 3316
#include <cstdio>
#include <iostream>

using namespace std;

struct dice{
	int q1,q2,q3,q4,q5,q6;
};

void mN(dice &d){
	int tmp=d.q1;
	d.q1=d.q2;
	d.q2=d.q6;
	d.q6=d.q5;
	d.q5=tmp;
}

void mE(dice &d){
	int tmp=d.q1;
	d.q1=d.q4;
	d.q4=d.q6;
	d.q6=d.q3;
	d.q3=tmp;
}
void mW(dice &d){
	int tmp=d.q1;
	d.q1=d.q3;
	d.q3=d.q6;
	d.q6=d.q4;
	d.q4=tmp;
}
void mS(dice &d){
	int tmp=d.q1;
	d.q1=d.q5;
	d.q5=d.q6;
	d.q6=d.q2;
	d.q2=tmp;
}

void spin(dice &d){
	int tmp=d.q2;
	d.q2=d.q3;
	d.q3=d.q5;
	d.q5=d.q4;
	d.q4=tmp;
}

int main(){
	dice z;
	int q;
	
	scanf(" %d %d %d %d %d %d", &z.q1, &z.q2, &z.q3, &z.q4, &z.q5, &z.q6);
	scanf(" %d", &q);
	
	for(int i=0; i<q; ++i){
		int a, b;
		dice x=z;
		
		scanf(" %d %d", &a, &b);
		
		if(a==x.q3 || a==x.q4) mE(x);
		while(a != x.q1) 
			mN(x);
		while(b != x.q2)
			spin(x);
		
		printf("%d\n", x.q3);	
	}
	
	return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  deque<char> dq;
  string s;
  int q, a, b, f = 0;
  cin >> s;
  cin >> q;
  dq.push_front('0');
  rep(i,q)
  {
    cin >> a;
    if (a == 2) {
      char c;
      cin >> b >> c;
      if ((b == 1) ^ f) {
        dq.push_front(c);
      } else {
        dq.push_back(c);
      }
    } else {
      f ^= 1;
    }
  }
  if(f){
    for (auto itr = dq.rbegin(); itr != dq.rend(); ++itr) {
      if(*itr!='0'){
        cout << *itr;
      }else{
        reverse(s.begin(), s.end());
        cout << s;
      }
    }
  }else{
    for (auto itr = dq.begin(); itr != dq.end(); ++itr) {
      if(*itr!='0'){
        cout << *itr;
      }else{
        cout << s;
      }
    }
  }
}

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

#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define SQ(x)           ((x)*(x))
#define LCM(x,y)        (((x)/gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             printf("Ripon\n")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define SC              scanf
#define PF              printf
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int kx[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
int ky[] = { -1, 1, 2, 2, 1, -1, -2, -2 };
int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;} // 0 no, 1 total, 2 partial
//--------------------------//
void pvec(auto v){
    for (auto x:v){
        cout<<x<<" ";
    }
    cout<<endl;
}
//------------done with useless stuff--------------//


struct DATA{
    int st,en,val;
};
#define TC 0
#define mod 10000007
#define N 1000000
int n,m;
string str;
vector<int> v;
int arr[200];

void solve(int T) {

    cin>>str;

    rep(i,0,SZ(str)-1){
        if(str[i]==str[i+1]){
            cout<<i+1<<" "<<i+1+1<<endl;
            return;
        }
    }

    rep(i,0,SZ(str)-2){
        if(str[i]==str[i+2]){
            cout<<i+1<<" "<<i+2+1<<endl;
            return;
        }
    }
    cout<<"-1 -1"<<endl;
    return;

}


int main(){

    ios_base::sync_with_stdio(0);cin.tie(nullptr);
	#ifdef RIPON
	    freopen("file.txt","r",stdin);
	#endif

    int T=1;
    if(TC) cin>>T;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}



Measured memory_bytes: 512
fun main(args: Array<String>) {
    val ans = IntArray(4) { 0 }
    val (a1, b1) = readLine()!!.split(' ').map(String::toInt)
    ans[a1 - 1] += 1
    ans[b1 - 1] += 1
    val (a2, b2) = readLine()!!.split(' ').map(String::toInt)
    ans[a2 - 1] += 1
    ans[b2 - 1] += 1
    val (a3, b3) = readLine()!!.split(' ').map(String::toInt)
    ans[a3 - 1] += 1
    ans[b3 - 1] += 1

    if (ans.contains(0) || ans.contains(3)) {
        println("NO")
    } else {
        println("YES")
    }
}


Measured memory_bytes: 38240
/**
       **********    ************
	  Author : Avi J Patel
	  University : DAIICT
       **********    ************
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
} 
ull powr(ull x1, ull n1) {
    if(x1==0)
    {
        return 0;
    }
    ull result=1;
    while(n1>0)
    {
        if(n1&1)
        {
            result=(result*x1);
        }
        n1=n1>>1;
        x1=(x1*x1);
    }
    return result;
}   
int main()
{
	FAST
	int n;
	cin>>n;
	vector<int> a(n);
	int r=1;
	int temp=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==r)
		{
			temp=1;
			r++;
		}
	}
	if(temp==0)
	cout<<-1;
	else
	cout<<n-r+1;
	return 0;
}















Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>


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

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long MOD = 1'000'000'007LL;
const long long mod = 998244353LL;

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


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

	ll M, N; scanf("%lld %lld", &M, &N);
	vector<ll> a(N); for (ll i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
		a[i]--;
	}
	ll res = 0;
	ll pre = -1;
	if (M == 2) {
		vector<ll> t1(N), t2(N);
		ll cnt1 = 0;
		ll cnt2 = 0;
		for (ll i = 0; i < N; i++) {
			if (a[i] != i % 2) cnt1++;
		}
		for (ll i = 0; i < N; i++) {
			if (a[i] != (i + 1) % 2) cnt2++;
		}
		res = min(cnt1, cnt2);
	}
	else {
		for (ll i = 0; i < N; i++) {
			if (pre == a[i]) {
				res++;
				pre = -1;
			}
			else {
				pre = a[i];
			}
		}
	}

	cout << res << endl;
	return 0;

}



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


int main() {
  int n;
  cin >> n;
  if(n <= 999) cout << "ABC" << endl;
  else cout << "ABD" << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
ans = [0 for i in range(10001)]
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            if x*x + y*y + z*z + x*y + x*z + y*z <= 10000:
                ans[x*x + y*y + z*z + x*y + x*z + y*z] += 1
            else:
              break
for i in range(1,n+1):
    print(ans[i])

Measured memory_bytes: 9152
#define scanf_s scanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 50//00
#define MIN -100001
#define _MAX 100
#define g 9.8
#define d 4.9
int main(void)
{
	int ans;
	double v, y, a, t;
	while (scanf_s("%lf", &a) != EOF) {
		t = a / g;
		y = d * t * t;
		ans = y / 5;
		if (y > ans * 5) ++ans;
		printf("%d\n", ans + 1);
	}
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e6+10;
const int mod=1e9+7;
ll a[maxn];
int mp[maxn];
int vis[maxn];

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


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    ll t=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        t=gcd(t,a[i]);
    }
    vector<int>cnt;
    for(int i=2;i<maxn;i++)
    {
        if(vis[i])
            continue;
        cnt.pb(i);
        for(int j=i;j<maxn;j+=i)
        {
            vis[j]=1;
        }
    }
    if(t==1)
    {
        for(int i=1;i<=n;i++)
        {
            for(auto &v:cnt)
            {
                if(1ll*v*v>a[i])
                    break;
                if(a[i]%v==0)
                {
                    mp[v]++;
                    if(mp[v]>1)
                    {
                        cout<<"setwise coprime"<<'\n';
                        return 0;
                    }
                    while(a[i]%v==0)
                        a[i]/=v;
                }


            }
             if(a[i]>1)
                    mp[a[i]]++;
                if(mp[a[i]]>1)
                {
                    cout<<"setwise coprime"<<'\n';
                        return 0;
                }
        }
        cout<<"pairwise coprime"<<'\n';
    }
    else
    {
        cout<<"not coprime"<<'\n';
    }





}


Measured memory_bytes: 15576
import java.util.Scanner;

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

		for(int i=0;i<N;i++) {
			Values[i]=sc.nextInt();
		}
		for(int i=0;i<N;i++) {
			Costs[i]=sc.nextInt();
		}

		for(int i=0;i<N;i++) {
			if((Values[i]-Costs[i])>0) {
				ans+=Values[i]-Costs[i];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int &elem : a) cin >> elem;
    for (int i = k; i < n; i++) {
        if (a[i] > a[i - k]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3980
#include<cstdio>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=500005;

int N,K,A[MAXN];
int pos[MAXN];
vector<int> adj[MAXN];
set<int> L,R; //L存储pos上，比当前数小，绝对值差<K的下标；R存储比当前数大的下标
priority_queue<int,vector<int>,greater<int> > Q;
vector<int> stk;
int pri[MAXN];
int deg[MAXN];

int main()
{
    scanf("%d%d",&N,&K);
    for(int i=1;i<=N;i++)
        scanf("%d",&A[i]),pos[A[i]]=i;
    for(int i=1;i<=K;i++)
        R.insert(A[i]);
    set<int>::iterator x,y;
    for(int i=1;i<=N;i++)
    {
        x=L.upper_bound(A[i]);
        y=R.upper_bound(A[i]);
        if(x!=L.end())
        {
            adj[i].push_back(pos[*x]);
            deg[pos[*x]]++;
        }
        if(y!=R.end())
        {
            adj[i].push_back(pos[*y]);
            deg[pos[*y]]++;
        }
        L.insert(A[i]);
        if(i-K+1>0)
            L.erase(A[i-K+1]);
        if(i+K<=N)
            R.insert(A[i+K]);
        R.erase(A[i]);
    }

    for(int i=1;i<=N;i++)
        if(deg[i]==0)
            Q.push(i);
    while(!Q.empty())
    {
        int u=Q.top();
        Q.pop();
        stk.push_back(u);
        for(int i=0;i<(int)adj[u].size();i++)
        {
            deg[adj[u][i]]--;
            if(deg[adj[u][i]]==0)
                Q.push(adj[u][i]);
        }
    }
    for(int i=0;i<N;i++)
        pri[stk[i]]=i+1;
    for(int i=1;i<=N;i++)
        printf("%d\n",pri[i]);

    return 0;
}



Measured memory_bytes: 64240
#include <iostream>
#include <algorithm>
#include <string> 
#include <math.h>
#include <vector>
#define rep(i,n) for(int i=0; i< int(n); i++)
using namespace std;



int main(){
	string s;
	cin >> s;
	string ans;
	rep(i,s.size()){
		if(i%2 == 0)ans += s[i];
	}
	cout << ans << endl;
} 



Measured memory_bytes: 512
import math
def is_prime(n):
  frag = 1
  if(n == 2 or n == 3):
    return True
  elif(n==4):
    return False
  else:
    for i in range(2, int(math.sqrt(n))+1):
      if(n % i == 0):
        frag = 0
  return frag == 1

n = int(input())
while(not(is_prime(n))):
  n += 1
print(n)


Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := nextInt()
	b := nextInt()

	if n*a < b {
		fmt.Println(n * a)
	} else {
		fmt.Println(b)
	}
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1772
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
using ll = long long;
using P = pair<int,int>;

int main(void) {
  int N, i;
  cin >> N >> i;

  cout << N-i+1 << endl;
  return 0;
}


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

int main() {
    int a,b;
    cin >> a >> b;
    vector<int> s ={0,14,2,3,4,5,6,7,8,9,10,11,12,13};
    if(s.at(a)>s.at(b)){
        cout << "Alice";
    }
    else if(s.at(a)==s.at(b)){
        cout << "Draw";
    }
    else{
        cout << "Bob";
    }
}

Measured memory_bytes: 256
N, M = [int(_) for _ in input().split()]
A = set([int(input()) for _ in range(M)])
dp0 = 1
dp1 = 0
for i in range(1, N + 1):
    if i in A:
        dp0, dp1 = 0, dp0
    else:
        dp0, dp1 = dp0 + dp1, dp0
    dp0 %= 10**9 + 7
    dp1 %= 10**9 + 7
print(dp0)


Measured memory_bytes: 13192
unittest
{
	assert( [ "4 4 1", "2 1", "1 3", "3 2", "3 4", "4 1" ].solve == "0 1 0 1" );
	assert( [ "5 10 0", "1 2", "1 3", "1 4", "1 5", "3 2", "2 4", "2 5", "4 3", "5 3", "4 5" ].solve == "0 0 0 0 0" );
	assert( [ "10 9 3", "10 1", "6 7", "8 2", "2 5", "8 4", "7 3", "10 9", "6 4", "5 8", "2 6", "7 5", "3 1" ].solve == "1 3 5 4 3 3 3 3 1 0" );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s %s"( n, m, k );
	auto abs = new long[ 2 ][ m ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
		ab[] -= 1;
	}
	auto cdss = new long[][ n ];
	foreach( i; 0L .. k )
	{
		input.popFront;
		auto cd = input.front.split.to!( long[] );
		cd[] -= 1;
		cdss[ cd[ 0 ] ] ~= cd[ 1 ];
		cdss[ cd[ 1 ] ] ~= cd[ 0 ];
	}
	
	// 友達ネットワークを構築、友達の数をカウント
	auto uft = UnionFindTree( n );
	auto fs = new long[ n ];
	foreach( ab; abs )
	{
		uft.unite( ab[ 0 ], ab[ 1 ] );
		fs[ ab[ 0 ] ]++;
		fs[ ab[ 1 ] ]++;
	}
	
	// 友達候補の数を計算
	auto anss = new long[ n ];
	foreach( i, ref ans, cds; lockstep( anss, cdss ) )
	{
		// 友達ネットワークから自分と友達を除いたものが友達候補
		ans = uft.weight( i ) - 1 - fs[ i ];
		
		// 友達候補からブロック対象も除外
		foreach( cd; cds )
		{
			if( uft.same( i, cd ) ) ans--;
		}
	}
	return anss.to!( string[] ).join( " " );
}

// UnionFind木
struct UnionFindTree
{
	long[] ps;
	long[] rs;
	long   rn;
	
	this( long n )
	{
		ps.length = n;
		ps[] = -1;
		rs.length = n;
		rn = n;
	}
	
	long root( long i )
	{
		if( ps[ i ] < 0 ) return i;
		else              return ps[ i ] = root( ps[ i ] );
	}
	
	auto same( long i, long j )
	{
		return root( i ) == root( j );
	}
	
	auto unite( long i, long j )
	{
		i = root( i );
		j = root( j );
		if( i == j ) return;
		if( rs[ i ] < rs[ j ] )
		{
			ps[ j ] += ps[ i ];
			ps[ i ] = j;
		}
		else
		{
			ps[ i ] += ps[ j ];
			ps[ j ] = i;
			if( rs[ i ] == rs[ j ] ) rs[ i ]++;
		}
		rn--;
	}
	
	auto weight( long i )
	{
		return -ps[ root( i ) ];
	}
	
	auto toString()
	{
		return ps.to!( string );
	}
}


Measured memory_bytes: 27876
#include<stdio.h>

int main(){
int N,M,i,goukei=0,P,X,drink,j;
scanf("%d",&N);
int mondaisu[N];
for(i=0;i<N;i++){
    scanf(" %d",&mondaisu[i]);
    goukei+=mondaisu[i];
}
scanf("%d",&M);
for(j=0;j<M;j++){
    scanf(" %d %d",&P,&X);
    drink=goukei-mondaisu[P-1]+X;
     printf("%d\n",drink);
}

return 0;
}

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

using namespace std;

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

int main() {
    int N;
    cin >> N;
    vector<string> ss(N);
    rep(i, N){
        cin >> ss.at(i);
    }
    int M;
    cin >> M;
    vector<string> ts(M);
    rep(i, M){
        cin >> ts.at(i);
    }
    int ans = 0;
    for(string s1 : ss){
        int tmp = 0;
        for(string s2: ss){
            if(s1 == s2){
                tmp++;
            }
        }
        for(string t : ts){
            if(s1 == t){
                tmp--;
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll n; cin >> n;
  ll p = 0;
  FOR(i,1,n+1){
    if(i%2==1) p++;
  }
  cout << fixed << setprecision(10) << (double) 1.0*p/n << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())

p = list(range(n))


def find(x):
    if p[x] != x:
        p[x] = find(p[x])
    return p[x]


def union(x, y):
    x, y = find(x), find(y)
    p[x] = p[y] = min(x, y)


for _ in range(m):
    x, y, z = [int(i) - 1 for i in input().split()]
    if find(x) != find(y):
        union(x, y)

ans = set()
for i in range(n):
    find(i)
print(len(set(p)))


Measured memory_bytes: 81112
main = do
  n <- readLn :: IO Int
  a <- map read . words <$> getLine :: IO [Int]
  let ave = div (sum a) n
      ave' = ave + 1
  print $ min (cost ave a) (cost ave' a)

cost :: Int -> [Int] -> Int
cost n a = sum $ map (\x -> (x - n)^2) a


Measured memory_bytes: 1020
#include <iostream>
#include <utility>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define fastIO                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
// g++ -std=c++11 -O2 -Wall *.cpp -o *
#define eps 1e-9
#define MAX 1000000001
#define MOD 998244353
#define Fi first
#define Se second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef pair<int, int> pr_int;



int main()
{
	//freopen("input.txt", "r", stdin);
	int a, b;
	scanf("%d %d", &a, &b);
	printf("%d", max(a-b, max(a+b, a*b)));

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int,int>
#define pill pair<int,long long>
#define ff first
#define ss second
#define ll long long
#define pb push_back
using namespace std;

const int lim=404;

ll t[lim][lim];

ll pref[lim];
int n;

int pocz;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	
	for(int i=1;i<=n;i++) {
		cin>>pref[i];
		pref[i]+=pref[i-1];
	}
	
	for(int i=2;i<=n;i++){//i to rozwiar przedzialu
		for(int j=i;j<=n;j++) {//j to koniec przedzialu
			pocz=j+1-i; t[pocz][j]=t[pocz][pocz]+t[pocz+1][j];
			for(int i2=pocz+1; i2<j; i2++) t[pocz][j]=min(t[pocz][j],t[pocz][i2]+t[i2+1][j]);
			t[pocz][j]+=(pref[j]-pref[pocz-1]);
		}
	}
	
	cout<<t[1][n];
	return 0;
}

Measured memory_bytes: 1536
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
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;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

signed main(){
  double r;
  cin>>r;
  cout << fixed << setprecision(10) << 2*PI*r << endl;
}


Measured memory_bytes: 3812