akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var gcd = Calculation.GCD(ar[0], ar[1]);
        for (var i = 2; i < num; i++)
            gcd = Calculation.GCD(gcd, ar[i]);
        WriteLine(gcd);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}
public class Calculation
{
  public static int GCD(int num1, int num2)
    {
        return num1 < num2 ? GCD(num2, num1) :
            num2 > 0 ? GCD(num2, num1 % num2) : num1;
    }
}

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

void done(){
    cout << "Yes" << endl;
    exit(0);
}

int main(){
    int A[3][3];
    for(int i=0; i<3; i++) for(int j=0; j<3; j++) cin >> A[i][j];
    int N;
    cin >> N;
    while(N--){
        int b;
        cin >> b;
        for(int i=0; i<3; i++) for(int j=0; j<3; j++) if(A[i][j] == b) A[i][j] = 0;
    }
    for(int i=0; i<3; i++){
        bool ok = true;
        for(int j=0; j<3; j++) if(A[i][j]) ok = false;
        if(ok) done();
    }
    for(int i=0; i<3; i++){
        bool ok = true;
        for(int j=0; j<3; j++) if(A[j][i]) ok = false;
        if(ok) done();
    }
    if(!A[0][0] && !A[1][1] && !A[2][2]) done();
    if(!A[0][2] && !A[1][1] && !A[2][0]) done();

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll N,D;
  cin >> N >> D;
  vector<array<ll,2>> A(N);
  ll ans = 0;
  for (auto& [a,b] : A) {
    cin >> a >> b;
    ans += a*a + b*b <= D*D;
  }
  cout << ans << endl;

}


Measured memory_bytes: 6368
from collections import deque
n = int(input())
a = [[] for i in range(n)]
e = []
for i in range(n-1):
  b, c = map(int, input().split())
  b -= 1
  c -= 1
  a[b].append(c)
  e.append(c)
col = [0 for i in range(n)]
v = deque([0])

while v:
  d = v.popleft()
  k = 1
  for i in a[d]:
    if col[d] == k:
      k += 1
    col[i] = k
    v.append(i)
    k += 1
print (max(col))
for i in e:
  print(col[i])

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

struct Node {
  vector<pair<int, ll>> edges;
  bool checked;
  bool color;
};

void dfs(int num, ll weight, vector<Node>& nodes) {
  if (nodes[num].checked) return;
  nodes[num].color = weight % 2;
  nodes[num].checked = true;

  for (pair<int, ll> p : nodes[num].edges) {
    dfs(p.first, weight + p.second, nodes);
  }

  return;
}

int main(int argc, char* argv[]) {
  long long n;
  scanf("%lld", &n);
  vector<Node> nodes(n);

  rep(i, 0, n - 1) {
    int n1, n2;
    ll w;
    cin >> n1 >> n2 >> w;
    n1--, n2--;
    nodes[n1].edges.pb({n2, w});
    nodes[n2].edges.pb({n1, w});
  }

  dfs(0, 0, nodes);

  for (Node& node : nodes) {
    put(node.color);
  }

  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 9984
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int a, b, c;
	
	cin>>a>>b>>c;
	
	cout<<min(b/a,c)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	// long long?
	int N;
	cin >> N;

	if (N == 25) {
		cout << "Christmas" << endl;
	}
	else if (N == 24) {
		cout << "Christmas Eve" << endl;
	}
	else if (N == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else if (N == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}

	return 0;

}

Measured memory_bytes: 256
N, M = list(map(int,input().split()))
L = []
R = []
for i in range(M):
    in1, in2 = list(map(int,input().split()))
    L.append(in1)
    R.append(in2)
ans = max(0, min(R) - max(L) + 1)
print(ans)

Measured memory_bytes: 56664
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

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

    int n, k;
    cin >> n >> k;
    modint ans = 0;
    for(int i = k; i <= n + 1; ++i){
        ll lb = (ll)i * (i + 1) / 2;
        ll ub = (ll)i * (2 * (n - i + 2) + i - 1) / 2;
        ans += modint(ub - lb + 1);
    }
    cout << ans << endl;
}

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

using namespace std;
vector<long long int>v[300002];
main()
{
 long long int n, m;
 cin >> n >> m;
 	long long int i, u, u1;
 	for(i=0;i<m;i++)
 	{
 		cin >> u1 >> u;
 		v[u].push_back(u1);
 		v[u1].push_back(u);
	 }
	 
	 queue<long long int >q;
	 q.push(1);
	 bool visited[n+2] = { false };
	long long int parent[n+2];
	
	while(!q.empty())
	{
		long long int a  = q.front();q.pop();
  		for(i=0;i<v[a].size();i++)
  		{
  			if(!visited[v[a][i]])
  			{
  				parent[v[a][i]] = a;
  				q.push(v[a][i]);
  				visited[v[a][i]] = true;
			  }
		  }
		
	}
	for(i=1;i<=n;i++)
	{
		if(!visited[i])
		{
		
			cout << "No";
		return 0;
		}
		
	}
	cout << "Yes" << endl;
	for(i=2;i<=n;i++)
	cout << parent[i] << endl;
	return 0;
}

Measured memory_bytes: 17800
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li      int32_t
#define lli     long long
#define ulli unsigned long long

#define pn           printf("\n")
#define nl           cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define sl          cout<<' '
#define ps          printf(" ")

#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))

#define pb      push_back
#define pob     pop_back
#define itr     iterator
#define sz()    size()
#define szof    sizeof
#define lb      lower_bound
#define ub      upper_bound
#define mp      make_pair
#define vlli    vector<lli>
#define plli    pair<lli,lli>
#define vplli   vector<plli >
#define F       first
#define S       second
#define Dup     erase(unique(V.begin(),V.end()),V.end())

#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define ALL(V)  V.begin(),V.end()

#define MX1     100000
#define MX2     1000000
#define mod     1000000007
#define Inf     1000000000000000
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;

    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }

        b=b>>1;
        a=(a*a)%mod;
    }

 return result;
}

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // */

    lli N,i,j;
    cin>>N;

    lli K;
    cin>>K;

    vlli V(N);
    rep(i,0,N)
    {
        cin>>V[i];
    }

    lli Max=*max_element(V.begin(),V.end());
    if(Max<K)
    {
        cout<<"IMPOSSIBLE";
        exit(0);
    }

    lli GCD=0;
    rep(i,0,N)
    {
        cin>>V[i];
        GCD=__gcd(GCD,V[i]);
    }
    
    if(K%GCD == 0){
        cout << "POSSIBLE";
    }
    else{
        cout<<"IMPOSSIBLE";
    }


 return 0;
}


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

const int MAXN = 205;
const int INF = 1 << 29;

int N;
char S[MAXN][MAXN];
int dis[MAXN][MAXN];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	for(int i = 0; i < N; i++) cin >> S[i];

	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) dis[i][j] = i == j ? 0 : INF;
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++)
		if(S[i][j] == '1') dis[i][j] = 1;
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) for(int k = 0; k < N; k++)
		dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]);
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++)
		if(S[i][j] == '1') if(dis[0][i] % 2 == dis[0][j] % 2) {
			cout << "-1\n";
			return 0;
		}
	int mx = 0;
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) mx = max(mx, dis[i][j]);
	cout << mx + 1 << "\n";
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N;
	std::cin >> N;
	ll ans = 0;
	repeq(i, 1, N) {
		for (ll j = i; j <= N; j += i) {
			ans += j;
		}
	}
	std::cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
long inf = 1000000007;

int main() {
    string s; cin >> s;
    if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
        cout << "Yes" << endl;
    }
    else {
        cout << " No" << endl;
    }
}





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

const int N=110;
int n,lL[N],lR[N],mL[N],mR[N],vis[N],g[N][N],ans,nl,nr;
set<int>L,R;
bool is_prime(int x){
	if(x==1)return 0;
	for(int i=2;i*i<=x;++i)if(x%i==0)return 0;
	return 1;
}

void ins(int x){
	if(x&1){if(L.count(x))L.erase(x);else L.insert(x);}
	else{if(R.count(x))R.erase(x);else R.insert(x);}
}

int dfs(int x){
	for(int i=1;i<=nr;++i)if(!vis[i]&&g[x][i]){
		vis[i]=1;
		if(!mL[i]||dfs(mL[i])){mL[i]=x;mR[x]=i;return 1;}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){int x;cin>>x;ins(x);ins(x+1);}
	for(int i:L)lL[++nl]=i;for(int i:R)lR[++nr]=i;
	for(int i=1;i<=nl;++i)
		for(int j=1;j<=nr;++j)
			g[i][j]=is_prime(abs(lL[i]-lR[j]));
	for(int i=1;i<=nl;++i)if(!mR[i]){
		memset(vis,0,sizeof vis);
		if(dfs(i))++ans;
	}
	nl-=ans;nr-=ans;
	ans+=nl/2*2+nr/2*2;
	nl%=2;nr%=2;
	assert(nl==nr);
	ans+=nl*3;
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 384
#[allow(unused_imports)]
use proconio::{input, fastout};
#[allow(unused_imports)]
use proconio::marker::{Chars};

#[fastout]
fn main() {
  input!{n:u128,a:[u128;n]}
  let max:u128 = 1000000000000000000;
  let mut res:u128 = 1;
  for i in a.clone() {
    if i==0 {
      println!("0");
      return;
    }
  }
  for j in a {
    res *= j;
    if res>max {
      println!("-1");
      return;
    }
  }
  println!("{}",res);
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

vector<ll> dijkstra(const WGraph &G, const int s) {
    int n = (int)G.size();
    std::vector<long long> dis(n, LINF);
    dis.at(s) = 0;
    using P = std::pair<long long, int>;
    std::priority_queue<P, std::vector<P>, std::greater<P>> que;
    que.push(std::make_pair(0, s));

    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        int v = p.second;
        if (dis.at(v) < p.first) {
            continue;
        }
        for (auto e : G.at(v)) {
            if (dis.at(e.first) > dis.at(v) + e.second) {
                dis.at(e.first) = dis.at(v) + e.second;
                que.push(std::make_pair(dis.at(e.first), e.first));
            }
        }
    }
    return dis;
}

void solve() {
    int n, m;
    cin >> n >> m;
    WGraph G(n);
    for (int i=0; i<m; ++i) {
        int a, b;
        cin >> a >> b;
        G.at(a-1).push_back({b-1, 1});
        G.at(b-1).push_back({a-1, 1});
    }

    auto dis = dijkstra(G, 0);
    vector<int> res(n);
    for (int i=1; i<n; ++i) {
        for (auto x : G.at(i)) {
            if (dis.at(x.first) == dis.at(i) - 1) {
                res.at(i) = x.first + 1;
                break;
            }
        }
    }

    cout << "Yes" << '\n';
    for (int i=1; i<n; ++i) cout << res.at(i) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 18716
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int h,w;
vector<string> v;
vector<string> vr;
vector<string> vc;

int pr[15];
int pc[15];
bool cr[15];

bool check(){
  // dbg(vector<int>(pr, pr+h));
  // dbg(vector<int>(pc, pc+w));
  fill(cr, cr+h, false);
  rep(i,h) if(!cr[i]){
    int ti = pr[i]==-1 ? i : pr[i];
    cr[i] = cr[ti] = true;
    rep(j,w){
      int tj = pc[j]==-1 ? j : pc[j];
      if(v[i][j] != v[ti][tj]) return false;
    }
  }
  return true;
}

bool dfs_c(int d = 0){
  if(d == w/2) return check();
  int x = 0;
  rep(_, 1 + w%2){
    while(x<w && pc[x] != -1) x++;
    rep(i,x+1,w) if(pc[i]==-1 && vc[x] == vc[i]){
      pc[x] = i;
      pc[i] = x;
      if(dfs_c(d+1)) return true;
      pc[i] = -1;
    }
    pc[x] = -1;
    x++;
  }
  return false;
}

bool dfs_r(int d = 0){
  if(d == h/2) return dfs_c();
  int x = 0;
  rep(_, 1 + h%2){
    while(x<h && pr[x] != -1) x++;
    rep(i,x+1,h) if(pr[i]==-1 && vr[x] == vr[i]){
      pr[x] = i;
      pr[i] = x;
      if(dfs_r(d+1)) return true;
      pr[i] = -1;
    }
    pr[x] = -1;
    x++;
  }

  return false;
}

bool solve(){
  cin>>h>>w;
  v = vector<string>(h);
  rep(i,h) cin>>v[i];
  vr = vector<string>(h);
  rep(i,h){ vr[i] = v[i]; sort(all(vr[i])); }
  vc = vector<string>(w);
  rep(i,w){
    rep(j,h) vc[i].pb(v[j][i]);
    sort(all(vc[i]));
  }

  fill(pr, pr+h, -1);
  fill(pc, pc+w, -1);
  return dfs_r();
}

int main(){
  cout << (solve() ? "YES" : "NO") << endl;
  return 0;
}


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

using namespace std;

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

    if(K > (N-1)*(N-2)/2) 
    {
        cout << -1 << endl; 
        return 0;
    }
        
    int m = N * (N-1)/2 - K;
    cout << m << endl;

    for(int i = 1; i < N; i++)
    {
        for(int j = i + 1; j <= N; j++)
        {
            cout << i << " " << j << endl;
            m--;
            if(m == 0) break;
        }
        if(m == 0) break;
    }
    
}


Measured memory_bytes: 256
//Δ_B
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
int main()
{
	int a,b,c,n,i,j,s;
	cin>>a>>b>>c>>n;
	s=0;
	for(i=0;i*a<=n;i=i+1)
		for(j=0;i*a+j*b<=n;j=j+1)
			if((n-i*a-j*b)%c==0)
				s++;
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define sz(s) (ll)s.size()
#define print(d) cout << fixed << setprecision(15) << d
#define pii pair<ll,ll>
#define ppii pair<ll,pii>
#define ff first
#define ss second
const ll MOD = 1000000007;
const ll MAXN = 1e6 + 5;
const ll inf = 2e18;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
tree_order_statistics_node_update> ord_set;
#define debug(x) cerr << #x << " = " << x << endl


ll power(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 

ll fun(ll x)
{
    if(x==1)return 1;
    return 1+2*fun(x/2);
}

int main()
{
    fast
  ll h;
  cin >> h;
  cout << fun(h);

    return 0;

}










Measured memory_bytes: 384
using System;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int n = (str[1] == "+") ? int.Parse(str[0]) + int.Parse(str[2]) : int.Parse(str[0]) - int.Parse(str[2]);
        Console.WriteLine(n);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N, K; cin >> N >> K;
    vector<int> V(N); for (auto &v : V) cin >> v;
    vector<int> X;
    X.reserve(N);
    Int ans = 0;
    for (int a = 0; a <= K; a++) {
        for (int b = 0; a + b <= K; b++) {
            if (a + b > N) continue;
            X.clear();
            int c = K - (a + b);
            for (int i = 0; i < a; i++) {
                X.push_back(V[i]);
            }
            for (int i = 0; i < b; i++) {
                X.push_back(V[N-1-i]);
            }
            sort(begin(X), end(X));
            Int sum = 0;
            for (int i = 0; i < X.size(); i++) {
                if (X[i] < 0 && c) {
                    c--;
                } else {
                    sum += X[i];
                }
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

int main(){
        int a, b, c;
        cin>>a>>b>>c;
        bool flag=false;
        for(int i=a;i<=100000;i+=a){
                if(i%b==c){
                        flag=true;
                        break;
                }
        }
        if(flag){
                cout<<"YES"<<endl;
        }
        else{
                cout<<"NO"<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))

# 最終的に全て1になるので、最初の1の場所からなるべく効率的に1を広めればよい
index_1 = A.index(1)

# 中央から進める場合と、1に近い方の端から順に進める場合
if K <= index_1 <= (N-1) - (K-1) -1:
    # 初手、長さKの区間のどこに1がくるか
    tmp = []
    for i in range(K):
        len_rest_left = index_1 - i
        len_rest_right = N - len_rest_left - K
        tmp.append(math.ceil(len_rest_left/(K-1)) + math.ceil(len_rest_right/(K-1)))
    ans = min(tmp) + 1
else:
    ans = math.ceil((N-1)/(K-1))
    
print(ans)

Measured memory_bytes: 13812
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;

int main(){
  ll N,ans;
  cin>>N;
  ll V[N],A[100010],B[100010];
  REP(i,100010){
    A[i]=0;
    B[i]=0;
  }
  
  REP(i,N){
    cin>>V[i];
    if(i%2==0) A[V[i]]++;
    else B[V[i]]++;
  }
  
  ll mxa=0,mxb=0;
  
  REP(i,100010){
    if(A[i]>A[mxa]){
      mxa=i;
    }
    if(B[i]>B[mxb]){
      mxb=i;
    }
  }
  
  if(mxa!=mxb){
    cout<<N-A[mxa]-B[mxb]<<endl;
    return 0;
  }
  
  ll mxaa=0,mxbb=0;
  
  REP(i,100010){
    if(A[i]>A[mxaa] && i!=mxa){
      mxaa=i;
    }
    if(B[i]>B[mxbb] && i!=mxb){
      mxbb=i;
    }
  }
  
  ll AA=A[mxa]+B[mxbb],BB=B[mxb]+A[mxaa];
  if(AA<BB) cout<<N-BB<<endl;
  else cout<<N-AA<<endl;
  return 0;
}

Measured memory_bytes: 2560
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
const ll mod=MOD;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1};
vl dy={1,-1,0,0};

//素因数分解O(√n)
map<ll,ll>prime_factor(ll n){
  map<ll,ll>res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}

const ll MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
//finvが階乗の逆元

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll mod) {
  
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll n;cin>>n;
  vl x(n),y(n),p(n);
  rep(i,n)cin>>x[i]>>y[i]>>p[i];
  vvl bitx((1<<n),vl(n)),bity((1<<n),vl(n));
  rep(bit,1<<n){
    rep(i,n){
      bitx[bit][i]=min(abs(x[i]),abs(y[i]));
      bity[bit][i]=min(abs(x[i]),abs(y[i]));
    }
  }
  vl ans(n+1,INF);
  vl pow(16);
  vl three(16);
  pow[0]=1;
  three[0]=1;
  rep(i,15)pow[i+1]=pow[i]*2;
  rep(i,15)three[i+1]=three[i]*3;
  rep(bit,(1<<n)){
    rep(i,n){
      rep(j,n){
        if(bit(bit,j))bitx[bit][i]=min(bitx[bit][i],abs(x[i]-x[j]));
      }
    }
  }
  rep(bit,(1<<n)){
    rep(i,n){
      rep(j,n){
        if(bit(bit,j))bity[bit][i]=min(bity[bit][i],abs(y[i]-y[j]));
      }
    }
  }
  // rep(bit,1<<n){
  //   rep(i,n)cout<<bitx[bit][i]<<" ";
  //   cout<<endl;
  // }
  
  rep(bit,three[n]){
    
    ll sumx=0,sumy=0;
    ll cnt=0;
    ll tmp=bit;
    
    rep(i,n){
      cnt++;
      if(tmp%3==1)sumx+=pow[i];
      else if(tmp%3==2)sumy+=pow[i];
      else cnt--;
      tmp/=3;
      if(tmp==0)break;
    }
    
    // cout<<bit<<" "<<sumx<<" "<<sumy<<endl;
    ll part=0;
    
    rep(i,n){
      part+=p[i]*min(bitx[sumx][i],bity[sumy][i]);
    }
    ans[cnt]=min(ans[cnt],part);
    // cout<<bit<<" "<<part<<" "<<cnt<<endl;
    
  }
  rep(i,n+1)cout<<ans[i]<<'\n';
  
}
  


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> g[n];
    vector<int> back[n];
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        back[v].push_back(u);
    }
    vector<bool> mark(n, false);
    vector<int> topo;
    function<void(int)> dfs = [&](int v){
        mark[v] = true;
        for(int x : g[v]){
            if(!mark[x]) dfs(x);
        }
        topo.push_back(v);
    };

    for(int i = 0; i < n; i++){
        if(!mark[i]) dfs(i);        
    }
    reverse(topo.begin(), topo.end());
    vector<int> dp(n, 0);
    for(int v: topo){
        for(int u : g[v]) dp[u] = max(dp[u], dp[v]+1);
    }
    int mx = 0;
    for(int i = 0; i < n; i++) mx = max(mx, dp[i]);
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 14204
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);++i)
constexpr long long MOD = (1e9+7);

main(){

  ll n,m;
  cin>>n>>m;
  vector<ll> a(m);
  vector<ll> dp(n+1,-1);
  rep(i,m){
    ll x;
    cin>>x;
    a[i]=x;
    dp[x]=0;
  }

  dp[0]=1;
  if(dp[1]==-1)dp[1]=1;
  for(ll i=2;i<=n;++i){
    if(dp[i]==0)continue;
    dp[i]=dp[i-1]+dp[i-2];
    dp[i]%=MOD;
  }
  cout<<(dp[n])<<endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string>

using namespace std;

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

	string s;
	int c = 0;

	int aa, bb, cc, dd = 0;
	for (int i = a; i <= b; ++i) {
		
		aa = i / 10000;
		bb = (i / 10) % 10;
		cc=(i / 1000) % 10;
		dd = i % 10;

		if (aa==dd && bb==cc)c++;	
	}

cout << c << endl;

	return 0;
}

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

PPP = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
    if (PPP[i] >= PPP[i-1] and PPP[i+1] > PPP[i]) or (PPP[i-1] > PPP[i] and PPP[i] >= PPP[i+1]):
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN = 100000+9;
int n,C;
struct PAIR{
	int l,r;
	PAIR(int _l=0,int _r=0):l(_l),r(_r){}
};
vector<PAIR> vec[40];
int sum[MAXN<<1];//差分
int tot[MAXN<<1];
int ans;

int main(){
	scanf("%d%d",&n,&C);
	for(int i=1;i<=n;i++){
		int l,r,c;
		scanf("%d%d%d",&l,&r,&c);
		vec[c].push_back(PAIR(l,r));
	}
	for(int i=1;i<=C;i++){
		memset(sum,0,sizeof(sum));
		for(int j=0;j<vec[i].size();j++){
			sum[(vec[i][j].l<<1)-1]++;
			sum[vec[i][j].r<<1]--;
		}
		for(int j=1;j<MAXN<<1;j++)
			sum[j]+=sum[j-1];
		for(int j=0;j<MAXN<<1;j++)
			tot[j]+=sum[j]>0?1:0;
	}
	for(int i=0;i<MAXN<<1;i++)
		ans=max(ans,tot[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3072
//Coded by tzc_wk
/*
Êý¾Ý²»Çå¿Õ£¬±¬ÁãÁ½ÐÐÀá¡£
¶à²â²»¶ÁÍê£¬±¬ÁãÁ½ÐÐÀá¡£
±ß½ç²»ÌØÅÐ£¬±¬ÁãÁ½ÐÐÀá¡£
Ì°ÐÄ²»Ö¤Ã÷£¬±¬ÁãÁ½ÐÐÀá¡£
D P Ë³Ðò´í£¬±¬ÁãÁ½ÐÐÀá¡£
´óÐ¡ÉÙµÈºÅ£¬±¬ÁãÁ½ÐÐÀá¡£
±äÁ¿²»Í³Ò»£¬±¬ÁãÁ½ÐÐÀá¡£
Ô½½ç²»ÅÐ¶Ï£¬±¬ÁãÁ½ÐÐÀá¡£
µ÷ÊÔ²»×¢ÊÍ£¬±¬ÁãÁ½ÐÐÀá¡£
Òç³ö²» l l£¬±¬ÁãÁ½ÐÐÀá¡£
ÍüÎÄ¼þ²Ù×÷£¬±¬ÁãÁ½ÐÐÀá¡£
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
#define int long long
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int suf[200005],n,cnt[2020],ans=0;
char s[200005];
const int MOD=2019;
signed main(){
	cin>>s+1;
	n=strlen(s+1);
	cnt[0]++;
	fd(i,n,1)	suf[i]=(suf[i+1]+(s[i]-'0')*qpow(10,n-i,MOD))%MOD,cnt[suf[i]]++;
	fz(i,0,2018)	ans+=(cnt[i])*(cnt[i]-1)/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5340
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <regex>

using namespace std;

string uniteBlanks( string t )
{
    int i=0;
    for(i=t.size()-1;i>0;i--){
        if(t[i-1]== ' ' && t[i]==' ')t.erase(t.begin()+i);
    }
    if(t[0] == ' ')t.erase(t.begin());
    return t;
}

int main() {
    string w, t, t_tmp;
    int i, j, count, ix;
    vector<string> list;
    string item;

    getline(cin, w);
    std::transform(w.begin(), w.end(), w.begin(), ::toupper);
    count = 0;

    getline(cin, t_tmp);
    t = uniteBlanks(t_tmp);

while(t!="END_OF_TEXT"){
    std::transform(t.begin(), t.end(), t.begin(), ::toupper);

    stringstream ss(t);
    while (getline(ss, item, ' ') && !item.empty()) {
        list.push_back(item);
    }

    for(i=0;i != list.size();i++){
        if(w == list[i]){
            count++;
        }
    }

    list.clear();
    getline(cin, t_tmp);
    t = uniteBlanks(t_tmp);
}
cout << count << endl;
    return 0;
}



Measured memory_bytes: 3132
import scala.io.StdIn.{readLine,readInt}

object Main {

  def main(args: Array[String]) = {
    val n = readInt
    val a = Array.ofDim[Int](4,3,10)

    1 to n foreach { _ =>
      val Array(b,f,r,v) = readLine.split(" ").map(_.toInt)
      a(b-1)(f-1)(r-1) += v
    }

    for(i <- 0 to 3) {
      for(j <- 0 to 2) {
        for(k <- 0 to 9) {
          print(" "+a(i)(j)(k))
        }
        println()
      }
      if(i<3) {
        println("####################")
      }
    }
  }
}

Measured memory_bytes: 44384
#include <stdio.h>
#include <stdlib.h>

#define N 10000
#define Q 500
int linearSearch(int);

int n,q,c=0;
int S[N];
int T[Q];

int main()
{
  int i,k;

  scanf("%d",&n);
  if(N<n) exit(1);

  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  if(Q<q) exit(2);

  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
  }

  for(i=0; i<q; i++){
    c += linearSearch(T[i]);
  }

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

  return 0;
}

int linearSearch(int key){

  int i=0;

  S[n] = key;
  while(S[i] != key){
    i++;
    if(i==n) return 0;
  }
  return 1;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int n; cin >> n;
    vector<int> a(0), b(n);
    for(int i = 0; i < n; i++){
        cin >> b[i];
        if(b[i] > i+1){
            cout << -1 << endl;
            return 0;
        }
    }
    while(b.size()){
        bool tmp = false;
        for(int i = b.size()-1; i >= 0; i--){
            if(b[i] == i+1){
                tmp = true;
                a.push_back(i+1);
                b.erase(b.begin()+i);
                break;
            }
        }
        if(!tmp){
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(a.begin(),a.end());
    for(int i = 0; i < n; i++){
        cout << a[i] << endl;
    }
}

 


Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int h,w;
  std::cin >> h >> w;

  char s[h][w];
  int gyou[h],retsu[w];
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      std::cin >> s[i][j];
      retsu[j]=0;
    }
    gyou[i]=0;
  }

  //行について
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(s[i][j]!='.') gyou[i]=1;
    }
  }
  //列について
  for(int i=0; i<w; i++){
    for(int j=0; j<h; j++){
      if(s[j][i]!='.') retsu[i]=1;
    }
  }

  for(int i=0; i<h; i++){
    if(gyou[i]==1){
    for(int j=0; j<w; j++){
      if( retsu[j]==1) std::cout << s[i][j] ;
      }
      printf("\n");
    }
    
  }


  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)



int main(){
	char s[4];
	cin >> s;
	
	sort(s, s+4);
	
	if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2])
		cout << "Yes\n";
	else 
		cout << "No\n";
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;

void main()
{
  immutable MAX = 10001;

  bool p[MAX];
  p[] = 1;
  p[0..2] = 0;
  foreach (i; 2..sqrt(MAX*1.0).ceil.to!int) {
    if (p[i]) {
      foreach (j; iota(i*2, MAX, i))
        p[j] = 0;
    }
  }

  while (1) {
    auto n = readln.chomp.to!int;
    if (!n) break;
    while (1) {
      if (p[n] && p[n-2]) {
        writeln(n-2, " ", n);
        break;
      }
      n--;
    }
  }
}

Measured memory_bytes: 1340
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;
const int mod = 1000000007;
const int MAX = 300000;

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

  ll ans = 0;
  // iはllにしないと酷いことになる
  for (ll i = K; i <= (N + 1); i++) {
    ll max = (N * 2 - i + 1) * i / 2;
    ll min = (i - 1) * i / 2;
    ans += max - min + 1;
    ans %= mod;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3612
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=a&&a<b)
#define Y1 b1[0]-'a'
#define X1 b1[2]-'1'
#define Y2 b2[0]-'a'
#define X2 b2[2]-'1'
#define INF (1<<20)
using namespace std;
int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
int m,n,ds,ns,nc,nj,sy,sx,gy,gx,t,
S[20][20],D[20][20][20][20]; bool V[20][20][101][4]; char ch,tmp;
void dfs(int y,int x,int t,int d){
	V[y][x][t][d]=1;
	int ny,nx,c,nt,nd;
	rep(i,4){
		nd=d+i&3,ny=y+dy[nd],nx=x+dx[nd];
		if(ck(ny,m)&&ck(nx,n)&&i!=2){
			c=D[y][x][ny][nx],nt=t+c;
			if((!S[ny][nx]||nd%2==nt/S[ny][nx]%2)&&c!=INF
			&&nt<101&&!V[ny][nx][nt][nd])dfs(ny,nx,nt,nd);
		}
	}
}
int main(){
	while(cin>>m>>n,m){
		cin>>ds; rep(y,m)rep(x,n){
			S[y][x]=0; rep(d,4){
				int ny=y+dy[d],nx=x+dx[d];
				if(ck(ny,m)&&ck(nx,n))D[y][x][ny][nx]=D[ny][nx][y][x]=ds;
			}
		}
		int x1,x2,y1,y2,k;
		cin>>ns; rep(i,ns){
			cin>>ch>>tmp>>x1>>k; x1--;
			S[ch-'a'][x1]=k;
		}
		cin>>nc; rep(i,nc){
			cin>>ch>>tmp>>x1; y1=ch-'a'; x1--;
			cin>>ch>>tmp>>x2; y2=ch-'a'; x2--;
			D[y1][x1][y2][x2]=D[y2][x2][y1][x1]=INF;
		}
		cin>>nj; rep(i,nj){
			cin>>ch>>tmp>>x1; y1=ch-'a'; x1--;
			cin>>ch>>tmp>>x2>>k; y2=ch-'a'; x2--;
			D[y1][x1][y2][x2]+=k,D[y2][x2][y1][x1]+=k;
		}
		cin>>ch>>tmp>>sx; sy=ch-'a'; sx--;
		cin>>ch>>tmp>>gx; gy=ch-'a'; gx--;
		
		rep(i,m)rep(j,n)rep(t,101)rep(d,4)V[i][j][t][d]=0;
		rep(d,4)dfs(sy,sx,0,d);
		rep(t,101)rep(d,4)if(V[gy][gx][t][d]){
			cout<<t<<endl; goto END;
		}
		END:;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int A,B,C;
	cin>>A>>B>>C;
	int ans=0;
	if(B<=C){
		ans+=B*2;
		ans+=min(A+1,C-B);
		ce(ans)
	}else{
		ce(B+C)
	}
	
	
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            int len = S.Length;
            int num1 = S.Count(x => x == '1');
            int num0 = len - num1;
            Console.WriteLine(Math.Min(num1, num0) * 2);
        }
    }
}


Measured memory_bytes: 13268
r,c=map(int,input().split())
lst=[list(map(int,input().split())) for i in range(r)]

lst.append([sum([x[j] for x in lst]) for j in range(c)])

for i in range(r+1):
    lst[i].append(sum(lst[i]))
    print(" ".join([str(x) for x in lst[i]]))



Measured memory_bytes: 5712
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll INF = 1e18;
ll dp[200005];
int main(){
	fastio;
  	ll x1, y1, x2, y2;
  	cin >> x1 >> y1 >> x2 >> y2;
  	ll d = 1; 
  	if ((x1 < x2 && y1 > y2) || (x1 > x2 && y1 < y2)) d = -1; 
  	ll n; cin >> n;
  	vpll f;
  	for (ll i = 0; i < n; ++i){
    	ll x, y; cin >> x >> y;
    	if (min(x1, x2) <= x && x <= max(x1, x2) && min(y1, y2) <= y && y <= max(y1, y2)) f.pb(mp(x, y * d));
  	}
  	sort(f.begin(), f.end());
	ll fc = f.size();
	for (ll i = 0; i < fc; i++) dp[i] = INF;
	for (ll i = 0; i < fc; i++) *lower_bound(dp, dp + fc, f[i].se) = f[i].se;
  	ll cnt = lower_bound(dp, dp + fc, INF) - dp;
  	ld ans = abs(x2 - x1) + abs(y2 - y1); ans *= 100.0;
  	ans -= (ld) cnt * (20.0 - 5.0 * PI);
  	if (cnt == min(abs(x2 - x1), abs(y2 - y1)) + 1) ans += 5.0 * PI;
	cout << fixed << setprecision(15); cout << ans << endl; 
  	return 0;
}

Measured memory_bytes: 6384
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9000000000000000000;
const double PI = acos(-1);

int main() {
	int n;
	cin >> n;
	int kisu = 0, gusu = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 2 == 0)gusu++;
		else kisu++;
	}
	LL ans = pow(3, n);
	ans -= pow(2, gusu);
	cout << ans << endl;
}

Measured memory_bytes: 256