akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using grid = vector<vector<int>>;

const int inf = 10000;

void editgrid(queue<pair<int, int>> &q, grid &d, pair<int, int> current, int y, int x) {
  if (d.at(y).at(x) > d.at(current.first).at(current.second) + 1) {
    d.at(y).at(x) = d.at(current.first).at(current.second) + 1;
    q.emplace(y, x);
  }
}

int bfs(queue<pair<int, int>> &q, grid &d) {
  if (q.empty()) return inf;
  pair<int, int> current = q.front();
  q.pop();
  int y = current.first, x = current.second;
  if (y == d.size() - 2 && x == d.at(0).size() - 2) return d.at(y).at(x);
  editgrid(q, d, current, y, x + 1);
  editgrid(q, d, current, y, x - 1);
  editgrid(q, d, current, y + 1, x);
  editgrid(q, d, current, y - 1, x);
  bfs(q, d);
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s.at(i);
  grid d(h + 2, vector<int>(w + 2, -1));
  int white = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s.at(i).at(j) == '.') {
        d.at(i + 1).at(j + 1) = inf;
        white++;
      }
    }
  }
  queue<pair<int, int>> q;
  q.emplace(1, 1);
  d.at(1).at(1) = 0;
  int d_best = bfs(q, d);
  if (d_best == inf) {
    cout << -1 << endl;
  } else {
    cout << white - d_best - 1 << endl;
  }
}


Measured memory_bytes: 256
let n = read_int ()
let h n = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ps = h n
let qs = h n
let f n = [|1; 1; 2; 6; 24; 120; 720; 5040; 40320; 362880|].(n)
let g xs = Array.(let fs = make n true in fold_left (fun (i, s) x -> fs.(x - 1) <- false; let c = ref 0 in iteri (fun j b -> if b && j + 1 < x then incr c) fs; i + 1, s + !c * f (n - i)) (1, 0) xs |> snd)
let _ = Printf.printf "%d\n" @@ abs (g ps - g qs)

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
using namespace std;
typedef long long LL;
const int N = 1e5+7 , INF = 0x3f3f3f3f , MOD = 1e9+7;
const double PI = acos(0.0) * 2;
template<typename T1>
T1 gcd(T1 a , T1 b){ return b ? gcd(b,a%b) : a;}

vector<int> mp[N];
bool f[N];
int op[N];

int main(){
#ifdef LOCAL
    freopen("F:\\c++\\in.txt", "r", stdin);
//  freopen("F:\\c++\\out.txt","w",stdout);
#endif
    int n,x,y;
    scanf("%d",&n);
    scanf("%d",&x);
    mp[x].push_back(1);
    y = x;
    f[0] = 1;
    f[x] = 1;
    op[x] = -1;
    for(int i = 2 ; i <= n ; i++){
        scanf("%d",&x);
        op[i] = -1;
        mp[x].push_back(i);
    }

    queue<int> q;
    q.push(2);
    if( f[2] ){
        printf("1\n");
        q.pop();
        f[0] = 0;
    }
    op[2] = 1;
    while( !q.empty() ){
        y = q.front();q.pop();
        for(int i = 0 ; i < mp[y].size() ; i++){
            if( op[ mp[y][i] ] == -1 ){
                op[ mp[y][i] ] = op[y] + 1;
                if( f[ mp[y][i] ] ){
                    printf("%d\n",op[ mp[y][i] ]);
                    f[0] = 0;
                    while( !q.empty() ) q.pop();
                    break;
                }
                q.push(mp[y][i]);
            }
        }
    }
    if( f[0] )  printf("-1\n");
    return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  sort(all(v));
  double ans=v[0];
  rep(i,n-1){
    
    ans=(v[i+1]+ans)/2;
   // cout<<v[i]<<endl;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  char n;
  cin >> n;
  char m = n + 1;
  cout << m << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll one=0;
  ll n;ll k;
  cin>>n>>k;
  ll ar[n];
  for(ll i=0;i<n;++i){cin>>ar[i];}
  ll dp[n];
  dp[0]=0;
  for(ll i=1;i<n;++i)
  {
      ll mi=INT_MAX;
      for(ll j=i-1;j>=max(i-k,one);--j)
      {
          mi=min(dp[j]+abs(ar[i]-ar[j]),mi);
      }
      dp[i]=mi;
  }
  cout<<dp[n-1];
}


Measured memory_bytes: 5112
#include<iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdlib>

using namespace std;
int main(){

  while(true){
    string str;
    int m=0;
    int sum=0;

    cin >> str;
    if(str.compare("-") == 0) break;
    cin >> m;

    for(int i=0;i<m;i++){
      int tmp;
      cin >> tmp;
      sum +=tmp;
    }

    sum = sum % str.size();

    int idx=sum;
    for(int i=0;i<str.size();i++,idx++){
      if(idx >= str.size()) idx = 0;
      cout << str[idx];
    }
    cout << endl;

  }

}


Measured memory_bytes: 3196
#include<stdio.h>

int n, A[50];

int solve(int i, int m){
    if(m == 0) return 1;
    if(i >= n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m-A[i]);
    return res;
}

int main(){
    int q, M, i;

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

    scanf("%d", &q);
    for(i=0; i<q; i++){
        scanf("%d", &M);
        if(solve(0, M)) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <bitset>
#include <queue>

using namespace std;
#define rep(i, n) for(i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
typedef long long ll;

struct rest{
    int id;
    int point;
    string city;

    bool operator<(const rest& ano) const {
        if(city != ano.city) {
            return city < ano.city;
        }
        return point > ano.point;
    }
};

int main() {
    int n;
    cin >> n;
    vector<rest> r(n);
    int i;
    rep(i, n) {
        string a;
        int b;
        cin >> a >> b;
        r[i] = rest{i+1, b, a};
    }
    sort(all(r));
    rep(i, n) {
        cout << r[i].id << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
using namespace std;
typedef long long ll;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
int main(){
	int n;
	cin>>n;
	ll sum=0;
	ll s=0;
	ll a[200010];
	rep(i,0,n){
		cin>>a[i];
		a[i]-=(i+1);
	
	}
	sort(a,a+n);
	ll ans=0;
	rep(i,0,n){
		ans+=abs(a[i]-a[n/2]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <bitset>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";}
template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";}
template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;

int main() {
  ll n,c; cin>>n>>c;
  ll a[n], b[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];
  ll x[n][c+1]; fill(x[0],x[n],0);
  for(int i=0;i<n;i++) {
    for(ll j=a[i];j<=b[i];j++) {
      ll su = 1;
      for(int k=0;k<=c;k++) {
        x[i][k] += su; x[i][k] %= M;
        su *= j; su%=M;
      }
    }
  }
  ll dp[n+1][c+1]; fill(dp[0], dp[n+1],0);
  dp[0][0]=1;

  for(int i=0;i<n;i++) {
    for(int j=0;j<=c;j++) {
      for(int k=j;k<=c;k++) {
        dp[i+1][k] += dp[i][j] * x[i][k-j];
        dp[i+1][k] %= M;
      }
    }
  }
  /*
  for(int i=0;i<=n;i++) {
    for(int j=0;j<=c;j++) {
      cout<<dp[i][j]<<" ";
    } cout<<endl;
  } cout<<endl;*/
  cout<<dp[n][c]<<endl;
}
// Thank you for making problems and running the contest

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
#define PB push_back
#define MP make_pair
#define ln "\n"
#define forn(i,e) for(ll i=0; i<e; i++)
#define forsn(i,s,e) for(ll i=s; i<e; i++)
#define rforn(i,e) for(ll i=e; i>=0; i--)
#define rforsn(i,s,e) for(ll i=e; i>=s; i--)
#define vasort(v) sort(v.begin(), v.end())
#define vdsort(v) sort(v.begin(), v.end(),greater<int>())
#define F first
#define S second

#define out1(x1) cout << x1 << ln
#define out2(x1,x2) cout << x1 << " " << x2 << ln
#define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << ln
#define out4(x1,x2,x3,x4) cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
#define out5(x1,x2,x3,x4,x5) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
#define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

#define in1(x1) cin >> x1
#define in2(x1,x2) cin >> x1 >> x2
#define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
#define in4(x1,x2,x3,x4) cin >> x1 >> x2 >> x3 >> x4
#define in5(x1,x2,x3,x4,x5) cin >> x1 >> x2 >> x3 >> x4 >> x5
#define in6(x1,x2,x3,x4,x5,x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

#define arrin(a,n) forn(i,n) cin >> a[i];
#define arrout(a,n) forn(i,n) {cout << a[i] << " ";} cout << ln;

#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main() {
    ll a,b;
    in2(a,b);
    out1(a*b);


    return 0;
}

Measured memory_bytes: 3600
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 

N, Q = map(int, input().split())

T = [[]for i in range(N)]

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

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

# def dfs(x, p):
#     for j in T[x]:
#         if j == p:
#             continue
#         X[j] += X[x]
#         dfs(j, x)
def dfs(nownode,oya=-1):
    for nextnode in T[nownode]:
        if oya == nextnode:
            continue
        X[nextnode] += X[nownode]
        dfs(nextnode,nownode)

dfs(0, -1)

print(*X)


Measured memory_bytes: 268424
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    val P = IntArray(N)
    
    for (i in 0 until N) {
        P[i] = readInputLine().toInt() - 1
    }
    
    val Q = IntArray(N)
    
    for (i in 0 until N) {
        Q[P[i]] = i
    }
    
    var longest = 1
    
    var cnt = 1
    
    for (i in 1 until N) {
        if (Q[i] < Q[i - 1]) {
            longest = Math.max(cnt, longest)
            cnt = 1
        } else {
            cnt++
        }
    }
    
    longest = Math.max(cnt, longest)
    
    println(N - longest)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 40956
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(x) (x).begin(), (x).end()
int main() {
  string s;
  cin >> s;
  string ans="";
  for (int i=0; i<s.size(); i++) {
    if (s[i] == 'B' && ans.size() > 0) {
      ans.pop_back();
    } else if (s[i] != 'B') {
      ans.push_back(s[i]);
    }
  }
  for(int i=0; i<ans.size(); i++) cout << ans[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
	int a[3][3];
	cin >> a[0][0] >> a[0][1] >> a[1][1];
	range(i,max(a[0][0] + a[0][1], a[0][1] + a[1][1]),10000000){
		a[0][2] = i - a[0][0] - a[0][1];
		a[2][1] = i - a[0][1] - a[1][1];

		a[2][0] = i - a[0][2] - a[1][1];
		a[1][0] = i - a[0][0] - a[2][0];

		a[1][2] = i - a[1][0] - a[1][1];
		a[2][2] = i - a[2][0] - a[2][1];

		if(a[2][0] + a[2][1] + a[2][2] == i && a[0][0] + a[1][1] + a[2][2] == i){
			rep(x,3){
				rep(y,3){
					if(y) cout << ' ';
					cout << a[x][y];
				}
				cout << endl;
			}
			return 0;
		}
	}
	assert(false);
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j) vector<vector<ll>> name(i,vector<ll>(j))
#define vec2f(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k)))
#define vec3f(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define vec4(name,i,j,k,l) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l))))
#define vec4f(name,i,j,k,l,m) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l,m))))
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

int main(){
    vector<ll> a(5);
    REP(i,5) cin >> a[i];
    REP(i,5){
        if (a[i]!=i+1) {
            cout << i+1 << endl;
            break;
        }
    }
}

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

using namespace std;

const int max_n = 55, inf = 1000111222;

int n, a[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            swap(a[i], a[j]);
            bool ok = true;
            for (int k = 0; k + 1 < n; ++k) {
                if (a[k] > a[k + 1]) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                cout << "YES" << endl;
                return 0;
            }
            swap(a[i], a[j]);
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define in insert
#define all(x) x.begin(),x.end()
#define zapp ios::sync_with_stdio(false);cin.tie(0)
const int MAXN = 1e5 + 5;

void constructXOR(ll A[], ll n)
{
	ll XOR = 0;
	for (ll i = 0; i < n; i++)
		XOR ^= A[i];
	for (ll i = 0; i < n; i++)
		A[i] = XOR ^ A[i];
}

int main()
{
	zapp;
	ll n;
	cin >> n;
	ll a[n], i;
	for (i = 0; i < n; i++)
		cin >> a[i];
	constructXOR(a, n);
	for (i = 0; i < n; i++)
		cout << a[i] << " ";

	return 0;
}



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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

#define MOD (long long)(1e9+7)
#define MAX_VAL (int)(1e5)

long long fac[MAX_VAL], mmi[MAX_VAL];

void factorial_mod(){
	 fac[0]=fac[1]=1;
	for(long long i = 2; i < MAX_VAL; fac[i]%=MOD,i++)
		fac[i] = fac[i-1]*(i%MOD);
}

long long power(long long x, long long n){
	long long ans = 1;
	for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
		if(n&1)ans*=x;
	return ans%MOD;
}

void exgcd(int a, int b, int &x, int &y){
	if(b == 0){
		x = 1;
		y = 0;
		return ;
	}
	exgcd(b,a%b,y,x);
	y -= a/b * x;
}

void modular_multiplicatibe_inverse(){
	int x, y;  
	exgcd(fac[MAX_VAL-1],MOD,x,y);
	mmi[MAX_VAL-1] = x;
	for(long long i = MAX_VAL-2; i >= 0; mmi[i]%=MOD,i--)
		mmi[i] = mmi[i+1]*((i+1)%MOD);
}

long long combination(long long n, long long r){
	if(n < r) return 0;
	return fac[n]*(mmi[r]*mmi[n-r]%MOD)%MOD;
}

signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	int N, K;
	
	factorial_mod();
	modular_multiplicatibe_inverse();
	
	
	cin>>N>>K;

	for(int i = 1; i <= K; i++){
		int ans = 1;

		ans = combination((N-K) + 1, i);
		// ans = ans*power(i,K - i);
		ans = ans*combination(K-i + i-1, i-1);
		// cout<<K-i + i-1<<" "<<i<<endl;
		cout<<ans%MOD<<endl;
	}
	
	return 0;
}

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

int main() {
  string a,b;
  cin>>a>>b;
  int x,y;
  if(a=="H") x=0;
  else x=1;
  if(b=="H") y=0;
  else y=1;
  int z =x^y;
  if(z==0) cout<<"H"<<endl;
  else cout<<"D"<<endl;


  }


Measured memory_bytes: 256
#![allow(non_snake_case)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        n: usize,
        mut l: [isize; n],
    );
    l.sort();
    let mut sum = 0;
    for i in 0..n {
        let a = l[i];
        for j in (i+1)..n {
            let b = l[j];
            for k in (j+1)..n {
                let c = l[k];
                if a + b <= c {
                    break;
                }
                sum += 1;
            }
        }
    }
    println!("{}", sum);
}


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


int main()
{
	vector<vector<int> > A(3, vector<int>(3));
	int N;
	
	rep(i, 3) {
		rep(j, 3) {
			cin >> A.at(i).at(j);
		}
	}
	cin >> N;
	vector<int> B(N);
	int S;
	vector<vector<bool> > buf(3, vector<bool>(3,false));
	rep(k, N) {
		cin >> S;
		rep(i, 3) {
			rep(j, 3) {
				if (A.at(i).at(j) == S) {
					buf.at(i).at(j) = true;
				}
			}
		}
	}
	rep(i, 3) {
		if (buf.at(i).at(0) && buf.at(i).at(1) && buf.at(i).at(2))
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	rep(i, 3) {
		if (buf.at(0).at(i)&& buf.at(1).at(i)&& buf.at(2).at(i))
		{
			cout << "Yes" << endl;
			return 0;
		}
	}

	if (buf.at(0).at(0)&& buf.at(1).at(1)&& buf.at(2).at(2))
	{
		cout << "Yes" << endl;
		return 0;
	}

	if (buf.at(0).at(2) && buf.at(1).at(1) && buf.at(2).at(0)) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3560
#!/usr/bin/env python3
n, k = map(int, input().split())
s = input()
li = [0] * n
ans = 0
for i in range(n - 1):
    if s[i] == s[i + 1]:
        ans += 1
    else:
        li[i + 1] += 1
    li[i + 1] += li[i]
for i in range(n):
    li[i] //= 2
ans += 2 * min(li[-1], k)
if s[0] != s[-1] and li[-1] < k:
    ans += 1
print(ans)


Measured memory_bytes: 7156
def chk_all(A):
	s_A = set(A)
	B = list(s_A)
	leng = len(s_A)
	if leng == 2:
		if A.count(B[0]) == 4 or A.count(B[1]) == 4:
			return "four card"
		else:
			return "full house"
	elif leng == 3:
		if A.count(B[0]) == 3 or A.count(B[1]) == 3 or A.count(B[2]) == 3:
			return "three card"
		else:
			return "two pair"
	elif leng == 4:
		return "one pair"
	else:
		A = sorted(A)

		if A[0] == 1 and A[1] == 10 and A[2] == 11 and A[3] == 12 and A[4] == 13:
			return "straight"

		for i in range(1,5):
			if A[i] - A[i-1] != 1:
				return "null"

		return "straight"

	return "null"

if __name__ == '__main__':

	while True:
		try:
			A = list(map(int,input().split(",")))
			print(chk_all(A))

		except EOFError:
			break




Measured memory_bytes: 5600
from collections import deque


# (sx, sy) から (gx, gy) への最短距離を求める
# 辿り着けないと INF
def bfs():
    # すべての点を INF で初期化
    #d = [[10 ** 12] * w for i in range(h)]
    d = []
    for i in range(h):
        d.append([10 ** 12] * w)

    # 移動4方向のベクトル
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    # スタート地点をキューに入れ、その点の距離を0にする
    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0

    # キューが空になるまでループ
    while que:
        # キューの先頭を取り出す
        p = que.popleft()
        # 取り出してきた状態がゴールなら探索をやめる
        if p[0] == gx and p[1] == gy:
            break
        # 移動4方向をループ
        for i in range(4):
            # 移動した後の点を (nx, ny) とする
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            # 移動が可能かの判定とすでに訪れたことがあるかの判定
            # d[nx][ny] != INF なら訪れたことがある
            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == 10 ** 12:
                # 移動できるならキューに入れ、その点の距離を p からの距離 +1 で確定する
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gx][gy]


h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]

count = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            count += 1
if count == 400:
    print(38)
    exit()

ans = 0
for sx in range(h):
    for sy in range(w):
        if maze[sx][sy] == ".":
            for gx in range(h):
                for gy in range(w):
                    if sx == gx and sy == gy:
                        continue
                    if maze[gx][gy] == ".":
                        ans = max(ans, bfs())

print(ans)


Measured memory_bytes: 58332
var input = require('fs').readFileSync('/dev/stdin', 'utf8');

var n = Number(input);

var result = [];

for (var i = 1; i <= n; i++) {
    if (i % 3 === 0 ){
        result.push(i);
        continue;
    }

    var x = i;
    while(x) {
        if (x % 10 === 3) {
            result.push(i);
            break;
        }
        x = Math.floor( x / 10);
    }
}
    console.log(" " + result.join(" "));





Measured memory_bytes: 16820
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k;
  cin >> n >> k;
  if (n == 1) {
    cout << k << endl;
    return 0;
  }
  long long int ans = k;
  for (int i=0; i<n-1; i++) {
    ans *= k-1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI pair<int,int>
#define mp make_pair
inline ll read(){
	bool pos=1; ll x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar())if(ch=='-')pos=0;
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	return pos?x:-x;
}
void write(ll x){
	if(x<0){
		x=-x; putchar('-');
	}
	if(x>=10)write(x/10);
	putchar(x%10+'0');
}
void writeln(ll x){
	write(x); puts("");
}
const int N=500005;
int n,k,rd[N],ans[N],pos[N],tree[N<<2];
priority_queue<int> q;
vector<int> v[N];
void insert(int l,int r,int pos,int de,int nod){
	if(l==r){
		tree[nod]=de; return;
	}
	int mid=(l+r)>>1;
	if(pos<=mid)insert(l,mid,pos,de,nod<<1);
	else insert(mid+1,r,pos,de,nod<<1|1);
	tree[nod]=max(tree[nod<<1],tree[nod<<1|1]);
}
int ask(int l,int r,int i,int j,int nod){
	if(i>j)return 0;
	if(l==i&&r==j)return tree[nod];
	int mid=(l+r)>>1;
	if(j<=mid)return ask(l,mid,i,j,nod<<1);
	else if(i>mid)return ask(mid+1,r,i,j,nod<<1|1);
	else return max(ask(l,mid,i,mid,nod<<1),ask(mid+1,r,mid+1,j,nod<<1|1));
}
int main(){
	n=read(); k=read();
	for(int i=1;i<=n;i++)pos[read()]=i;
	for(int i=1;i<=n;i++){
		int x=ask(1,n,max(pos[i]-k+1,1),pos[i]-1,1);
		if(x){v[pos[i]].push_back(pos[x]); rd[pos[x]]++;}
		x=ask(1,n,pos[i]+1,min(pos[i]+k-1,n),1);
		if(x){v[pos[i]].push_back(pos[x]); rd[pos[x]]++;}
		insert(1,n,pos[i],i,1);
	}
	for(int i=1;i<=n;i++)if(rd[i]==0)q.push(i);
	for(int i=n;i;i--){
		int t=q.top();
		q.pop();
		ans[t]=i; 
		for(unsigned j=0;j<v[t].size();j++){
			if(--rd[v[t][j]]==0){
				q.push(v[t][j]);
			}
		}
	}
	for(int i=1;i<=n;i++){
		write(ans[i]); putchar(' ');
	}
}
/*
每次找一个最大位置使得可以和当前所有数换 
to1 to2 to3 to4 to5 to6
 4 6
x->y 连边当且仅当 x>y并且abs(ax-ay)<k 
发现只需要连O(n)条边
线段树+堆支持即可 
//为出题人点赞 
8 3
4 5 7 8 3 1 2 6

*/ 

Measured memory_bytes: 42624
s = input()
def check(substr):
    ret = 0
    for i in range(len(substr)):
        if substr[i] !='A' and substr[i] !='C' and substr[i] != 'G' and substr[i] !='T':
            return 0
        else:
            ret +=1
    return ret
ans = 0
for i in range(len(s)):
    for j in range(i,len(s)+1):
        sub = s[i:j]
        ans = max(ans, check(sub))
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
lint gcd(lint a, lint b) {
  if(a < b) {
    swap(a, b);
  }
  while(b > 0) {
    lint r = a % b;
    a = b;
    b = r;
  }
  return a;
}
lint lcm(lint a, lint b) {
  return a * b / gcd(a, b);
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  REP(t, T) {
    lint A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A < B || D < B) {
      cout << "No" << "\n";
      continue;
    }
    if(C >= B-1) {
      cout << "Yes" << "\n";
      continue;
    }
    lint g = gcd(B, D);
    A = A % g;
    lint cnt = (B-1-A)/g;
    yes(A+cnt*g <= C);
  }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <list>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

#define xx first
#define yy second
#define $1 first
#define $2 second

void solve() {
	int n; cin >> n;
	map<int, int> mp;
	for (int i = 2; i <= n; i++) {
		int t; cin >> t;
		mp[t]++;
	}
	for (int i = 1; i <= n;i++) {
		cout << mp[i] << "\n";
	}
}
int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	solve();
}

Measured memory_bytes: 12976
n,m=map(int,input().split())
if n>m:
	n,m=m,n
if n==m:
	ans=2
elif n==m-1:
	ans=1
else:
	ans=0
mod=10**9+7
if ans!=0:
	for i in range(1,n+1):
		ans=(ans*i)%mod
	for i in range(1,m+1):
		ans=(ans*i)%mod
	print(ans)
else:
	print(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;int n;long long s[110000];bool F(long long key){for(int i=1;i<n;i++){long long* f=lower_bound(s+i,s+n+1,key+s[i-1]);long long* g=lower_bound(f,s+n+1,key+*f);if(*g&&*g+key-s[i-1]<=s[n])return 1;}return 0;}int main(){cin>>n;s[0]=0;for(int i=0;i<n;i++){cin>>s[i+1];s[i+1]+=s[i];}long long l=0,r=s[n]/3+1,m,a=0;while(l<r){m=(l+r)/2;if(F(m))l=m+1,a=max(a,m);else r=m;}cout<<a<<endl;return 0;}

Measured memory_bytes: 3880
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
 
const int N = 2e5 + 5;
const int mod = 1e7 + 7;
const int INF = 1e15;
const int LG = 21;

int arr[N];
int n, m, k;
vector<string> v1, v2;
int cnt[N];

int p[N];
int q[N];
int r[N];

void solve()
{
	int n;
	cin >> n;
	int left = n % 500;
	cout << (left / 5) * 5 + (n / 500) * 1000 << endl;
}

 
int32_t main()
{	
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

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

typedef long long int lli;

int main() {
	lli N, K;
	cin >> N >> K;
	lli max_val = K;

	vector<lli> A(N);
	for (auto& i : A) {
		cin >> i;
		max_val = max(max_val, i);
	}

	lli d = 1LL;
	while ((d << 1) < max_val) {
		d <<= 1;
	}

	lli x = 0;
	lli fx = 0;
	while (d > 0) {
		lli count = 0;
		for (int i = 0; i < N; i++) {
			if (d & A[i]) count++;
		}

		if (count <= N - count && x + d <= K) {
			x += d;
			fx += d * (N - count);;
		} else {
			fx += d * count;
		}

		d /= 2LL;
	}

	cout << fx << endl;

	return 0;
}


Measured memory_bytes: 1024
from heapq import *
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
G=[[] for i in range(3*N)]
for i in range(M):
    u,v=map(int,input().split())
    u,v=u-1,v-1
    G[3*u+0].append([3*v+1,0])
    G[3*u+1].append([3*v+2,0])
    G[3*u+2].append([3*v+0,1])
S,T=map(int,input().split())
INF=10**9+7
def dijkstra(G,s):

  d=[INF]*(3*N)
  d[s]=0
  visited={s}
  que=[(0,s)]
  while(que):
    p=heappop(que)
    v=p[1]
    visited.add(v)
    for node,cost in G[v]:
      if (node not in visited) and d[node]>d[v]+cost:
        d[node]=d[v]+cost
        heappush(que,(d[node],node))
  return d
d=dijkstra(G,(S-1)*3)
if d[(T-1)*3]==INF:
  print(-1)
else:
  print(d[(T-1)*3])


Measured memory_bytes: 125648
m, d = map(int, input().split())

cnt = 0
for j in range(1, m+1):
    for i in range(22, d+1):
        d1 = i % 10
        d10 = i // 10

        if d1 * d10 == j and d1 >= 2 and d10 >= 2:
            cnt += 1

print(cnt)


Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int a, b; 
	scanf("%d %d",&a, &b);
	if((a + b) % 2 == 0)
	{
		printf("%d\n",(a + b) / 2);
	}
	if((a + b) % 2 != 0)
	{
		printf("%d\n", ((a + b) / 2)+ 1);
	}
}
	

Measured memory_bytes: 128
// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  if(/A/.test(input) && /B/.test(input)){
    console.log('Yes')
  }else{
    console.log('No')
  }

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21956
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    map<char, int> mp;
    rep(i, n) {
        char ch; cin >> ch;
        mp[ch]++;
        
    }
    if (mp.size() == 3) {
        cout << "Three" << endl;
    } else {
        cout << "Four" << endl;
    }
    
}




Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 1000)
	sc.Buffer(buf, 100000000)

	for i := 0; i < 2; i++ {
		sc.Scan()
	}
	listA := strings.Split(sc.Text(), " ")
	for i := 0; i < 2; i++ {
		sc.Scan()
	}
	listB := strings.Split(sc.Text(), " ")

	for _, v := range listB {
		num := contains(v, listA)
		if num == -1 {
			fmt.Println(0)
			os.Exit(0)
		}
		listA = listA[num:]
	}
	fmt.Println(1)
}

func contains(s string, list []string) int {
	for i, v := range list {
		if s == v {
			return i
		}
	}
	return -1
}



Measured memory_bytes: 13944
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}

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

	ll ans=0;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				ans+=gcd(i,gcd(j,k));
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll h, w;
  cin >> h >> w;
  if(min(h, w) == 1) {
    cout << 1 << endl;
    return 0;
  }
  cout << (h * w + 1) / 2 << endl;
}

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

using namespace std;
const int INF = 1000000000;
int n, m, a[3];
int go[110][60][60], ok[60];
int matrix[60][60], dp[60][3], dp2[60];
int main(){
//freopen("in.txt", "r", stdin);
    scanf("%d %d %d %d %d", &n, &m, &a[0], &a[1], &a[2]);
    for (int i = 1; i <= m; ++ i){
        int u, v; scanf("%d %d", &u, &v);
        matrix[v][u] = 1;
    }
    for (int i = 1; i <= n; ++ i) go[0][i][i] = 1;
    for (int k = 1; k <= 100; ++ k){
        for (int i = 1; i <= n; ++ i){
            for (int j = 1; j <= n; ++ j){
                if (go[k - 1][i][j] == 0) continue;
                for (int l = 1; l <= n; ++ l){
                    //if (k == 1 && i == 8 && l == 1) printf("%d\n", j);
                    go[k][i][l] |= go[k - 1][i][j] & matrix[j][l];
                }
            }
        }
    }
    for (int i = 1; i <= n; ++ i){
        for (int j = 0; j < 3; ++ j){
            dp[i][j] = INF;
        }
        dp2[i] = INF;
    }

    queue <int> q;
    q.push(n); dp2[n] = 0;
    while (!q.empty()){
        int h = q.front(); q.pop();

        for (int i = 0; i < 3; ++ i){
            for (int j = 1; j <= n; ++ j){
                if (go[a[i]][h][j]){
                    if (dp2[h] + 1 < dp[j][i]){

                        ok[j] |= 1 << i;
                        dp[j][i] = dp2[h] + 1;

                        if (ok[j] == 7){
                            dp2[j] = *max_element(dp[j], dp[j] + 3);
                            q.push(j);
                        }
                    }
                }
            }
        }
    }
    //printf("%d\n", go[0][8][1]);
    int ans = dp2[1];
    if (ans == INF) puts("IMPOSSIBLE");
    else{
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 4664
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<cmath>
#include<cstdlib>
#include<utility>
#include<queue>
#include<ctime>
#include<string>
#include<string.h>
#include<cstring>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<functional>
#include<cassert>
#include<complex>
#include<deque>
#include<stdio.h>
using namespace std;
int c[11][11]={0},h,k,a[200][200],number[10]={0},magic=1000000000,ans=0;
bool b[11]={0};
void dfs(int x,int now,int l){
	if (x==1||x==-1){
		magic=min(magic,now);
		return ;
	}
	//cout<<now<<endl;;
	for (int i=0;i<=9;i++) if (b[i]==0&&i!=x&&c[x][i]<=l){
		b[i]=1;
		dfs(i,now+c[x][i],l);
		b[i]=0;
	}
}
int main()
{
	cin>>h>>k;
	for (int i=0;i<=9;i++)
		for (int j=0;j<=9;j++)
			cin>>c[i][j];
	for (int i=0;i<h;i++)
		for (int j=0;j<k;j++)
			cin>>a[i][j];
	number[1]=0;
	for (int i=0;i<h;i++)
		for (int j=0;j<k;j++){
			memset(b,0,11);
			magic=1000000000;
			if (number[a[i][j]]==0){
				dfs(a[i][j],0,c[a[i][j]][1]);
				number[a[i][j]]=magic;
			}
			ans+=number[a[i][j]];
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define MAX 200005
using namespace std;

int n, k;
ll p[MAX];

int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        scanf("%lld", &p[i]);
    }
    double s = 0, ans = 0;
    for(int i = 1; i <= k; i++){
        s += 1.0*(p[i]+1)/2;
    }
    ans = max(ans, s);
    for(int i = k+1; i <= n; i++){
        s -= 1.0*(p[i-k]+1)/2;
        s += 1.0*(p[i]+1)/2;
        ans = max(ans, s);
    }
    printf("%.7lf", ans);

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
void YesNo(bool);
void YESNO(bool);


int main(){
    int a, b;
    cin >> a >> b;
    YesNo(a * b % 2 == 1);
    
    return 0;
}


void YesNo(bool x){
    if (x) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

void YESNO(bool x){
    if (x) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int h, w, k;
string fi[300];
int ans[300][300];


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

	cin >> h >> w >> k;
	rep(i,h) {
		cin >> fi[i];
	}

	int id = 1;
	rep(y, h) {
		int px = -1;
		rep(x,w) {
			if (fi[y][x] == '#') {
				for (int xx = px + 1; xx <= x; xx++)
					ans[y][xx] = id;

				id++;
				px = x;
			}
		}
		if (px != -1) {
			for (int xx = px + 1; xx < w; xx++)
				ans[y][xx] = id - 1;
		}
	}

	rep(y, h) {
		if (ans[y][0]) {
			rep(yy, y) {
				rep(x, w)
					ans[yy][x] = ans[y][x];
			}
			break;
		}
	}
	rep(y, h) {
		if (ans[y][0] == 0) {
			rep(x, w)
				ans[y][x] = ans[y - 1][x];
		}
	}


	rep(y, h) {
		cout << ans[y][0];
		rep(x, w - 1)cout << ' ' << ans[y][x + 1];
		cout << endl;
	}


	return 0;
}

Measured memory_bytes: 1280
s = input()
a = -1
z = 0
for i in range(len(s)):
  if s[i] == "A" and a == -1:
    a = i
  if s[-(i + 1)] == "Z" and z == 0:
    z = len(s) - (i + 1)
print(z - a + 1)

Measured memory_bytes: 3512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,A;
  cin>>N>>A;
  ll X[N+1];
  RREP(i,N){
    cin>>X[i];
    X[i]-=A;
  }
  
  ll DP[N+1][6000];
  REP(i,N+1) REP(j,6000) DP[i][j]=0;
  DP[0][3000]=1;
  
  RREP(i,N){
    REP(j,5500){
      DP[i][j]+=DP[i-1][j];
      DP[i][j+X[i]]+=DP[i-1][j];
    }
  }
  
  cout<<DP[N][3000]-1<<endl;
  return 0;
}

Measured memory_bytes: 5956
#include <bits/stdc++.h>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> L(2 * N);
  REP(i, 0, 2 * N) { cin >> L[i]; }
  sort(L.begin(), L.end());
  int ans = 0;
  REP(i, 0, N) { ans += L[2 * i]; }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
LL L, R;
int main() {
	cin >> L >> R;
	for (LL i = 1; i * 2019ll <= R; ++i) {
		if (i * 2019ll >= L && i * 2019ll <= R) return puts("0"), 0;
	}
	LL ans = 1e17;
	for (LL i = L; i <= R; ++i) {
		for (LL j = i + 1; j <= R; ++j) ans = min(ans, i * j % 2019ll);
	} 
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lli n;
	cin>>n;
	vector<lli> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	vector<lli> cum(n);
	cum[0]=a[0];
	for(int i=1;i<n;i++)cum[i]=a[i]+cum[i-1];
	vector<vector<lli>> dp(n,vector<lli>(n,1e18));
	//printvec(cum);

	for(int l=1;l<=n;l++){
		for(int i=0;i<n-l+1;i++){
			int j=i+l-1;
			if(i==j){
				dp[i][j]=0;
				continue;
			}
			for(int k=i;k<j;k++){
				if(dp[i][k]!=1e18&&dp[k+1][j]!=1e18)
				setmin(dp[i][j],dp[i][k]+dp[k+1][j]+cum[j]-(i-1>=0?cum[i-1]:0));
			}
		}
	}	
	cout<<dp[0][n-1]<<endl;

}

Measured memory_bytes: 1536