akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	ll N;
	cin >> N;
	vector<ll> a(N), pos(N + 2, -1);
	for(ll i = 0; i < N; i++) {
		cin >> a[i];
		pos[a[i]] = i;
	}

	ll ans = 0;
	set<ll> st;
	st.insert(-1);
	st.insert(N);

	for(ll i = 1; i <= N; i++) {
		auto itr = st.lower_bound(pos[i]);
		ll r_value = *itr;
		itr--;
		ll l_value = *itr;

		ans += i * (pos[i] - l_value) * (r_value - pos[i]);

		st.insert(pos[i]);
	}

	cout << ans << endl;


}


Measured memory_bytes: 12800
n = int(input())
A = [int(x) for x in input().split()]
q = int(input())
m = [int(x) for x in input().split()]

flag = {}
for j in range(2 ** n):
    tot = 0
    for k in range(n):
        tot += ((j >> k) & 1) * A[k]
    flag[tot] = True

for i in range(q):
    if m[i] in flag:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5648
# B - Papers, Please

N = int(input())
my_list = list(input().split())
j = 0

for i in range(0, N):
    if int(my_list[i]) % 2 == 0:
        if int(my_list[i]) % 3 != 0 and int(my_list[i]) % 5 != 0:
            j += 1

if j != 0:
    print('DENIED')
else:
    print('APPROVED')


Measured memory_bytes: 9144
import java.util.Scanner;

public class Main
{
    public static int f(int[] arr)
    {
        int sum =0;
        int even =arr[0];
        int odd = arr[1];
        for(int i=0; i<arr[0];i++)
        {
            even = even-1;
            sum = sum + even;
            
        }
        for(int i=0; i<arr[1]; i++)
        {
            odd = odd-1;
            sum = sum + odd;
            
        }
        return sum;
    }
    public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);
        int[] arr = new int[2];
        for(int i=0; i<2 ;i++)
        {
            arr[i] = keyboard.nextInt();
        }
        int pairs = 0;
        pairs = f(arr);
        System.out.println(pairs);
    }
}



Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N,K,x[51],y[51],res=INF_LL;
  cin >> N >> K;
  REP(i,N)
    cin >> x[i] >> y[i];
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=0;k<N;k++){
        for(int l=k+1;l<N;l++){
          int cnt=0;
          ll maxx = max(x[i],x[j]);
          ll minx = min(x[i],x[j]);
          ll maxy = max(y[l],y[k]);
          ll miny = min(y[l],y[k]);
          for(int d = 0;d < N;d++){
            if((x[d] <= maxx && x[d] >= minx && y[d] <= maxy && y[d] >= miny)){
              cnt++;
            }
          }
          if(cnt >= K){
              res = min(res,(abs(x[i]-x[j])*abs(y[k]-y[l])));
            }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <time.h>
#include <stdlib.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(),a.end()
#define ign cin.ignore();

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

using namespace std;
using namespace __gnu_pbds;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef MY_PROJECT
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main()
{
    IOS
    ll x;
    cin>>x;
    ll temp=500;
    ll num=x/temp;
    ll out=num*1000;
    x=x%temp;
    out=out+x-x%5;
    cout<<out;
    return 0;
}


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

int main() {
	int n;
	cin>>n;
	int* f = new int[n];
	for(int i=0;i<n;i++){
	    cin>>f[i];
	}
	int* dp = new int[n];
	dp[0] = 0;
	dp[1] = abs(f[1]-f[0]);
	dp[2] = min(abs(f[2]-f[0]),dp[1]+abs(f[2]-f[1]));
	for(int i=3;i<n;i++){
	    dp[i] = min(dp[i-2]+abs(f[i]-f[i-2]),dp[i-1]+abs(f[i]-f[i-1]));
	}
	cout<<dp[n-1]<<'\n';
	return 0;
}

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

#define mem(arr, i) fill(arr, arr + sizeof(arr), i)
#define MEM(arr, i) memset(arr, i, sizeof(arr))
#define Push push_back
#define Pair make_pair
#define ALL(x) x.begin(), x.end()
#define X first
#define Y second
#define ACCEL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef pair<pll,lli> p3l;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
typedef vector<p3l> v3L;
typedef vector<vcL> vvL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
      lli   mod = 1000000007;

/// templates ///

const lli maxN = 2E5;

vcL inv(maxN+5, 1);
vcL fac(maxN+5, 1);

void ADD(lli &x, lli y) {
	x += y;
	if (x >= mod) x -= mod;
	if (x < 0) x += mod;
}

void MUL(lli &x, lli y) {
	x *= y;
	x = (x % mod + mod) % mod;
}

lli mypow(lli b, lli e) {
	lli ans = 1;
	while (e) {
		if (e & 1) MUL(ans, b);
		MUL(b, b);
		e >>= 1;
	}
	return ans;
}

lli modinv(lli n) {
	return mypow(n, mod - 2);
}

void calcInv(lli n) {
	for (int i = 2; i <= n; ++i) {
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	}
}

void calcFac(lli n) {
	for (int i = 2; i <= n; ++i) {
		fac[i] = fac[i - 1] * i % mod;
	}
}

lli cm(lli a, lli b) {
	lli ans = 1;
	if (a < b) return 0;

	MUL(ans, inv[fac[a - b]]);
	MUL(ans, inv[fac[b]]);
	MUL(ans, fac[a]);

	return ans;
}

lli Lucas(lli n, lli m) {
	if (m == 0) return 1;
	return cm(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;
}

lli doLucas(lli n, lli m) {
	calcInv(mod);
	calcFac(mod);
	return Lucas(n, m);
}

/// coding area ///

const lli maxn = 1E5;

void precal() {

	return;
}

void solve() {
	lli n, t = 3;
	cin >> n;
	
	lli act[n][t];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < t; ++j) {
			cin >> act[i][j];
		}
	}
	
	lli dp[n][t];
	memset(dp, 0, sizeof(dp));
	
	for (int i = 0; i < t; ++i) {
		dp[0][i] = act[0][i];
	}
	
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < t; ++j) {
			for (int k = 1; k < t; ++k) {
				dp[i][j] = max(dp[i][j], dp[i - 1][(j + k) % t] + act[i][j]);
			}
//			cout << dp[i][j] << ' ';
		}
//		cout << '\n';
	}
	
	lli maxA = -1;
	for (int i = 0; i < t; ++i) {
		maxA = max(maxA, dp[n - 1][i]);
	}
	
	cout << maxA << '\n';
}

int main() {
	precal();
	int t = 1;
	#ifdef LOCAL
		t = INT_MAX;
	#else
		ACCEL;
	#endif
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}




Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int mxn = 2e5 + 1;
vector<ll> edges[mxn], tim(mxn, -1);
ll dist = -1, st = -1;
void dfs(int x, int time){
	tim[x] = time;
	if(dist!=-1) return;
	for(auto i : edges[x]){
		if(tim[i]!=-1){
			st = i;
			dist = time - tim[i] + 1;
			return;
		} else dfs(i, time + 1);
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, k;cin>>n>>k;
	for(int i = 0; i< n;++i){
		int x;cin>>x;
		edges[i+1].push_back(x);
	}
	dfs(1, 0);
	for(int i = 1; i <=n; ++i){
		//cout<<i<<" "<<tim[i]<<endl;
		if(tim[i]==k){
			cout<<i<<endl;
			return 0;
		}
	}
	k -= tim[st];
	k%=dist;
	dist = -1;
	for(auto &x : tim) x = -1;
	dfs(st, 0);
	for(int i = 1; i<=n; ++i){
		if(tim[i]==k){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<12412<<endl;
	return 0;
}




Measured memory_bytes: 25032
#include<bits/stdc++.h>
using namespace std;
#define MAXN (int)1e+5
#define MAXK 500

int main() {
    int N, K, k;
    int ans = 0;

    cin >> N >> K;

    for (int i=0; i<N; i++) {
        cin >> k;
        if (k>=K) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#define R(i, n) for(int i = 0;i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define SC(a) scanf("%c", &a);
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

int N;

struct plan {
	int t;
	int x;
	int y;
};

int main() {
	S(N);
	vector<plan> plans(N);
	R(i, N) {
		int t = 0, x = 0, y = 0;
		S3(t, x, y);
		plans[i] = { t, x, y };
	}
	int nowt = 0;
	PR nowp = make_pair(0, 0);
	R(i, N) {
		int t = plans[i].t;
		PR to = make_pair(plans[i].x, plans[i].y);
		if ((t - nowt) % (abs(nowp.first - to.first) + abs(nowp.second - to.second)) != 0) {
			printf("No");
			return 0;
		}
		nowt = t;
		nowp = to;
	}
	printf("Yes");
}

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

using namespace std;

typedef long long LL;

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define fin "\n"


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

template <typename T>
inline void chmin(T &l,T r){l=min(l,r);}

template <typename T>
inline void chmax(T &l,T r){l=max(l,r);}

template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

int main(){
    LL x;
    cin>>x;
    LL res=0;
    res=(x+10)/11;
    res*=2;
    if((res/2)*11-5>=x)res--;
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int width,high,r,x,y,check;

  scanf("%d %d %d %d %d",&width,&high,&x,&y,&r);
  if(x-r >= 0){
    if(y+r > high) check = -1;
    else if(y-r < 0) check = -1;
    else check = 1;
  }
  if(x+r<=width){
    if(y+r > high) check = -1;
    else if(y-r < 0) check = -1;
    else check = 1;
  }
  if(x -r < 0) check = -1;
  if(x+r > width) check = -1;
  if(check == -1)printf("No\n");
  else printf("Yes\n");
  return 0;
}







Measured memory_bytes: 2148
var
i,j,k,m,n:longint;
c:char;
s:string;
begin
    read(c);
    while not eoln do
    begin
        if c='0' then s:=s+'0'
        else if c='1' then s:=s+'1'
        else delete(s,length(s),1);
        read(c);
    end;
    if c='0' then s:=s+'0'
    else if c='1' then s:=s+'1'
    else delete(s,length(s),1);
    writeln(s);
end.

Measured memory_bytes: 128
#include<iostream>
using namespace std;
 
int main(){
    int y[7];
    int x[6][6]={{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};
    int a,b,c,d;
    int q;
    cin>>y[1]>>y[2]>>y[3]>>y[4]>>y[5]>>y[6];
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>a>>b;
        for(int j=1;j<=6;j++){
            if(a==y[j]){
                c=j;
            }
            if(b==y[j]){
                d=j;
            }
        }
        cout<<y[x[c-1][d-1]]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
const int MAXN=55,MOD=1e9+7,MAXL=61;
struct matrix{
	
	long long mat[MAXN][MAXN];
	
	matrix(int id=0)
	{
		for(int i=0;i<MAXN;i++)
			for(int j=0;j<MAXN;j++)
				mat[i][j]= (i==j)? id : 0;
	}
	 
	matrix operator*(matrix other)const{
		
		matrix ans;
		
		for(int i=0;i<MAXN;i++)
		{
			for(int j=0;j<MAXN;j++)
			{
				for(int k=0;k<MAXN;k++)
				{
					ans.mat[i][j]+=mat[i][k]*other.mat[k][j];
					
					if(ans.mat[i][j]>=MOD)ans.mat[i][j]%=MOD;	
				}	
			}	
		}	
		return ans;
	}	
	
};
matrix fst_exp(matrix base,long long k)
{
	matrix r(1);
	for(long long i=MAXL-1;i>=0LL;i--)
	{
		r=r*r;
		if((1LL<<i)&k)r=base*r;	
	}	
	return r;
}
int main()
{
	int n;
	long long k;
	scanf("%d %lld",&n,&k);
	matrix a;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			long long b;
			scanf("%lld",&b);
			a.mat[i][j]=b;
		}
	}
	a=fst_exp(a,k);
	long long resp=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			resp+=a.mat[i][j];
		}
	}
	resp%=MOD;
	printf("%lld\n",resp);
	return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m;
    cin >> n >> m;
    int cnt = -1;
    long long l = 1;
    for (int i=0; i<n; i++) {
        long long a;
        cin >> a;
        int cur = 0;
        l = lcm(l, a);
        while (a % 2 == 0) {
            cur++;
            a /= 2;
        }
        if (i > 0 && cnt != cur) {
            cout << "0\n";
            return 0;
        }
        cnt = cur;
    }
    cout << (2 * m / l + 1) / 2 << "\n";

    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

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

  repi(i, 1, N+1){
    if(N / i == 1) ans += i;
    else ans += (N / i + 1) * (N / i) * i / 2;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3520
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct segtree {
	int N, dat[2 * 300000];
	segtree() {}
	segtree(int n) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++)
			dat[i] = INF;
	}
	// update k th element
	void update(int k, int a) {
		k += N - 1; // leaf
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	// min [a, b)
	int query(int a, int b) { return query(a, b, 0, 0, N); }
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INF;
		if (a <= l && r <= b) return dat[k];
		int m = (l + r) / 2;
		return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
	}
};


signed main(void) {
	int n;
	cin >> n;
	string a, b, c;
	cin >> a >> b >> c;

	int ans = 0;

	REP(i, n) {
		map<char, int> cou;
		cou[a[i]]++;
		cou[b[i]]++;
		cou[c[i]]++;
		int Max = 0;
		for (auto itr : cou) {
			Max = max(Max, itr.second);
		}
		ans += 3 - Max;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a = list(map(int,input().split()))
aa = []
for i in range(len(a)):
    aa.append(-a[i])
from heapq import heappop,heappush
h_que = []
ans = 0 
for i in range(n):
    heappush(h_que,aa[i])
for _ in range(m):
    tmp = heappop(h_que)
    tmp = -tmp
    tmp = tmp // 2
    tmp = -tmp
    heappush(h_que,tmp)
for i in range(n):
    tmp = heappop(h_que) * (-1)
    ans += tmp
print(ans)


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

int main() {
	int n;
	scanf("%d", &n);

	unsigned long int *a = (unsigned long int *)malloc((n +10)* sizeof(unsigned long int));
	int even = 0;
	int onlytwo_even = 0;
	int uneven = 0;

	for (int i = 0; i < n; i++) {
		scanf("%lu", &a[i]);
		if (a[i] % 2 == 0) {
			if (a[i]%4 == 0) {
				even++;
			}
			else {
				onlytwo_even++;
			}
		}
		else {
			uneven++;
		}
	}

	if (even >= onlytwo_even%2+uneven-1) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

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

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int ans=0;
  
	for(int i=1;i<n;i++){
		int cnt=0;
      for(char c='a';c<='z';c++){
			bool left=false,right=false;
			
			for(int j=0;j<i;j++)
				if(s[j]==c)
					left=true;
			
			for(int j=i;j<n;j++)
				if(s[j]==c)
					right=true;
			
			if((left==true)&&(right==true))
				cnt++;
		}
      ans=max(ans,cnt);
    }
  cout<<ans<<endl;
  return 0;
}

      
      
  
  


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			sc.nextInt();
			String s = sc.next();
			String s2 = s.replaceAll("ABC", "1");
			int ans = 0;
			for(char c : s2.toCharArray()) {
				if(c == '1') {
					ans++;
				}
			}
			System.out.println(ans);

		}
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

	int k = -1;
	for(int i=1; ; i++){
		long long n = 1LL * i*i - i - 2*N;
		if(n == 0){
			k = i;
			break;
		}
		else if(n > 0){
			break;
		}
	}

	if(k == -1){
		cout << "No" << endl;
		return 0;
	}

	vector<vector<int>> S(k, vector<int>());
	int n = 1;
	for(int i=0; i<k; i++){
		for(int j=i+1; j<k; j++){
			S[i].push_back(n);
			S[j].push_back(n);
			n++;
		}
	}

	cout << "Yes" << endl;
	cout << k << endl;
	for(int i=0; i<k; i++){
		cout << S[i].size() << " ";
		for(int j=0; j<S[i].size(); j++)
			cout << S[i][j] << (j+1 == S[i].size() ? '\n' : ' ');
	}

	return 0;
}


Measured memory_bytes: 2304
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=1e7+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }
  
int n;


void solve() {
    cin>>n;
    vi a(n,0);
    rep(i,0,n) cin>>a[i];
   
   
    
    sort(all(a));
    reverse(all(a));
    
    int sum=0;
    sum+=a[0];
    int ct=1,ind=1;
    while(ct<n-1) {
		   if(ct+2<n) {
			      sum+=2*a[ind++];
			      ct+=2;
			   }
		   else {
			      sum+=a[ind];
			      ct++;
			   }	   
		}
		
		cout<<sum<<endl;
    
    
   
   					   
 }

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();


return 0;	   
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  int n;
  cin>>n;
  int ans=n;
  if(ans%2==1)ans=n*2;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 125568
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int A,B,C,D,L;
int main() {
	cin>>L>>A>>B>>C>>D;
	int E=0,F=0;
	E=A/C;
	if(A%C!=0)E+=1;
	F=B/D;
	if(B%D!=0)F+=1;
	if(E>F)cout<<L-E<<endl;
	if(E<F||E==F)cout<<L-F<<endl;

	return 0;
}

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

int main(){
    ll N, P;
    scanf("%lld %lld",&N, &P);

    ll ans = 1;
    for(ll i=2; i*i <= P; i++){
        int Count = 0;
        while(P % i == 0){
            P = P / i;
            Count++;
        }

        Count = Count / N;
        while(Count--) ans = ans * i;
    }

    if(P > 1 && N == 1) ans = ans * P;
    printf("%lld",ans);
}


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

using namespace std;

int main(){

    int H, W, A, B;
    cin >> H >> W >> A >> B;

    for(int i = 0; i < B; i++){
        for(int j = 0; j < A; j++){
            cout << "0";
        }
        for(int j = A; j < W; j++){
            cout << "1";
        }
        cout << "\n";
    }

    for(int i = B; i < H; i++){
        for(int j = 0; j < A; j++){
            cout << "1";
        }
        for(int j = A; j < W; j++){
            cout << "0";
        }
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 1280
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    l=[int(input()) for i in range(5)]
    l2=list(map(lambda x: x%10 if x%10!=0 else 10,l))
    l3=list(map(lambda x: -(-x//10)*10,l))
    print(sum(l3)-(10-sorted(l2)[0]))

if __name__ == '__main__':
    main()


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

int main(){
  string s1, s2;
  cin >> s1 >> s2;
  
  if(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 384
void main() {
    int n = readln.chomp.to!int;
    int[] a = new int[n];
    foreach (i; 0 .. n) {
        a[i] = readln.chomp.to!int;
    }
    bool[] light = new bool[n];
    light[0] = true;
    int now = a[0];
    int cnt;
    while (!light[1]) {
        if (light[now-1]) {
            cnt = -1;
            break;
        }
        light[now-1] = true;
        now = a[now-1];
        ++cnt;
    }
    cnt.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 3836
#define _LIBCPP_DEBUG 0
#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 <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#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 <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> vec(n);
  REP(i,n) cin >> vec[i];
  int sum = 0;
  REP(i,n) {
    int ans = min(vec[i], abs(k - vec[i]));
    sum = sum + ans * 2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		m: usize,
		x: usize,
		mut a: [usize; m],
	}

	let i = a.binary_search(&x);
	match i {
		Ok(t) => {
			if m/2 < t {
				println!("{}", m - t);
				return;
			}
			else {
				println!("{}", t);
				return;
			}
		},
		Err(t) => {
			if m/2 < t {
				println!("{}", m - t);
				return;
			}
			else {
				println!("{}", t);
				return;
			}
		}
	}
}



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

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

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

    let x = if n < b - 1 { n } else { b - 1 };
    let ans = a * x / b - a * (x / b);

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


Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
int n,z;
string s;
int d,x;
int main()
{
	cin>>n;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(z==0&&s[i]=='I')z=1;
		if(s[i]=='I')x++;
		if(z==1&&s[i]=='D')
		{
		z=0;
		if(x>d)d=x;
		}
		if(s[i]=='D')x--;
	}
	if(x>d)d=x;
	cout<<d<<endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = list(str(input()))

tmp = list(set(s))
tmp.sort()
if len(tmp) == 2 and ((tmp[0] == 'E' and s[1] == 'W') or (tmp[0] == 'N' and tmp[1] == 'S')):
    print("Yes")
elif len(tmp) == 4:
    print("Yes")
else:
    print("No")

"""
if len(set(s)) == 1 or len(set(s)) == 3:
    print("No")
else:
    print("Yes")
"""

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>

typedef struct point{
  double x,y;
}point;

void cohho(int,point,point);

void cohho(int n,point a,point b)
{
  point A,B,C;
  double z = M_PI * 60.0 / 180.0;
  
  if(n == 0)
    return;

  A.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  A.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  B.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  B.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  C.x = (B.x - A.x) * cos(z) - (B.y - A.y) * sin(z) + A.x;
  C.y = (B.x - A.x) * sin(z) + (B.y - A.y) * cos(z) + A.y;

  cohho(n-1,a,A);
  printf("%.8f %.8f\n",A.x,A.y);
  cohho(n-1,A,C);
  printf("%.8f %.8f\n",C.x,C.y);
  cohho(n-1,C,B);
  printf("%.8f %.8f\n",B.x,B.y);
  cohho(n-1,B,b);
}
  
int main()
{
  point a,b;
  int n;

  scanf("%d",&n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n",a.x,a.y);
  cohho(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;
}
  



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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>to[100010];
    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<int>dist(n,1e9);
    queue<int>q;
    q.push(0);
    dist[0]=0;
    while(!q.empty()){
        int v=q.front(); q.pop();
        for(int u:to[v]){
            if(dist[u]!=1e9)continue;
            dist[u]=v;
            q.push(u);
        }
    }
    cout<<"Yes"<<endl;
    for(int i=1; i<n; ++i){
        cout<<dist[i]+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 10156
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

string s;

long long S[100010];

int main(int argc, char *argv[])
{

  int N;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> S[i];

  long long ans1 = 0, ans2 = 0, sum = 0;
  // S[0] > 0
  for (int i = 0, s = 1; i < N; i++, s *= -1) {
    sum += S[i];
    if (sum*s <= 0) {
      ans1 += abs(sum-s);
      sum = s;
    }
  }

  sum = 0;
  // S[0] < 0
  for (int i = 0, s = -1; i < N; i++, s *= -1) {
    sum += S[i];
    if (sum*s <= 0) {
      ans2 += abs(sum-s);
      sum = s;
    }
  }

  printf("%lld\n", min(ans1, ans2));
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
a.sort()
mx = a[-1]
dp = ["#"]*(mx+1)
for i in a:
    if dp[i]==True: dp[i] = False
    elif dp[i]=="#":
        dp[i] = True
        mult = 2
        while i*mult<=mx:
            dp[i*mult] = False
            mult+=1
ans = 0
for i in a:
    if dp[i]==True:
        ans+=1
print(ans)


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

#define MOD 1000000007

long long pow2(long long a, long long b){
    long long ret = 1;
    while(b > 0){
        if(b%2 == 1){
            ret = ret*a%MOD;
        }
        a = a*a%MOD;
        b /= 2;
    }
    return ret;
}
 
long long mul(int s, int e){
    long long ret = 1;
    for(int i = s; i <= e; i++){
        ret = ret * i % MOD;
    }
    return ret;
}
 
long long fact(int n){
    return mul(1, n);
}
 
long long nCr(int n, int r){
    return mul(n-r+1, n) * pow2(fact(r), MOD-2) % MOD;
}

int main()
{
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);

    long long ans = (pow2(2, n) - 1 + MOD - nCr(n, a) + MOD - nCr(n, b)) % MOD;
    printf("%lld",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int sx, sy, ex, ey;
  cin >> sx >> sy >> ex >> ey;
  sx--, sy--, ex--, ey--;
  vector<string> g(n);
  for (auto &s : g) {
    cin >> s;
  }

  vector<vector<int>> dis(n, vector<int>(m, -1));

  auto in = [&](int x, int y) {
    return x >= 0 && y >= 0 && x < n && y < m;
  };

  queue<pair<int, int>> q, qq;
  q.emplace(sx, sy);
  dis[sx][sy] = 0;

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

  while (q.size() || qq.size()) {
    while (q.size()) {
      const auto [x, y] = q.front();
      qq.push(q.front());
      q.pop();
      for (int d = 0; d < 4; ++d) {
        const int tx = x + dx[d];
        const int ty = y + dy[d];
        if (!in(tx, ty) || g[tx][ty] == '#' || dis[tx][ty] >= 0) continue;
        q.emplace(tx, ty);
        dis[tx][ty] = dis[x][y];
      }
    }
    while (qq.size()) {
      const auto [x, y] = qq.front();
      qq.pop();
      for (int i = -2; i <= 2; ++i) {
        for (int j = -2; j <= 2; ++j) {
          const int tx = x + i;
          const int ty = y + j;
          if (!in(tx, ty) || g[tx][ty] == '#' || dis[tx][ty] >= 0) continue;
          q.emplace(tx, ty);
          dis[tx][ty] = dis[x][y] + 1;
        }
      }
    }
  }
  cout << dis[ex][ey] << endl;

  return 0;
}



Measured memory_bytes: 8708
import sys
import numpy as np

def retmin(a, b):
    if a > b:
        return b
    return a

n = int(input())

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

dp = np.full(n+1+100, 9999999999999)
dp[0] = 0

for i in range(n-1):
    # １つどばし
    dp[i+1] = retmin(dp[i+1], abs(h[i+1]-h[i])+dp[i])
    # ２つとばし
    if i + 2 < n:
        dp[i+2] = retmin(dp[i+2], abs(h[i+2]-h[i])+dp[i])
print(int(dp[n-1]))

Measured memory_bytes: 22728
def f(n):
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int,raw_input().split(' '))
    try: D[a]+=b*c
    except:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  return B
 
while 1:
  n=input()
  if n==0:break
  x=f(n)
  for e in x: print e

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<long long> B(N + 1, 0); //累積和テーブル
	int mod = 1000000007;

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

	long ans = 0;

	//i について全探索する
	for (int i = 0; i < N; i++)
	{
		//累積和を使ってA[i+1] + ... + A[N] を求める
		long long sum = (B[N] - B[i + 1]) % mod;

		ans += A[i] * sum;
		ans %= mod;
	}

	cout << ans << endl;
}



Measured memory_bytes: 5572
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
 
int main() {
	long long N, C, K;
	vector<long long> T;
	cin >> N >> C >> K;
	REP(i, 0, N){
		long long t;
		cin >> t;
		T.push_back(t);
	}
	sort(T.begin(), T.end());
	
	long long count=1, acom=1, cur=T[0];
	REP(i, 1, N){
		if(T[i]<=cur+K && acom<C) acom++;
		else{
			count++;
			acom=1;
			cur=T[i];
		}
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(),d=scan.nextInt(),x=scan.nextInt(),a,s=x,i;
		for(i=0;i<n;i++) {
			a=scan.nextInt();
			s+=(d+a-1)/a;
		}
		scan.close();
		System.out.print(s);
	}
}

Measured memory_bytes: 23764
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

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

    int h = 0;
    for (int i = 1; i < 999; ++i) {
        h += i;
        if (h - a == h + i + 1 - b) {
            cout << h - a;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout<<'\n';
#define MOD 1000000007
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n';
#define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n';
#define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n';

const int N=1e5+7;

void solve(){
	int n; cin>>n;
	vector<pair<int,int>> v;
	int cnt=0;
	while(n%2==0){
		cnt++;
		n/=2;
	}
	if(cnt>0) v.pb({2,cnt});
	for(int i=3 ; i*i<=n ; i+=2){
		cnt=0;
		while(n%i==0){
			cnt++;
			n/=i;
		}
		if(cnt>0) v.pb({i,cnt});
	}
	if(n>1){
		int f=0;
		for(int i=0 ; i<sz(v) ; i++){
			if(v[i].f==n){
				v[i].s++;
				f=1;
				break;
			}
		}
		if(f==0) v.pb({n,1});
	}
	int ans=0;
	for(int i=0 ; i<sz(v) ; i++){
		int x=sqrt(1+8*v[i].s);
		x--;
		x/=2;
		ans+=x;
	}
	cout<<ans;LOL
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  cout<<setprecision(2);
  int _=1; //cin>>_;
  for(int i=1 ; i<=_ ; i++) solve();
  return 0;
}


Measured memory_bytes: 3680
n,m = map(int,input().split())
x = 2**n
dp = [1000000000 for _ in range(x)]
dp[0] = 0
for i in range(m):
    ai,bi = map(int,input().split())
    c = list(map(int,input().split()))
    bit = 0
    for j in range(bi):
        bit += 2**(c[j]-1)
    for k in range(x):
        dp[k | bit] = min(dp[k | bit],dp[k] + ai)
if dp[x-1] == 1000000000:
    print(-1)
else:
    print(dp[x-1])


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC
{
    class QuestionA
    {
        public static void Main(string[] args)
        {
			var scanner = new Scanner();

			var (d, t, s) = scanner.Int3();

			var x = s * t;

            Console.WriteLine(x >= d ? "Yes" : "No");
        }

		public class Scanner
		{
			private readonly char[] delimiter_ = new char[] { ' ' };
			private readonly string filePath_;
			private readonly Func<string> reader_;
			private string[] buf_;
			private int index_;

			public Scanner(string file = "")
			{
				if (string.IsNullOrWhiteSpace(file)) {
					reader_ = Console.ReadLine;
				} else {
					filePath_ = file;
					var fs = new StreamReader(file);
					reader_ = fs.ReadLine;
				}
				buf_ = new string[0];
				index_ = 0;
			}

			public string NextLine() => reader_();
			public string Next()
			{
				if (index_ < buf_.Length) {
					return buf_[index_++];
				}

				string st = reader_();
				while (st == "") {
					st = reader_();
				}

				buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
				if (buf_.Length == 0) {
					return Next();
				}

				index_ = 0;
				return buf_[index_++];
			}

			public int Int() => int.Parse(Next());
			public long Long() => long.Parse(Next());
			public double Double() => double.Parse(Next());

			public int[] ArrayInt(int N, int add = 0)
			{
				int[] Array = new int[N];
				for (int i = 0; i < N; i++) {
					Array[i] = Int() + add;
				}
				return Array;
			}

			public long[] ArrayLong(int N, long add = 0)
			{
				long[] Array = new long[N];
				for (int i = 0; i < N; i++) {
					Array[i] = Long() + add;
				}
				return Array;
			}

			public double[] ArrayDouble(int N, double add = 0)
			{
				double[] Array = new double[N];
				for (int i = 0; i < N; i++) {
					Array[i] = Double() + add;
				}
				return Array;
			}

			public (int, int) Int2(int add = 0)
			{
				var array = ArrayInt(2, add);
				return (array[0], array[1]);
			}

			public (int, int, int) Int3(int add = 0)
			{
				var array = ArrayInt(3, add);
				return (array[0], array[1], array[2]);
			}

			public (long, long) Long2(int add = 0)
			{
				var array = ArrayLong(2, add);
				return (array[0], array[1]);
			}

			public (long, long, long) Long3(int add = 0)
			{
				var array = ArrayLong(3, add);
				return (array[0], array[1], array[2]);
			}

			public (double, double) Double2(int add = 0)
			{
				var array = ArrayDouble(2, add);
				return (array[0], array[1]);
			}

			public (double, double, double) Double3(int add = 0)
			{
				var array = ArrayDouble(3, add);
				return (array[0], array[1], array[2]);
			}

			public void Save(string text)
			{
				if (string.IsNullOrWhiteSpace(filePath_)) {
					return;
				}

				File.WriteAllText(filePath_ + "_output.txt", text);
			}
		}
	}
}



Measured memory_bytes: 27552
#include<stdio.h>
#include<string.h>

char X[1001],Y[1001];

void LCSLength(int m,int n)
{
  int i,j,c[1001][1001];

  for(i = 0;i <= m;i++)
    c[i][0] = 0;
  for(j = 1;j <= n;j++)
    c[0][j] = 0;
  for(i = 1;i <= m;i++){
    for(j = 1;j <= n;j++){
      if(X[i - 1] == Y[j - 1])
	{
	  c[i][j] = c[i - 1][j - 1] + 1;
	}
      else if(c[i - 1][j] >= c[i][j - 1])
	{
	  c[i][j] = c[i - 1][j];
	}
      else c[i][j] = c[i][j - 1];
    }
  }
  printf("%d\n",c[m][n]);
}
    

int main()
{
  int m,n,q,i;

    scanf("%d",&q);

    for(i = 0;i < q;i++)
      {
	scanf("%s%s",X,Y);

	m = (int)strlen(X);
	n = (int)strlen(Y);
	
	LCSLength(m,n);
      }
    return 0;
}

	



Measured memory_bytes: 5680
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
	double a, b;
	cin >> a >> b;
    cout << a/b << endl;
}

Measured memory_bytes: 256
N = input()
K = int(input())
dp = [[[0 for k in range(K+2)] for j in range(2)] for i in range(len(N)+1)]
dp[0][0][0] = 1
for i in range(len(N)):
    Ni = int(N[i])
    for j in range(2):
        for k in range(K+1):
            for d in range(10 if j else int(Ni)+1):
                dp[i+1][j or (d < Ni)][k + (d != 0)] += dp[i][j][k]
                # print(i, j, k, d)

ans = dp[-1][0][K] + dp[-1][1][K]
# print(dp)
print(ans)

Measured memory_bytes: 71436