akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]

for i in range(n - m + 1):
    for j in range(n - m + 1):
        for k in range(m):
            for l in range(m):
                if a[k + i][l + j] != b[k][l]:
                    break
            else:
                continue
            break
        else:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
///Code Forces - DP Educational Contest


#include <iostream>
#include <string.h>
#include <algorithm>


int main() 
{
	int N;
	std::cin >> N;
	
	int a = 0, b = 0, c = 0;
	std::cin >> a >> b >> c;

	//std::cout << '\n';
	for (int i = 2; i <= N; ++i) {
		//std::cout << "asdasdasasd: " <<  a << ' ' << b << ' ' << c << '\n';

		int _a, _b, _c;
		std::cin >> _a >> _b >> _c;

		int tmpa = 0, tmpb = 0, tmpc = 0;
		tmpa = std::max(_a + b, _a + c);
		tmpb = std::max(_b + a, _b + c);
		tmpc = std::max(_c + b, _c + a);

		a = tmpa;
		b = tmpb;
		c = tmpc;
	}

	//std::cout << "asdasdasasd: " << a << ' ' << b << ' ' << c << '\n';
	std::cout << std::max({a, b, c});
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll x[200005],y[200005],ind[200005],par[200005],sz[200005],suf[200005];
bool comp(ll i,ll j){
	return x[i]<x[j];
}
ll find(ll i){
	if(par[i]==i)
		return i;
	return par[i]=find(par[i]);
}
void merge(ll x,ll y){
	x=find(x),y=find(y);
	if(x==y)
		return;
	if(sz[x]<sz[y])
		swap(x,y);
	par[y]=x;
	sz[x]+=sz[y];
}
void solve(){
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>x[i]>>y[i];
		ind[i]=i;
		par[i]=i;
		sz[i]=1;
	}
	sort(ind+1,ind+n+1,comp);
	for(ll qc=n;qc>=1;qc--){
		ll i=ind[qc];
		suf[qc]=max(y[i],suf[qc+1]);
	}
	for(ll i=1;i<=n;i++){
		ll j=i,lo=y[ind[i]];
		while(j<=n&&lo<=suf[j]){
			lo=min(lo,y[ind[j]]);
			merge(ind[i],ind[j]);
			j++;
		}
		i=j-1;
	}
	for(ll i=1;i<=n;i++)
		cout<<sz[find(i)]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}


Measured memory_bytes: 13180
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
xyu=[list(input().split()) for i in range(n)]
for i in range(n):
    x,y,u=xyu[i]
    xyu[i]=[int(x),int(y),u]

ans=mod

xyu.sort(lambda x: x[1])
tate=[-1]*200001
for i in range(n):
    x,y,u=xyu[i]
    if u=="D":
        if tate[x]!=-1:
            ans=min(ans,(y-tate[x])*5)
    elif u=="U":
        tate[x]=y

xyu.sort(lambda x: x[0])
yoko=[-1]*200001
for i in range(n):
    x,y,u=xyu[i]
    if u=="L":
        if yoko[y]!=-1:
            ans=min(ans,(x-yoko[y])*5)
    elif u=="R":
        yoko[y]=x



cnt=[[] for i in range(2*200001)]
for i in range(n):
    x,y,u=xyu[i]
    cnt[x+y].append(i)

for i in range(len(cnt)):
    ul=[-1]*2
    cnt[i].sort(lambda x: xyu[x][1])
    for j in range(len(cnt[i])):
        x,y,u=xyu[cnt[i][j]]
        if u=="U":
            ul[0]=y
        elif u=="L":
            ul[1]=y
        elif u=="D" and ul[1]!=-1:
            ans=min(ans,(y-ul[1])*10)
        elif u=="R" and ul[0]!=-1:
            ans=min(ans,(y-ul[0])*10)
    
cnt=[[] for i in range(2*200001)]
for i in range(n):
    x,y,u=xyu[i]
    cnt[200000-x+y].append(i)

for i in range(len(cnt)):
    ur=[-1]*2
    cnt[i].sort(lambda x: xyu[x][1])
    for j in range(len(cnt[i])):
        x,y,u=xyu[cnt[i][j]]
        if u=="U":
            ur[0]=y
        elif u=="R":
            ur[1]=y
        elif u=="D" and ur[1]!=-1:
            ans=min(ans,(y-ur[1])*10)
        elif u=="L" and ur[0]!=-1:
            ans=min(ans,(y-ur[0])*10)

if ans!=mod:
    print(ans)
else:
    print("SAFE")

Measured memory_bytes: 207460
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    n = int(readline())
    a = list(map(int, readline().split()))
    memo = 0
    for aa in a:
        memo ^= aa
    for i in range(n):
        a[i] ^= memo
    print(*a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 29060
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <queue>
using namespace std;

pair<int,int> operator+(const pair<int,int> &lhs, const pair<int,int> &rhs){
  pair<int,int> p = { lhs.first + rhs.first, lhs.second + rhs.second };
  return p;
}

bool operator==(const pair<int,int> &lhs, const pair<int,int> &rhs){
  return (lhs.first == rhs.first) && (lhs.second == rhs.second);
}


int main(){
  int H,W,ans=0;
  cin>>H>>W;
  vector<string> s(H);
  vector<vector<int> > A(H, vector<int>(W, -1));
  queue<pair<int,int> > q;
  for(int i=0;i<H;i++){
    cin>>s[i];
    for(int j=0;j<W;j++){
      if(s[i][j]=='.'){
        A[i][j]=-1;
      }else{
        A[i][j]=0;
        q.push(make_pair(i,j));
      }
    }
  }

  const pair<int,int> moves[] = { 
    { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 },
  };  

  while( !q.empty() ) {
    pair<int,int> cur = q.front(); q.pop();
    for(auto &move : moves){
      pair<int,int> next=cur+move;
      if(next.first<0||next.first>=H||next.second<0||next.second>=W)continue;
      if(A[next.first][next.second]==-1){
        A[next.first][next.second]=A[cur.first][cur.second]+1;
        q.push(next);
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      ans=max(ans,A[i][j]);
    }
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 13456
from collections import deque

def replace(l, a, max_idx, min_idx):
    if max_idx == min_idx:
        l[max_idx] = a
        return

    center = (max_idx + min_idx)//2
    if l[center] >= a:
        return replace(l, a, max_idx, center+1)
    else:
        return replace(l, a, center, min_idx)


N = int(input())
A = [int(input()) for _ in range(N)]


l = []

for a in A:
    if len(l) == 0:
        l.append(a)
    elif l[-1] >= a:
        l.append(a)
    else:
        replace(l, a, len(l)-1, 0)

print(len(l))


Measured memory_bytes: 8176
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    ll n;
    while(cin>>n)
    {
        if(n%2)
        {
            cout<<0<<endl;
            continue;
        }
        //n=(n/10);
        ll res=5;
        ll ans=0;
        while(res<=n)
        {
            ans+=(n/res)/2;
            res*=5;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()
#define int long long
typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    vector <int> a(n), b(n);
    int sum = 0;
    for (auto &it : a) {
        cin >> it;
        sum += it;
    }
    for (auto &it : b)
        cin >> it;
    sort(all(a));
    sort(rall(b));
    int l = 0, r = 1e15, ans = r;
    while (l <= r) {
        int m = l + r >> 1;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            int x = m / b[i];
            cnt += max((ll)0, a[i] - x);
        }
        if (cnt <= k) {
            r = m - 1;
            ans = m;
        } else
            l = m + 1;
    }
    cout << ans;


    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <numeric>
#include <vector>
 
namespace
{
template <typename N, typename D>
decltype(auto) round_div(N n, D d)
{
    return ((n < 0) ^ (d < 0)) ? ((n - d / 2) / d) : ((n + d / 2) / d);
}
template <typename T>
decltype(auto) pow2(T n)
{
    return n * n;
}
}
int main()
{
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for(auto &i : a)
        std::cin >> i;
    int average = round_div(std::accumulate(a.begin(), a.end(), 0), n);
    std::size_t cost = 0;
    for(auto &i : a)
        cost += pow2(average - i);
    std::cout << cost << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long a, b, c, d;
  std::vector<std::array<long, 2>> xs;
  Solver() {
    S002 reader;
    reader >= a >= b >= c >= d;
  }
  void solve() {
    std::string ans;
    long dx = c - a;
    long dy = d - b;
    char xs[] = "RULDLURDRDLU";
    long ys[] = {dx, dy, dx, dy, 1, dy + 1, dx + 1, 1, 1, dy + 1, dx + 1, 1};
    for(long i = 0; i < 12; ++i) {
      for(long j = 0; j < ys[i]; ++j) {
        ans.push_back(xs[i]);
      }      
    }
    printf("%s\n", ans.c_str());
  }
};
 
int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
 
int rot[5][7] = {
{0,1,2,3,4,5,6},{0,2,6,3,4,1,5},{0,4,2,1,6,5,3},{0,3,2,6,1,5,4},{0,5,1,3,4,6,2}};
int assign[7];      // サイコロの1～6の各面に割り当てる数字
int tr['Z'];
 
void dice_init(int *a)
{
    int i;
    int t[5] = {0,'N','E','W','S'};
    for (i = 1; i <= 6; i++) assign[i] = a[i];
    for (i = 1; i <= 4; i++) tr[t[i]] = i;
}
 
char s[102];
int main()
{
    int i, k1, k2;
    int a[7], dice[2][7];
    char *p;
 
    for (i = 1; i <= 6; i++) scanf("%d", a+i);
    dice_init(a);
    scanf("%s", p=s);
    for (i = 1; i <= 6; i++) dice[0][i] = rot[0][i];
    for (k1 = 0, k2 = 1; *p; k1 = k2, k2 = !k2) {
        for (i = 1; i <= 6; i++) dice[k2][i] = dice[k1][rot[tr[*p]][i]];
        p++;
    }
    printf("%d\n", assign[dice[k1][1]]);
    return 0;
}


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


int main(){
    int N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int cnt[N+1] = {0};
    for (int i = 1; i < N; i++)
    {
        if(S[i-1] == 'A' && S[i] == 'C') cnt[i+1] = cnt[i] + 1;
        else cnt[i+1] = cnt[i];
    }
    for (int i = 0; i < Q; i++)
    {
        int l,r;
        cin >> l >> r;
        cout << cnt[r] - cnt[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;
ll bigp = 1000000007;

vector<pair<char,ll>> run_length_comp(string s){
    vector<pair<char,ll>> rl;
    ll l = s.size();
    rep(i,l){
        if(i>=1 && s[i]==s[i-1]){
            rl[rl.size()-1].second ++;
        }else{
            rl.pb(make_pair(s[i],1));
        }
    }
    return rl;
}

int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<pair<char,ll>> rl = run_length_comp(s);
    cout << rl.size();
}


Measured memory_bytes: 2676
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
int n;
int arr[100];
cin>>n;
forn(i,n)
cin>>arr[i];

sort(arr,arr+n);
int sum=0;
forn(i,n-1)
sum+=arr[i];
if(sum<=arr[n-1])
cout<<"No";
else cout<<"Yes";


    return 0;
  }


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

int main(){
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	vector<int> pre, nxt;
	pre = nxt = a;
	if(prev_permutation(pre.begin(), pre.end())) {
		for(int i = 0; i < n-1; i++)
			printf("%d ", pre[i]);
		printf("%d\n", pre[n-1]);
	}
	for(int i = 0; i < n-1; i++)
		printf("%d ", a[i]);
	printf("%d\n", a[n-1]);
	if(next_permutation(nxt.begin(), nxt.end())) {
		for(int i = 0; i < n-1; i++)
			printf("%d ", nxt[i]);
		printf("%d\n", nxt[n-1]);
	}
}



Measured memory_bytes: 3276
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

constexpr int MOD = 998244353;
struct mint
{
	int v;
	mint():v(0){}
	mint(int v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(int k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(int n, int k) {
		if(n-k<k) k=n-k;
		mint num(1), dom(1);
		for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; }
		return num/dom;
	}
};
std::istream& operator>>(std::istream&i,mint&a){ int t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


void f(std::vector<mint>& a) {
	int n=a.size();
	for(int i=1;i<n;i++) {
		for(int j=2;j*i<n;j++) {
			a[i]+=a[j*i];
		}
	}
}

void finv(std::vector<mint>& a) {
	int n=a.size();
	for(int i=n-1;i>0;i--) {
		for(int j=2;j*i<n;j++) {
			a[i]-=a[j*i];
		}
	}
}

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	int MAX=1;
	rep(i,n) MAX=std::max(MAX,a[i]);
	MAX+=1;
	std::vector<mint> x(MAX,0);
	rep(i,n) x[a[i]]+=a[i];
	f(x);
	rep(i,MAX) x[i]*=x[i];
	finv(x);
	rep(i,n) x[a[i]]-=mint(a[i]).pow(2);
	mint ans=0;
	for(int i=1;i<MAX;i++) ans+=x[i]/mint(i)/mint(2);
	print(ans);

	return 0;
}


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

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

using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}
typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

int main(){
   int N;
   cin >> N;
   vector<int> a(N);
   rep(i,N){
     cin >> a[i];
   }
   int k = 1;
   vector<int> ans;

   for(int i = 0;i<N;i++){
     if(a[i] == k){
       ans.push_back(k);
       k++;
     }
   }
   if(ans.size() == 0) cout << -1 << endl;
   else cout << N - ans.size() << endl;
 }

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  ll n; cin >> n;
  int ans = 0;
  for (int p = 2; p < 1000000 && n > 1; p++) {
    if (n % p == 0) {
      int f = 0;
      while (n % p == 0) {
        n /= p;
        f++;
      }
      for (int t = 1; t <= f; t++) {
        if (t <= f) {
          ans++;
          f -= t;
        }
      }
    }
  }
  if (n > 1) ans++;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,a,b;
    cin>>a>>b;
    ans=max(max(a+b,a-b),a*b);

    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

int S;
int ans=0;
int mod=1000000007;
signed main(){
    scanf("%lld",&S);
    if(S%10==(int)(S/10)%10)ans=1;
    if((int)(S/10)%10==(int)(S/100)%10)ans=1;
    if((int)(S/100)%10==(int)(S/1000)%10)ans=1;
    if(ans==0)printf("Good\n");
    else printf("Bad\n");
}

Measured memory_bytes: 128
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    L = intin()

    r = 0
    while True:
        if 2**(r+1) > L:
            break
        r += 1

    n = r + 1

    path_list = []
    path_list.extend([(i + 1, i + 2, 0) for i in range(r)])
    path_list.extend([(i + 1, i + 2, 2**i) for i in range(r)])

    remain = L - 2**r
    next = 2**r

    for i in reversed(list(range(r))):
        if remain >= 2**i:
            path_list.append((i + 1, n, next))
            remain -= 2**i
            next += 2**i

    print('%d %d' % (n, len(path_list)))
    for path in path_list:
        print('%d %d %d' % path)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
  while ( u != NIL && k != u->key ) {
    if ( k < u-> key ) u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while ( x != NIL ) {
    y = x;
    if ( z ->key < x->key ) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ) {
    root = z;
  } else {
    if ( z->key < y->key ) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node *u) {
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

  for( i = 0; i < n; i++ ) {
    cin >> com;
    if ( com[0] == 'f' ) {
      scanf("%d", &x);
      Node *t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com == "insert" ) {
      scanf("%d", &x);
      insert(x);
    } else if ( com == "print" ) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if ( A == B && A != C ){
        cout << "Yes" << endl;
    } else if ( B == C && B != A ){
        cout << "Yes" << endl;
    } else if ( C == A && C != B ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long long y[30000010]={};
int main(){
  long long n,i,j,ans=0,c;
  scanf("%lld",&n);
  for(i=1;i<=n;i++){
    for(j=0;j<=n;j+=i)y[j]++;
    ans+=i*y[i];//printf("%lld %lld\n",i,y[i]);
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 79856
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    ll a,b;
    cin >> a >> b;
    if((a < 0 && b > 0) || (a > 0 && b < 0))cout << "Zero\n";
    else{
        if(a > 0 && b > 0)cout << "Positive\n";
        else if((b-a+1)%2)cout << "Negative\n";
        else cout << "Positive\n";
    }
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int) 2e5 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

struct Node{
    char name[20];
    int t;
}q[MAXN];

int n,max_time;
int st,en;

Node Front(){
    Node ret=q[st];
//    printf("st = %d\n",st);
//    printf("<-- %s %d\n",ret.name,ret.t);
//    printf("<-- %s %d\n",q[st].name,q[st].t);
    st=(st+1)%MAXN;
    return ret;
}

void Push(Node x){
    en=(en+1)%MAXN;
    q[en]=x;
//    printf("--> %s %d\n",q[en].name,q[en].t);
}

void work(){
    scanf("%d%d",&n,&max_time);
    for(int i=1;i<=n;i++){
        scanf("%s%d",q[i].name,&q[i].t);
    }
    st=1,en=n;
    int cnt=n;
    int cur_time=0;
    while(cnt>0){
        Node x=Front();
        if(x.t<=max_time){
            cur_time+=x.t;
            cnt--;
            printf("%s %d\n",x.name,cur_time);
        }
        else{
            cur_time+=max_time;
            x.t-=max_time;
            Push(x);
        }
    }
}

int main(){
    work();
    return 0;
}










Measured memory_bytes: 7020
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;


int32_t main() {

    fast
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<3;i++){
        if(s[i]=='R')cnt++;
    }
    if(cnt==2){
        if(s[0]=='R' && s[2]=='R'){
            cout<<1<<endl;
        }
        else{
            cout<<2<<endl;
        }
        return 0;
    }
    cout<<cnt;



    return 0;
}



Measured memory_bytes: 3648
#include<stdio.h>
#define N 20000001
int extract(void);
void insert(int);
void increase(int,int);
void maxHeapify(int i);
int A[N];
int main(){
  char s[10];
  int num;
  A[0]=0;
  while(1){
    scanf("%s",s);
    switch(s[2]){
    case 's':
      scanf("%d",&num);
      insert(num);
      break;
    case 't':
      printf("%d\n", extract());
      break;
    case 'd':
      goto END;
      break;
    }
  }
 END:
  return 0;
}
void insert(int num){
  A[0]++;
  increase(A[0],num);
  
}
int extract(){
  int max=A[1];
  A[1]=A[A[0]];
  A[0]--;
  maxHeapify(1);
  return max;
}
void maxHeapify(int i){
  int l,r,H,largest;
  l=i*2;
  r=i*2+1;

  if(l<=A[0]&&A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=A[0]&&A[r]>A[largest])
    largest=r;
  if(largest!=i){
    H=A[i];
    A[i]=A[largest];
    A[largest]=H;
    maxHeapify(largest);
  }
}
void increase(int i,int key){
  int c;
  A[i]=key;
  while(i>1&&A[i/2]<A[i]){
    c=A[i/2];
    A[i/2]=A[i];
    A[i]=c;
    i=i/2;
  }
}



Measured memory_bytes: 5608
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        System.out.println((int)Math.ceil((double)a/(double)(2*b+1)));
        
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
            return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 21204
#include<stdio.h>
#include<stdlib.h>
int main(void) 
{
    int a,b,c,num;
    
    scanf("%d %d %d", &a,&b,&c);
    
    if (b>c) num=b,b=c,c=num;
    if (a>b) {
        num=a,a=b,b=num;
        if (b>c) num=b,b=c,c=num;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2112
#include<iostream>

using namespace std;

int step=0;

int gcd(int x,int y){
	if(y==0)return x;
	else{
		step++;
		return gcd(y,x%y);
	}
}

int main(void){
	int x,y,ans;
	while(1){
		scanf("%d%d",&x,&y);
		if(x==0 && y==0)break;
		step=0;
		if(x>y)ans=gcd(x,y);else ans=gcd(y,x);
		cout << ans << " " << step << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    if (A >= 13)
    {
        cout << B;
    }
    else if (A >= 6)
    {
        cout << (B / 2);
    }
    else
    {
        cout << 0;
    }
    return 0;
}

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

int main(){
	double a , b , c , d , e , f ,ans1 , ans2;
	while(cin>>a>>b>>c>>d>>e>>f){
		ans1=(double)((c*e-b*f)/(a*e-b*d));
		ans2=(double)((c*d-a*f)/(b*d-a*e));
		if (ans1==0) ans1=0;
		if (ans2==0) ans2=0;
		printf("%.3f %.3f\n" , ans1 , ans2);
	}
	return 0;
}

Measured memory_bytes: 1236
import java.util.Scanner;

// Java8
public class Main {
	Scanner sc = new Scanner(System.in);

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

	void run() throws Exception {
		int n = sc.nextInt();
		int[][] s = new int[n+1][n+1];
		for(int y=1; y<=n; y++) {
			for(int x=1; x<=n; x++) {
				s[y][x] = sc.nextInt();
				s[y][x] += s[y-1][x] + s[y][x-1] - s[y-1][x-1];
			}
		}
		int max = s[n][n];
		for(int b=1; b<=n; b++) {
			for(int t=0; t<b; t++) {
				for(int r=1; r<=n; r++) {
					for(int l=0; l<r; l++) {
						max = Math.max(max, s[b][r] - s[b][l] + s[t][l] - s[t][r]);
					}
				}
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 40736
N,M = map(int,input().rstrip().split(" "))
ans = 0
n = [-1 for i in range(N)]
for i in range(M):
  s,c = map(int,input().rstrip().split(" "))
  s -= 1
  if n[s] == -1 or n[s] == c:
    n[s] = c
  else:
    ans = -1
if N != 1 and n[0] == 0:
  ans = -1

if ans == -1:
  print(-1)
elif N == 1 and M == 0:
  print(0)
else:
  for i in range(N):
    if n[i] == -1:
      if i == 0:
        ans += 10 ** (N -1)
    else:
      ans += 10 ** (N - i -1) * n[i]
  print(ans)

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,sum=0,i,k;
    cin>>a;
    for(i=3;i<=a;i++)
    {
        {
            if(i%3==0 || i%5==0 || i%15==0)
            {
                sum+=i;
            }

        }
    }
    k=(a*(a+1))/2;
    cout<<k-sum<<endl;
    return 0;
}



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

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			while ((x = in.readLine()).equals("0") == false) {
				int sum = 0;
				for (int i = 0; i < x.length(); i++) {
					sum = sum + x.charAt(i) - '0';
				}
				
				System.out.println(sum);
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

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

int a[222222], s;
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i], s ^= a[i];
    for(int i = 0; i < n; i++)
        cout << (a[i] ^ s) << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 4208
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol inf=(1LL<<60);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,-1,1,-1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
lol n,m,k,r,q;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>n;
  vector<int> a(n+1,0);
  for(int i=0;i<n;i++) cin >>a[i];
  sort(a.begin(),a.end()-1);
  lol ma=a[n-1];
  vector<int> dp(1000000+1,0);
  lol ans=0;
  for(int i=0;i<n;i++){
    if(dp[a[i]]==0){
      
      if(a[i]!=a[i+1]) ans++;
      for(int j=a[i];j<=1000000;j+=a[i]) dp[j]++;
    }
  }
  cout <<ans<<'\n';
  return (0);
}


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

int main(){
    string S; cin >> S;

    int cnt = 0;
    for(int i = 0; i < 4; ++i) {
        if(S[i] == '+') {
            cnt++;
        } else {
            cnt--;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

const vector<int> D = {-2,-1,0,1,2};
const vector<int> D2 = {-1,0,1};

int main() {
    int H,W,N; cin >> H >> W >> N;
    set<P> point;
    rep(i,N) {
        int a,b; cin >> a >> b;
        point.insert(P(a,b));
    }
    set<P> searched;
    vector<ll> ans(10,0);
    ll tot = 0;

    for (P p: point) {
        int y = p.first,x = p.second;
        vector<vector<bool>> neighbor(5,vector<bool>(5,false));
        for (int dy:D) {
            for (int dx:D) {
                if (point.count(P(y + dy,x + dx))) {
                    neighbor[dy + 2][dx + 2] = true;
                }
            }
        }

        for (int i = 1;i < 4;i ++) {
            for (int j = 1;j < 4;j ++) {
                if (y + i - 2 <= 1 || y + i - 2 >= H) continue;
                if (x + j - 2 <= 1 || x + j - 2 >= W) continue;
                if (searched.count(P(y + i - 2,x + j - 2))) continue;
                searched.insert(P(y + i - 2,x + j - 2));
                int cnt = 0;
                for (int dy: D2) {
                    for (int dx:D2) {
                        if (neighbor[i + dy][j + dx]) {
                            ++cnt;
                        }
                    }
                }
                ++ans[cnt] ;
                ++tot ;
            }
        }
    }
    ans[0] = (ll)(H - 2)*(W - 2) - tot;
    rep(i,10) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 49152
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0


int main(){
  int i,j,s,n;
  scanf("%d",&n);
  int a[n+1];
  a[0]=0;
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }

  int ans[n+1],count=0;
  
  for(i=n;i>0;i--){
    int s=a[i];
    for(j=2*i;j<=n;j+=i){
      s^=ans[j];
    }
    if(s)count++;
    ans[i]=s;
  }
  printf("%d\n",count);
  for(i=1;i<=n;i++){
    if(ans[i])printf("%d ",i);
  }

  return 0;
}


/// confirm df==0 ///


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  rep(i,s.length()) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a) ;
#define vi vector<int>
#define ull unsigned long long
#define ll long long 
#define db double 
#define ldb long double
#define fl float
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lrep(i,a,b) for(ll i=a;i<b;i++)
//#define mod 1000000007
#define mpr make_pair
#define pb push_back
#define fr first
#define sn second
#define bpp(x) __builtin_popcountll(x)
const ldb PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899863;
const int INF = 1e9+7;
bool ok(string &s ,int l ,int r)
{
while(s[l]==s[r]) l++,r--;
return l>=r; 
}/*
ll por(ll a,int b)
{
ll res=1,M=998244353;
while(b)
{
if(b&1)
res=(res*a)%M;
a=(a*a)%M;
b/=2;
}
return res;
}
void rev(vector<int>&arr,int l,int r)
{
    for(;l<r;l++,r--) swap(arr[l],arr[r]);
}
void solve()
{
// Dont apply return before taking all the input of particular test case
/* carry operation
int cr=1;
int y=k-1;
while(cr)
{
char op=str[y];
op++;
if(op<='9') cr=0;
else op='0';
str[y]=op;
y--;
}
return;
}
*/
int prime[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,97,101,103};
const int sz=2e5+2;
long long a[sz],pr[sz],sf[sz];
void solve()
{
int n,k,x; cin>>n>>k>>x;
long long m=1,ans=0;
while(k--)
m*=x;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
pr[i]=pr[i-1] | a[i];
for(int i=n;i;i--)
sf[i]=sf[i+1] | a[i];
for(int i=1;i<=n;i++)
{
ans=max(ans,pr[i-1] | (a[i]*m) | sf[i+1]);
 }
 cout<<ans; 
return ;
}
int add(int a,int b)
{
long x=a+b;
if(x>=INF)
x-=INF;
return x;
}
void pd()
{
int h,w; cin>>h>>w;
char ar[h][w];
int dp[h][w];
rep(i,0,h)
{
rep(j,0,w)
{
cin>>ar[i][j]; dp[i][j]=0;
}
}
dp[0][0]=1;
rep(i,1,w)
{
if(ar[0][i]=='#')
dp[0][i]=0;
else
dp[0][i]=dp[0][i-1];
}
rep(i,1,h)
{
if(ar[i][0]=='#')
dp[i][0]=0;
else
dp[i][0]=dp[i-1][0];
}
rep(i,1,h)
{
rep(j,1,w)
{
if(ar[i][j]=='#')
dp[i][j]=0;
else
dp[i][j]=add(dp[i-1][j],dp[i][j-1]);
}
}
cout<<dp[h-1][w-1];
}
void pl() // To analyse
{
string s; cin>>s;
int l=s.length();
bool arr[l][l];
mem(arr,0);
int st=0,mx=1;
rep(i,0,l)
arr[i][i]=1;
rep(i,0,l-1)
{
if(s[i]==s[i+1])
{
arr[i][i+1]=1;
st=i; mx=2;
}
}
rep(k,3,l+1)
{
rep(i,0,l-k+1)
{
int j=i+k-1;
if(arr[i+1][j-1]&&s[i]==s[j]) // i+1 & j-1 suggest minimum length of 3
{
arr[i][j]=1;
if(k>mx)
{
mx=k; st=i;
}
}
}
}
cout<<mx;
}
int main()
{
ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
//	cin>>t;
while(t--)
{
pd(); 
}
return 0;
}

Measured memory_bytes: 5120
// Always have fun - aNONYMOUS //

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define mod 1e9+7
#define inf 1e18
#define pb push_back
#define mp make_pair
#define vll vector<ll>

int main(){
	IOS;
	ll t,n,i,j,k,ans;
	t=1;//cin >> t;
	while(t--){
		ans=0;
		cin >> n;
		ll a[n+2];
		for(i=0;i<n;i++)
			cin>>a[i];
		for(i=1;i<n;i++){
			if(a[i]<a[i-1]){
				ans+=a[i-1]-a[i];
				a[i]=a[i-1];
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 5248
n, x = gets.split.map &:to_i
a = gets.split.map(&:to_i).sort
r = 0
s = 0
(0...n).each do |i|
  s += a[i]
  if s == x
    puts r + 1
    exit
  elsif s < x
    r += 1
  else
    puts r
    exit
  end
end

puts r - 1

Measured memory_bytes: 1788
import sys
sys.setrecursionlimit(10**9)
N = int(input())
nood = [[]for i in range(0,N+1,1)]
h_color = [1]*(N+1)
for i in range(1,N,1):
    a,b=map(int,input().split())
    nood[a].append([b,i])
    nood[b].append([a,i])

max_color_count = -1

def bfs(nowNood,preNood,preColor):
    global max_color_count
    colorCount=1
    for i in range(0,len(nood[nowNood]),1):
        if nood[nowNood][i][0]!=preNood:
            if colorCount == preColor:
                colorCount+=1
            h_color[nood[nowNood][i][1]]=colorCount
            bfs(nood[nowNood][i][0],nowNood,colorCount)
            max_color_count = max(max_color_count,colorCount)
            colorCount+=1

bfs(1,-1,-1)
print(max_color_count)
for i in range(1,N,1):
    print(h_color[i])

Measured memory_bytes: 114332
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,x,i;
    cin>>n;
    map<int,int>mp;
    for(i=1; i<n; i++)
    {
        cin>>x;
        mp[x]++;
    }
    for(i=1; i<=n; i++)
    {
        cout<<mp[i]<<endl;
    }
    return 0;
}


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

using namespace std;

const int inf = 1e9 + 7;
const int N = 1e6 + 5;

int a[N];

int main() {
	int n, mx = -inf, mn = inf, cost = inf;
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		mn = min(a[i], mn);
		mx = max(a[i], mx);
	}
	for (int i = mn; i <= mx; i ++) {
		int sum = 0;
		for (int j = 1; j <= n; j ++) {
			sum += (a[j] - i) * (a[j] - i);
		}
		cost = min(cost, sum);
	}
	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

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

int main(void){
	int n, m;
	scanf("%d%d", &n, &m);
	int ans = (m*1900 + (n-m)*100)*(1<<m);
	printf("%d\n", ans);
}


Measured memory_bytes: 128
N, C = map(int, input().split())
R = [[0, 0]]
L = [[0, 0]]
R_half = -1
for i in range(N):
    x, v = map(int, input().split())
    R.append([x, v])
for i in R[::-1]:
    L.append([C - i[0], i[1]])
L.pop(-1)

R_sum = [0]
L_sum = [0]
R_sum2 = [0]
L_sum2 = [0]
total_1 = 0
total_2 = 0
total_3 = 0
total_4 = 0
for i in range(1, N + 1):
    total_1 += R[i][1] - (R[i][0] - R[i-1][0])
    total_2 += L[i][1] - (L[i][0] - L[i-1][0])
    total_3 += R[i][1] - 2*(R[i][0] - R[i-1][0])
    total_4 += L[i][1] - 2*(L[i][0] - L[i-1][0])
    R_sum.append(total_1)
    L_sum.append(total_2)
    R_sum2.append(total_3)
    L_sum2.append(total_4)
result_1 = max(R_sum)
result_2 = max(L_sum)
big_R = []
big_L = []
t = 0
p = 0
for i in range(N+1):
    t = max(t, R_sum[i])
    big_R.append(t)
    p = max(p, L_sum[i])
    big_L.append(p)
result_3 = 0
result_4 = 0
for i in range(N+1):
    result_3 = max(result_3, L_sum2[i] + big_R[N - i])
    result_4 = max(result_4, R_sum2[i] + big_L[N - i])
print(max([result_1, result_2, result_3, result_4]))

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

int main(){
  int n, k;
  cin >>n>> k;
  int ans = 0;
  if(n% k!=0){ans++;}
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

typedef ll Type;
typedef vector<vector<Type>> Matrix;

Matrix mul(const Matrix &a, const Matrix &b) {
  Matrix c(a.size(), vector<Type>(b[0].size()));
  for (int i = 0; i < a.size(); i++) {
    for (int k = 0; k < b.size(); k++) {
      for (int j = 0; j < b[0].size(); j++) {
        c[i][j] = (c[i][j] + (a[i][k] * b[k][j]) % MOD) % MOD;
      }
    }
  }
  return c;
}

Matrix pow(Matrix &a, ll n) {
  Matrix res(a.size(), vector<Type>(a[0].size()));
  REP(i, a.size()) { res[i][i] = 1; }
  while (n > 0) {
    if (n & 1LL)
      res = mul(res, a);
    a = mul(a, a);
    n >>= 1LL;
  }
  return res;
}

void PrintMatrix(const Matrix &a) {
  int h = a.size(), w = a[0].size();
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << a[i][j] << ' ';
    }
    cout << endl;
  }
}

int main() {
  int n;
  ll k;
  cin >> n >> k;
  Matrix A(n, vector<ll>(n));
  REP(i, n) {
    REP(j, n) {
      int aij;
      cin >> aij;
      A[i][j] = aij;
    }
  }
  auto D = pow(A, k);

  ll ans = 0;
  REP(i, n) {
    REP(j, n) { ans = (ans + D[i][j]) % MOD; }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <queue>
 
using namespace std;
 
int main() {
  int N, M, tmp;
  cin >> N >> M;
  priority_queue<int> A;
  
  for (int i=0; i<N; i++) {
    cin >> tmp;
    A.push(tmp);
  }
  
  while(M>0) {
    tmp = A.top();
    A.pop();
    if(tmp==0) {break;}
    A.push(tmp/2);
    M--;
  }
 
  long long sum = 0;
  for(int i=0; i<N; i++) {
    sum += A.top();
    A.pop();
  }
  
  cout << sum << endl;
  
  return 0; 
}

Measured memory_bytes: 892