akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(int i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(int i=(a);i<(n);i++)cout<<(arr)[i]<<' ';

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

int main(){
	fast;
	ll n, k;
	cin>>n>>k;
	ll a[n], dp[n];
	scan(a, 0, n);
	dp[0] = 0;
	dp[1] = abs(a[0]-a[1]);
	
	forn(i, 2, n){
		dp[i] = inf;
		forn(j, 1, k+1){
			dp[i] = min(dp[i], dp[i-j]+abs(a[i] - a[i-j]));
			if(i-j == 0){
				break;
			}
		}

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

Measured memory_bytes: 5220
import sys
input = sys.stdin.readline

N = int(input())
S = list(map(int, input().split()))

def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            tmp = A[i]
            A[i] = A[j]
            A[j] = tmp
    tmp = A[i+1]
    A[i+1] = A[r]
    A[r] = tmp
    return i + 1

r = partition(S, 0, N-1)

S = [str(x) for x in S]

print('{} [{}] {}'.format(' '.join(S[:r]), S[r], ' '.join(S[r+1:])))


Measured memory_bytes: 15676
#include<stdio.h>
#define N 20

int cur;

void goAble(char map[N][N],int h,int w,int x,int y){
  if(x<0 || w<=x || y<0 || h<=y) return ;
  if(map[y][x]=='#' || map[y][x]=='+') return ;

  map[y][x]='+';
  cur++;

  goAble(map,h,w,x-1,y);
  goAble(map,h,w,x+1,y);
  goAble(map,h,w,x,y-1);
  goAble(map,h,w,x,y+1);

  return ;
}

int main(void){
  int i,j;
  int w,h;
  char map[N][N];
  char hoge;
  int x,y;

  for(;;){
    scanf("%d%d",&w,&h);
    if(!w && !h) break;

    for(i=0;i<h;i++){
      scanf("%c",&hoge);
      for(j=0;j<w;j++){
        scanf("%c",&map[i][j]);
        if(map[i][j]=='@'){
          x=j;
          y=i;
        }
      }
    }

    cur=0;
    goAble(map,h,w,x,y);

    printf("%d\n",cur);
  }

  return 0;
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

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

    cout << a * b << endl;


    return 0;
}


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

int main() {
  int n,m,a;
  cin >> n >> m;
  int n_count = 1,m_count = 1;
  for(int i = n; i > n - 2; i--) {
    n_count *= i;
  }
  for(int i = m; i > m - 2; i--) {
    m_count *= i;
  }
  a = n_count / 2 + m_count / 2;
  cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <vector>
#include <utility>
#include <time.h>
#include <set>
#include <unordered_set>
#include <list>
#include <iterator>
#include <time.h>
#include <chrono>
#include <deque>
#include <cstdio>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <climits>
#include <tuple>
using namespace std;

#define ll long long
#define ldb long double

ll mod(ll a, ll b)
{
	return (b + (a % b)) % b;
}

ll subMod(ll a, ll b, ll M)
{
	return mod((mod(a, M) - mod(b, M)), M);
}

ll dayofweek(ll d, ll m, ll y)
{
	static ll t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
	y -= m < 3;
	return (y + y / 4 - y / 100 +
		y / 400 + t[m - 1] + d) % 7;
}

void test()
{

}

void solve()
{
	ll n;

	cin >> n;

	bool test = true;

	for (int i = 0; i < n; i++)
	{
		ll a;
		cin >> a;

		if (a % 2 == 0)
		{
			if (a % 3 != 0 && a % 5 != 0)
			{
				test = false;
			}
		}
	}

	if (test)
	{
		cout << "APPROVED";
	}
	else
	{
		cout << "DENIED";
	}
}

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

	//test();

	solve();

	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

vector<long long> result;
bool validate(const vector<vector<pair<int, int> > >& c2) {
  int n = c2.size();
  vector<int> visited(n);
  result.clear();
  result.resize(n);
  for (int i=0; i<n; i++) {
    if (visited[i]) continue;
    visited[i] = 1;
    queue<int> Q;
    result[i] = 0;
    Q.push(i);
    vector<int> cur;
    cur.push_back(i);
    long long low = 0;
    while (!Q.empty()) {
      int now = Q.front();
      low = min(low, result[now]);
      Q.pop();
      for (int i=0; i<c2[now].size(); i++) {
        int id = c2[now][i].first;
        int val = c2[now][i].second;
        if (visited[id] && result[now] + val != result[id]) return false;
        if (visited[id]) continue;
        visited[id] = 1;
        result[id] = result[now] + val;
        Q.push(id);
        cur.push_back(id);
      }
    }
    for (int j=0; j<cur.size(); j++)
      result[cur[j]] -= low;
  }
  return true;
}

int main()
{
  int R, C;
  cin >> R >> C;
  int N;
  cin >> N;
  vector<vector<pair<int, int> > > row(R), column(C);
  vector<int> rr, cc, aa;
  for (int i=0; i<N; i++) {
    int r, c, a;
    cin >> r >> c >> a;
    r --;
    c --;
    row[r].push_back(pair<int, int>(c, a));
    column[c].push_back(pair<int, int>(r, a));
    rr.push_back(r);
    cc.push_back(c);
    aa.push_back(a);
  }

  vector<vector<pair<int, int> > > c2(C), r2(R);
  for (int i=0; i<R; i++)
    for (int j=1; j<row[i].size(); j++) {
      int id1 = row[i][0].first;
      int sc1 = row[i][0].second;
      int id2 = row[i][j].first;
      int sc2 = row[i][j].second;
      c2[id1].push_back(pair<int, int>(id2, sc2 - sc1));
      c2[id2].push_back(pair<int, int>(id1, sc1 - sc2));
    }
  for (int i=0; i<C; i++)
    for (int j=1; j<column[i].size(); j++) {
      int id1 = column[i][0].first;
      int sc1 = column[i][0].second;
      int id2 = column[i][j].first;
      int sc2 = column[i][j].second;
      r2[id1].push_back(pair<int, int>(id2, sc2 - sc1));
      r2[id2].push_back(pair<int, int>(id1, sc1 - sc2));
    }
  if (!validate(c2)) {
    cout << "No" << endl;
    return 0;
  }
  vector<long long> c_res = result;
  if (!validate(r2)) {
    cout << "No" << endl;
    return 0;
  }
  vector<long long> r_res = result;

//  for (int i=0; i<C; i++) printf("%d ", c_res[i]); printf("\n");
//  for (int i=0; i<R; i++) printf("%d ", r_res[i]); printf("\n");

  for (int i=0; i<N; i++)
    if (c_res[cc[i]] + r_res[rr[i]] > aa[i]) {
      cout << "No" << endl;
      return 0;
    }

  cout << "Yes" << endl;
}


Measured memory_bytes: 21860
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

const int grey=1;
const int white=0;
const int black=-1;

const int maxn=100005;
int head[maxn+5],pos=0;
int color[maxn+5],id[maxn+5];
int n,m;

struct node
{
    int k;
    int next;
};
struct node G[2*maxn+5];

void add(int u,int v)
{
    G[++pos].k=v;
    G[pos].next=head[u];
    head[u]=pos;
}

void bfsvisit(int u,int k)
{
    color[u]=black;
    queue<int> q;
    q.push(u);
    id[u]=k;
    while(!q.empty())
    {
        int r=q.front();
        q.pop();
        for(int j=head[r];j;j=G[j].next)
        {
            int v=G[j].k;
            if(color[v]==white)
            {
                q.push(v);
                color[v]=black;
                id[v]=k;
            }
        }
    }
}

void bfs()
{
    memset(id,0,sizeof(id));
    memset(color,0,sizeof(color));
    int k=0;

    for(int i=0;i<n;i++)
    {
        if(color[i]==white)
        {
            bfsvisit(i,k++);
        }
    }
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        add(u,v);
        add(v,u);
    }

    bfs();
    int q,s,t;
    scanf("%d",&q);
    while(q--)
    {
        scanf("%d%d",&s,&t);
        if(id[s]==id[t])
            printf("yes\n");
        else printf("no\n");
    }
}

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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    cin >> n;
    ll ans = 1;
    vector<int> x(n);
    for (int i = 0;i < n;++i) cin >> x[i];
    int j = 0,r = -1;
    for (int i = 0;i < n;++i) {
        while (j < n) {
            r += 2;
            j++;
            if (r > x[j-1]) break;
        }
        (ans *= (r+1)/2) %= mod;
        r -= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
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;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int a,b; cin >> a >> b;
    cout << (a+b+1)/2 << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n)  for(int i=0;i<(n);++i)
#define ALL(x) (x).begin(),(x).end()
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3, y3, x4, y4;
  x3 = x2 - (y2 - y1);
  y3 = y2 + (x2 - x1);
  x4 = x1 - (y2 - y1);
  y4 = y1 + (x2 - x1);
  cout << x3;
  cout << ' ';
  cout << y3;
  cout << ' ';
  cout << x4;
  cout << ' ';
  cout << y4;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n, a[10101] = { 0, }; scanf ("%d", &n);
	for (int x = 1; x <= 100; x++) for (int y = 1; y <= 100; y++) for (int z = 1; z <= 100; z++){
		int v = x * x + y * y + z * z + x * y + y * z + z * x;
		if (v <= n) a[v]++;
	}

	for (int i = 1; i <= n; i++) printf ("%d\n", a[i]);

	return 0;
}

Measured memory_bytes: 3260
N, X = map(int, input().split())

a, p = [1], [1]
for i in range(N):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)

def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))


Measured memory_bytes: 3064
n = int(input())
c = 1
alphabet = [chr(ord('a') + i) for i in range(26)]
while n > 26**c:
    n -= 26**c
    c += 1
n -= 1

arg26 = []
n_dumy = n
while n_dumy>0:
    arg26.append(n_dumy%26)
    n_dumy = n_dumy//26

anslist = [alphabet[i] for i in arg26]
anslist.reverse()
if len(anslist) < c:
    anslist = [alphabet[0]]*(c - len(anslist)) + anslist
ans = ''.join(anslist)
print(ans)


Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N,A;
	cin>>N;
	for(int i=2;i<=9;i++)
	{
		if(N%i==0 && (N/i)<10)
		{
			cout<<"Yes";
			return 0;
		}
	}
	if(N==1)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 256
def main():
    N = int(input())
    a = list(map(int, input().split()))
    c1, c2, c3 = 0, 0, 0
    for ai in a:
        if ai == 1:
            c1+=1
        elif ai == 2:
            c2 += 1
        else:
            c3 += 1
    dp = [[[0]*(c1+c2+c3+1) for i in range(c2+c3+1)] for j in range(c3+1)]
    for i in range(c3+1):
        for j in range(c2+c3+1):
            for k in range(c1+c2+c3+1):
                if i+j+k>N:
                    continue
                if i>0 and j<c2+c3:
                    dp[i][j][k] += (i/N)*dp[i-1][j+1][k]
                if j>0 and k<c1+c2+c3:
                    dp[i][j][k]+=(j/N)*dp[i][j-1][k+1]
                if k>0:
                    dp[i][j][k]+=(k/N)*dp[i][j][k-1]
                if  i+j+k == 0:
                    continue
                dp[i][j][k]+=1
                dp[i][j][k]*=N/(i+j+k)
    print(dp[c3][c2][c1])
main()



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

using namespace std;

int main(void){
  vector<int > bingo(9);
  vector<int > bingoflag(9,0);
  for (int i = 0; i < 9; i++)
  {
    cin >> bingo[i];
  }

  vector<int > per;
  int n;
  cin >> n;

  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    int a; cin >> a;
    per.push_back(a);
  }

  for (int i = 0; i < 9; i++)
  {
    if(find(per.begin(), per.end(), bingo[i]) != per.end())
      bingoflag[i] = 1;
  }
  
  if(bingoflag[0]*bingoflag[1]*bingoflag[2] ||
     bingoflag[3]*bingoflag[4]*bingoflag[5] ||
     bingoflag[6]*bingoflag[7]*bingoflag[8]) {
       cout << "Yes" << endl;
   }else if(bingoflag[0]*bingoflag[3]*bingoflag[6] ||
     bingoflag[1]*bingoflag[4]*bingoflag[7] ||
     bingoflag[2]*bingoflag[5]*bingoflag[8]
   ) {
       cout << "Yes" << endl;
   }else if(
     bingoflag[0]*bingoflag[4]*bingoflag[8] ||
     bingoflag[2]*bingoflag[4]*bingoflag[6]
   ) {
       cout << "Yes" << endl;
   }else {
       cout << "No" << endl;
   }
    

  
  

  return 0;
}

Measured memory_bytes: 888
use std::io;
fn main() {
  let stdin = io::stdin();
  let mut buf = String::new();
  stdin
    .read_line(&mut buf)
    .expect("ERROR");
  let r: i64 = buf.trim().parse().unwrap();
  buf = String::new();
  stdin
    .read_line(&mut buf)
    .expect("ERROR");
  //println!("{}",buf);
  let g: i64 = buf.trim().parse().unwrap();

  println!("{}",2*g-r);
}


Measured memory_bytes: 4352
// ref: https://img.atcoder.jp/abc119/editorial.pdf
// ref: https://drken1215.hatenablog.com/entry/2019/02/24/224100

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int solve_rec(const int A, const int B, const int C,
              const vector<int>& vL, int i, int a, int b, int c)
{
    if(i==(int)vL.size()){
        if(a==0 || b==0 || c==0){ return INT_MAX-10000; }
        return abs(a-A) + abs(b-B) + abs(c-C) - 30;
    }
    
    int ret0 = solve_rec(A,B,C, vL, i+1, a      , b      , c      );
    int ret1 = solve_rec(A,B,C, vL, i+1, a+vL[i], b      , c      ) + 10;
    int ret2 = solve_rec(A,B,C, vL, i+1, a      , b+vL[i], c      ) + 10;
    int ret3 = solve_rec(A,B,C, vL, i+1, a      , b      , c+vL[i]) + 10;
    
    return min(min(ret0, ret1), min(ret2, ret3));
}

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    
    int N; int A, B, C; cin >> N >> A >> B >> C;
    vector<int> vL(N); for(int i=0; i<N; ++i){ cin>>vL[i]; }
    
    cout << solve_rec(A,B,C, vL, 0, 0, 0, 0) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;

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

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

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

// int rec(vector<vector<int>> &dp, vector<int> &daruma, int i, int j){
// 	if (dp[i][j] =! -1)
// 		return dp[i][j];
// 	if (j - i <= 1)
// 		return dp[i][j] = 0;
// 	if (abs(daruma[i]-daruma[j-1]) <= 1 && rec(dp,daruma,i+1,j-1) == (j-1)-(i+1)){
// 		return dp[i][j] = j - i;
// 	}
// 	dp[i][j] = 0;
// 	rep2(mid, i + 1, j)
// 	{
// 		dp[i][j] = max(dp[i][j], rec(dp,daruma,i,mid) + rec(dp,daruma,mid,j));
// 	}
// 	return dp[i][j];
// }

int main(){
	while(true){
		int n;
		cin >> n;
		if (n == 0)
			break;
		vector<int> daruma(n);
		rep(i, n) cin >> daruma[i];
		vector<vector<int>> dp(n+1, vector<int>(n+1, 0));
		// cout << rec(dp, daruma, 0, n) << endl;
		for(int W = 2;W <= n;W++)
		{
			for(int l = 0;l < n;l++)
			{
				int r = l + W;
				if(r > n) continue;

				if(dp[l + 1][r - 1] == W - 2 && abs(daruma[l] - daruma[r - 1]) <= 1)
					dp[l][r] = W;

				for(int mid = l;mid <= r;mid++)
				{
					dp[l][r] = max(dp[l][r] , dp[l][mid] + dp[mid][r]);
				}

			}

		}
		cout << dp[0][n] << endl;
	}
	return 0;
}


Measured memory_bytes: 3212
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bitset>
#define N 2020
using namespace std;
bitset<N*N> dp;
int n;
int main()
{
	scanf("%d",&n);
	int sum=0;
	dp[0]=1;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		sum+=x;
		dp |= (dp<<x);
	}
	int ans=(sum+1)/2;
	while(!dp[ans]) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <array>
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;

  vector<array<int, 4>> answers;
  int grid[H][W];
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      cin >> grid[h][w];
    }
  }

  for (int h = 0; h < H; h++) {
    for (int w = 1; w < W; w++) {
      if (grid[h][w-1]%2 == 1) {
        grid[h][w-1]--;
        grid[h][w]++;
        answers.push_back({h+1, w, h+1, w+1});
      }
    }
  }

  for (int h = 1; h < H; h++) {
    if (grid[h-1][W-1]%2 == 1) {
      grid[h-1][W-1]--;
      grid[h][W-1]++;
      answers.push_back({h, W, h+1, W});
    }
  }

  cout << answers.size() << endl;
  for (int i = 0; i < answers.size(); i++) {
    array<int, 4> ans = answers[i];
    cout << ans[0] << ' ' << ans[1] << ' ' << ans[2] << ' ' << ans[3] << endl;
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++)
    cin >> a.at(i);
  
  bool flag = true;
  for(int i=0; i<n; i++) {
    if(a.at(i) % 2 == 0) {
      if(a.at(i) % 3 != 0 && a.at(i) % 5 != 0) {
        flag = false;
        break;
      }
    }
  }
  if(flag)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define ENDL "\n"
#define PRINT(x) cout << (x) << ENDL

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


int N;
vector<pint> work;

signed main(){
    cin >> N;
    int A, B;
    REP(i, N){
        cin >> A >> B;
        work.push_back(pint(B, A));
    }
    sort(ALL(work));
    ll tm = 0;
    for(auto p : work){
        tm += p.second;
        if(tm > p.first){
            PRINT("No");
            return 0;
        }
    }
    PRINT("Yes");
    return 0;
}

Measured memory_bytes: 2420
def String2List(s):
    L = []
    flag = True
    l = len(s)
    for i in range(l):
        if s[i].isdigit() and flag:
            t = ""
            j = 0
            while s[i+j].isdigit():
                t += s[i+j]
                if i+j == l-1:
                    break
                j += 1
            L.append(t)
            flag = False

        elif not s[i].isdigit():
            L.append(s[i])
            flag = True

    return L


def Generate_RPN(L):
    S, L2 = [], []
    table = {"*": 1, "/": 1, "+": 0, "-": 0, "(": -1, ")": -1}
    for i in L:
        if i.isdigit():
            L2.append(i)
        elif i == "(":
            S.append(i)
        elif i == ")":
            while S[-1] != "(":
                L2.append(S.pop())
            S.pop()
        else:
            while len(S) != 0 and (table[S[-1]] >= table[i]):
                L2.append(S.pop())
            S.append(i)

    while len(S) != 0:
        L2.append(S.pop())

    return L2


def Calculate_RPN(L):
    St = []

    for i in L:
        if i == '+':
            St.append(int(St.pop()) + int(St.pop()))
        elif i == '-':
            St.append(-int(St.pop()) + int(St.pop()))
        elif i == '*':
            St.append(int(St.pop()) * int(St.pop()))
        elif i == '/':
            a = int(St.pop())
            b = float(St.pop())
            St.append(b/a)
        else:
            St.append(i)
 
    return St[0]


N = int(raw_input())

for i in range(N):
    s = raw_input()
    L = Generate_RPN(String2List(s[:-1]))
    print int(Calculate_RPN(L))

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

void dice_roll( int *dice, char i){
	if( i == 'W'){
		int tmp = dice[0];
		dice[0] = dice[1];
		dice[1] = dice[5];
		dice[5] = dice[4];
		dice[4] = tmp;
	}
	if( i == 'S'){
		int tmp = dice[0];
		dice[0] = dice[4];
		dice[4] = dice[5];
		dice[5] = dice[1];
		dice[1] = tmp;
	}
	if( i == 'D'){
		int tmp = dice[0];
		dice[0] = dice[3];
		dice[3] = dice[5];
		dice[5] = dice[2];
		dice[2] = tmp;
	}
	if( i == 'A'){
		int tmp = dice[0];
		dice[0] = dice[2];
		dice[2] = dice[5];
		dice[5] = dice[3];
		dice[3] = tmp;
	}
	if( i == 'd'){
		int tmp = dice[1];
		dice[1] = dice[2];
		dice[2] = dice[4];
		dice[4] = dice[3];
		dice[3] = tmp;
	}
}


int main(){
	/*
		0
	3	1	2	4
		5
	*/
	int dice[6];
	for(int i = 0; i < 6; i++) cin >> dice[i];
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		int u,f;
		cin >> u>>f;
		int cnt = 0;
		while(u != dice[0]){
			dice_roll(dice, 'W');
			cnt++;
			if(cnt == 4 )break;
		}
		if(cnt ==4){
			cnt = 0;
			while(u != dice[0]){
				dice_roll(dice, 'D');
			}
			while(f != dice[1]){
				dice_roll(dice, 'd');
			}
			cout << dice[2] << endl;
		}
		else {
			cnt = 0;
			while(f != dice[1]){
				dice_roll(dice, 'd');
			}
			cout << dice[2] << endl;
		}
	}
	return 0;
}




Measured memory_bytes: 3080
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
S = LS2()

# 左N個のマスをどう塗るかで半分全列挙

ans = 0
left = []
right = []
for i in range(2**N):
    red = []
    blue = []
    for j in range(N):
        if (i >> j) & 1:
            red.append(S[j])
        else:
            blue.append(S[j])
    red = ''.join(red)
    blue = ''.join(blue)
    left.append((red,blue))
for i in range(2**N):
    red = []
    blue = []
    for j in range(N):
        if (i >> j) & 1:
            red.append(S[j+N])
        else:
            blue.append(S[j+N])
    red,blue = blue,red
    red.reverse()
    blue.reverse()
    red = ''.join(red)
    blue = ''.join(blue)
    right.append((red,blue))

from operator import itemgetter

right = sorted(right,key = itemgetter(0,1))

from bisect import bisect_left,bisect

ans = 0
for i in range(2**N):
    ans += bisect(right,left[i]) - bisect_left(right,left[i])

print(ans)

Measured memory_bytes: 223272
k = int(input())
a, b = map(int, input().split())
count = a
ans = 0
while b > count:
    if count % k == 0:
        print("OK")
        ans = 1
        count = 10000
    else:
        count += 1
if ans == 0:
    if b % k == 0:
        print("OK")
    else:
        print("NG")


Measured memory_bytes: 61664
def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)

a,b=map(int,input().split())
print(lcm(a,b))

Measured memory_bytes: 38256
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
using namespace std;

long long  int gcd(long long int a,long long int b)
{
	for (;;)
	{
		if (a == 0) return b;
		b %= a;
		if (b == 0) return a;
		a %= b;
	}
}
long long int lcm(long long int a,long long  int b)
{
	 long long int  temp = gcd(a, b);

	return temp ? (a / temp * b) : 0;
}
int main()
{
	long long int a, b, c, d;
	cin >> a >> b >> c >> d;
	long long int sum = b - a + 1;
	long long int sumc = b / c - a / c;
	if (a%c == 0)sumc = sumc + 1;
	long long int sumd = b / d - a / d;
	if (a%d == 0)sumd = sumd + 1;
	long long int sumcd = b / lcm(c, d) - a / lcm(c, d);
	if (a%lcm(c,d) == 0)sumcd = sumcd + 1;
	sum = sum - (sumc + sumd - sumcd);
	cout << sum;

}

Measured memory_bytes: 384
#include <iostream>

int main()
{
  int A, B, K;
  std::cin >> A >> B >> K;
  int cnt = 0;
  int ans = 0;
  for (int i = A; i >= 0; i--)
  {
    if (A % i == 0)
    {
      if (B % i == 0)
      {
        ans = i;
        cnt++;
      }
    }
    if (cnt == K) break;
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        while (x + y > 0) {
            if (x > y) {
                int a = x;
                x = y;
                y = a;
            }
            System.out.println(x + " "+ y);
       x = scanner.nextInt();
            y = scanner.nextInt();

        }

    }
}


Measured memory_bytes: 34200
#include<cstdio>
#include<iostream>
using namespace std;
char a,b;
int main()
{
    cin>>a>>b;
    if(b=='H'&&a=='H')
    cout<<"H";
    if(b=='D'&&a=='H')
    cout<<"D";
    if(b=='H'&&a=='D')
    cout<<"D";
    if(b=='D'&&a=='D')
    cout<<"H";
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	String s = scan.next();
      	int counter = 0;
      	for(int i = 0; i < 3 ; i ++){
        	if(s.charAt(i) == s.charAt(i + 1)){
              counter++;
            }
        }
      if(counter >= 1){
      	System.out.print("Bad");
      }
      else{
      	System.out.print("Good");
      }
    
    }

}

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

#define	mp	make_pair
#define	pb	push_back
#define	h	first
#define	r	second

using namespace std;

typedef	pair<int,int>	pii;

vector< vector<int> > child;
vector<int> memo;
// max number of matrioshka which i-th matrioshka can have (i-th one is included)

int rec(int i)
{
	if(memo[i]!=-1)	return memo[i];

	int nmax=1;
	for(int j=0;j<child[i].size();j++)
		nmax=max(nmax,1+rec(child[i][j]));
	return memo[i]=nmax;
}

int main()
{
	while(1){
		vector<pii>	mat;
		int n;	cin>>n;
		for(int i=0,h,r;i<n;i++)	cin>>h>>r,mat.pb(mp(h,r));
		int m;	cin>>m;
		for(int i=0,h,r;i<m;i++)	cin>>h>>r,mat.pb(mp(h,r));
		if(n==0)	break;

		child=vector< vector<int> >(n+m);
		for(int i=0;i<n+m;i++){
			for(int j=0;j<n+m;j++){
				if(mat[i].h>mat[j].h && mat[i].r>mat[j].r)
					child[i].pb(j);
			}
		}

		memo=vector<int>(n+m,-1);
		int ans=0;
		for(int i=0;i<n+m;i++)	ans=max(ans,rec(i));
		cout<<ans<<endl;
	}

	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 100005;
bool pos[N];
int cnt[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m;
	cin>>n>>m;
	for(int i = 1; i <= n; i++){
		pos[i] = false;
		cnt[i] = 1;
	}
	pos[1] = true;
	for(int i = 1; i <= m; i++){
		int x, y;
		cin>>x>>y;
		if(pos[x]){
			if(cnt[x] == 1)pos[x] = false;
			pos[y] = true;
		}
		cnt[x]--;
		cnt[y]++;
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(pos[i])ans++;
	}
	cout<<ans<<endl;

	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0; i<n; i++){
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    cout << d.size() << endl;
    return 0;
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int a, b;
	cin >> a >> b;
	a *= pow(10, to_string(b).size());
	a += b;
	if (sqrt(a) == floor(sqrt(a))) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = Integer.parseInt(sc.next());
		if (d == 22){
			System.out.println("Christmas Eve Eve Eve");
		}else if(d == 23){
			System.out.println("Christmas Eve Eve");
		}else if(d == 24){
			System.out.println("Christmas Eve");
		}else {
			System.out.println("Christmas");
		}
	}
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
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; };

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

class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};



typedef tuple<ll, ll, ll> T;


int main(){
    int N, M; cin >> N >> M;
    UnionFind uni(N);
 
    for(int i=0; i<M; i++){
        int x,y,z; cin >> x >> y >> z;
        x--; y--;
        uni.connect(x, y);
    }
 
    map<int, int> mp;
    for(int i=0; i<N; i++) mp[uni.root(i)]++;
    cout << mp.size() << endl;

	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
ll table[1000][1000];
const ll mod =1000000007;

int main(){
    string s;
    cin >> s;
    int st=-1;
    int end=-1;
    for (int i =0;i < s.size();i++){
        if (i+1 < s.size()){
            if (s[i]==s[i+1]){
                st=i;
                end=i+1;
                break;
            }
        }
        if (i+2 < s.size()){
            if (s[i]==s[i+2]){
                st=i;
                end=i+2;
                break;
            }
        }
    }
    if (st==-1 && end==-1){
        cout << -1 << " " << -1 << endl;
    }
    else{
        st++;end++;
        cout << st  << " " << end << endl;
    }
    return 0;
}


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

#define I inline void 

using namespace std ; 

using ll = long long ; 
using ld = long double ; 

const int N = 2e6 + 7 ; 

// How interesting!

int n; 


int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	//freopen("in.in", "r" , stdin) ;

	ll a, b , c; 
	cin >> a >> b >> c; 
	ll x = ( a + b - 1) / b ; 
	cout<< c * x ; 
	return 0 ; 
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <memory>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

typedef pair<int, int> p;

int n;
vector<p> red;
vector<p> blue;

int main(int argc, char *argv[]) {
    scanf("%d", &n);
    int a, b;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &a, &b);
        red.push_back(p(a, b));
    }
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &a, &b);
        blue.push_back(p(a, b));
    }
    sort(red.begin(), red.end());
    sort(blue.begin(), blue.end());
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        int ymax = -1;
        int ind = -1;
        for (int j = 0; j < red.size(); ++j) {
            if (red[j].first < blue[i].first &&
                red[j].second < blue[i].second &&
                ymax < red[j].second)
            {
                ymax = red[j].second;
                ind = j;
            }
        }
        if (ind != -1) {
            ++cnt;
            red.erase(red.begin() + ind);
        }
    }
    printf("%d\n", cnt);
}


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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n/2))%mod)%mod;
    return power((a*a)%mod,n/2)%mod;
}*/
//const int md = 998244353;

int c[5];

signed main()
{
    showoff;
    int a1,b1,a2,b2,a3,b3;
    cin >> a1 >> b1 >> a2 >> b2 >> a3 >> b3;
    c[a1]++;
    c[a2]++;
    c[a3]++;
    c[b1]++;
    c[b2]++;
    c[b3]++;
    vector<int>v;
    v.pb(c[1]);
    v.pb(c[2]);
    v.push_back(c[3]);
    v.push_back(c[4]);
    sort(v.begin(),v.end());
    if(v[0] == 1 && v[1] == 1 && v[2] == 2 && v[3] == 2)cout << "YES";
    else cout << "NO";
}
//*->for large size of matrix take int not long long if possible......

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [(i32,i32,i32); n],
    }
    // annotate for rust-analyzer
    let a: Vec<(i32, i32, i32)> = a;

    let mut r = "Yes";
    let (mut pt, mut px, mut py) = (0, 0, 0);
    for (t, x, y) in a {
        let dt = t - pt;
        let dxy = x - px + y - py;
        if ((dt % 2).abs() != (dxy % 2).abs()) || !(-dt <= dxy && dxy <= dt) {
            r = "No";
            break;
        }
        pt = t;
        px = x;
        py = y;
    }

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


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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
using V = vector<int>;
using Vll = vector<ll>;
using Vstr = vector<string>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };
const int perm[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

bool isOK(V v, int index, int key) {
  if (v[index] >= key) return true;
  else return false;
}

int binary_search(V v, int key) {
  int left = -1;
  int right = (int)v.size();

  while (right - left > 1) {
    int mid = left + (right - left) / 2;

    if (isOK(v, mid, key)) right = mid;
    else left = mid;
  }

  return right;
}

/*
int prime[1001001];
bool is_prime[1001001];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < n; i++){
    if (is_prime[i]){
      prime[p++] = i;
      for (int j = 2*i; j < n; j+=i) is_prime[j] = false;
    }
  }
  return p;
}
*/

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

  int N;
  cin >> N;
  V A(N),B(N),C(N);
  REP(i,N) cin >> A[i];
  REP(i,N) cin >> B[i];
  REP(i,N) cin >> C[i];

  sort(ALL(A));
  sort(ALL(C));

  ll ans = 0;
  REP(i,N) {
    auto ra = lower_bound(ALL(A), B[i]);
    auto rc = upper_bound(ALL(C), B[i]);
    ll ia = distance(A.begin(), ra);
    ll ic = distance(C.begin(), rc);
    ans = ans + ia * (N - ic);
  }

  print(ans);
}



Measured memory_bytes: 4484
#include<iostream>
using namespace std;
int main()
{
    int i,n,m;
 	string t,s;
 	
    // 入力
    cin >>n>>m;
    
    if (n>=m){
    	for(i=0;i<n;i++){
    		s += std::to_string(m);
    	}
    }else{
        for(i=0;i<m;i++){
    		s += std::to_string(n);
    	}
    }
    // 出力
    cout <<s<< endl;
    return 0;
}


Measured memory_bytes: 256
import math

x, n = map(int, input().split())
p = list(map(int, input().split()))

ans = -1
dif = 10000
for i in range(102):
  if i in p: #含まれている時
    continue
  else:
    if abs(x - i) < dif:
      ans = i
      dif = abs(x - i)

print(ans)

Measured memory_bytes: 9176
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> temp(3);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> temp[j];
			temp[j] = pow(temp[j], 2);
		}
		sort(temp.begin(), temp.end());
		if (temp[0] + temp[1] == temp[2]) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
		return 0;
}


Measured memory_bytes: 3076
N = int(input())
x = 0

for i in range(1,N+1):

    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()



Measured memory_bytes: 5876
while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break

    count = 0
    start = n if n < x else x
    for a in range(start, 0, -1):
        if a >= x:
            continue
        for b in range(a - 1, 0, -1):
            if a + b >= x:
                continue
            for c in range(b - 1, 0, -1):
                if a + b + c == x:
                    count += 1
    print(count)

Measured memory_bytes: 6724
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

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

int main(){
    int Atmp,Btmp,AB,Xtmp,Ytmp;
    cin >> Atmp >> Btmp >> AB >> Xtmp >> Ytmp;
    int ans;
    int A,B,X,Y;
    X = min(Xtmp,Ytmp);
    Y = max(Xtmp,Ytmp);
    if(X==Xtmp){
        A = Atmp;
        B = Btmp;
    }else{
        A = Btmp;
        B = Atmp;
    }
    if(A+B>2*AB){
        ans = min(AB*2*X+B*(Y-X),AB*2*Y);
    }else{
        ans = A*X + B*Y;
    }
    cout << ans;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

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

	int n,m,c;
	cin>>n>>m>>c;
	vvi in(n+1,vi(m));
	rep(i,n+1)rep(j,m)cin>>in[i][j];
	int co=0;
	rep(i,n){
		int s=c;
		rep(j,m)s+=in[0][j]*in[i+1][j];
		if(s>0)co++;
	}
	cout<<co<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin >> a>>b>>c;
    if ((a==b)&&(b==c))
        cout << 1;
    else if ((a!=b)&&(a!=c)&&(c!=b))
        cout << 3;
    else
        cout <<2;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main()
{
	int n = 0;

	while(scanf("%d", &n) != EOF)
	{
		int sum = 0;

		for(int a = 0; a <= 9; a++)
		{
			for(int b = 0; b <= 9; b++)
			{
				for(int c = 0; c <= 9; c++)
				{
					for(int d = 0; d <= 9; d++)
					{
						if(a + b + c + d == n)
						{
							sum++;
						}
					}
				}
			}
		}

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

	return 0;
}

Measured memory_bytes: 1024