akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var H = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);


            bool flag = true;

            for (int i = N - 1; i >0; i--)
            {
                if (H[i] < H[i-1] )
                {
                    H[i - 1]--;
                }
            }

            for (int i = 0; i < N - 1; i++) if (H[i + 1] < H[i]) flag = false;


            Console.WriteLine(flag ? "Yes" : "No");


        }
    }
}


Measured memory_bytes: 27100
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include <cmath>

using namespace std;

using ll = long long int;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp; 
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

// [beg, end)の範囲を，添え字indexでループするfor文に置換します
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

template<class T>
T min(T a, T b) {
    return (a < b) ? a : b;
}

template<class T>
T max(T a, T b) {
    return (a > b) ? a : b;
}

int main() {
    int r;
    cin >> r;

    cout << 3 * r * r;

    return 0;
}



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

//string型文字列をint型整数にして返す
int str_to_num(string s) {return atoi(s.c_str());}
//約数の総数を返す
int count_divisor(int n){int c[n/2] = {1}; int n_half = n/2; for(int i=2;i<n_half;i++){if(n%i==0){n /= i;c[i]+=1;i--;if(n>1) continue;else break;}  }int r = 1;for(int i=2;i<n_half;i++){r *= c[i];}return r;}
//各桁の数の和を返す
int dig_num(int n){return (n<10) ? n: dig_num(n/10) + n%10;}

int main(){
  string s; cin >> s;
  bool flag = s.substr(0,4)=="YAKI";
  
  cout << (flag? "Yes\n":"No\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;

int main(){
  ll ans=0;
  ll n; cin>>n;
  for(int i=1;i<=n;i++){
    ll cnt=0;
    ll x=i;
    while(x>0){
      cnt++;
      x/=10;
    }
    if(cnt%2==1)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(var,n)  for(int var=0;var<(n);++var)
int main() {
    int H,W; cin >> H >> W;
    int c[10][10];
    rep(i,10) rep(j,10) cin >> c[i][j];
    rep(k,10) rep(i,10) rep(j,10) c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
    // 200 x 200 x 1000 = 4e7
    int total = 0;
    rep(i,H) rep(j,W) {
        int aij; cin >> aij;
        if (aij == -1) continue;
        total += c[aij][1];
    }
    cout << total << endl;
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  if (n > m) swap(n, m);
  if (m == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (n == 1) {
    cout << m - 2 << endl;
    return 0;
  }
  ll ret = (ll)(n - 2) * (m - 2);

  cout << ret << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(){
	int n, ans = 0;
	string s;
	cin >> s;
	bool f = true;
	n = s.size();
	if(s[0] == '0' || s.back() == '1') f = false;
	for(int i = 0; i < n / 2; i++){
		if(s[i] != s[n - 2 - i]){
			f = false;
			break;
		}
	}
	if(f){
		int p1 = 1, p2;
		for(int i = 0; i < n; i++){
			if(s[i] == '1'){
				p2 = i + 1;
				for(; p1 < p2; p1++){
					cout << p1 << " " << p2 << endl;
				}
			}else if(i == n - 1){
				for(int i = p1 + 1; i <= n; i++){
					cout << p1 << " " << i << endl;
				}
			}

		}
	}else{
		cout << "-1" << endl;
	}
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    int arr[n];
    for (int in=0;in<n;in++) cin>>arr[in];
    if (n==2) {
        cout<<abs(arr[0]-arr[1])<<"\n";
        return 0;
    }
    int llstate=0, lstate=abs(arr[0]-arr[1]), curr,i=3;
    for (;i<=n;i++) {
        curr=min(llstate+abs(arr[i -1]-arr[i-2 -1]), lstate+abs(arr[i -1]-arr[i-1 -1]));
        llstate=lstate;
        lstate=curr;
    }
    cout<<curr<<"\n";
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n,x,i;
     cin>>n>>x;
  
     int arr[n];
        for(i=0;i<n;i++)
          cin>>arr[i];
                       
       int d1=0,op=0;
          i=0;
       while(d1<=x && i<=n)
       {
           op++;
         d1=d1+arr[i];
           i++;
       }
   cout<<op;
   return 0;
}

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

using namespace std;

int solve(int d, const vector<int> &A) {
  int r = 0;
  vector<int> mods;
  for (int a : A) {
    int mod = a % d;
    r += mod;
    mods.push_back(mod);
  }
  sort(mods.begin(), mods.end());
  if (not r) {
    // cout << d << " " << 0 << endl;
    return 0;
  }
  int l = 0, n = (int) mods.size();
  for (int i = 0; i < n; ++i) {
    l += mods[i];
    r -= mods[i];
    if ((n - i - 1) * d - r == l) {
      // cout << d << " " << l << endl;
      return l;
    }
  }
  // cout << d << " " << INT_MAX << endl;
  return INT_MAX;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  int sum = 0;
  for (int &a : A) {
    cin >> a;
    sum += a;
  }
  int asw = 0;
  for (int i = 1; i * i <= sum; ++i) {
    if (sum % i) {
      continue;
    }
    if (solve(i, A) <= k) {
      asw = max(asw, i);
    }
    if (solve(sum / i, A) <= k) {
      asw = max(asw, sum / i);
    }
  }
  cout << asw << endl;
  return 0;
}


Measured memory_bytes: 256
x,n = map(int, input().split())
if n == 0:
  print(x)
else:
  p_list = list(map(int, input().split()))
  if x in p_list:
    p_list.sort()
    pos = p_list.index(x)
    tmp1 = p_list[-1]+1
    tmp2 = p_list[0]-1
    for i, val in enumerate(p_list[pos+1:]):
      if val != p_list[pos + i] + 1:
        tmp1 = p_list[pos + i]+1
        break
    for i, val in enumerate(p_list[pos-1::-1]):
      if val != p_list[pos - i] - 1:
        tmp2 = p_list[pos - i]-1
        break
    if tmp1 - x < x - tmp2:
      print(tmp1)
    else:
      print(tmp2)
  else:
    print(x)

Measured memory_bytes: 9232
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, m, tot, c[N], a[N], head[N], nex[N], to[N], id[N];
void add(int u, int v, int i) {to[++tot] = v; nex[tot] = head[u]; head[u] = tot; id[tot] = i;}
bool vis[N];
int dis[N];
int ans;
struct node
{
	int u, x;
	node(int u = 0, int x = 0): u(u), x(x) {}
	bool operator<(const node&o)const
	{
		return x < o.x;
	}
};
priority_queue<node>q;
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	bool flag = false;
	for (int i = 1; i <= m; i++)
	{
		int u, v; scanf("%d%d", &u, &v);
		add(u, v, i); add(v, u, i);
		if (a[u] == a[v] && !vis[u] && !vis[v])
		{
			q.push(node(u, a[u]));
			q.push(node(v, a[v]));
			c[u] = 1; c[v] = 0;
			vis[u] = vis[v] = true;
			ans += 2;
			dis[i] = a[u];
			flag = true;
		}
	}
	if (!flag) {printf("-1\n"); return 0;}
	while (!q.empty())
	{
		node now = q.top(); q.pop();
		for (int i = head[now.u]; i; i = nex[i])
		{
			int v = to[i]; if (vis[v] || a[v] < now.x) continue;
			vis[v] = true; ans++;
			dis[id[i]] = a[v];
			c[v] = c[now.u] ^ 1;
			q.push(node(v, a[v]));
		}
	}
	if (ans != n) {printf("-1\n"); return 0;}
	for (int i = 1; i <= n; i++)
		putchar(c[i] ? 'B' : 'W');
	putchar('\n');
	for (int i = 1; i <= m; i++)
		printf("%d\n", !dis[i] ? 1000000000 : dis[i]);
}



Measured memory_bytes: 14456
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main()
{
	FAST;
	ll n, m, i, j, k;
	cin >> n >> m;
	ll ac[n+1];
	ll pen[n+1];
	fr(i,1,n+1)
	{
		ac[i] = 0;
		pen[i] = 0;
	}
	fr(i,0,m)
	{
		ll t1;
		string tmp;
		cin >> t1 >> tmp;
		if(ac[t1])
			continue;
		else
		{
			if(tmp[0] == 'A')
				ac[t1] = 1;
			else
				pen[t1]++;	
		}
	}
	ll ta = 0, tp = 0;
	fr(i,1,n+1)
	{
		if(ac[i])
		{
			ta++;
			tp += pen[i];
		}
	}
	cout << ta << " " << tp;
}


Measured memory_bytes: 1792
#include<stdio.h>
int n,a[10000],sum;
int main(void){
  scanf("%d",&n);
  for(int loop=1;loop<=n;loop++){
    scanf("%d",&a[loop]);
    while(a[loop]%2==0){
      a[loop]/=2;
      sum++;
    }
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 256
from itertools import count

def furthest(v0,N,adj):
    q = [v0]
    visited = [False]*N
    visited[v0] = True
    x = -1

    for dist in count():
        if not q:
            break
        x = q[0]
        nq = []
        for v in q:
            for u in adj[v]:
                if not visited[u]:
                    visited[u] = True
                    nq.append(u)
        q = nq
    return dist, x

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

for _ in range(N-1):
    a,b = map(int,input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)

d,v = furthest(0,N,adj)
# print(d,v)
d,v = furthest(v,N,adj)
# print(d,v)
# print(d)

print('First' if d != 0 and d%3 != 2 else 'Second')

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

int main() {
  
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<double> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  for (int i = 1; i < n; i++) {
    vec[i] = (double)(vec[i] + vec[i-1])/2.0;
  }
  cout << vec[n-1] << '\n';
}


Measured memory_bytes: 256
n = int(raw_input().rstrip())
a = map(int, raw_input().split())
a_odd = a[0::2]
a_even = a[1::2]
a_even.reverse()
a_even.extend(a_odd)
b = map(str, a_even)
if len(b) % 2 !=0:
    b.reverse()
print ' '.join(b)


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

using namespace std;

#define int long long

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    if (n % 2 == 0) {
        int x = 1, cnt = 0, ans = 0, lst = 0;
        while (x <= n) x *= 5, cnt++;
        for (int i = cnt; i >= 1; --i) {
            ans += n / (2 * x);
            x /= 5;
        }
        cout << ans << '\n';
    }
    else {
        cout << 0 << '\n';
    }
    return 0;
}



Measured memory_bytes: 256
n = gets.to_i
ans = Array.new(10**5, 0)

## x <= y <= zとする。

max_x = Math.sqrt(n/6).to_i + 1
max_y = Math.sqrt(n/3).to_i + 1
max_z = Math.sqrt(n).to_i + 1


(1..max_x).each do |x|
  (x..max_y).each do |y|
    (y..max_z).each do |z|
      result = x**2 + y**2 + z**2 + x*y + y*z + z*x
      if x == y && x == z
	      plus_cnt = 1
      elsif x == y || y == z || z == x
          plus_cnt = 3
      else
          plus_cnt = 6
      end
	      ans[result] += plus_cnt
    end
  end
end

(1..n).each do |i|
  puts ans[i]
end


Measured memory_bytes: 15120
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int board[400][400];
bool visited[400][400];
int H, W;
ll color[2];

const int BLACK = 0;
const int WHITE = 1;

void dfs(int x, int y){
    visited[x][y] = true;
    color[board[x][y]]++;
    for (int i=0;i<4;i++){
        if (0<=x+DX[i] && x+DX[i]<H && 0<=y+DY[i] && y+DY[i]<W){
            if (board[x][y]!=board[x+DX[i]][y+DY[i]])
                if (!visited[x+DX[i]][y+DY[i]])
                    dfs(x+DX[i],y+DY[i]);
            }
        }
    
}

void print_vector(vector<vector<int> > vector){
    for (int i = 0; i < vector.size(); i++){
        for (int j = 0; j < vector[i].size(); j++)
            cout << vector[i][j] << " ";
        cout << endl;
    }
}

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

    cin >> H >> W;
    string S;
    for (int h=0; h<H;h++){
        cin >> S;
        for (int w=0; w<W; w++){
            if (S[w]=='.'){
                board[h][w] = WHITE;
            }
        }
    }
    //print_vector(board);
    ll ans = 0;
    REP(h,H)REP(w,W){
        if (!visited[h][w]){
            color[BLACK] = 0;
            color[WHITE] = 0;
            dfs(h,w);
            ans += color[BLACK]*color[WHITE];

        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const int MX = 1005, mod = 1000000007;
int n, k, a[MX];
ll mem[22][MX], fac[MX], inv[MX];

ll pot (ll b, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= b) %= mod;
		(b *= b) %= mod;
		p /= 2;
	}
	return res;
}

ll comb (int n, int k) {
	if (n < k || n < 0 || k < 0) return 0;
	return fac[n] * inv[k] % mod * inv[n - k] % mod;
}

ll dp (int i, int j) {
	if (i == k) return j == 0;

	ll &res = mem[i][j];
	if (res != -1) return res;
	res = 0;

	for (int l = 0; l <= min(j, a[i]); l++)
		(res += comb(n - l, a[i] - l) * inv[l] % mod * dp(i + 1, j - l)) %= mod;

	return res;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	fac[0] = inv[0] = 1;
	for (int i = 1; i < MX; i++) {
		fac[i] = fac[i-1] * i % mod;
		inv[i] = pot(fac[i], mod - 2);
	}

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

	memset(mem, -1, sizeof(mem));
	cout << fac[n] * dp(0, n) % mod << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 200010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll dp[101][101010];
ll sum[101][101010];

int main(void) {
    ll N, K;
    cin >> N >> K;
    ll a[101];
    ll i, j;
    
    for(i=0; i<N; i++) {
        cin >> a[i];
    }
    
    
    dp[0][0]=1;
    sum[0][0]=0;
    for(i=1; i<=K+1; i++) sum[0][i]=1;
    
    for(i=1; i<=N; i++) {
        for(j=0; j<=K; j++) {
            dp[i][j]=sum[i-1][j+1]-sum[i-1][max(0, j-a[i-1])]+MOD;
            dp[i][j]%=MOD;
            sum[i][j+1]+=sum[i][j]+dp[i][j];
            sum[i][j+1]%=MOD;
        }
        
    }
    
    pr(dp[N][K]);
    
}
















Measured memory_bytes: 159616
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")



int main() {
    ll n, k;
    ll ans = 0;
    cin >> n >> k;

    vector<int> a(n);
    rep(i,n) cin >> a[i];

    rep(i,n){
        ll front = 0, back = 0;
        rep(j,i){
            if(a[j] > a[i]) front ++;
        }
        for(int j=i; j<n; j++){
            if(a[j] > a[i]) back ++;
        }
        ans += ((k * (k-1) / 2) % MOD) * (front + back) + front * k;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  if(n%2==0) cout << 0.5000 << endl;
  else{
    float z = n;
    int y = n/2+1;
    float x = y/z;
    cout << fixed << setprecision(8) << x << endl;
}
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a[n],b[n],c[n-1],ans=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		a[i]-=1;
	}
	for (int i = 0; i < n; ++i)
	{
		cin>>b[i];
		ans+=b[i];
	}
	for (int i = 0; i < n-1; ++i)
	{
		cin>>c[i];
	}
	for (int i = 0; i < n-1; ++i)
	{
		if (a[i]+1==a[i+1])
		{
			ans+=c[a[i]];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as np

A, B, C, D = map(int,input().split())

a = [0 for _ in range(100)]
b = [0 for _ in range(100)]

a[A:B] = [1 for _ in range(B - A)]
b[C:D] = [1 for _ in range(D - C)]

c = np.array(a) * np.array(b)

print(c.sum())

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

bool isPrime(int x)
{
  if(x == 2) return true;

  if(x < 2 || x%2 == 0) return false;

  int i = 3;
  while(i <= sqrt(x)) {
    if(x%i == 0) return false;
    i += 2;
  }
  return true;
}

int main() {
  int n, x, count = 0;
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> x;
    if(isPrime(x)) count++;
  }
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll dp[ohara];

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin >> n;
    rep(i,n+1)dp[i] = i;
    dp[0] = 0;
    rrep(i,6,n+1){
        for(ll j = 6; j <= i; j *= 6){
            dp[i] = min(dp[i - j] + 1, dp[i]);
        }
    }
    rrep(i,9,n+1){
        for(ll j = 9; j <= i; j *= 9){
            dp[i] = min(dp[i - j] + 1, dp[i]);
        }
    }
    Cout(dp[n]);
    return 0;
}


Measured memory_bytes: 1024
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let S: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };
    let T: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };
    let q: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let (a, b, c, d): (Vec<usize>, Vec<usize>, Vec<usize>, Vec<usize>) = {
        let (mut a, mut b, mut c, mut d) = (vec![], vec![], vec![], vec![]);
        for _ in 0..q {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            a.push(iter.next().unwrap().parse().unwrap());
            b.push(iter.next().unwrap().parse().unwrap());
            c.push(iter.next().unwrap().parse().unwrap());
            d.push(iter.next().unwrap().parse().unwrap());
        }
        (a, b, c, d)
    };

    // 並び替えは任意に可能
    // A, Bの個数は+1/+1または+3/+0または+0/+3できることを利用する
    let mut acc_S = vec![0; S.len() + 1];
    let mut acc_T = vec![0; T.len() + 1];
    for i in 0..(S.len()) {
        acc_S[i + 1] = if S[i] == 'A' {
            acc_S[i] + 1
        } else {
            acc_S[i]
        };
    }
    for i in 0..(T.len()) {
        acc_T[i + 1] += if T[i] == 'A' {
            acc_T[i] + 1
        } else {
            acc_T[i]
        };
    }
    let ans = (0..q).map(|i| {
            let a_s = (acc_S[b[i]] - acc_S[a[i] - 1]) as i64;
            let b_s = ((b[i] - a[i] + 1) as i64) - a_s;
            let a_t = (acc_T[d[i]] - acc_T[c[i] - 1]) as i64;
            let b_t = ((d[i] - c[i] + 1) as i64) - a_t;
            if b_t % 3 == (((b_s + (a_t - a_s))) % 3 + 3) % 3 {
                "YES"
            } else {
                "NO"
            }
        })
        .collect::<Vec<_>>()
        .join("\n");

    println!("{}", ans);
}


Measured memory_bytes: 14260
N = int(input())
A = list(map(int,input().split()))
cnt=0
flg=1
while flg:
    flg=0
    for i in range(N-1,0,-1):
        if A[i]<A[i-1]:
            A[i],A[i-1]=A[i-1],A[i]
            cnt+=1
            flg=1

[print(A[x],end=' ') for x in range(N-1)];print(A[N-1]);print(cnt)


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int x, a, b;
    cin >> x >> a >> b;
    if(abs(x - a) > abs(x - b)) cout << "B";
    else cout << "A";
    cout << endl;

    return 0;
}



Measured memory_bytes: 3616
import itertools
 
n = int(input())
H = list(map(int, input().split()))
 
count = 0
h_max = max(H)
for i in range(1, h_max + 1): #これが水位を上げる役割をしているのか
    watering = [(1 if h >= i else 0) for h in H] #これ以上いらないなら0　いるなら1
 
    itrs = itertools.groupby(watering)
    watering_group = [k for k, v in itrs if sum(list(v)) > 0] #ｋは要素の数字そのもの，連続するｋの並び
    count += sum(watering_group)

print(count)

Measured memory_bytes: 3064
a,b = map(int,input().split())
m = 0
if a<=0 and 0<=b:
    print('Zero')
elif a<0:
    if b < 0:
        m = a-b+1
    else:
        m = abs(a)
    if m%2:
        print('Negative')
    else:
        print('Positive')
else:
    print('Positive')

Measured memory_bytes: 9176
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let x = nextInt()
    if(400 <= x && x <= 599){
        console.log(8)
        return
    } else if(600 <= x && x <= 799){
        console.log(7)
        return
    } else if(800 <= x && x <= 999){
        console.log(6)
        return
    } else if(1000 <= x && x <= 1199){
        console.log(5)
        return
    } else if(1200 <= x && x <= 1399){
        console.log(4)
        return
    } else if(1400 <= x && x <= 1599){
        console.log(3)
        return
    } else if(1600 <= x && x <= 1799){
        console.log(2)
        return
    } else if(1800 <= x && x <= 1999){
        console.log(1)
        return
    }
     

}
Main()


Measured memory_bytes: 29672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1000000000+5;
const int N=2e5+5;
const ll oo=1e18+5;
const ll mod=1e9+7;

void add_self(int& a,int b){
	a+=b;
	if(a>=mod) a-=mod;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin>>n;
	vector<int> dp(n+5);
	dp[0]=1;
	for(int sum=3;sum<=n;++sum){
		for(int num=3;num<=sum;++num){
			if(sum-num>=0) add_self(dp[sum],dp[sum-num]);
		}
	}
	cout<<dp[n];
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i=(l); i<(r); ++i)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;
// get<K>(tuple型の変数)

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

    int N, K; cin >> N >> K;
    vector<ll> x(N), y(N);
    rep(i, 0, N) cin >> x[i] >> y[i];

    ll ans = (1LL<<62);
    rep(i, 0, N) rep(j, 0, N) rep(k, 0, N) rep(l, 0, N) {
        ll x1 = x[i], x2 = x[j];
        ll y1 = y[k], y2 = y[l];
        int cnt = 0;
        if(x2 <= x1 || y2 <= y1) continue;
        rep(m, 0, N) if(x1<=x[m] && x[m]<=x2 && y1<=y[m] && y[m]<=y2) cnt++;
        if(cnt>=K) chmin(ans, (x2-x1)*(y2-y1));
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
    std::vector<long> A(2);
    std::cin >> A[0] >> A[1];
    std::sort(A.begin(),A.end());
    if(A[0]==1 && A[1]==2){
        std::cout << 3 << std::endl;
    }else if(A[0]==1 && A[1]==3){
        std::cout << 2 << std::endl;
    }else{
        std::cout << 1 << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
 
using namespace std;


int main()
{ 
	int n,k;
	int r,s,p;
	cin>>n>>k>>r>>s>>p;
	string arr;
	cin>>arr;
	int scr=0;
	for(int i=0;i<k;i++){
		char cur=arr[i];
		int cnt=1;
		if(cur=='r')scr+=p;
		if(cur=='s')scr+=r;
		if(cur=='p')scr+=s;
		for(int j=i+k;j<n;j=j+k){
			if(arr[j]!=cur){
				cur=arr[j];
				cnt=1;
				if(cur=='r')scr+=p;
				if(cur=='s')scr+=r;
				if(cur=='p')scr+=s;
				continue;
			}
			else {
				cnt++;
				if(cnt%2==0)continue;
				if(cur=='r')scr+=p;
				if(cur=='s')scr+=r;
				if(cur=='p')scr+=s;
			}
		}
	}
	cout<<scr<<endl;		
	return 0;
}


	


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

#define INDEX (i * m + j)

int main() {
	int n, m,num;
	cin >> n >> m;
	int* matrix = new int[n*m];
	int* vec = new int[m];
	for (int i = 0; i < n; i++) {
	    for(int j = 0; j < m; j++){
	    	cin >> num;
	    	matrix[INDEX] = num;
	    }
	}
	for (int i = 0; i < m; i++) {
		cin >> num;
		vec[i] = num;
	}
	for (int i = 0; i < n; i++) {
		int c = 0;
		for (int j = 0; j < m; j++) {
			c += matrix[INDEX] * vec[j];
		}
		cout << c << endl;
	}
	delete[] matrix;
	delete[] vec;
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
using namespace std;
const int MAXC = 1001;

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

    int N, T; cin >> N >> T;
    int ans = MAXC;
    for (int i = 0; i < N; i++) {
        int c, t; cin >> c >> t;
        if (t <= T) ans = min(ans, c);
    }
    if (ans == MAXC)
        cout << "TLE\n";
    else
        cout << ans << "\n";
}

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

int main(void) {
  int N;
  cin >> N;
  int cnt = 0;

  for(int i = 1; i <= N; i++) {
    if( i < 10 ) {
      cnt++; // 1-9
    }
    else if( i > 99 && i < 1000) {
      cnt++; //100 - 999
    }
    else if( i > 9999 && i < 100000) {
      cnt++; //10000 - 99999
    }
  }
  cout << cnt << endl;
  
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,answer=INT_MAX;
  string S;
  cin >> N >> S;
  int E[N], W[N];
  W[0] = 0;
  E[N-1] = 0;
  for (int i = N-2; i+1; i--) {
    E[i] = E[i+1]+(S[i+1] == 'E');
  }
  for (int i = 1; i < N; i++) {
    W[i] = W[i-1]+(S[i-1] == 'W');
  }
  for (int i = 0; i < N; i++) {
    answer = min(answer,E[i]+W[i]);
  }
  cout << answer;
}

Measured memory_bytes: 6132
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if (b < 0){
		cout << max(a-b, a*b) << endl;
	}else{
		cout << max(a+b, a*b) << endl;
	}

	



	return 0;
}

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

#define llint long long int

using namespace std;

int main(){
    int N, K;

    cin >> N >> K;

    vector<int> H(N);

    for(int i = 0; i < N; i ++){
        cin >> H[i];
    }
    sort(H.begin(), H.end());

    llint sum = 0;

    for(int i = 0; i < N - K; i ++){
        sum += H[i];
    }
    cout << sum << endl;
}

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

#define int long long

signed main(){
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;

	priority_queue<pair<int,int> > h;

	while(a--){
		int w;
		cin>>w;
		h.push(make_pair(w,1));
	}
	
	while(b--){
		int w;
		cin>>w;
		h.push(make_pair(w,2));
	}
	
	while(c--){
		int w;
		cin>>w;
		h.push(make_pair(w,3));
	}
	
	int z=x+y;
	int ans=0;
	
	while(z){
		pair<int,int> f=h.top();
		h.pop();
		if(f.second==3){
			ans+=f.first;
			--z;
		}
		else if(f.second==1 && x){
			ans+=f.first;
			--x;
			--z;
		}
		else if(f.second==2 && y){
			ans+=f.first;
			--y;
			--z;
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10348
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			long[] a = new long[n+1];
			long[] b = new long[n];
			
			for(int i = 0 ; i < n+1; i++ ) {
				a[i] = sc.nextInt();
			}
			for(int i = 0 ; i < n ; i++ ) {
				b[i] = sc.nextInt();
			}
			
			long count = 0;
			for(int j = 0 ; j < n ; j++ ) {

				if ( a[j] < b[j]) {
					count += a[j];
					long rest = b[j] - a[j];
					if ( a[j+1] < rest ) {
						count+= a[j+1];
						a[j+1] = 0;
					}
					else {
						count+=rest;
						a[j+1] = a[j+1] - rest;
					}
				}
				else {
					count+= b[j];
				}
			}
			
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 89320
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
         break
    for i in range(H):
        for j in range(W):
            if i==0 or j==0 or i==H-1 or j==W-1:
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()
            


Measured memory_bytes: 7000
import java.util.*

fun main(args: Array<String>) {
    val a = readLine()!!.toInt()

    val prime = ArrayList<Int>()
    prime.add(2)

    var x = 3
    while (prime.last() < a) {
        if (isPrime(x, prime)) prime.add(x)
        x += 2
    }
    println(prime.last())
}

fun isPrime(a: Int, p: List<Int>): Boolean {
    return p.takeWhile { it * it <= a }.all { a % it != 0}
}

Measured memory_bytes: 41240
fun main(args: Array<String>) {
    val (m1, d1) = readLine()!!.split(' ').map { it.toInt() }
    val (m2, d2) = readLine()!!.split(' ').map { it.toInt() }
    println(if (d1 + 1 == d2) 0 else 1)
}

Measured memory_bytes: 36384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define vvl vector<vector<ll>>
#define vl  vector<ll>
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,W;
	cin>>N>>W;
	ll dp[N+1][W+1];
	ll weight[N],value[N];
	rep(i,0,N) cin>>weight[i]>>value[i];

	rep(w,0,W+1) dp[0][w]=0;
	rep(i,0,N){
		rep(w,0,W+1){
			if(w>=weight[i]){
				dp[i+1][w]=dp[i][w-weight[i]]+value[i];
              	if(dp[i][w]>dp[i+1][w])dp[i+1][w]=dp[i][w];
			}
			else{
				dp[i+1][w]=dp[i][w];
			}
		}
	}
	cout<<dp[N][W]<<endl;
	return 0;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e16;
const int N = 2e5 + 5;

map <LL,LL> dp[ N ];
int n;
LL a[ N ];

LL solve(int idx, int taken) {
  int need = n/2 - (n - idx + 1)/2;
  if (taken < need) return -INF;
  if (idx >= n) return taken == n/2 ? 0 : -INF;
  if (dp[idx].count(taken)) return dp[idx][taken];
  LL ret = -INF;
  ret = max(ret, solve(idx + 2, taken + 1) + a[idx]);
  ret = max(ret, solve(idx + 1, taken));
  return dp[idx][taken] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << solve(0, 0) << endl;
  return 0;
}


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

struct Node {
    int p, bro, l, r, deg = 0, dep, hei;
};
Node u[26];
void get_depth(int node, int depth){
    u[node].dep = depth;
    if(u[node].l != -1)get_depth(u[node].l, depth + 1);
    if(u[node].r != -1)get_depth(u[node].r, depth + 1);
}
int get_height(int node){
    int left = 0, right = 0;
    if(u[node].l != -1)left += get_height(u[node].l) + 1;
    if(u[node].r != -1)right += get_height(u[node].r) + 1;

    return u[node].hei = max(left, right);
}
int main(){
    int n; cin >> n;
    rep(i,n)u[i].p = u[i].bro = -1;
    rep(i,n){
        int id, left, right;
        cin >> id >> left >> right;
        u[id].l = left;
        u[id].r = right;
        if(left != -1){
            u[left].p = id;
            u[left].bro = right;
            u[id].deg++;
        }
        if(right != -1){
            u[right].bro = left;
            u[right].p = id;
            u[id].deg++;
        }
    }

    int root;
    rep(i,n)if(u[i].p == -1)root = i;
    get_depth(root, 0);
    get_height(root);

    rep(i,n){
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", i, u[i].p, u[i].bro, u[i].deg, u[i].dep, u[i].hei);
        if(i == root)printf("root");
        else if(u[i].deg == 0)printf("leaf");
        else printf("internal node");
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3216
n=int(input())
l=[]
for i in range(n):
    a=list(map(int,input().split()))
    l.append(a)
b=sorted(l,key=lambda x:x[1])
sum=0
flag=0
for i in b:
    sum+=i[0]
    if sum>i[1]:
        flag=1
if flag==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 55252
s = input()
if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
elif s == "SAT":
    print(1)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 5, INF = 0x3f3f3f3f;
int read() {
	int x = 0, f = 0; char ch = 0;
	while (!isdigit(ch)) f |= ch == '-', ch = getchar();
	while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}
int a[N][N], f[N];
int main() {
    int n = read();
    for (int i = 1; i <= n; i++)
    	for (int j = 1; j <= n; j++){
    		char c; scanf(" %c", &c); a[i][j] = c - '0';
    		if (!a[i][j] && i != j) a[i][j] = INF;
		}
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
    for (int i = 1; i <= n; i++) f[i] = a[1][i] & 1;
    int ans = -INF;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if ((a[i][j] & 1 == 0 && f[i] != f[j]) || (a[i][j] & 1 && f[i] == f[j])) {
                puts("-1");
                return 0;
            }
            ans = max(ans, a[i][j]);
        }
    }
    printf("%d\n", ans + 1);
    return 0;
}

Measured memory_bytes: 640
s = input()
t = input()
ls = len(s)
lt = len(t)

dp = [[-1 for _ in range(ls+1)] for _ in range(lt+1)]
dp[0] = [0] * (ls+1)

for i in range(lt+1):
  dp[i][0] = 0

for i in range(1,lt+1):
  for j in range(1,ls+1):
    if t[i-1] == s[j-1]:
      dp[i][j] = max((dp[i-1][j-1] + 1),(dp[i-1][j]))
    else:
      dp[i][j] = max((dp[i][j-1]),(dp[i-1][j]))

res = ""
while ls > 0 and lt > 0:
  if dp[lt][ls] == dp[lt][ls-1]:
    ls -= 1
  elif dp[lt][ls] == dp[lt-1][ls]:
    lt -= 1
  else:
    res = s[ls-1] + res
    ls -= 1
    lt -= 1

print(res)

Measured memory_bytes: 147948
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
// #define int long long    // %d=>%lld
#define pb push_back
#define INF 100000000
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;


char buf1[26+1];

signed main(){
    bool ans=1;
    scanf("%s", buf1);
    string s(buf1);

    for(int i = 0;i < s.length();i++){
        for(int j = i+1;j < s.length();j++){
            if(s[i] == s[j]){
                ans=0;
                goto out;
            }
        }
    }
out:
    if (ans) printf("yes\n");
    else printf("no\n");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
} 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  COMinit();
  int n,k;
  cin >> n >> k;
  for(int i=1;i<=k;i++){
    ll ans=COM(k-1,i-1)*COM(n-k+1,i)%MOD;
    cout << ans << endl;
  }
  return 0;     
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
	 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
#define clr(a) memset(a,0,sizeof(a))
#define umap unordered_map
#define uset unordered_set
#define fr first
#define sc second
#define pb push_back
#define M int(1e9+7)
#define endl '\n'	
#define largest(a,b,c) (a>b?(a>c? a:c):(b>c? b:c))
#define smallest(a,b,c) (a<b?(a<c? a:c):(b<c? b:c))	

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;

 
int main(){
	fast_io; cout_precision;
	int n;	cin >> n;	ll l[n];	for(int i=0; i<n; i++)	cin >> l[i];
	map <ll,ll> mp;
	ll res = 0;
	//for(int i=0; i<n; i++)	mp[l[i]]++;
	for(int i=0; i<n-2; i++){
		for(int j=i+1; j<n-1; j++){
			for(int k=j+1; k<n; k++){
				if(l[i] != l[j] && l[i] != l[k] && l[j] != l[k] && l[i]+l[j] > l[k] && l[k]+l[j] > l[i] && l[i]+l[k] > l[j] )	res++;
			}
		}
	}
	cout << res <<endl;

	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k, q;

    cin >> n >> k >> q;
    vector<ll> a(n, 0);

    rep(i, q)
    {
        ll tmp;
        cin >> tmp;
        a[tmp - 1] += 1;
    }

    rep(i, n)
    {
        a[i] = k - q + a[i];
        // cout << a[i] << endl;
        if (a[i] <= 0)
        {
            cout << "No" << endl;
            continue;
        }
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> S;
    REP(i, S.size() / 2) {
        if (S[i] != S[S.size() - i - 1]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384