akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
  int N;
  cin>>N;
  double ans=0,A;
  for(int i=0;i<N;i++){
    cin>>A;
    ans+=1/A;
  }
  ans=1/ans;
  cout << setprecision(16) << ans << endl;
  /*int A[N-1];
  double B[N-1];
  double score=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    int k=A[i];
    double B[i]=1/k;
    score+=B[i];
  }
  */
}
  
    
  

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

int zerocnt(int temp,int left, int right) {
	if (temp == 0) {
		return (right - left) / 2 + 1;
	}
	else {
		return (right - left + 1) / 2;
	}
}

int main() {
	int n, k;
	string s;
	cin >> n >> k >> s;
	vector<vector<ll>>li;
	int cnt = 0;
	int l = 0;
	rep(i, 0, n) {
		if (i == 0) {
			continue;
		}
		else {
			if (s[i] == s[i - 1])continue;
			else {
				int temp = s[i - 1] - '0';
				li.pb({ temp,l,i - 1 });
				l = i;
			}
		}
	}
	li.pb({ s[n - 1] - '0',l,n - 1 });
	

	int ans = 0;
	rep(left, 0, li.size()) {
		int temp = li[left][0];
		int l = li[left][1];
		int r;
		if (zerocnt(temp, left, li.size() - 1) <= k) {
			r = li[li.size() - 1][2];
		}
		else {
			int ok = left, ng = li.size() - 1;
			while (ng - ok > 1) {
				int mid = (ng + ok) / 2;
				if (zerocnt(temp, left, mid) <= k)ok = mid;
				else ng = mid;
			}
			r = li[ok][2];
		}
		ans = max(ans,r-l+1);
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 6580
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<cmath>
#include<algorithm>
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define rFOR(i, a, b) for(int i=b-1; i>=a; i--)
#define MAX 10000
typedef long long ll;
using namespace std;

int sumDigit(int n){
  int sum=0;
  while(n!=0){
    sum += (n%10);
    n/=10;
  }
  return sum;
}

int main(void){
  int n, a, b;  cin >> n >> a >> b;
  int sum=0;
  FOR(i, 1, n+1){
    int t = sumDigit(i);
    if(a<=t&&t<=b)  sum+=i;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

vector<int> G[2505];
vector<int> rG[2505];
bool reachable_0[2505];
bool reachable_N[2505];
bool reachable[2505];

void dfs_0(int v = 0){
  if(reachable_0[v]) return;
  reachable_0[v] = true;
  for(auto& nv: G[v]) dfs_0(nv);
  return;
}
void dfs_N(int v){
  if(reachable_N[v]) return;
  reachable_N[v] = true;
  for(auto& nv: rG[v]) dfs_N(nv);
  return;
}

struct edge{
  int src, dst;
  long long cost;
};

int main(){
  using namespace std;
  int n, m;
  long long p;
  cin>>n>>m>>p;
  int a[m], b[m];
  long long c[m];
  REP(i, m){
    cin>>a[i]>>b[i]>>c[i];
    a[i]--; b[i]--;
  }
  
  REP(i, m){
    G[a[i]].push_back(b[i]);
    rG[b[i]].push_back(a[i]);
  }
  dfs_0(); dfs_N(n - 1);
  REP(i, n) reachable[i] = reachable_0[i] && reachable_N[i];
  
  vector<edge> edges;
  REP(i, m){
    if(!reachable[a[i]] || !reachable[b[i]]) continue;
    edges.push_back({a[i], b[i], -(c[i] - p)});
  }
  
  vector<long long> dist(n, INF);
  dist[0] = 0;
  REP(_, n - 1){
    for(auto& e: edges){
      int src = e.src, dst = e.dst;
      if(dist[dst] > dist[src] + e.cost) dist[dst] = dist[src] + e.cost;
    }
  }
  for(auto& e: edges){
    int src = e.src, dst = e.dst;
    if(dist[dst] > dist[src] + e.cost){
      cout << -1 << endl;
      return 0;
    }
  }
  
  long long ans = max(0LL, -dist[n - 1]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4200
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;


int main() {
	LL n,k;
	cin>>n>>k;
	LL res = 0;
	for(int i=k; i<=n+1; i++) {
		res+=(i*(n+1-i))%mod+1;
//		if(res>mod) res-=mod;
//		res++;
	}
//	if(res>mod) res-=mod;
	cout<<res%mod<<endl;
	return 0;
}

Measured memory_bytes: 3632
const main = (arg) => {
  const lines = arg.trim().split('\n');
  const [x1, y1, x2, y2] = lines[0].split(' ').map((v) => Number.parseInt(v));
  const x = x2 - x1,
    y = y2 - y1;
  const x3 = x2 - y,
    y3 = y2 + x,
    x4 = x1 - y,
    y4 = y1 + x;
  console.log(`${x3} ${y3} ${x4} ${y4}`);
};
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29764
#include<stdio.h>
#include<math.h>
#define MAX 10001

int GetPrime(int n){
 int i;

  for(i=2;i<=sqrt(n);i++)
   if(n % i ==0)return 0;

return n;
}


void FillPrime(int P[],int n){
 int i,j;

 for(i=1;i<=n;i++){
  if(P[i]==0){
    for(j=P[i-1]+1;j>=0;j++){
      if(GetPrime(j)!=0){
        P[i]=GetPrime(j);
        break;
      }
     }
   }
  }


return;
}

int main(){
 int n,i;
 int P[MAX]={0};
 int sum;

 P[1]=2;

 while(1){
  sum=0;
  scanf("%d",&n);
  if(n==0)break;

  FillPrime(P,n);

  for(i=1;i<=n;i++)sum+=P[i];

  printf("%d\n",sum);

 }

return 0;
}


Measured memory_bytes: 2032
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int main() {
    vector<int> prize(300, 0);
    prize[1] = 300000; prize[2] = 200000; prize[3] = 100000;
    int X, Y;
    cin >> X >> Y;
    int sum = prize[X] + prize[Y];
    if (X == 1 && Y == 1) sum += 400000;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
typedef long long LL;
LL N,k,i,j,T;
queue<LL>X;
queue<LL>Y[123456];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N;
    for(k=1;k<=N*2;k++)
        if(k*(k+1)==2*N)
            break;
    if(k>N*2)
        return cout<<"No"<<endl,0;
    cout<<"Yes"<<endl;
    cout<<k+1<<endl;
    for(i=1;i<=N;i++)
        X.push(i);
    for(i=0;i<=k;i++)
    {
        cout<<2*N/(k+1);
        for(j=0;j<k-i;j++)
        {
            T=X.front();
            X.pop();
            cout<<' '<<T;
            Y[i].push(T);
        }
        for(j=0;j<i;j++)
        {
            T=Y[j].front();
            Y[j].pop();
            cout<<' '<<T;
        }
        cout<<endl;
    }
    return 0;
}


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

using namespace std;

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

	vector<int> l(n), r(n);
	for (int i = 1; i < n; i++) {
		l[i] = l[i - 1] ^ a[i - 1];
	}
	for (int i = n - 2; i >= 0; i--) {
		r[i] = r[i + 1] ^ a[i + 1];
	}
	
	for (int i = 0; i < n; i++) {
		cout << (r[i] ^ l[i]) << (i == n - 1 ? "\n" : " ");
	}

	return 0;
}

Measured memory_bytes: 5584
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

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

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

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	string s; cin >> s;
	int res = 0;
	rep(i, 6)res += (s[i] == '1');
	cout << res << endl;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;

    ll r = 0, g = 0, b = 0;
    rep(i, n) {
        if (s[i] == 'R')
            r++;
        else if (s[i] == 'G')
            g++;
        else
            b++;
    }

    ll total = r * g * b;

    ll cnt = 0;
    rep(i, n) {
        for (int j = i + 1; j < n; j++) {
            if (s[i] == s[j]) continue;
            int k = 2 * j - i;
            if (k >= n) continue;
            if (s[j] == s[k] || s[k] == s[i]) continue;
            cnt++;
        }
    }

    cout << total - cnt << endl;

    return 0;
}

Measured memory_bytes: 3620
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define BigInt      __int128
#define endl        '\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define sim         template < class c
#define ris         return * this
#define dor         > debug & operator <<
#define eni(x)      sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

using namespace std;

sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug 
{
	~debug() 
	{ 
		cerr<<endl; 
	}
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) 
	{
		ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) 
	{
	  	*this << "[";
	  	for (auto it = d.b; it != d.e; ++it)
	    	*this << ", " + 2 * (it == d.b) << *it;
	  	ris << "]";
	}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		string s,t;
		cin>>s>>t;
		t.pop_back();
		if(s==t)
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3652
#include <cstdio>

int count_combinations_of_sums(int n, int num_rests) {
  if (num_rests * 9 < n) { return 0; }
  if (num_rests == 1) { return 1; }
  int count = 0;
  for (int i = 0; i <= 9 && i <= n; ++i) {
    count += count_combinations_of_sums(n - i, num_rests - 1);
  }
  return count;
}

int main() {
  int n;
  while (true) {
    if (scanf("%d", &n) != 1) { break; }
    printf("%d\n", count_combinations_of_sums(n, 4));
  }
  return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env ruby
N,K = gets.split.map(&:to_i)
ary = Array.new(N,0)
(0...K).each do
  d = gets.chomp.to_i
  a = gets.split.map(&:to_i)
  a.each do |i|
    ary[i-1] += 1
  end
end
z = 0
ary.each do |i|
  z += 1 if i == 0
end
puts z


Measured memory_bytes: 14328
/*
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. 
So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover."
- Unknown
*/
 
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <algorithm>
#include <math.h>
#include <map>
#include <cstdlib>
 
#define INF 1e9
 
using namespace std;
 
 
int main(){
 
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t, x, inp;
    vector<int> count(100, 0);

    cin >> x >> t;

    for(int i=0; i<t; i++){
        cin >> inp;
        count[inp-1] = 1;
    }

    int n1 = 0, n2 = 0;

    while(x-n1-1>=0 && count[x-n1-1])n1++;
    while(x+n2-1<100 && count[x+n2-1])n2++;

    if(n1 > n2)cout << x+n2 << "\n";
    else cout << x-n1 << "\n";

    return 0;
}

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

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

money=1000
best = money
pos = 1
kabu = 0

#初動 買うか買わないか
if A[0]<=A[1]:
    kabu = money//A[0]
    money -= kabu*A[0]
    pos=0
else:
    pos=1

#二回目以降　買うか売るか保留か
for i in range(1,N):
    if pos==0:#売り
        if A[i-1]>=A[i]:
            money+=kabu*A[i-1]
            kabu=0
            pos=1
    elif pos==1:#買い
        if A[i-1]<A[i]:
            kabu = money//A[i-1]
            money -= kabu*A[i-1]
            pos=0
            
    best = max(best,money+kabu*A[i])
            
print(best)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int dp[105][105][105];
int mod=1e9+7;
int main(){ 
    int n;
    scanf("%d",&n);
    int a[105];
    for(int i = 1;i<=2*n-1;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+2*n);
    dp[0][1][1]=1;
    LL ans=0;
    for(int i = 0;i<n-1;i++){
        int l=0,r=0;
        if(a[n-i]!=a[n-i-1])l++;
        if(a[n+i]!=a[n+i+1])r++;
      //  printf("%d %d %d %d %d %d\n",l,r,a[n-i],a[n-i-1],a[n+i],a[n+i+1]);
        for(int j=1;j<=2*n-1;j++){
            for(int k=1;k<=j;k++){
                for(int x=1;x<=j+l+r;x++){
                    dp[i+1][j+l+r-max(abs(x-k-l)-1,0)][min(x,k+l+1)]+=dp[i][j][k];
                    dp[i+1][j+l+r-max(abs(x-k-l)-1,0)][min(x,k+l+1)]%=mod;
                }
            }
        }
    }
    for(int j =1;j<=2*n-1;j++) 
        for(int k=1;k<=j;k++)
        {
            ans=(ans+dp[n-1][j][k])%mod;
        }
    printf("%lld\n",ans);
}
/*
1 2 2 3 3 3 4
2 2 1
3 2 3
4 2 4 4 7
 
*/

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
const ll mod=1e9+7;
vector<int>g[N];
int n,x,y;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll p[N],s[N],f[N];

void dfs(int u){
    s[u]=1;
    f[u]=1;
    for(auto v:g[u]){
        if(!s[v]){
            dfs(v);
            s[u]+=s[v];
            p[v]=u;
            f[u]=f[u]*f[v]%mod;
        }
    }
    f[u]=f[u]*s[u]%mod;
}

void calculate(int u){
    for(auto v:g[u]){
        if(v!=p[u]){
            f[v]=f[u]*(n-s[v])%mod*power(s[v],mod-2)%mod;
            calculate(v);
        }
    }
}

int main()
{
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    ll S=1;
    for(int i=1;i<=n;i++) S=S*i%mod;
    dfs(1);
    calculate(1);
    for(int i=1;i<=n;i++)
        cout<<S*power(f[i],mod-2)%mod<<endl;
    return 0;
}


Measured memory_bytes: 18548
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int ans;
	if ((a + b) < (c * 2))ans=a*x + b * y;
	else if (x <= y) {
		ans = min((c*x*2 + b * (y - x)),(c*y*2));
	}
	else {
		ans = min((c*y*2 + a * (x - y)), (c*x*2));
	}
	print(ans);
}

Measured memory_bytes: 3632
#include<stdio.h>
int map[21][21],m[5]={0,1,0,-1,0},mh,mw,mt;

void s(int h,int w,int t)
{
	int i,j,x=w,y=h;
	if(t<11)
		for(i=j=0;i<4;x=w,y=h,j=0,i++)
			while(++j)
			{
				y+=m[i];
				x+=m[i+1];
				if((0>y||y>=mh||0>x||x>=mw)||(j==1&&map[y][x]==1))
					break;
				if(map[y][x]==3)
				{
					mt=t+1<mt?t+1:mt;
					return;
				}
				if(map[y][x]==1)
				{
					map[y][x]--;
					s(y-m[i],x-m[i+1],t+1);
					map[y][x]++;
					break;
				}
			}
}

int main()
{
	int i,j,sh,sw;
	for(;;)
	{
		scanf("%d%d",&mw,&mh);
		if(mw==0&&mh==0)
			break;
		for(i=0;i<mh;i++)
			for(j=0;j<mw;j++)
			{
				scanf("%d",&map[i][j]);
				if(map[i][j]==2)
					sh=i,sw=j;
			}
		mt=11;
		s(sh,sw,0);
		printf("%d\n",mt>10?-1:mt);
	}
	return 0;
}

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

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

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

#define int long long

const int MAXN = 4e5;
const int MOD = 998244353;

int fac[MAXN + 100];
int inv[MAXN + 100];

int pow(int base, int k, int mod) {
    int ret = 1;
    while (k) {
        if (k & 1) ret = (ret * base) % mod;
        base = (base * base) % mod, k >>= 1;
    }
    return ret;
}

void init() {
    fac[0] = fac[1] = inv[0] = 1;
    for (int i = 2; i <= MAXN; i++) fac[i] = (fac[i - 1] * i) % MOD;
    for (int i = 1; i <= MAXN; i++) inv[i] = pow(fac[i], MOD - 2, MOD);
    // for (int i = 1; i <= 10; i++)
    //     printf("inv(%lld!) is %lld, fac(%lld) is %lld\n", i, inv[i], i, fac[i]);
}

int C(int n, int m, int mod) {
    if (m < n) return 0;
    // printf("C(%lld, %lld) is %lld\n", n, m,
    //        (inv[n] * ((inv[m - n] * fac[m]) % mod)) % mod);
    return (inv[n] * ((inv[m - n] * fac[m]) % mod)) % mod;
}

signed main() {
    init();
    int n, a, b, k;
    scanf("%lld%lld%lld%lld", &n, &a, &b, &k);

    int ans = 0;

    int cnt_b;
    for (int cnt_a = 0; cnt_a <= n; cnt_a++) {
        cnt_b = (k - cnt_a * a) / b;
        if (cnt_b * b + cnt_a * a == k && cnt_b <= n && cnt_b >= 0)
            ans = (ans + C(cnt_a, n, MOD) * C(cnt_b, n, MOD)) % MOD;
    }

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

Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
int N;
main()
{
	cin>>N;
	vector<pair<pair<int,int>,int> >A(N);
	for(int i=0;i<N;i++)
	{
		cin>>A[i].first.first>>A[i].first.second;
		A[i].second=i;
	}
	sort(A.begin(),A.end());
	deque<pair<int,int> >P;
	UF uf(N);
	for(int i=0;i<N;i++)
	{
		int y=A[i].first.second;
		int id=A[i].second;
		int my=y;
		while(!P.empty()&&P.front().first<y)
		{
			uf.unite(id,P.front().second);
			my=min(my,P.front().first);
			P.pop_front();
		}
		P.push_front(make_pair(my,id));
	}
	deque<pair<int,int> >Q;
	for(int i=N;i--;)
	{
		int y=A[i].first.second;
		int id=A[i].second;
		int My=y;
		while(!Q.empty()&&Q.back().first>y)
		{
			uf.unite(id,Q.back().second);
			My=max(My,Q.back().first);
			Q.pop_back();
		}
		Q.push_back(make_pair(My,id));
	}
	for(int i=0;i<N;i++)cout<<uf.size(i)<<endl;
}


Measured memory_bytes: 7220
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define For(i,u) for(int i=hed[u],v=e[i].to;i;i=e[i].nex,v=e[i].to)
using namespace std;
const int inf=1e9,maxn=5e5+10;
int n,k,x,a[maxn],c[maxn<<2],hed[maxn],id[maxn],d[maxn],cnt,ed;
struct edge{
    int to,nex;
    edge(int _=0,int __=0):to(_),nex(__){}
}e[maxn<<1];
void build(int l,int r,int cur){
    if(l==r){c[cur]=inf;return;}
    int mid=(l+r)>>1;
    build(l,mid,cur<<1);build(mid+1,r,cur<<1|1);
    c[cur]=min(c[cur<<1],c[cur<<1|1]);
}
void upd(int l,int r,int cur,int x,int y){
    if(l==r){c[cur]=y;return;}
    int mid=(l+r)>>1;
    if(x>mid) upd(mid+1,r,cur<<1|1,x,y);
    else upd(l,mid,cur<<1,x,y);
    c[cur]=min(c[cur<<1],c[cur<<1|1]);
}
int que(int l,int r,int cur,int ql,int qr){
    if(ql>r||qr<l) return inf;
    if(ql<=l&&r<=qr) return c[cur];
    int mid=(l+r)>>1;
    return min(que(l,mid,cur<<1,ql,qr),que(mid+1,r,cur<<1|1,ql,qr));
}
inline void add_edge(int u,int v){++d[v];e[++ed]=edge(v,hed[u]);hed[u]=ed;}
void topsort(){
    priority_queue<int,vector<int>,greater<int> > q;
    rep(i,1,n) if(!d[i]) q.push(i);
    while(!q.empty()){
        int u=q.top();q.pop();id[u]=++cnt;
        For(i,u){
            --d[v];
            if(!d[v]) q.push(v);
        }
    }
}
int main(){
    scanf("%d%d",&n,&k);
    rep(i,1,n) scanf("%d",&x),a[x]=i;
    build(1,n,1);
    per(i,n,1){
        int x=que(1,n,1,max(1,a[i]-k+1),a[i]-1),y=que(1,n,1,a[i]+1,min(a[i]+k-1,n));
        if(x!=inf) add_edge(a[i],a[x]);
        if(y!=inf) add_edge(a[i],a[y]);
        upd(1,n,1,a[i],i);
    }
    topsort();
    rep(i,1,n) printf("%d\n",id[i]);
    return 0;
}

Measured memory_bytes: 25192
#include <iostream>
using namespace std;
int main() {
    string s; cin >> s;
    int n = s.size() / 2;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] != s[s.size() - i - 1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string S; cin >> S;
	for (int i = 1; i < 3; i++) {
		if (S.at(i - 1) == S.at(i) && S.at(i) == S.at(i + 1)) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;


int main() {
  int n; cin>>n;
  cout << ((1000 - n % 1000) % 1000) << endl;

}

Measured memory_bytes: 3600
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int N;
int* table;

void init(int first_N){
	while(N < first_N)N *= 2;
}

void add(int loc,int value){
	loc += N-1;

	table[loc] += value;

	if(N == 1)return;

	int parent = (loc-1)/2;

	while(true){
		table[parent] =  table[2*parent+1]+table[2*parent+2];

		if(parent == 0)break;
		else{
			parent = (parent-1)/2;
		}
	}
}


int getSUM(int search_left,int search_right,int node_id,int node_left,int node_right){

	if(search_right < node_left || search_left > node_right)return 0;

	if(search_left <= node_left && search_right >= node_right){
		return table[node_id];
	}

	int left_sum = getSUM(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
	int right_sum = getSUM(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);

	return left_sum+right_sum;
}


int main(){

	int first_N,Q,command,left,right;
	table = new int[263000];
	N = 1;

	scanf("%d %d",&first_N,&Q);

	init(first_N);

	for(int i = 0; i <= 2*N-2; i++)table[i] = 0;

	for(int i = 0; i < Q; i++){
		scanf("%d %d %d",&command,&left,&right);

		if(command == 0){
			left--;
			add(left,right);
		}else{
			left--;
			right--;
			printf("%d\n",getSUM(left,right,0,0,N-1));
		}
	}

	return 0;
}

Measured memory_bytes: 3704
//https://atcoder.jp/contests/dp/tasks/dp_c

#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  


using namespace std;

typedef long long int ll;

const int precision = 16;
const int modulo =  1000000007; // 10^9 + 7
using ll = long long;
const double EPS = 1e-9;

int maxOfTree(ll a, ll b, ll c) {
	ll ret = max(a, b);
	return max(ret, c);
}

// int recVacV1(int ind, int excludeAct, const vector<vector<int>> & act) 
// {
// 	if(ind >= (int) act.size()) return 0;

// 	int ret = INT_MIN;
// 	int retEx = -1;
// 	for(auto i : {0, 1, 2}) {
// 		if(i == excludeAct) continue;
// 		if (act[ind][i] > ret) {
// 			retEx = i;
// 			ret = act[ind][i];
// 		}
// 	}

// 	ret += recVac(ind + 1, retEx, act);
// 	return ret;
// }


ll recVacV2(int ind, int excludeAct, const vector<vector<int>> & act, map<pair<int, int>, ll> & memo) 
{
	if(ind >= (int) act.size()) return 0;
	if(memo.count({ind, excludeAct})) return memo[{ind, excludeAct}];
	ll ret = INT_MIN;

	for(auto i : {0, 1, 2}) {
		if(i == excludeAct) continue;
		ret = max(recVacV2(ind + 1, i, act, memo), ret);
	}

	ret +=  act[ind][excludeAct];
	memo[{ind, excludeAct}] = ret;
	return ret;
}


void solveVacation() {
	int n; cin >> n;

	vector<vector<int>> act(n, vector<int>(3, 0));

	for(auto i = 0; i < n; ++i) {
		cin >> act[i][0] >> act[i][1] >> act[i][2];
	}

	map<pair<int, int>, ll> memo;

	// int maxVal = maxOfTree(recVacV1(0, 0, act, memo), 
	// 			recVacV1(0, 1, act, memo), recVacV1(0, 2, act, memo));
	ll maxVal = maxOfTree(recVacV2(0, 0, act, memo), 
				recVacV2(0, 1, act, memo), recVacV2(0, 2, act, memo));
	cout <<  maxVal <<endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(precision);
	cout.setf(ios_base::fixed);

	solveVacation();
	return 0;
}


Measured memory_bytes: 38528
#include <iostream>

int main() {
    std::ios::sync_with_stdio(false);

    int n, height;
    long sum_base_height;

    std::cin >> n;
    std::cin.ignore();

    sum_base_height = 0;

    for (int i = 0; i < n; i++) {
        int j;
        std::cin >> j;
        if (i == 0) {
            height = j;
        }
        else {
            int diff = height - j;
            if (diff > 0) {
                sum_base_height += diff;
            }
            else if (diff < 0) {
                height = j;
            }
        }
    }

    std::cout << sum_base_height << std::endl;

    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N, Count, min;
    bool flg;
    

    cin >> N;
    int* P =  new int[N];

    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }



    
    Count = 1;
    min = P[0];
    for (int i = 1;i< N; i++) {
        
       
       
      if (P[i] <= min) {
          Count++;
          min = P[i];
           
            }
    }
    cout << Count;
    
    
    return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		int n = scan.nextInt();
		while(n != -1){
			String mozi = "";
			while(n/4 != 0){
				mozi = String.valueOf(n%4)+mozi;
				n = n/4;
			}
			mozi = String.valueOf(n)+mozi;
			System.out.println(mozi);
			n = scan.nextInt();
		}
	}
}

Measured memory_bytes: 31116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> c(m);
	for (int i = 0; i < m; i++) cin >> c[i];

	vector<vector<int>> dp(m, vector<int>(n + 1, INT_MAX));
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		if (0 <= i - c[0] && dp[0][i - 1] != INT_MAX) dp[0][i] = dp[0][i - c[0]] + 1;
	}

	for (int i = 1; i < m; i++) {
		for (int j = 0; j <= n; j++) {
			dp[i][j] = dp[i - 1][j];
			if (0 <= j - c[i] && dp[i][j - c[i]] != INT_MAX) dp[i][j] = min(dp[i][j], dp[i][j - c[i]] + 1);
		}
	}

	cout << dp[m - 1][n] << endl;
}


Measured memory_bytes: 7024
a,b = map(int, input().split())
if a == 1:
  if b==1:
    print("Draw")
  else:
    print("Alice")
elif b == 1:
  print("Bob")
elif a <= b:
  if a == b:
    print("Draw")
  else:
    print("Bob")
else:
  print("Alice")
  

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

int n;
int a[101];

int dfs(int v = 0, bool f = false) {
  if (v == n) return f;
  int ret = 0;
  for (int i = -1; i < 2; ++i) {
    ret += dfs(v + 1, f || !((a[v] + i) & 1));
  }
  return ret;
}

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

  cout << dfs() << endl;
}


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

using namespace std;

typedef long long ll;

const int N = 1 << 17;
ll seg[2 * N];
ll A, B, P;

void init(){ memset(seg, 0, sizeof(seg)); }
void update(int x, ll v){
  x += N - 1;
  seg[x] = v % P;
  while (x > 0){
    x = (x - 1) >> 1;
    seg[x] = seg[x + x + 1] + seg[x + x + 2];
    seg[x] %= P;
  }
}
inline ll sum(int a, int b, int x=0, int l=0, int r=N){
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b) return seg[x];
  ll lr = sum(a, b, x + x + 1, l, (l + r) >> 1);
  ll rr = sum(a, b, x + x + 2, (l + r) >> 1, r);
  return (lr + rr) % P;
}

inline ll rten(ll x){
  ll r = 1;
  while (r * 10 <= x) r *= 10;
  return r;
}

int main()
{
  while (cin >> A >> B >> P, A){
    init();
    update(0, 1);
    for (ll x = A + 1; x <= B; x++){
      ll s = sum(max(rten(x) - A, 0ll), x - A) + 1;
      for (ll y = x / 10; y >= A; y /= 10){
        s += sum(max(rten(y) - A, 0ll), y - A + 1);
        s %= P;
      }
      update(x - A, s);
    }
    cout << sum(0, N) << endl;
  }

  return 0;
}

Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==22) cout<<"Christmas Eve Eve Eve"<<endl;
		if(n==23) cout<<"Christmas Eve Eve"<<endl;
		if(n==24) cout<<"Christmas Eve"<<endl;
		if(n==25) cout<<"Christmas"<<endl;
	}
}

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

int main()
{
    int n, count = 0, max = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++) {
        
        if(s[i] == 'I') count++;
        else if (s[i] == 'D') count--;
        if (max < count) max = count;
    }
    cout << max << endl;;

    return 0;
}


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

int main(){
  ll a,b;
  cin>>a>>b;
  ll y=1;
  for(ll x=min(a,b); x>0; x--){
    if( a%x==0 && b%x==0 ){
      y*=x;
      a/=x;
      b/=x;
    }
  }
  ll ans=a*b*y;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
l=[]
for i in range(3):
  a=list(map(int, input().split()))
  for j in a:
    l.append(j)


n=int(input())
l2=[]
for i in range(n):
  l2.append(int(input()))

  
for i in range(len(l)):
  if l[i] in l2:
    l[i]=0
#print(l)

y1=l[0]+l[1]+l[2]
y2=l[3]+l[4]+l[5]
y3=l[6]+l[7]+l[8]
t1=l[0]+l[3]+l[6]
t2=l[1]+l[4]+l[7]
t3=l[2]+l[5]+l[8]
n1=l[0]+l[4]+l[8]
n2=l[2]+l[4]+l[6]

if y1*y2*y3*t1*t2*t3*n1*n2==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
from collections import deque

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]


class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * (n + 1)
        self.rank = [0] * (n + 1)

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        elif self.rank[x] > self.rank[y]:
            self.parent[x] += self.parent[y]
            self.parent[y] = x
        else:
            self.parent[y] += self.parent[x]
            self.parent[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

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

    def count(self, x):
        return -self.parent[self.find(x)]


uf = UnionFind(n)

for a, b in ab:
    uf.union(a, b)

ans = 0
for i in range(1, n + 1):
    ans = max(ans, uf.count(i))

print(ans)


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

int main() {
  int N;
  cin >> N;
  vector < string > S(N);
  for (int i = 0; i < N; i++) {
    string temp;
    cin >> temp;
    sort(temp.begin(), temp.end());
    S[i] = temp;
  }

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

  long ans = 0;
  long n=1;
  string prev = "";
  for (int i=0;i<N;i++) {
    if (prev == S[i]){
      n += 1;
    }
    else {
      ans += (n * (n-1)) / 2;
      n = 1;
    }
    prev = S[i];
  }
  
  ans += (n * (n-1)) / 2;
  cout << ans << endl;
}

Measured memory_bytes: 5760
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    s = gets.chomp

    if s[0] == '9' || s[1] == '9'
      puts "Yes"
    else
      puts "No"
    end

  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2044
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vint cnt(n,0);
    REP(i,k){
        int d;
        cin >> d;
        REP(j,d){
            int a;
            cin >> a;
            a--;
            cnt[a]++;
        }
    }
    int ans = 0;
    REP(i,n){
        if(cnt[i]==0){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
#include<iostream>

using namespace std;

int main()
{
	int N,L; cin>>N>>L;int count=(2*L+N-1)*N/2;
  	if(N+L-1<0)
    {cout<<count-(L+N-1)<<endl;}
  	else
    {if(L>0)
	  cout<<count-L<<endl;
     else
       cout<<count<<endl;
    }
  	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#define MAXN 2010
#define LL long long

const LL P=924844033;

struct Poly{
	LL a[MAXN];
	int len;
}g[MAXN][2],res;

int n,k;
LL fac[MAXN];

void add(Poly &x,Poly &y){
	if(x.len>y.len) y.len=x.len;
	for(int i=0;i<=x.len;i++) y.a[i]=(y.a[i]+x.a[i])%P;
}

void add2(Poly &x,Poly &y){
	if(x.len+1>y.len) y.len=x.len+1;
	for(int i=0;i<=x.len;i++) y.a[i+1]=(y.a[i+1]+x.a[i])%P;
}

void mul(Poly &x,Poly &y){
	static LL temp[MAXN];
	for(int i=0;i<=x.len+y.len;i++) temp[i]=0;
	for(int i=0;i<=x.len;i++)
		for(int j=0;j<=y.len;j++)
			temp[i+j]=(temp[i+j]+x.a[i]*y.a[j])%P;
	y.len+=x.len;
	for(int i=0;i<=y.len;i++)
		y.a[i]=temp[i];
}

void gao(int x){
	int p1=x,p2=x+(n-x)/(2*k)*(2*k);
	bool flag1=(p1-k>=1),flag2=(p2+k<=n);
	g[p2][1].len=1;
	g[p2][1].a[1]=1;
	if(flag2){
		g[p2][0].len=1;
		g[p2][0].a[0]=g[p2][0].a[1]=1;
	}else{
		g[p2][0].len=0;
		g[p2][0].a[0]=1;
	}
	for(int i=p2-2*k;i>=p1;i-=2*k){
		int i2=i+2*k;
		add(g[i2][0],g[i][0]);
		add2(g[i2][0],g[i][0]);
		add2(g[i2][0],g[i][1]);
		add(g[i2][1],g[i][0]);
		add2(g[i2][1],g[i][1]);
	}
	if(flag1) add(g[p1][1],g[p1][0]);
}

int main(){
#ifdef DEBUG
	freopen("D.in","r",stdin);
#endif
	fac[0]=1;
	for(int i=1;i<MAXN;i++) fac[i]=fac[i-1]*i%P;
	scanf("%d%d",&n,&k);
	res.a[0]=1;
	for(int i=1;i<=2*k && i<=n;i++){
		gao(i);
		mul(g[i][0],res);
	}
	LL ans=0;
	for(int i=0;i<=n;i++){
		LL delta=(i&1)?(-1):1;
		ans=(ans+delta*res.a[i]*fac[n-i])%P;
	}
	ans=(ans+P)%P;
	printf("%lld\n",ans);
}


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

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

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            var answer = 0;
            for (var i = 1; i < s.Length - 1; i++)
            {
                var left = new Dictionary<char, int>();
                var right = new Dictionary<char, int>();
                for (var j = 0; j < i; j++)
                {
                    left[s[j]] = 0;
                }
                for (var j = i; j < s.Length; j++)
                {
                    right[s[j]] = 0;
                }
                var count = 0;
                foreach (var c in left.Keys)
                {
                    if (right.ContainsKey(c)) count++;
                }
                answer = Math.Max(answer, count);
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
int const mod = 998244353;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x , int m){
    return power(x,m-2,m);
}

int const N = 1e7+5;
int const inf = 2e16;

int f[N];

void solve(){  
    int i,j,l;
    int n,m;
    cin>>n;
    int ans = 0;

    for(i=1;i<=n;i++){
        for(j=i;j<=n;j+=i){
            f[j]++;
        }
    }

    for(i=1;i<=n;i++){
        ans = ans + i*f[i];
    }

    cout<<ans<<endl;
}           


int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


/*

1 3 4 7 8 8 


*/

Measured memory_bytes: 81776
package main

import "fmt"

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	var d, ans int
	for i := 0; i < n; i++ {
		var l int
		fmt.Scan(&l)

		d += l
		if d <= x {
			ans = i
		}
	}

	fmt.Println(ans+2)
}


Measured memory_bytes: 512
let cnt = ref 0 
let (g : int list ref) = ref []
  
let insertion_sort (a : int array) n g =
  let rec insert j v =
    if j < 0 || a.(j) <= v then a.(j+g) <- v
    else (a.(j+g) <- a.(j); incr cnt; insert (j - g) v)
  and doit i =
    if i < n then (insert (i - g) a.(i); doit (i + 1))
  in doit g 

let generate_g n =
  let rec doit i g acc =
    if g > n then acc
    else doit (i + 1) (int_of_float (4.**(float_of_int i) +. 3.*.2.**(float_of_int (i - 1)) +. 1.)) (g :: acc)
  in doit 1 1 []
  
let shell_sort (a : int array) n =
  cnt := 0;
  g := generate_g n;
  let rec doit = function
    | [] -> ()
    | hd :: tl -> (insertion_sort a n hd; doit tl)
  in doit !g

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> read_int ()) in
  shell_sort a n; 
  Printf.printf "%d\n" (List.length !g);
  List.iteri (fun i n -> if i <> 0 then print_string " "; print_int n) !g;
  print_newline ();
  Printf.printf "%d\n" !cnt;
  Array.iter (fun n -> Printf.printf "%d\n" n) a

Measured memory_bytes: 12656
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a==1&&b==1)
        printf("2");
   else if(b%a==0)
        printf("%d",a+b);
    else
        printf("%d",b-a);
    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++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

void print_arr(vector<int> &a){
    rep(i,a.size()-1){
        printf("%d ",a[i]);
    }
    printf("%d\n",a[a.size()-1]);
}

void selection_sort(vector<int> &a){
    int swaps = 0;
    for(int i=0; i<a.size(); i++){
        int min_idx = i;
        for(int j=i; j<a.size(); j++){
            if(a[j]<a[min_idx]){
                min_idx = j;
            }
        }
        if(min_idx==i) continue;
        int temp = a[i];
        a[i] = a[min_idx];
        a[min_idx] = temp;
        swaps++;
    }
    print_arr(a);
    cout << swaps << endl;
}

int main(){
    int n; cin >> n;
    vector<int> a(n); collect(a, n);
    selection_sort(a);
    return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (1<<(4*4-1))
#define MOD 1000000007

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

   int H,W;
   cin>>H>>W;
   vector<vector<int> >a(W,vector<int>(H));
   for(int y=0;y<H;y++){
      for(int x=0;x<W;x++){
         int A;
         cin>>A;
         a[x][y] = A%2;
      }
   }

   struct A{int x1,y1,x2,y2;};
   vector<A>ans;

   //for(int y=0;y<H;y++){for(int x=0;x<W;x++){cout<<a[x][y];}cout<<endl;}
   
   for(int y=0;y<H;y++){
      for(int x=0;x<W-1;x++){
         if(a[x][y]){
            a[x][y]-=1;
            a[x+1][y]=(a[x+1][y]+1)%2;
            A res = {.x1=x+1,.y1=y+1,.x2=x+2,.y2=y+1};
            ans.push_back(res);
         }
      }
   }

   //for(int y=0;y<H;y++){for(int x=0;x<W;x++){cout<<a[x][y];}cout<<endl;}

   for(int y=0;y<H-1;y++){
      if(a[W-1][y]){
         a[W-1][y]-=1;
         a[W-1][y+1]=(a[W-1][y+1]+1)%2;
         A res = {W,y+1,W,y+2};
         ans.push_back(res);
      }
   }

   //for(int y=0;y<H;y++){for(int x=0;x<W;x++){cout<<a[x][y];}cout<<endl;}

   cout<<ans.size()<<endl;
   for(auto it:ans)cout<<it.y1<<" "<<it.x1<<" "<<it.y2<<" "<<it.x2<<endl;

   return 0;
}


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

// a >= b
int ea(int a, int b)
{
	//cout << "(a,b)=" << a << "," << b << ")" << endl;
	int r = a % b;
	if (r == 0)
		return b;
	
	return ea(b, r);
}

int main()
{
	int x, y;
	cin >> x >> y;
	if (x < y)
	{
		cout << ea(y, x) << endl;;
	}
	else
	{
		cout << ea(x, y) << endl;
	}

	return 0;
}

Measured memory_bytes: 1160