akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll H; cin >> H;

  ll ans = 0;
  ll cnt = 1;
  while(1) {
    H /= 2;
    ans +=  cnt;
    cnt *= 2;
    if(H == 0) break;
  }
  
  

  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


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

using namespace std;

const int N = 1e5 + 8;
long long x[N], m[N] , w[N] , tmp , p , q , cnt , n , l , t;

int main()
{
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	cin >> n >> l >> t;
	for(int i = 0 ; i < n ; i++)
		cin >> x[i] >> w[i];
	for(int i = 1 ; i < n ; i++)
	{
		if(w[i] != w[0])
		{
			if(w[0] == 1)
			{
				q = (2 * t - (x[i] - x[0]) + l - 1) / l;
				cnt += q;
			}
			else
			{
				q = (2 * t + (x[i] - x[0]) - 1) / l;
				cnt -= q;
			}
			cnt += n;
			cnt %= n;
		}
	}
	for(int i = 0 ; i < n ; i++)
	{
		if(w[i] == 1)
		{
			m[i] = ((x[i] + t) % l + l) % l;
		}
		else
		{
			m[i] = ((x[i] - t) % l + l) % l;
		}
	}
	tmp = m[0];
	sort(m , m + n);
	if(w[0] == 1)
	{
		p = 0;
		for(p = 0 ; m[p] != tmp ; p++);
	}
	else
	{
		p = n - 1;
		for(p = n - 1 ; m[p] != tmp ; p--);
	}
	for(int i = 0 ; i < n ; i++)
		cout << m[(i + p - cnt + n) % n] << endl;
}

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

typedef struct {
  double x;
  double y;
}Point ;
void kohho(int num,Point a,Point b);
int main()
{
  Point p1,p2;
  int num;
  scanf("%d",&num);
  p1.x=0;
  p1.y=0;
  p2.x=100;
  p2.y=0;
  printf("%.8f %.8f\n",p1.x,p1.y);
  kohho(num,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);

  return 0;
}

void kohho(int num ,Point a ,Point b)
{
  Point s,t,u;
  if (num==0)return ;

  s.x =(2.0 * a.x + 1.0 * b.x)/3.0;
  s.y =(2.0 * a.y + 1.0 * b.y)/3.0;
  t.x =(1.0 * a.x + 2.0 * b.x)/3.0;
  t.y =(1.0 * a.y + 2.0 * b.y)/3.0;
  u.x =(t.x - s.x) * cos(M_PI*60.0/180.0) - (t.y - s.y) * sin(M_PI*60.0/180.0) + s.x;
  u.y =(t.x - s.x) * sin(M_PI*60.0/180.0) + (t.y - s.y) * cos(M_PI*60.0/180.0) + s.y;
  kohho(num-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  kohho(num-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  kohho(num-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  kohho(num-1,t,b);
}

Measured memory_bytes: 640
# comb_mod(n, c, r, mod, fac, den) ≡ nCr
def prepare(n, mod):
    # fac[i] ≡ i!
    fac = [1]
    for i in range(1, n+1):
        fac.append((fac[-1] * i) % mod)

    # rec ≡ 1 / n!
    rec = pow(fac[-1], mod-2, mod)

    # den[i] ≡ 1 / i!
    den = [1 for _ in range(n+1)]
    den[n] = rec
    for i in range(n-1, 0, -1):
        rec = (rec * (i+1)) % mod
        den[i] = rec
    
    return fac, den

def comb_mod(n, r, mod, fac, den):
    return (fac[n] * den[r] * den[n - r]) % mod

r1, c1, r2, c2 = map(int, input().split())

# n:max(n), mod:prime number を入力
mod = 10**9 + 7
fac, den = prepare(r2+c2+2, mod)

ans = comb_mod(r2+1+c2+1, c2+1, mod, fac, den)
ans -= comb_mod(r2+1+c1, c1, mod, fac, den)
ans -= comb_mod(r1+c2+1, c2+1, mod, fac, den)
ans += comb_mod(r1+c1, c1, mod, fac, den)

print(ans % mod)

Measured memory_bytes: 133760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,n,m,cnt=0,a=1,x;
	cin>>n>>m;
	int ara[n];
	for(i=0;i<n;i++){
		cin>>x;
		cnt+=x;
		ara[i]=x;
	}
	sort(ara,ara+n);
	for(i=n-1;i>=n-m;i--){
		if(ara[i]<(cnt/(4.0*m))){
			a=0;
			break;
		}
	}
	if(a==1){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

int main() {
  string S;
  cin >> S;

  int cnt0 = count(S.begin(), S.end(), '0');
  int cnt1 = count(S.begin(), S.end(), '1');

  cout << 2 * min(cnt0, cnt1) << endl;
  return 0;
}

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

int linerSearch(int *,int *, int, int);


int main() {
  int i, n, q, *S, *T;

  scanf( "%d" , &n );
  S = (int *)malloc((n+1) * sizeof(int));
  for( i=0; i<n; i++ ) scanf( "%d" , &S[i] );
  scanf( "%d" , &q );
  T = (int *)malloc(q * sizeof(int));
  for( i=0; i<q; i++ ) scanf( "%d" , &T[i] );

  printf( "%d\n" , linerSearch(S, T, n, q) );

  return 0;
}


int linerSearch(int *S, int *T, int n, int q) {
  int i, j, key, count=0;

  for ( j=0; j<q; j++ ) {
    i=0;
    S[n] = T[j];
    while ( S[i] != T[j] ) i++;
    if ( i != n ) count++;
  }
  
  return count;
}



Measured memory_bytes: 2108
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, K;
    cin >> N >> K;
    int cnt = 0;

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

    for (int i = 0; i < N; i++) {
        int left = 0;
        for (int j = 0; j < i; j++) {
            if (A[j] < A[i]) left++;
        }

        int right = 0;
        for (int j = i + 1; j < N; j++) {
            if (A[j] < A[i]) right++;
        }

        //cnt += (K * (K - 1) * left) / 2;
        int a = (K * (K - 1)) / 2;
        a %= MOD;
        a *= left;
        a %= MOD;
        cnt += a;
        cnt %= MOD;

        // cnt += (K * (K + 1) * right) / 2;
        int b = (K * (K + 1)) / 2;
        b %= MOD;
        b *= right;
        b %= MOD;
        cnt += b;
        cnt %= MOD;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.split(" ").map(&:to_i)[0]

line = gets.chomp.split(" ").map(&:to_i)

flag = true
(line.length - 1).times do |i|
    if line[i] < line[i + 1]
        line[i + 1] -= 1
    end
    if line[i] > line[i + 1]
        flag = false
    end
end

puts flag ? "Yes" : "No"


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


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

    string S; cin >> S;
    int N = S.size();

    rep(i, N - 1) {
        if (S[i] == S[i + 1]) {
            cout << i + 1 << " " << i + 2 << '\n';
            return 0;
        }
    }
    rep(i, N - 2) {
        if (S[i] == S[i + 2]) {
            cout << i + 1 << " " << i + 3 << '\n';
            return 0;
        }
    }
    cout << -1 << " " << -1 << '\n';
    return 0;
}

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

int main() {
    int R, G, B;
    cin >> R >> G >> B;
    int K;
    cin >> K;
    while (!(R < G)) {
        G *= 2;
        K--;
    }
    while (!(G < B)) {
        B *= 2;
        K--;
    }
    if (K < 0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <utility>
#include <stdint.h>
#include <set>
#include <map>

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;

  map<unsigned, multiset<unsigned, greater<unsigned>>, greater<unsigned>> jobs;
  multiset<unsigned, greater<unsigned>> available_jobs;

  for (int n=0; n<N; ++n) {
    unsigned a, b;
    cin >> a >> b;
    if (jobs.count(a)==0)
      jobs[a] = multiset<unsigned, greater<unsigned>>();
    jobs[a].emplace(b);
  }

  uint64_t sum = 0;
  for (int m=1; m<=M; ++m) {
    if (jobs.count(m) > 0)
      available_jobs.insert(jobs[m].begin(), jobs[m].end());
    if (available_jobs.size()==0)
      continue;
    sum += *available_jobs.begin();
    available_jobs.erase(available_jobs.begin());
  }
  
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 14208
#include<iostream>
#include<cstdio>
#define W 0
#define G 1
#define B 2
#define inf 1000000
#define MAX 100
#define NIL -1
using namespace std;

int n;
int A[MAX][MAX];

void Prim(){
    int color[MAX],d[MAX],p[MAX];
    int min,u;
    for(int i = 0; i < n; i++){
        color[i] = W;
        d[i] = inf;
        p[i] = NIL;
    }
    
    d[0] = 0;
    
    while(1){
        u = -1;
        min = inf;
        for(int i = 0; i < n; i++){
            if(d[i] < min && color[i] != B){
                u = i;
                min = d[i];
            }
        }
        
        if(u == -1) break;
            
        color[u] = B;
            
        for(int i = 0; i < n; i++){
            if(color[i] != B && A[u][i] != NIL){
                if(A[u][i] + d[u] < d[i]){
                    d[i] = A[u][i] + d[u];
                    color[i] = G;
                    p[i] = u;
                }
            }
        }
    }
    
    for (int i = 0; i < n; i++){
        printf("%d %d\n",i,d[i]);
    }
}

int main(){
    int u,k,c,v;
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            A[i][j] = inf;
        }
    }
    for(int i = 0; i < n; i++){
        scanf("%d %d", &u, &k);
        for(int j =0; j < k; j++){
            scanf("%d %d",&v,&c);
            A[i][v] = c;
        }
    }
    
    
    Prim();
    return 0;
}




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

using namespace std;

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

    int d, t, s;
    cin >> d >> t >> s;

    if(d <= t * s){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr(be, en) for(int i = be; i <= en; i++) 
ll mod = 1e9 + 7;
ll power(ll a, ll b)
{
	if(b == 0) return 1;
	ll ans = power(a, b/2);
	ans = (ans*ans)%mod;
	if(b%2) ans*=a;
	return ans%mod;
}
ll mul(ll a,ll n, ll mod)
{
	ll ret;
	if(n==0) return 0;
	ret = mul(a,n/2, mod);
	ret = (ret+ret)%mod;
	if(n%2)	ret=(ret+a)%mod;
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	int n; cin >> n;
	vector<vector<ll> > dp(n/3 + 2, vector<ll>(n + 1, 0));
	ll ans = 0;
	dp[0][0] = 1;
	for(int i = 1; i <= n/3; i++){
		ll be = 0;
		ll sum = 0;
		for(int j = 3; j<= n; j++){
			sum = (sum + dp[i - 1][be])%mod;
			dp[i][j] = sum;
			be++;  
		}
		ans += dp[i][n];
		ans %= mod;
	}
	cout << ans;
}

Measured memory_bytes: 13756
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


double pi = acos(-1.0);
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	double a, b, x;
	cin >> a >> b >> x;

	double ans;

	if (x >= (a*a*b) / 2.0)ans = atan(a*a*a / (2.0*(a*a*b - x)));
	else ans = atan(2*x/(a*b*b));

	cout << setprecision(20) << (90.0-(ans*180.0)/pi) << endl;

	
	return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

bool cmp(ii &a, ii &b) {
  return a.sc > b.sc;
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  map<int, int> mo, me;
  for (int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    if (i % 2) mo[t]++;
    else me[t]++;
  }
  vector<ii> vo(all(mo)), ve(all(me));
  sort(all(vo), cmp);
  sort(all(ve), cmp);
  if (vo[0].fi != ve[0].fi) {
    cout << n - (vo[0].sc + ve[0].sc) << '\n';
    return 0;
  }
  if (vo.size() == 1 && ve.size() == 1) {
    cout << n / 2 << '\n';
    return 0;
  }
  int ans = 2e9;
  if (vo.size() >= 2) ans = min(ans, n - (vo[1].sc + ve[0].sc));
  if (ve.size() >= 2) ans = min(ans, n - (vo[0].sc + ve[1].sc));
  cout << ans << '\n';
}


Measured memory_bytes: 10964
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BMI
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) break;
                string[] temp = input.Split(',');
                double w = double.Parse(temp[1]);
                double h = double.Parse(temp[2]);
                double bmi = w / h / h;
                if (bmi >= 25) Console.WriteLine(temp[0]);

            }
        }
    }
}



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

int main(void){
    int a,b,c,d;
    cin >> a >> b >> c >> d;


    while(a > 0 && c > 0){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
        }
    }

    return 0;
}

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

char isUnder(long n,char a[]);
void adder(char a[]);
char is753(char a[]);

int main(void)
{
	long n,ans;
	char a[10]={};
	scanf("%ld",&n);

	a[0] = 7;
	a[1] = 5;
	a[2] = 3;

	ans = 0;
	while (isUnder(n,a)) {
		if (is753(a)) ans++;
		adder(a);
	}

	printf("%ld\n",ans);
	return 0;
}

char isUnder(long n,char a[])
{
	long ai=0;
	char i;
	for (i=0;i<10;i++) ai += a[i]*pow(10,i);
	if (n>=ai) return 1;
	return 0;
}

void adder(char a[])
{
	char i;
	for (i=0;i<10;i++) {
		a[i]+=(a[i]==0)?3:2;
		if (a[i]<=7) break;

		a[i]=3;
	}
	return;
}

char is753(char a[])
{
	char i,c[10]={};
	for (i=0;i<10;i++) {
		c[a[i]]++;
	}
	if (c[3]>0 && c[5]>0 && c[7]>0) return 1;
	else return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n,a,b;
  
  scanf("%d%d%d",&n,&a,&b);
  
  int i,j;
  int sum=0;
  int ans=0;
  int tmp;
 
  for(i=1;i<=n;i++)
  {
    tmp=i;
    while(tmp!=0)
    {
      sum+=tmp%10;
      tmp/=10;
    }
    if(a<=sum&&sum<=b)
    {
      ans+=i;
    }
    sum=0;
  }
  
  printf("%d\n",ans);
  
  return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))
def sad(b):
    ret = 0
    for i in range(N):
        ret += abs(A[i]-b-i)
    return ret
L = -(10**10)
R = 10**10
tmp = sad(R)
while L+1<R:
    mid = (L+R)//2
    sm = sad(mid)
    sm1 = sad(mid-1)
    if sm1 < sm:
        R = mid
    elif sm1 == sm:
        ans = sm
        break
    else:
        L = mid
else:
    ans = sad(L)
print(ans)


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

using namespace std;
        
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
        
#define print(a) {for(auto xxxxx : (a)) cout << xxxxx << ' '; cout << '\n';}
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

ll next(){ll x; cin >> x; return x;}
const int maxn = 3e5 + 5, intf = 2e9;
const ll inf = 1e18, mod = 998244353;
const ld eps = 1e-9;


void solve(){
  int n; cin >> n;
  ll res = 1;
  bool flag = false;
  while(n--){
    ll x = next();
    if (x != 0 && res > ll(1e18 / x))
      flag = true;
    else 
      res *= x;
  }
//  cout << (res <=  ll(1e18)) << '\n';
  if ((res == 0 || !flag) && res <= ll(1e18)){
    cout << res;
  } else {
    cout << -1;
  }
}

signed main(){
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(20);
  
  for (int t = 1; t--;) {
    solve();
  }
        
  return 0;
}
/*

*/


Measured memory_bytes: 3632
#include<stdio.h>
int a[100005];
int main()
{
    int n;
    int flag=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
    {
        if(a[i]==i)
        {
           int t=a[i+1];
           a[i+1]=a[i];
           a[i]=t;
           flag++;
        }
    }
    printf("%d\n",flag);
    return 0;
}

Measured memory_bytes: 512
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000//10^12
#define INFINT 2000000001//2*10^9+1
#define ALL(a) (a).begin(),(a).end()

using namespace std;


struct kouzou_t{
	string str;	
	int idnum;

/*	bool operator<(const kouzou_t& another) const {
		int x=str.compare(another.str);
		if(x==1) return 1;
		return 0;
	}*/
};

int asc(const void *a, const void *b) {
	struct kouzou_t *A = (struct kouzou_t *)a;
	struct kouzou_t *B = (struct kouzou_t *)b;
	return B->str.compare(A->str);
}


int main(void)
{
	//変数の宣言
	int n;
	char s[40];
//	string str;
	struct kouzou_t memo;
	static struct kouzou_t dp[300000];
	struct kouzou_t kouzou;
	int ng,ok;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	ll int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;



	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);

	scanf("%s",&s);
//	scanf_s("%s",&s,40);

//	for(i=1;i<=n;i++){
//		scanf("%lld %lld %d",&x[i],&y[i],&r[i]);
//		scanf_s("%lld %lld %d",&x[i],&y[i],&r[i]);
//	}
	
	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	for(i=0;i<(1<<n);i++){
		temp=0;
		for(j=0;j<n;j++){
			if((i&(1<<j))==0){
				kouzou.str.push_back(s[j]);
				temp++;
			}
		}
		kouzou.str.push_back(',');
		for(j=0;j<n;j++){
			if((i&(1<<j))!=0){
				kouzou.str.push_back(s[j]);
			}
		}

//		printf("%s\n",kouzou.str.c_str());

		dp[i].str=kouzou.str;
		dp[i].idnum=1;
		kouzou.str.erase(kouzou.str.begin(),kouzou.str.end());
		
	}

	
/*	for(auto itr=dp.begin();itr!=dp.end();++itr){
		memo=*itr;
		printf("%s\n",memo.str.c_str());
	}
*/
	qsort(dp,(1<<n),sizeof(kouzou_t),asc);

	for(i=0;i<(1<<n);i++){
		dp[i].idnum=i;
	}

/*	for(auto itr=dp.begin();itr!=dp.end();++itr){
		memo=*itr;
		printf("%s\n",memo.str.c_str());
	}
*/




	for(i=0;i<(1<<n);i++){
		for(j=0;j<n;j++){
			if((i&(1<<j))==0){
				kouzou.str.push_back(s[2*n-1-j]);
			}
		}
		kouzou.str.push_back(',');
		for(j=0;j<n;j++){
			if((i&(1<<j))!=0){
				kouzou.str.push_back(s[2*n-1-j]);
			}
		}

		ng=-1;
		ok=(1<<n);
		while(ok-ng>1){
//			printf("%d\n",dp[(ok+ng)/2].str.compare(kouzou.str));
			if(dp[(ok+ng)/2].str.compare(kouzou.str)>0){
				ng=(ok+ng)/2;
			}else{
				ok=(ok+ng)/2;
			}
		}
		ans=ans-ok;
		
		ng=-1;
		ok=(1<<n);
		while(ok-ng>1){
			if(dp[(ok+ng)/2].str.compare(kouzou.str)>=0){
				ng=(ok+ng)/2;
			}else{
				ok=(ok+ng)/2;
			}
		}
		ans=ans+ok;
		
		kouzou.str.erase(kouzou.str.begin(),kouzou.str.end());
	}


	//	printf("計算部分終了\n");

	//出力

	printf("%lld",ans);

	//	printf("結果の出力終了\n");


	return 0;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int64 N;
vector<int64> G[212345];
vector<int64> d;
vector<int64> vs[2];

void dfs(int64 v, int64 p, int64 dep=0) {
  d[v] = dep;
  vs[d[v]%2].push_back(v);
  for (auto &u : G[v]) {
    if (u == p) continue;
    dfs(u, v, dep+1);
  }
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	d.resize(N, 0);
	REP(i, N-1) {
	  int64 a, b;
	  cin >> a >> b; a--; b--;
	  G[a].push_back(b);
	  G[b].push_back(a);
	}
	dfs(0, 0);
	int64 thr = N/3;
	if (vs[0].size() > vs[1].size()) swap(vs[0], vs[1]);
	vector<int64> res(N, -1);
	vector<queue<int64>> rest(3);
	REP(i, 3) {
	  for (int64 j = (i == 0 ? 3 : i); j <= N; j += 3) {
	    rest[i].push(j);
	  }
	}
	if (vs[0].size() <= thr) {
	  REP(i, vs[0].size()) {
	    res[vs[0][i]] = rest[0].front(); rest[0].pop();
	  }
	  REP(i, vs[1].size()) {
	    REP(j, 3) {
	      if (rest[j].size() == 0) continue;
	      res[vs[1][i]] = rest[j].front(); rest[j].pop();
	      break;
	    }
	  }
	} else {
	  REP(i, vs[0].size()) {
	    int64 x = -1;
	    if (rest[2].size()) {
	      x = rest[2].front(); rest[2].pop();
	    } else {
	      x = rest[0].front(); rest[0].pop();
	    }
	    res[vs[0][i]] = x;
	  }
    REP(i, vs[1].size()) {
      int64 x = -1;
      if (rest[1].size()) {
        x = rest[1].front(); rest[1].pop();
      } else {
        x = rest[0].front(); rest[0].pop();
      }
      res[vs[1][i]] = x;
    }
	}
	REP(i, res.size()) {
	  cout << res[i] << " ";
	}
	cout << endl;
}


Measured memory_bytes: 25324
#include <bits/stdc++.h>
#define rep(i,N) for(int i=1;i<N;i+=1)
using namespace std;
int main() {
  int A,B;
  cin>>A>>B;
  if(A-2*B<=0) {
    int C='A';
    C=C-65;
    cout<<C<<endl;
  }
  else {
    int C=A-2*B;
    cout<<C<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
   int n;
   cin>>n;
   vector<string>s(n);
   ll ans=0;
   int p=0,q=0,r=0;
   for(int i=0;i<n;i++){
      cin>>s[i];
      for(int j=0;j<s[i].size()-1;j++){
         if(s[i][j]=='A' and s[i][j+1]=='B')ans++;
      }
      if(s[i][0]=='B' and s[i][s[i].size()-1]=='A'){
         r++;
      }else if(s[i][0]=='B'){
         q++;
      }else if(s[i][s[i].size()-1]=='A'){
         p++;
      }
   }
   //cout<<ans<<endl;
   //cout<<p<<" "<<q<<" "<<r<<endl;
   if(r>1){
      ans+=(r-1);
      r=1;
   }
   if(p>q){
      if(p>=1 and r){
      ans++;
      r--;
   }
   }else{
      if(q>=1 and r){
      r--;
      ans++;
   }
   }
   ans+=min(p,q);
   cout<<ans<<endl;

   return 0;    
}

Measured memory_bytes: 896
n = int(input())
l = list(map(int, input().split()))
ans = []
while l:
  for i in range(n-1,-1,-1):
    if l[i] == i+1:
      ans.append(l.pop(i))
      n -= 1
      break
  else:
    print(-1)
    exit()
ans = ans[::-1]
for i in range(n):
  if ans[i] > i+1:
    print(-1)
    break
else:
  for i in ans:
    print(i)

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int p[4], t[4];

int main(){
    cin>>n;
    REP(i,4)cin>>p[i];
    REP(i,4)cin>>t[i];
    int ans = 252521;
    REP(a,101)REP(b,101)REP(c,101)REP(d,101){
        int cc = t[0]*a + t[1]*b + t[2]*c + t[3]*d;
        int vv = p[0]*a + p[1]*b + p[2]*c + p[3]*d;
        if(cc>=n)CHMIN(ans,vv);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3104
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
t = [0] * (max(a) + 2)
for x in a:
  if x > 0: t[x - 1] += 1
  t[x] += 1
  t[x + 1] += 1
print(max(t))

Measured memory_bytes: 52892
import java.util.*;
class Main
{
		public static void main(String[] args)
		{
			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			int sum = 0;
			
			for(int i=1 ; i<=n ; i++){
				
				int num = 0;
				int suuti = i;
				
				do{
					num+= suuti%10;
					suuti /=10;
				}while(suuti!=0);
					
				
				if ( (a<=num) && (num<=b) ){
					sum += i;
				}
			}
			System.out.println(sum);
		}
}

Measured memory_bytes: 22868
#include<stdio.h>
int main()
{
	int n,t=0,max=0,a,b;
	scanf("%d",&n);
		for(int i=1;i<=n;i++){
			b=i;
			while(b%2==0){
				b=b/2;
				t++;
			}
			if(t>=max){
				max=t;
				a=i;
			} t=0;
		}
		printf("%d",a);
		return 0;	
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s[0] == s[s.size() - 1])
        cout << (s.size() & 1 ? "Second" : "First");
    else
        cout << (s.size() & 1 ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int>data(0,0), A(0,0), B(0,0);
  int x=0;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    x=max(x,a);
    data.push_back(a);
    A.push_back(x);
  }
  x=0;
  for(int i=N-1; i>=0; i--){
    x=max(x, data[i]);
    B.push_back(x);
  }
  for(int i=0; i<N; i++){
    if(i==0) cout << B[N-2] << endl;
    else if(i==N-1) cout << A[i-1] << endl;
    else{
      int a;
      a=max(A[i-1], B[N-2-i]);
        cout << a << endl;
    }
  }
}

Measured memory_bytes: 4076
#include<iostream>

int main(){
    int i,j,k,s,n,x;
    int test=0;
    int count;

    n=3;
    x=3;
    for(s=0;s<1000;s++){
        count=0;
        std::cin>>n>>x;

        if(n==0&&x==0){
            break;
        }

        for(i=1;i<=n-2;i++){
            for(j=i+1;j<=n-1;j++){
                for(k=j+1;k<=n;k++){
                    test=i+j+k;

                    if(test==x){
                        count+=1;
                    }
                }
            }
        }
        std::cout<<count<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
  double speed, v, t;
  int height;
  int N;

  while (cin >> speed) {
    N = 1;
    while (1) {
      height = 5 * N - 5;
      t = sqrt(height / 4.9);

      v = 9.8 * t;
      if (v >= speed) {
        break;
      }

      N++;
    }

    cout << N << endl;
  }

  return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  string S;
  int w;
  cin >> S;
  cin >> w;
  string a;
  int b=S.size();
  for(int i=0;i<b;i++){
    if(i%w==0){
      a+=S.at(i);}
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    ll tmp;
    for(ll i = 0; i < N; i++){
        cin >> tmp; tmp--;
        A.at(i) = tmp;
    }
    vector<ll> searched(N, -1);
    ll cnt, now;
    cnt = 0;
    now = 0;
    searched.at(0) = 0;
    while(1){
        cnt++;
        now = A.at(now);
        if(searched.at(now) != -1){
            break;
        }
        searched.at(now) = cnt;
    }
    
    ll b = cnt;
    ll a = searched.at(now);
    if(K >= a){
        K = K-a;
        K = K % (b-a);

        for(ll i = 0; i < K; i++){
            now = A.at(now);
        }
        printf("%lld\n", now+1);
    }
    else{
        now = 0;
        for(ll i = 0; i < K; i++){
            now = A.at(now);
        }
        printf("%lld\n", now+1);
    }
    

}


Measured memory_bytes: 6428
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;

int main()
{
	int n;
	cin>>n;
	vl A(n+1);
	take(A,1,n);
	vl PS(n+1);
	PS[n] = A[n];
	for(int i=n-1;i>0;i--)
	{
		PS[i] = (A[i] + PS[i+1])%MOD;
	}
	ll ans = 0;
	for(int i=1;i<n;i++)
	{
		ans += (A[i]*PS[i+1])%MOD;
		ans%=MOD;
	}
	cout<<ans<<endl;
}	

Measured memory_bytes: 6404
N=int(input())
A=list(map(int,input().split()))

even=[0 for i in range(N)]
odd=[0 for i in range(N)]
even[0]=max(0,A[0])
for i in range(1,N):
    if i%2==1:
        even[i]=even[i-1]
        odd[i]=odd[i-1]+max(0,A[i])
    else:
        even[i]=even[i-1]+max(0,A[i])
        odd[i]=odd[i-1]

eval=-10**20
L=-1
R=-1
for i in range(N):
    for j in range(i,N):
        if j==i:
            test=A[i]
            if eval<test:
                eval=test
                L,R=i,i
        elif (j-i)%2==0:
            if i%2==0:
                test=even[j]-even[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j
            else:
                test=odd[j]-odd[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j

print(eval)
print(N-1-R+L+(R-L)//2)
#print(L,R)

for i in range(N-1,R,-1):
    print(i+1)

for i in range(L):
    print(1)

for i in range(L+2,R-1,2):
    if A[i]>0:
        print(2)
    else:
        print(3)
        
if L!=R:
    print(2)

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

int main() {
	int n, m;
	const char output[] = { '#', 'A', 'B', 'C', 'D' };
	std::vector<int> seat;
	
	while (std::cin >> n >> m) {
		if (n == 0 && m == 0)
			break;

		seat.resize(n);

		for (int i = 0; i < m; ++i) {
			char who;
			std::cin >> who;

			if (who == 'A') {
				for (int j = 0; j < n; ++j) {
					if (seat[j] == 0) {
						seat[j] = 1;
						break;
					}
				}
			}
			else if (who == 'B') {
				int firstEmpty = 334;
				bool isRightA = false;

				for (int j = n - 1; j >= 0; --j) {
					if (seat[j] == 0) {
						firstEmpty = std::min(firstEmpty, j);
						if (!isRightA && (j == 0 || seat[j - 1] != 1)) {
							seat[j] = 2;
							break;
						}
					}
					isRightA = seat[j] == 1;
				}
			}
			else if (who == 'C') {
				for (int j = 0; j < n; ++j) {
					if (seat[j] != 0) {
						if (j != n - 1 && seat[j + 1] == 0) {
							seat[j + 1] = 3;
							break;
						}
						if (j != 0 && seat[j - 1] == 0) {
							seat[j - 1] = 3;
							break;
						}
					}
					if (j == n - 1)
						seat[n / 2] = 3;
				}
			}
			else if (who == 'D') {
				int maxDist = 0;
				int maxIdx = 0;

				int dist = 0;

				int fromTop = 0;
				int toLast = 0;

				for (int j = 0; j < n; ++j) {
					++dist;
					if (seat[0] != 0 && j == n - 1)
						toLast = dist;

					if (seat[j] != 0) {
						if (fromTop == 0)
							fromTop = j + 1;

						if (maxDist < dist / 2) {
							maxDist = dist / 2;
							maxIdx = j - dist;
						}
						dist = 0;
					}
				}

				if (seat[n - 1] == 0 && toLast > maxDist && fromTop < toLast)
					seat[n - 1] = 4;
				else if (seat[0] == 0 && fromTop > maxDist && fromTop > toLast)
					seat[0] = 4;
				else
					seat[maxIdx + maxDist] = 4;
			}
		}

		for (int i = 0; i < n; ++i)
			std::cout << output[seat[i]];
		std::cout << std::endl;
		seat.clear();
	}

	return 0;
}

Measured memory_bytes: 1192
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

typedef struct{
  int m; //?????±?????\????????????????????§??????
  long L;
}guy;

int n;
guy g[100];

long dp[101][65537]; //2^16+1
//???x???????????¨??????????????????y????????±?????\????????¶?????§???????¶????????????§???
long rec(int x, int y){
  if(dp[x][y]>=0) return dp[x][y];

  if(x==n) return 0;

  long ret=0;

  //x??????????????±?????\????????¶?????¨????????¶???y?????????
  if((g[x].m & y)==0){
    //??????????????????????????????????????????????????????
    //x????????¨????????????????????????????????????????¨??????????
    ret = max( rec(x+1,y), rec(x+1,y|g[x].m)+g[x].L );
  }
  else ret = rec(x+1,y);

  return dp[x][y] = ret;
}

int main(){

  int sq[16];
  sq[0]=1;
  for(int i=1; i<16; ++i) sq[i]=sq[i-1]*2;

  while (1) {
    //input
    cin >> n;
    if(n==0) break;
    for(int i=0; i<n; ++i){
      int p;
      cin >> p >> g[i].L;
      g[i].m=0;
      for(int j=0; j<p; ++j){
        int s,e;
        cin >> s >> e;
        for(int k=s; k<e; ++k) g[i].m += sq[k-6];
      }
    }

    //solve
    memset(dp, -1, sizeof(dp));
    cout << rec(0,0) << endl;
  }
}

Measured memory_bytes: 52884
//abc155_b.cpp
//Sat Apr  4 20:45:37 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	for (int i=0;i<n;i++){
		int a;
		cin >> a;
		if (a%2==0){
			if (a%3!=0 && a%5!=0){
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}

	cout << "APPROVED" << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
using namespace std;

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

const long long INF = 1LL << 60;
char s[60][60];
int bomb[60][60];
int main()
{
	int h, w;cin >> h >> w;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			cin >> s[i][j];
		}
	}

	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			if (s[i][j] == '.') {
				bomb[i][j] = 0;
				for (int k = -1;k < 2;k++) {
					for (int l = -1;l < 2;l++) {
						if (i + k >= 0 && i + k < h&&j + l >= 0 && j + l < w) {
							if (s[i + k][j + l] == '#') {
								bomb[i][j]++;
							}
						}
					}
				}
			}
		}
	}
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			if (s[i][j]=='.') {
				if (j == w - 1) {
					cout << bomb[i][j] << endl;
				}
				else {
					cout << bomb[i][j];
				}
			}
			else {
				if (j == w - 1) {
					cout << s[i][j] << endl;
				}
				else {
					cout << s[i][j];
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include <vector>
#include <map>
#include<cstdlib>
#include<iomanip>
#include<queue>


using namespace std;

void Solution()
{
   	int n;
    
    long long number, perPrice, amount;
    
    bool isUsed;
    //long long valueCheck[4000];
    vector<long long> valueCheck(4001, 0);
    queue<int> que;
    
    while(true)
    {
        isUsed = false;
        
        cin>>n;
        
        if (n == 0)
        {
            break;
        }
        
        while(n--)
        {
            cin>>number>>perPrice>>amount;
            
            valueCheck[number] += perPrice * amount;
            que.push(number);
        }
        
        while (!que.empty())
        {
            if (valueCheck[que.front()] >= 1000000)
            {
                cout<<que.front()<<endl;
                isUsed = true;
            }
            
            valueCheck[que.front()] = 0;
            que.pop();
        }
        
        if (!isUsed)
        {
            cout<<"NA"<<endl;
        }
        
//            if ( valueCheck >= 1000000)
//            {
//                cout<<number<<endl;
//            }
//            else
//            {
//                count++;
//            }
//            
//            if (count == m)
//            {
//                cout<<"NA"<<endl;
//            }
        
    }
}

int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define sz(a) (int)a.size()
#define B_E(a) a.begin(),a.end()
#define pb push_back
#define pob pop_back
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);

const ll MaxN=1e5+5;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main(){
	ll n,m;
	cin>>n>>m;
	char x[n+1][m+1];
	REP(i,n){
		REP(j,m){
			cin>>x[i][j];
		}
	}
	REP(i,n){
		REP(j,m){
			ll cnt=0;
			if(x[i][j]=='.'){
				if(x[i][j+1]=='#'){
					cnt++;
				}
				if(x[i][j-1]=='#'){
					cnt++;
				}
				if(x[i-1][j]=='#'){
					cnt++;
				}
				if(x[i+1][j]=='#'){
					cnt++;
				}
				if(x[i+1][j+1]=='#'){
					cnt++;
				}
				if(x[i+1][j-1]=='#'){
					cnt++;
				}
				if(x[i-1][j+1]=='#'){
					cnt++;
				}
				if(x[i-1][j-1]=='#'){
					cnt++;
				}
				x[i][j]=cnt+'0';
			}
		}
	}
	REP(i,n){
		REP(j,m){
			cout<<x[i][j];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int r = sc.nextInt();
		int c = sc.nextInt();

		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				rc[i][j] = sc.nextInt();
			}
		}

		for(int i = 0; i < r; i++){ //
			int sum = 0;
			for(int j = 0; j < c; j++) {
				System.out.print(rc[i][j] + " ");
				sum += rc[i][j];
			}
			System.out.println(sum);
		}

		int allsum = 0;
		int sum = 0;
				
			for(int i = 0; i < c; i++) {
				sum = 0;
				for(int j = 0; j < r; j++) {
					sum += rc[j][i];
				}
				System.out.print(sum + " ");
				allsum += sum;
			}
		
		System.out.println(allsum);
		sc.close();
	}
}



Measured memory_bytes: 41144
# -*- coding: utf-8 -*-
# 整数の入力

def isKaibun(a):
    for i in range(int(len(a)/2)):

        if a[i]!=a[len(a)-i-1]:

            return 0
    return 1
a = input()

if isKaibun(a)*isKaibun(a[0:int((len(a)-1)/2)])*isKaibun(a[int((len(a)+3)/2)-1:len(a)])==1:
    print("Yes")
else :
    print("No")
# スペース区切りの整数の入力


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define Re register
#define LL long long
#define U unsigned
#define FOR(i,a,b) for(Re int i = a;i <= b;++i)
#define ROF(i,a,b) for(Re int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int p[]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};

int n;
bool check(int x,int cnt) {
	int ret=0;
	for(int i=1;i<=n;++i) {
		int j=i;
		while(j%x==0) j/=x,++ret;
	}
	return ret>=cnt;
}
int main() {
	scanf("%d",&n);
	int ans=0;
	FOR(i,1,25) FOR(j,i+1,25) FOR(k,j+1,25) {
		int x=p[i],y=p[j],z=p[k];
		if(check(x,2)&&check(y,4)&&check(z,4)) ++ans;
		if(check(x,4)&&check(y,2)&&check(z,4)) ++ans;
		if(check(x,4)&&check(y,4)&&check(z,2)) ++ans;
	}
	FOR(i,1,25) FOR(j,i+1,25) {
		int x=p[i],y=p[j];
		if(check(x,4)&&check(y,14)) ++ans;
		if(check(x,14)&&check(y,4)) ++ans;
		if(check(x,2)&&check(y,24)) ++ans;
		if(check(x,24)&&check(y,2)) ++ans;
	}
	FOR(i,1,25) {
		int x=p[i];
		if(check(x,74)) ++ans;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (pointCount, dimension) = readLine()!!.split(" ").map { it.toInt() }
    val coordinate = mutableListOf<List<Double>>()
    repeat(pointCount) {
        coordinate.add(readLine()!!.split(" ").map { it.toDouble() })
    }
    var ans = 0

    for (i in 0 until pointCount) {
        for (j in i + 1 until pointCount) {
            var temp = 0.0
            for (k in 0 until dimension) {
                temp += Math.pow(Math.abs(coordinate[i][k] - coordinate[j][k]), 2.0)
            }
            if ((Math.sqrt(temp) - Math.sqrt(temp).toInt()) == 0.0) ans += 1
        }
    }
    print(ans)
}

Measured memory_bytes: 37924
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,M;
    cin >> N >> M;
    vector<pair<ll,ll>> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i].first >> A[i].second;
    }
    sort(A.begin(),A.end());
    ll ans = 0;
    for(int i=0; i<N; i++){
        ll now = min(A[i].second,M);
        ans += now * A[i].first;
        M -= now;
    }
    cout << ans << enld;
    return 0;
}

Measured memory_bytes: 1792
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue

mod = 1000000007

if __name__ == "__main__":
    N, M = map(int, sys.stdin.readline().split())

    broken = [False for _ in range(N + 2)]
    for _ in range(M):
        broken[int(sys.stdin.readline())] = True

    dp = [0 for _ in range(N + 2)]
    dp[N] = 1
    for i in range(0, N)[::-1]:
        if not broken[i]:
            dp[i] = dp[i + 1] + dp[i + 2]
    print(dp[0] % mod)

Measured memory_bytes: 461736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const ll INF = 1e18 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int cnt[220000];
vector<int> vec[220000];

void dfs(int x, int p){
  cnt[x] += cnt[p];
  for(int y : vec[x]){
    if(y == p) continue;
    dfs(y, x);
  }
}

int main(){
  int n, q;
  cin >> n >> q;
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    vec[a].push_back(b);vec[b].push_back(a);
  }

  fill(cnt, cnt + 220000, 0);
  rep(i, q){
    int p, x;
    cin >> p >> x;
    p--;
    cnt[p] += x;
  }
  dfs(0, -1);
  rep(i, n) printf("%d%c", cnt[i], i == n-1 ? '\n' : ' ');
}
  
  

Measured memory_bytes: 25416
import           Data.Ord
import           Data.List

main :: IO ()
main = do
    n      <- fmap read getLine :: IO Int
    [t, a] <- fmap (map read . words) getLine :: IO [Double]
    hs     <- fmap (map read . words) getLine :: IO [Double]
    print $ solve t a hs

solve :: Double -> Double -> [Double] -> Int
solve t a hs = minindex ds where ds = map (\h -> abs $ t - a - h * 0.006) hs

minindex :: [Double] -> Int
minindex ls = fst . head $ sortOn snd $ zip [1 ..] ls


Measured memory_bytes: 1404
#include<iostream>
#include<algorithm>
#include <vector>
#include <numeric>
using namespace std;

int main(){
    int n;
    int max_s=0;
    int sum_s=0;
    int L;

    cin>>n;
    for (int i=0;i<n;i++){
        cin>>L;
        sum_s+=L;
        max_s=max(max_s,L);
    }  	
	if (max_s<sum_s-max_s){
    cout<<"Yes"<<endl;
    }else{
    cout<<"No"<<endl;
    }
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  rep(i, n) {
    int h;
    cin >> h;
    if (h >= k) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long

#define MAX_N 1000000
#define MAX_W 10000

int check(int w[MAX_N], int n, int k, ll p)
{
    int i = 0;
    REP(j, k)
    {
        ll sum = 0;
        for(; sum + w[i] < p; i++)
        {
            sum += w[i];
        }
    }
    return i;
}

int main()
{
    int n, k, w[MAX_N];
    cin >> n >> k;
    REP(i, n) cin >> w[i];

    ll r = n * MAX_W;
    ll l = 0;
    while(r - l > 0)
    {
        ll mid = (l + r)/2;
        int v = check(w, n, k, mid);
        if(v >= n) r = mid;
        else l = mid + 1;
    }
    cout << l - 1 << endl;
}

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

int main() {
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'o') cnt++;
    }

    if (15 - s.size() + cnt >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256