akhauriyash/Code-Regression huggingface dataset:
MOD = 10 ** 9 + 7


def main():
    n, s1, s2 = int(input()), input(), input()

    com, idx = 1, 0
    while idx < n:
        if idx == 0:
            if s1[idx] == s2[idx]:
                com *= 3
                idx += 1
            else:
                com *= 6
                idx += 2

        elif s1[idx] == s2[idx]:
            if s1[idx-1] == s2[idx-1]:
                com = com * 2 % MOD
            idx += 1
        else:
            if s1[idx-1] == s2[idx-1]:
                com = com * 2 % MOD
            else:
                com = com * 3 % MOD
            idx += 2

    print(com)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;

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

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

// 第一引数 == 第二引数 ? true : false
template<class T, class U>
bool check(T first, U second) {
    return (first == second);
}

// 約数列挙
vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


// 数字和
template<class T>
T digitSum(T num) {
    T dig;
    T sum = 0;
    while (num) {
        dig = num % 10;
        sum += dig;
        num /= 10;
    }
    return sum;
}

string background_black(string s) { return "\x1b[40m" + s; }
string background_red(string s) { return "\x1b[41m" + s + "\x1b[40m"; }
string background_green(string s) { return "\x1b[42m" + s + "\x1b[40m"; }
string background_yellow(string s) { return "\x1b[43m" + s + "\x1b[40m"; }
string background_bleu(string s) { return "\x1b[44m" + s + "\x1b[40m"; }
string background_white(string s) { return "\x1b[47m" + s + "\x1b[40m"; }

string black(string s) { return "\x1b[30m" + s + "\x1b[37m"; }
string red(string s) {return "\x1b[31m" + s + "\x1b[37m"; }
string green(string s) { return "\x1b[32m" + s + "\x1b[37m"; }
string yellow(string s) { return "\x1b[33m" + s + "\x1b[37m"; }
string blue(string s) { return "\x1b[34m" + s + "\x1b[37m"; }
string white(string s) { return "\x1b[37m" + s + "\x1b[37m"; }

const int ten = 10;
const int hundred = 100;
const int thousand = 1000;

typedef long long ll;
typedef unsigned long long ull;

string tolower(string s) {
  string c;
  for (int i = 0; i < s.size(); i++) {
    if ((s[i] >= 'A') && (s[i] <= 'Z')) {
        c.push_back((s[i] + 0x20));
    } else {
        c.push_back(s[i]);
    }
  }
  return c;
}
#include <cstdlib>
string solve() {
  string str = "";
// int->string: to_string, string->int: stoi
//=============================================================================


  int a, b, c;
  cin >> a >> b >> c;
  if (b-a == c-b) {
    str += "YES";
  } else {
    str += "NO";
  }


//=============================================================================
  return str;
}

int main() {	
  std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
  cout << solve() << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	sl := [4]string{"A", "C", "G", "T"}
	maxLength := 0
	cnt := 0
	var isDetected bool
	for _, c := range s {
		isDetected = false
		for i := 0; i < 4; i++ {
			if sl[i] == string([]rune{c}) {
				isDetected = true
			}
		}
		if isDetected {
			cnt++
			if cnt > maxLength {
				maxLength = cnt
			}
		} else {
			cnt = 0
		}
	}
	fmt.Print(maxLength)
}


Measured memory_bytes: 512
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lo;
typedef pair< lo,lo > PII;
 
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
 
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,dp[305][305][305];
int cev;
string s;
vector<int> v;

inline int f(int sira,int yuk,int hak){
	int cevv=inf;
	if(hak<0)return inf;
	if(sira>n)return 0;
	if(~dp[sira][yuk][hak])return dp[sira][yuk][hak];
	cevv=min(cevv,f(sira+1,sira,hak)+max(0ll,a[sira]-a[yuk]));
	cevv=min(cevv,f(sira+1,yuk,hak-1));
	return dp[sira][yuk][hak]=cevv;
}

main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&m);
	FOR{
		scanf("%lld",&a[i]);
	}
	printf("%lld\n",f(1,0,m));
	return 0;
}



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

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

string a, b;
set<int> forth[26], backwards[26];

void run() {
    cin >> a >> b;

    if (a.length() != b.length()) {
        cout << "No\n";
        return;
    }

    int n = a.length();

    REP(i, n) {
        forth[a[i] - 'a'].insert(b[i] - 'a');
        if (forth[a[i] - 'a'].size() > 1) {
            cout << "No\n";
            return;
        }
        backwards[b[i] - 'a'].insert(a[i] - 'a');
    }

    REP(i, 26) {
        int n_exist = 0;
        for (int j: backwards[i]) {
            if (forth[j].size() != 0) {
                n_exist += 1;
            }
        }
        if (n_exist > 1) {
            if (forth[i].size() != 0) {
                cout << "No\n";
                return;
            }
        }
    }

    cout << "Yes\n";
}

static void run_with_stack_size(void (*func)(), size_t stackSize) {
    char *stack, *send;
    stack = (char*) malloc(stackSize);
    send = stack + stackSize - 16;
    send = (char*) ((uintptr_t) send / 16 * 16);
    asm volatile(
    "mov %%rsp, (%0)\n"
    "mov %0, %%rsp\n"
    :
    : "r" (send));
    func();
    asm volatile(
    "mov (%0), %%rsp\n"
    :
    : "r" (send));
    free(stack);
}

int main() {
#ifdef LOCAL
    freopen("input", "r", stdin);
#endif
    run_with_stack_size(run, 256*1024*1024);
#ifdef LOCAL
    fclose(stdin);
#endif
    return 0;
}

Measured memory_bytes: 776
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"print.hpp"
#include"debug.hpp"
#endif
// }}}

Int N;
vector<Int> s;

void solve(){
	Int ans = 0;
	for(int S = 1;S <= N - 1;S++){
//		int r = (N-1)%S;
		Int sum = 0;
		unordered_set<int> vis;
		int left = 0, right = N - 1;
		for(;;){
			right-=S;
			left+=S;
			if(right<=S or left>=N-1)break;
			if(vis.find(left)!=vis.end())break;
			vis.insert(left);
			if(vis.find(right)!=vis.end())break;
			vis.insert(right);
			if(left==right)break;
			sum += s[left];
			sum += s[right];
			ans = max(ans,sum);
		}
	}
	cout<<ans<<endl;
}

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

	cin >> N;
    s.assign(N-1-0+1,Int());
    for(int i = 0 ; i < N-1-0+1 ; i++){
        cin >> s[i];
    }
	solve();
	return 0;
}

//}}}



Measured memory_bytes: 5168
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)o.size())
#define run(x) for(int k=head[x];k;k=e[k].ne)
#define v e[k].t
#define all(a) o.begin(),o.end()
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<int,int> pa;
const int N=800+5,INF=1e9;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il void judge(){
	freopen("dato.in","r",stdin);
	freopen("dato.out","w",stdout);
}
char s[N][N];
int qx[N*N],qy[N*N],dis[N][N],n,m,k,vis[N][N];
const int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
int main(){
	read(n,m,k);int res=INF;
	rep(i,1,n)rep(j,1,m)dis[i][j]=INF,vis[i][j]=0;
	rep(i,1,n){
		scanf("%s",s[i]+1);
		rep(j,1,m)if(s[i][j]=='S')dis[qx[1]=i][qy[1]=j]=0,vis[i][j]=1;
	}
	int t=1;
	rep(h,1,t){
		int oo=min(min(qx[h]-1,n-qx[h]),min(qy[h]-1,m-qy[h]));
		gmin(res,(oo-1+k)/k);
		if(dis[qx[h]][qy[h]]<k)re(j,0,4){
			int nx=qx[h]+dx[j],ny=qy[h]+dy[j];
			if(s[nx][ny]=='.'&&!vis[nx][ny])qx[++t]=nx,qy[t]=ny,vis[nx][ny]=1,dis[nx][ny]=dis[qx[h]][qy[h]]+1;
		}
	}cout<<res+1<<endl;
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int h, w; cin >> h >> w;
	vector<string> in(h);
	rep(i, h) cin >> in[i];
	
	vector<string> s(h + w, string(h + w, '.'));
	rep(i, h) rep(j, w) if(in[i][j] == '#'){
		int y = i + j, x = i - j + w;
		s[y][x] = '#';
	}
	//rep(i, s.size()) cerr<<s[i]<<endl;
	int ans = 0;
	rep(it, 4){
		vector<vi> sum(s.size(), vi(s[0].size()));
		rep(i, s.size()){
			rep(j, s[0].size()) {
				if(s[i][j] == '#') sum[i][j] = 1;
				if(j) sum[i][j] += sum[i][j - 1];
				if(s[i][j] != '#') continue;
				
				for(int k = 1; k <= i && j + k < s[0].size(); k++) if(s[i][j + k] == '#'){
					ans += sum[i - k][j + k] - sum[i - k][j];
				}
			}
		}
		vector<string> ns(s[0].size(), string(s.size(), '.'));
		rep(i, s.size()) rep(j, s[0].size()) ns[j][s.size() - i - 1] = s[i][j];
		s = ns;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


def get_int():
    return int(input())


def get_str():
    return input().strip()


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


def get_char_list():
    return list(input().strip())


def split_goals_by_m(goals, m):
    ret = []
    tmp = []
    for g in goals:
        if g == m:
            if tmp:
                ret.append(tmp)
                tmp = []
        else:
            tmp.append(g - m)
    if tmp:
        ret.append(tmp)
    return ret


def get_ans(goals):
    m = min(goals)
    gs = split_goals_by_m(goals, m)
    if len(gs) == 0:
        return m
    ret = m
    for g in gs:
        ret += get_ans(g)
    return ret


def main():
    n = get_int()
    hs = get_int_list()

    print(get_ans(hs))


if __name__ == '__main__':
    main()


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

#define ll long long
#define pii pair<int,int>
#define two(x) (x<<1)
#define towd(x) (x>>1)
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define x first
#define y second

ll a[200001];

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

	ll n,k;
	cin>>n>>k;
	for (int i=0;i<n;i++) cin>>a[i];
	
	ll L=-2e18,R=2e18;
	sort(a,a+n);
	while (L+1!=R){
		ll m=towd(L+R);
		ll cnt=0;
		for (int i=0; i<n; i++){
			if (a[i]<0){
				ll l=i,r=n;
				while (l+1!=r){
					int mid=towd(l+r);
					if (a[mid]*a[i]<=m) r=mid;
					else l=mid;
				}
				cnt+=n-r;
			}
			else{
				ll l=i,r=n;
				while (l+1!=r){
					int mid=towd(l+r);
					if (a[mid]*a[i]<=m) l=mid;
					else r=mid;
				}
				cnt+=l-i;
			}
		}
		if (cnt<k) L=m;
		else R=m;
	}
	cout<<R<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
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> b(N);
  for (int i = 0; i < N; ++i) {
    if (a[i] % 4 == 1 || a[i] % 4 == 3) b[i] = 0;
    if (a[i] % 4 == 2) b[i] = 1;
    if (a[i] % 4 == 0) b[i] = 2;
  }
  vector<int> c(N, 0);
  for (int i = 0; i < N; ++i) ++c[b[i]];
  
  if (c[1] == 0) {
    if (c[0] - 1 <= c[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
  } else {
    if (c[0] <= c[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
n=int(input())
a=list(map(int,input().split()))
a+=a
b=list(map(int,input().split()))
aa=[a[i-1]^a[i] for i in range(1,n*2)]
bb=[b[i-1]^b[i] for i in range(1,n)]
s=bb+aa
from random import randint
roli_mod=1370757747362922367
roli_r=1#randint(2,roli_mod-2)
roli_table=[0]
roli_rr=1
for i in range(3*(n-1)):
  roli_table.append((roli_table[-1]+roli_rr*s[i])%roli_mod)
  roli_rr*=roli_r
  roli_rr%=roli_mod
def roli_hash(i,j):return ((roli_table[j+1]-roli_table[i]+roli_mod)%roli_mod)*pow(roli_r,roli_mod-1-i,roli_mod)%roli_mod
def roli_check(i1,j1,i2,j2):return roli_hash(i1,j1)==roli_hash(i2,j2)
ans=[]
for k in range(n-1,2*(n-1)+1):
  if roli_check(0,n-2,k,k+(n-1)-1):
    ans.append(k-(n-1))
for i in ans:
  print(i,a[i]^b[0])

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

struct Seg{
  vector<ll> mx, sum;
  Seg(){
    mx.resize(1<<19);
    sum.resize(1<<19);
  }

  void add(ll l, ll r, ll score, ll pos=0, ll bottom=0, ll top=1<<18){
    if(top <= l || r <= bottom)return;
    if(l <= bottom && top <= r){sum[pos]+=score; return;}

    ll mid = (bottom+top)/2;
    add(l, r, score, pos*2+1, bottom, mid);
    add(l, r, score, pos*2+2, mid, top);
    mx[pos] = max<ll>(mx[pos*2+1]+sum[pos*2+1], mx[pos*2+2]+sum[pos*2+2]);
  }

  ll mxv(ll l, ll r, ll pos=0, ll bottom=0, ll top=1<<18){
    if(top <= l || r <= bottom)return -INF;
    if(l <= bottom && top <= r)return mx[pos]+sum[pos];

    ll mid = (bottom+top)/2;
    return max<ll>(
      mxv(l, r, pos*2+1, bottom, mid),
      mxv(l, r, pos*2+2, mid, top)
    )+sum[pos];
  }
};

int main(){
  ll n,m;cin>>n>>m;
  vector<vector<pll>>is(1<<20);
  rep(i, m){
    ll l,r,a;cin>>l>>r>>a;
    is[r].push_back({l, a});
  }

  Seg seg;

  rep1(r, n){
    ll mx = seg.mxv(0, r);
    seg.add(r, r+1, mx);
    for(auto p: is[r]){
      ll l=p.first;
      ll a = p.second;
      seg.add(l, r+1, a);
    }
  }

  cout<<seg.mxv(0, n+1)<<endl;

  return 0;
}

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

int checkYearMonth(string x_s) {
    int num = stoi(x_s);

    if (1 <= num % 100 && num % 100 <= 12
        && 1 <= num / 100 && num / 100 <= 12) {
        return 0;
    } else if (1 <= num % 100 && num % 100 <= 12) {
        return 1;
    } else if (1 <= num / 100 && num / 100 <= 12) {
        return 2;
    } else {
        return 3;
    }
}

int main(void) {
    string s, ans = "";

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    switch (checkYearMonth(s)) {
    case 0:
        ans = "AMBIGUOUS";
        break;
    case 1:
        ans = "YYMM";
        break;
    case 2:
        ans = "MMYY";
        break;
    default:
        ans = "NA";
        break;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> X, N;
  invec<ll> p(N);
  bst::sort(p);
  
  REP(i, 200) {
    if (!bst::binary_search(p, X - i))
      return X - i;
    else if (!bst::binary_search(p, X + i))
      return X + i;

  }


  return 0LL;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 3600
// AOJ 1370 Hidden Anagrams
// 2018.2.8 bal4u

#include <stdio.h>
#include <string.h>

#define HASHSIZ		10007
typedef struct { int s; short f[26]; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash+HASHSIZ;			// Hash table

void insert(int s, short *f)
{
	int i;
	unsigned long long k;
	HASH *tp;

	k = 0; for (i = 0; i < 26; i+=2) k = (k << 4) + f[i];
	tp = hash + (int)(((k << 12) + s) % HASHSIZ);
	while (tp->s) {
		if (tp->s == s && !memcmp(tp->f, f, 52)) return;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, memcpy(tp->f, f, 52);
}

int lookup(int s, short *f)
{
	int i;
	unsigned long long k;
	HASH *tp;

	k = 0; for (i = 0; i < 26; i+=2) k = (k << 4) + f[i];
	tp = hash + (int)(((k << 12) + s) % HASHSIZ);
	while (tp->s) {
		if (tp->s == s && !memcmp(tp->f, f, 52)) return 1;
		if (++tp == hashend) tp = hash;
	}
	return 0;
}

#define MAGIC 101
char sa[4004]; int wa;
char sb[4004]; int wb;
short f[26];

int main()
{
	int i, k, w, s;
	char *p, *q;

	fgets(p=sa, 4004, stdin); while (*p > ' ') *p -= 'a', p++; wa = p - sa;
	fgets(p=sb, 4004, stdin); while (*p > ' ') *p -= 'a', p++; wb = p - sb;
	w = MAGIC; if (w > wa) w = wa; if (w > wb) w = wb;

	for (k = w; k > 0; k--) {
		memset(hash, 0, sizeof(hash));

		memset(f, 0, sizeof(f));
		s = 1, p = sa; for (i = 0; i < k; i++) s += *p, f[*p++]++;
		insert(s, f);

		i = wa - k, q = sa; while (i--) {
			s -= *q, f[*q++]--;
			s += *p, f[*p++]++;
			insert(s, f);
		}

		memset(f, 0, sizeof(f));
		s = 1, p = sb; for (i = 0; i < k; i++) s += *p, f[*p++]++;
		if (lookup(s, f)) goto done;

		i = wb - k, q = sb; while (i--) {
			s -= *q, f[*q++]--;
			s += *p, f[*p++]++;
			if (lookup(s, f)) goto done;
		}
    }
done:
	printf("%d\n", k);
	return 0;
}


Measured memory_bytes: 2408
import fractions

N = int(input())
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i in range(0, N - 1):
    L[i + 1] = fractions.gcd(L[i], A[i])
for i in range(N - 1, 0, -1):
    R[i - 1] = fractions.gcd(R[i], A[i])
ans = 1
for i in range(N):
    ans = max(ans, fractions.gcd(L[i], R[i]))
print(ans)


Measured memory_bytes: 16148
import sys
input = sys.stdin.readline
from collections import defaultdict, deque

n, s, res, MOD = int(input()), list(map(int, input().split())), 0, int(1e9) + 7
for i in range(61):
    x, c = int(pow(2, i, MOD)), [0, 0]
    for j in range(n): c[1 if s[j] & 1 << i else 0] += 1
    x = (x * c[0]) % MOD; x = (x * c[1]) % MOD; res = (res + x) % MOD
print(res)

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

int main() {
  int N; cin >> N;
  vector<int> x(N), y(N), h(N);
  int px, py, ph;
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i) >> h.at(i);
    if (h.at(i) != 0) {
      px = x.at(i); py = y.at(i); ph = h.at(i);
    }
  }
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      int H = ph + abs(px - i) + abs(py - j);
      bool found = true;
      for (int k = 0; k < N; k++) {
        if (max(H - abs(i - x.at(k)) - abs(j - y.at(k)), 0) != h.at(k)) {
          found = false;
        }
      }
      if (found) {
        cout << i << " " << j << " " << H << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
   ll a, b , c , d; cin >> a >> b >> c >> d;

   ll mn_x = min(a, b);
   ll mx_x = max(a, b);

   ll mn_y = min(c, d);
   ll mx_y = max(c, d);

   ll aa = mn_x * mn_y;
   ll bb = mn_x * mx_y;
   ll cc = mx_x * mn_y;
   ll dd = mx_x * mx_y;

   cout << max(aa, max(bb, max(cc, dd))) << endl;
   return 0;


}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int [] a;
		a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		for(int i=0;i<n-1;i++) {
			System.out.printf("%d ",a[n-1-i]);
		}
		System.out.printf("%d\n",a[0]);
	}
}



Measured memory_bytes: 26276
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	Int m = 0;
	Int a = 0;
	Int r = 0;
	Int c = 0;
	Int h = 0;
	string temp;
	for (Int i = 0; i < N; i++) {
		cin >> temp;
		if (temp[0] == 'M') {
			m++;
			continue;
		}
		if (temp[0] == 'A') {
			a++;
			continue;
		}
		if (temp[0] == 'R') {
			r++;
			continue;
		}
		if (temp[0] == 'C') {
			c++;
			continue;
		}
		if (temp[0] == 'H') {
			h++;
			continue;
		}
	}

	Int ans = 0;
	ans += m * (a * (r + c + h) + r * (c + h) + c * h) + a * (r * (c + h) + c * h) + r * c * h;

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
LL a,b,c,k;
int main(){
	LL ans=0;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	if( a <= k ){
		ans=ans+a;
		k=k-a;
	}
	else{
		ans=k;
		k=0;
	}
	if( b <= k && k )
		k=k-b;
	else 
		k=0;
	if( c <= k ){
		ans-=c;
		k=k-c;
	}
	else if( k )
		ans-=k;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3228
#include "bits/stdc++.h"
// #include <cmath>
// #include <algorithm>
// #include <iostream>
// #include <map>
// #include <numeric>
// #include <string>
// #include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;

template <typename iterator> size_t maxElem(iterator beginIt, iterator endIt) {
  return std::max_element(beginIt, endIt);
}

template <typename iterator> size_t maxIndex(iterator beginIt, iterator endIt) {
  return std::distance(beginIt, *std::max_element(beginIt, endIt));
}

template <typename iterator> size_t minElem(iterator beginIt, iterator endIt) {
  return std::min_element(beginIt, endIt);
}

template <typename iterator> size_t minIndex(iterator beginIt, iterator endIt) {
  return std::distance(beginIt, *std::min_element(beginIt, endIt));
}

template <typename iterator> int sum(iterator beginIt, iterator endIt) {
  return std::accumulate(beginIt, endIt, 0);
}

std::string lower(std::string src) {
  std::string dst = src;
  std::transform(src.begin(), src.end(), dst.begin(), tolower);
  return dst;
}

std::string upper(std::string src) {
  std::string dst = src;
  std::transform(src.begin(), src.end(), dst.begin(), toupper);
  return dst;
}

int main(void) {
  // int num = 0;
  // int max = std::numeric_limits<int>::min();
  // int min = std::numeric_limits<int>::max();
  long long num = 0;
  // long long max = std::numeric_limits<long long>::min();
  // long long min = std::numeric_limits<long long>::max();
  int N;

  int A[2 * 100000];
  int B[2 * 100000];

  std::map<int, int> M{};

  cin >> N;

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    B[i] = A[i] - (i + 1);
  }

  std::sort(B, B + N);

  int b = B[N / 2];
  for (int i = 0; i < N; ++i) {
    num += abs(B[i] - b);
  }

  cout << num << endl;
  // cout << max << endl;
  // cout << min << endl;

  return 0;
}


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

typedef long long ll;

int main()
{
    int a, b;
    cin >> a >> b;

    if (a == b){
        cout << a + b << endl;
    }else{
        cout << 2 * max(a, b) - 1 <<endl; 
    }

}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long


int main()
{
	int M;
	cin >> M;
	cout << 24 + 24 - M << endl;
}


Measured memory_bytes: 3596
# include <bits/stdc++.h>
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
using namespace std;
void _cin(){}
template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
#define Cin(Type, ...) Type __VA_ARGS__; _cin(__VA_ARGS__)

static const int n_max = 44;
int fib[n_max + 1];

int main()
{
    Cin(int, n);

    fib[0] = fib[1] = 1;
    range_for (i, 2, n+1)
    {
        fib[i] = fib[i-1] + fib[i-2];
    }

    cout << fib[n] << endl;

    return 0;
}



Measured memory_bytes: 3076
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text.RegularExpressions;
using System.Threading;

namespace Atcoder
{
	class Program
	{
		//string s = Console.ReadLine();
		//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		//int H = intArray[0];
		//int W = intArray[1];
		//int N = int.Parse(Console.ReadLine());
		//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
		//Boolean ok = false;

		//Console.WriteLine(ans);
		//Console.WriteLine("Yes");
		//Console.WriteLine("No");
		//Console.ReadKey();
		//Console.WriteLine(cnt);

		//string[] strArray = Console.ReadLine().Split(' ').ToArray();
		//string S = strArray[0];
		//string T = strArray[1];
		static void Main(string[] args)
		{
			Console.WriteLine(Regex.Replace(Console.ReadLine(), ".","x"));
		}

		/// <summary>
		/// 回文
		/// </summary>
		/// <param name="Target"></param>
		/// <param name="len"></param>
		/// <returns></returns>
		static bool Palindrome(string Target , int len)
        {
			bool yes = true;

			for(int i = 0;i < len; i++)
            {
				if(Target[i] != Target[len - 1 - i])
                {
					yes = false;
					break;
                }
            }
			return yes;
        }

		/// <summary>
		/// アナグラム
		/// </summary>
		/// <param name="word1"></param>
		/// <param name="word2"></param>
		/// <returns></returns>
		static bool IsAnagramOf(string word1, string word2)
		{
			return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x));
		}
		/// <summary>
		/// 最小公倍数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Lcm(BigInteger a, BigInteger b)
		{
			return a * b / Gcd(a, b);
		}

		/// <summary>
		/// 最大公約数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Gcd(BigInteger a, BigInteger b)
		{
			if (a < b)
				// 引数を入替えて自分を呼び出す
				return Gcd(b, a);
			while (b != 0)
			{
				var remainder = a % b;
				a = b;
				b = remainder;
			}
			return a;
		}
	}
}

Measured memory_bytes: 27028
mod=10**9+7
n,*a=map(int,open(0).read().split())
d=[-1,-1,-1]
ans=1
for x in a:
	ans *= d.count(x-1)
	ans %= mod
	for i in range(3):
		if d[i] == x - 1:
			d[i] = x
			break
print(ans)

Measured memory_bytes: 13980
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());
    int C = Integer.parseInt(sc.next());
    int D[][] = new int[C][C];
    for (int i = 0; i < C; i++) {
      for (int j = 0; j < C; j++) {
        D[i][j] = Integer.parseInt(sc.next());
      }
    }
    int mod[][] = new int[3][C];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        mod[(i + j) % 3][Integer.parseInt(sc.next()) - 1]++;
      }
    }

    int sum[][] = new int[3][C];
    for (int i = 0; i < 3; i++) {
      for (int color = 0; color < C; color++) {
        for (int j = 0; j < C; j++) {
          sum[i][color] += D[j][color] * mod[i][j];
        }
      }
    }

    int ans = Integer.MAX_VALUE - 12345;
    for (int i = 0; i < C; i++) {
      for (int j = 0; j < C; j++) {
        if (j == i) {
          continue;
        }
        for (int k = 0; k < C; k++) {
          if (k == i || k == j) {
            continue;
          }
          ans = Math.min(ans, sum[0][i] + sum[1][j] + sum[2][k]);
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 47924
//アフィン暗号のプログラム

#include <iostream>
#include <string>

using namespace std;

string henkan( string s ){
  string t;
  for( int i = 0 ; ; i++ ){
    for( int j = 0 ; j < 26 ; j++ ){
      t = s;
      for( int k = 0 ; k < t.size() ; k++ ){
	if( 'a' <= t[k] && t[k] <= 'z'){
	  t[k] = ( i * ( t[k] - 'a' ) + j ) % 26 + 'a';
       	}
      }
      if( t.find("that") != t.npos || t.find("this") != t.npos ){
	return t;
      }
    }
  }
}

int main(void){
  int n;
  cin >> n;
  cin.get();
  while(n--){
    string s;
    getline( cin, s );
    cout << henkan(s) << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int G;
  int count=0;
  cin >> G;
  if(G/100==1)
    count++;
  if(((G%100)/10)==1)
    count++;
  if(((G%100)%10)==1)
    count++;
  cout << count << endl;
}

  

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

typedef std::pair<char, int> Card;

void BubbleSort(Card card[], int N) {
  for(int i = 0; i < N; ++i) {
    for(int j = N-1; j >= i; --j) {
      if( card[j].second < card[j-1].second ) {
        std::swap(card[j], card[j-1]);
      }
    }
  }
  return;
}

void SelectionSort(Card card[], int N) {
  for(int i = 0; i < N; ++i) {
    int minj = i;
    for(int j = i; j < N; ++j) {
      if( card[j].second < card[minj].second ) {
        minj = j;
      }
    }
    std::swap(card[i], card[minj]);
  }
  return;
}

void print_cards(Card card[], int N) {
  for(int i = 0; i < N-1; ++i) {
    std::cout << card[i].first << card[i].second << " ";
  }
  std::cout << card[N-1].first << card[N-1].second << std::endl;
}

int main(void) {

  Card card[64];
  int N;
  bool check[64][64];
  int ctoi[256];

  ctoi['S'] = 0;
  ctoi['H'] = 9;
  ctoi['C'] = 18;
  ctoi['D'] = 27;

  std::cin >> N;
  for(int i = 0; i < N; ++i) {
    std::string str;
    std::cin >> str;
    card[i].first = str[0];
    card[i].second = str[1] - '0';
  }

  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      check[i][j] = false;
    }
  }
  
  for(int i = 0; i < N; ++i) {
    for(int j = i + 1; j < N; ++j) {
      check[ctoi[card[i].first]+card[i].second][ctoi[card[j].first]+card[j].second] = true;
    }
  }

  Card card2[64];
  for(int i = 0; i < N; ++i) {
    card2[i] = card[i];
  }
  BubbleSort(card2, N);
  print_cards(card2, N);


  bool b;
  
  b = true;
  for(int i = 0; i < N; ++i) {
    for(int j = i+1; j < N; ++j) {
      if( card2[i].second == card2[j].second ) {
        if( not check[ctoi[card2[i].first]+card2[i].second][ctoi[card2[j].first]+card2[j].second] ) {
          b = false;
        }
      }
    }
  }
  if( b ) std::cout << "Stable" << std::endl;
  else    std::cout << "Not stable" << std::endl;

  Card card3[64];
  for(int i = 0; i < N; ++i) {
    card3[i] = card[i];
  }
  SelectionSort(card3, N);
  print_cards(card3, N);

  b = true;
  for(int i = 0; i < N; ++i) {
    for(int j = i+1; j < N; ++j) {
      if( card3[i].second == card3[j].second ) {
        if( not check[ctoi[card3[i].first]+card3[i].second][ctoi[card3[j].first]+card3[j].second] ) {
          b = false;
        }
      }
    }
  }
  if( b ) std::cout << "Stable" << std::endl;
  else    std::cout << "Not stable" << std::endl;

  
  return 0;
}

Measured memory_bytes: 1216
(N,T),*A = ARGF.map{_1.split.map(&:to_i)}
onaka = Array.new(6001, 0)
A.compact.sort.map{|time, value|
  next if !(time && value)
  T.downto(1){total = _1 + time
    onaka[total] = [onaka[total], (onaka[_1] + value)].max
    }
  }
p onaka.max

Measured memory_bytes: 14372
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <memory.h>
using namespace std;
 
const int INF=1e9;
 
int nexta[26][200005];
int last[26];
int dp[200005];
 
string s;
 
int find(int i){
	if(i==s.length()) return 1;
	if(i>s.length()) return 0;
	if(dp[i]<INF) return dp[i];
	for(int j=0;j<26;j++){
		dp[i]=min(dp[i],find(nexta[j][i]+1)+1);
	}
return dp[i];
}
 
int main(){
	fill(last,last+26,INF);
	fill(dp,dp+200005,INF);
	cin>>s;
	for(int i=s.length()-1;i>=0;i--){
		last[s[i]-'a']=i;
		for(int j=0;j<26;j++) nexta[j][i]=last[j];
	}
	find(0);
	int len=dp[0],pos=0;
	string ans;
	while(len){
		if(len==1){
			for(int i=0;i<26;i++){
                                if(pos>=s.length()){
					ans+='a';
					break;
				}
				else if(nexta[i][pos]>=s.length()) {
					ans+=char(i+'a');
					break;
				}
			}
		}
		else{
			for(int i=0;i<26;i++){
				if(dp[nexta[i][pos]+1]+1==dp[pos]){
					pos=nexta[i][pos]+1;
					ans+=char(i+'a');
					break;
				}
			}
		}
		len--;
	}
	cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 21892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9 + 7;
const int inf = 1e8;

int main() {
	string S;
	cin>>S;
	int N=S.size();
	string ans = "None";
	vector<bool> f(26);
	rep(i,26){
		f[i]=false;
		char c = 'a'+i;
		rep(j,N){
			if(S[j] == c)
				f[i]=true;
		}
	}
	rep(i,26){
		if(!(f[i])){
			ans='a'+i;
			break;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>

using namespace std;

constexpr static int MAXN = 3e5;
constexpr static int64_t INF = 1e18;

int64_t N, C;
int64_t x[MAXN], xsum[MAXN];

int64_t calc(int l) {
    // solution using l chains
    // C + 5*x1 + 5*x2 + 7*x3 + ...
    // arrange s.t. coeffs are minimized
    double dsum = 0;
    int64_t isum = 0;
    int i = N, k = 1;
    while (i > 0) {
        int j = max(i - l, 0);
        dsum += 1.0 * (2 * k + 1) * (xsum[i] - xsum[j]);
        if (dsum > INF)
            return INF;
        isum += (2 * k + 1) * (xsum[i] - xsum[j]);
        i = j;
        k++;
    }

    isum += 2 * (xsum[N] - xsum[N - l]);
    isum += C * (l + N);
    return isum;
}

int main() {
    cin >> N >> C;
    for (int i = 0; i < N; i++) {
        cin >> x[i];
        xsum[i + 1] = xsum[i] + x[i];
    }

    int64_t best = 5 * xsum[N] + 2 * N * C;
    for (int l = 1; l <= N; l++) {
        int64_t val = calc(l);
        if (val < best)
            best = val;
    }
    cout << best << endl;
}


Measured memory_bytes: 3840
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] s_in = line.split(" ");
		System.out.println(Integer.parseInt(s_in[0]) + Integer.parseInt(s_in[1])/2);
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;




ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int main(){
    int N, K;
    cin >> N >> K;
    map<int, int> m;
    rep(i, K){
        int d;
        cin >> d;
        rep(j, d){
            int A;
            cin >> A;
            m[A]++;
        }
    }
    int ans = N;
    // cout << endl;
    for(auto x :m){
        ans--;
        // cout << x.first << " " << x.second << endl;
    }
    cout << ans << endl;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

struct value {
    long long n;
    int bit;
};

int rec(long long N, value v) {
    if (N < v.n) {
        return 0;
    }

    int ans = 0;
    if (v.bit == 7) {
        ans++;
//        cout << v.n << endl;
    }
    ans += rec(N, {v.n * 10 + 3, v.bit | 1});
    ans += rec(N, {v.n * 10 + 5, v.bit | 2});
    ans += rec(N, {v.n * 10 + 7, v.bit | 4});

    return ans;
}

int main() {
    long long N;
    cin >> N;
    cout << rec(N, value{0, 0}) << endl;
}

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


int main(){
  int n;
  cin >> n;
  string c;
  cin >> c;
  int cnt_r = 0, cnt_w = 0;
  rep(i, n){
    if(c[i] == 'R') cnt_r++;
  }
  c.erase(cnt_r);
  rep(i, c.size()){
    if(c[i] == 'W') cnt_w++;
  }
  cout << cnt_w << endl;
}

Measured memory_bytes: 3748
// 失敗するからこそ そこから立ち向かって行く強さがあって そんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/pavan/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#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)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
	FIO
	
	int a[3][3];
	for(int i = 0; i < 3; i++){
		forn(j, 3)cin >> a[i][j];
	}
	int n;cin >> n;
	int nums[n];
	for(int i = 0; i < n; i++){
		cin >> nums[i];
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++)if(a[j][k] == nums[i])a[j][k] = -1;
		}
	}
	int cnt = 0;
	for(int i = 0; i < 3; i++)if(a[i][i] == -1)cnt++;
	if(cnt == 3){
		cout << "Yes";
		return 0;
	}
	cnt = 0;
	for(int i = 0; i < 3; i++){
		cnt = 0;
		for(int j = 0; j < 3; j++)if(a[i][j] == -1)cnt++;
		if(cnt == 3){
			cout << "Yes";
			return 0;
		}
	}
	for(int j = 0; j < 3; j++){
		cnt = 0;
		for(int i = 0; i < 3; i++)if(a[i][j] == -1)cnt++;
		if(cnt == 3){
			cout << "Yes";
			return 0;
		}
	}
	if(a[0][2] == -1 && a[1][1] == -1 && a[2][0] == -1){
		cout << "Yes";
		return 0;
	}
	cout << "No";
	
	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;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main() {
    int a, b, x; cin >> a >> b >> x;
    bool ok = true;
    if(a>x || (a+b)<x) ok = false;
    cout << ((ok)?"YES":"NO");
}



Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<cstdint>
#include<algorithm>
using namespace std;

int main() {


	uint64_t N, cap[5];
	cin >> N;
	for (int i = 0; i < 5; i++) 
		cin >> cap[i];

	uint64_t minv = cap[0];
	for (int i = 1; i < 5; i++)
		minv = min(minv, cap[i]);
	
	cout << 4 + N / minv + ((N % minv) ? 1 : 0);
}

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

int main() {
  int N;
  int l,r;
  int sum=0;
  
  cin >> N;
  for(int i=0;i<N;i++){
    cin>> l >> r;
    sum += r - l + 1;
  }
  cout << sum;
}

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

int xn(int x, int n) {
  int X = x;
  for (int i = 1; i < n; i++) {
    X *= x; 
  }
  return X;
}

int main() {
  int D,N;
  cin >> D >> N;
  if (N == 100)
    N = 101;
  
  if (D == 0)
    cout << N << endl;
  else 
    cout << xn(100,D) * N << endl;
  
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int q;
int x, d;
int n;
int fact[20000000];
signed main() {
	cin >> q;
	int mod = 1000003;
	fact[0] = 1;
	for (int i = 1; i < 20000000; i++) {
		fact[i] = fact[i - 1] * i % mod;
	}
	for (int i = 0; i < q; i++) {
		cin >> x >> d >> n;
		int k = mod_pow(-d, n, mod);
		if (d == 0) {
			cout << mod_pow(x, n, mod) << endl;
			continue;
		}
		int res = -x * mod_pow(d, mod - 2, mod) % mod;
		res = (res + mod) % mod;
		if (n > res) {
			cout << 0 << endl;
		}
		else {
			cout << ((fact[res] % mod *
				mod_pow(fact[res - n], mod - 2, mod) % mod *
				k % mod) +
				mod) % mod << endl;
		}
	}
}

Measured memory_bytes: 157184
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

var MOD = 1000000007

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	// nが偶数なら1,3,5,...n-1までが2つずつ
	// nが奇数なら0がひとつ、2,4,6,...n-1までが2つずつ
	// 出力は数え方なので同じ数の者同士を入れ替えるので(n//2)**2
	// Goで無理やり実装する感じの雑感。。。こういうのはPythonのがサクッと作れる。。。
	// 無限にWA出るな〜と思ったら問題文を読んでなかった "ただし、答えは非常に大きくなることがあるので、109+7 で割った余りを出力してください。"
	n := nextInt()
	arr := nextInts(n)
	sort.Ints(arr)
	compare_arr := make([]int, n)
	if n%2 == 0 {
		i := 1
		for j := 0; j < n/2; j++ {
			compare_arr[2*j], compare_arr[2*j+1] = i, i
			i += 2
		}
	} else {
		i := 2
		for j := 1; j < n/2+1; j++ {
			compare_arr[2*j-1], compare_arr[2*j] = i, i
			i += 2
		}
	}
	flag := true
	for i := 0; i < n; i++ {
		if compare_arr[i] != arr[i] {
			flag = false
		}
	}
	if !flag {
		fmt.Fprint(out, 0)
		return
	}
	fmt.Fprint(out, pow(2, (n/2)))
}

func pow(a, b int) int {
	ret := 1
	for i := 0; i < b; i++ {
		ret *= a
		ret %= MOD
	}
	return ret
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}


Measured memory_bytes: 2816