akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

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

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

    int count = 0;
    int min_P = P[0];
    for(int i = 0; i < N; i++){
        if(min_P >= P[i]){
            min_P = P[i];
            count++;
        }
    }
/*
    for(int i = 1; i<= N; ++i){
        for(int j = 0; j < tail; ++j){
            if(i == P[j]){
                count++;
                tail = j;
            }
        }
    }
*/
    cout << count << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

		//get
		int companyXFeeRate = Integer.parseInt(bufferedReader.readLine());
		int companyYBase = Integer.parseInt(bufferedReader.readLine());
		int companyYLimit = Integer.parseInt(bufferedReader.readLine());
		int companyYAdd = Integer.parseInt(bufferedReader.readLine());
		int usedWater = Integer.parseInt(bufferedReader.readLine());

		int companyXFee = companyXFeeRate * usedWater;
		int companyYFee = 0;

		if(companyYLimit < usedWater) {
			int over = usedWater - companyYLimit;
			companyYFee = companyYBase + companyYAdd * over;
		} else {
			companyYFee = companyYBase;
		}

		System.out.println(companyXFee < companyYFee ? companyXFee : companyYFee);
	}

	public static String getStringCharAt(String str, int position) {
		return String.valueOf(str.charAt(position));
	}

	public static String[] getStringCharArr(String str) {

		String[] arrResult = new String[str.length()];

		for(int i = 0; i < str.length(); i++) arrResult[i] = getStringCharAt(str, i);

		return arrResult;
	}

	public static boolean isInnerPosition(int x1, int x2, int searchPosition) {
		return x1 <= searchPosition && searchPosition <= x2;
	}

}

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

/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______
 * |\  \|\  \  |\  ___ \  |\  ___ \
 * \ \  \/  /|_\ \   __/| \ \   __/|
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 100010;

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

	long long A,B,C,K;
	cin>>A>>B>>C>>K;
	if(K&1) swap(A,B);
	cout<<A-B<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
using ll = long long;
#define max(a,b) ((a)>(b) ? (a):(b))
#define min(a,b) ((a)<=(b) ? (a):(b))
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

int main(){
  ll H,N;
  cin >> H >> N;
  vector<int> A(N);
  ll sum = 0;
  ll i;
  rep(i,N){
    cin >> A[i];
    sum += A[i];
  }
  if(sum >= H) cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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


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

ll dp[101010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> h(n);
    REP(i,n) cin>>h[i];
    REP(i,101010) dp[i]=1LL<<60;
    dp[0]=0;
    for(int i=1;i<n;i++){
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i>1) chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1408
#include <limits.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
template <typename T = long long>
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...));
}

int main() {
  int n, p;
  cin >> n >> p;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<vector<ll>> dp(n, vector<ll>(2, 0));
  dp[0][0] = 1;
  dp[0][a[0] % 2] += 1;
  for (int i = 1; i < n; i++) {
    if (a[i] % 2 == 0) {
      dp[i][0] = dp[i - 1][0] * 2;
      dp[i][1] = dp[i - 1][1] * 2;
    } else {
      dp[i][0] = dp[i - 1][1] + dp[i - 1][0];
      dp[i][1] = dp[i - 1][1] + dp[i - 1][0];
    }
  }
  cout << dp[n - 1][p] << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;



int main(){
  ll N;
  cin >> N;
  vector<ll> A(N,0);
  vector<ll> B(N,0);
  for(ll i=0;i<N;i++){
    cin>>A[i]>>B[i]
  ;}
  priority_queue<P>  fora;
  priority_queue<P>  forb;
  for(ll i=0;i<N;i++){
    fora.push(P(A[i]+B[i],i));
    forb.push(P(B[i]+A[i],i));
  ;}

  //    食ったら１
  vector<ll> check(N,0);
  ll ans=0;
  while(1){
    //Aの番
    while(1){
    if(fora.empty()){cout<<ans<<endl;return 0;};
    P x=fora.top();fora.pop();
    if(check[x.second]){continue;}
    else {
      ans+=A[x.second];check[x.second]++;break;
    }
    }
    //Bの番
    while(1){
    if(forb.empty()){cout<<ans<<endl;return 0;};
    P x=forb.top();forb.pop();
    if(check[x.second]){continue;}
    else {
      ans-=B[x.second];check[x.second]++;break;
    }
    }
    
  }
    
    return 0;
}


Measured memory_bytes: 5732
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();

        sc.close();

        BigDecimal bdA = new BigDecimal(a);
        BigDecimal bdB = new BigDecimal(b);

        if (bdA.compareTo(bdB) == 0) {
            System.out.println("EQUAL");
        } else if (bdA.compareTo(bdB) > 0) {
            System.out.println("GREATER");
        } else {
            System.out.println("LESS");
        }
    }
}

Measured memory_bytes: 23124
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N,K,Q = inputMap()
	A = []

	mem = [0 for i in range(N)]

	for i in range(Q):
		tmp = inputInt()
		mem[tmp-1] += 1

	ans = [K-Q for i in range(N)]

	for i,val in enumerate(mem):
		ans[i] += val
		if ans[i] <= 0:
			print("No")
		else:
			print("Yes")




if __name__ == "__main__":
	main()


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

bool is_kibun(string s, int begin, int end)
{
	int b = begin - 1;
	int e = end - 1;
	while (b < e){
		if(s[b] != s[e]) return false;
		b++;
		e--;
	}
	
	return true;
}

int main() 
{
	string s;
	cin >> s;
	
	int N = s.length();
	bool b = is_kibun(s, 1, N);
	b &= is_kibun(s, 1, (N-1)/2);
	b &= is_kibun(s, (N+3)/2, N);
	
	cout << (b ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;

#define lim 105
ll a[lim],b[lim];

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll x,n;
    sfl(x),sfl(n);
    FOR(i,n){
        sfl(a[i]);
        b[a[i]]=1;
    }
    ll mn = INF,mn1=INF,c=-1,d=-1;
    ll p = x;
    while(p>=0){
        if( !b[p] ){
            mn = x-p;
            c = p;
            break;
        }
        else{
            p--;
        }
    }
    p = x;
    while(1){
        if( !b[p] ){
            mn1 = p-x;
            d = p;
            break;
        }
        else{
            p++;
        }
    }
    if( mn<=mn1 ){
        pfl(c);
    }
    else{
        pfl(d);
    }
    
    return 0;
}


Measured memory_bytes: 3752
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
using namespace std;
int r[110];
double eps=1e-9;
double d[110];
double x[110];
double y[110];
int ret[110];
int used[110];
const int D_MAX_V=212;
const int D_v_size=212;
struct D_wolf{
	int t,c,r;
	D_wolf(){t=c=r=0;}
	D_wolf(int t1,int c1,int r1){
		t=t1;c=c1;r=r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from,int to,int cap){
	D_G[from].push_back(D_wolf(to,cap,D_G[to].size()));
	D_G[to].push_back(D_wolf(from,0,D_G[from].size()-1));
}
void D_bfs(int s){
	for(int i=0;i<D_v_size;i++)D_level[i]=-1;
	queue<int> Q;
	D_level[s]=0;
	Q.push(s);
	while(Q.size()){
		int v=Q.front();
		Q.pop();
		for(int i=0;i<D_G[v].size();i++){
			if(D_G[v][i].c>0&&D_level[D_G[v][i].t]<0){
				D_level[D_G[v][i].t]=D_level[v]+1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
int D_dfs(int v,int t,int f){
	if(v==t)return f;
	for(;D_iter[v]<D_G[v].size();D_iter[v]++){
		int i=D_iter[v];
		if(D_G[v][i].c>0&&D_level[v]<D_level[D_G[v][i].t]){
			int d=D_dfs(D_G[v][i].t,t,min(f,D_G[v][i].c));
			if(d>0){
				D_G[v][i].c-=d;
				D_G[D_G[v][i].t][D_G[v][i].r].c+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	for(;;){
		D_bfs(s);
		if(D_level[t]<0)return flow;
		for(int i=0;i<D_v_size;i++)D_iter[i]=0;
		int f;
		while((f=D_dfs(s,t,99999999))>0){flow+=f;}
	}
	return 0;
}
int a,b;
int chk(){
	for(int i=0;i<212;i++){
		D_G[i].clear();
		D_level[i]=D_iter[i]=0;
	}
	int s=210;
	int t=211;
	int f=0;
	for(int i=0;i<b;i++)if(!ret[i]){
		add_edge(s,i,1);
		f++;
	}
	for(int i=0;i<a;i++)if(!used[i])add_edge(b+i,t,1);
	for(int i=0;i<b;i++)for(int j=0;j<a;j++){
		if(!ret[i]&&!used[j]&&d[i]-eps<r[j])add_edge(i,b+j,1);
	}
	return max_flow(s,t)==f;
}
int main(){
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d",r+i);
	}
	for(int i=0;i<b;i++){
		int p;scanf("%d",&p);
		for(int j=0;j<p;j++)scanf("%lf%lf",x+j,y+j);
		double mv=100;
		double X=0;
		double Y=0;
		double t=999999999;
		for(int j=0;j<1000;j++){
			double dist=0;
			int at=0;
			for(int k=0;k<p;k++){
				double tmp=(x[k]-X)*(x[k]-X)+(y[k]-Y)*(y[k]-Y);
	//			printf("%f ",tmp);
				if(dist<tmp){
					dist=tmp;at=k;
				}
			}
		//	printf("%f\n",dist);
			t=min(t,sqrt(dist));
			double dx=x[at]-X;
			double dy=y[at]-Y;
			double dl=sqrt(dx*dx+dy*dy);
			X+=dx/dl*mv;
			Y+=dy/dl*mv;
			if(j%20==19)mv/=2;
		}
		d[i]=t;
	//	printf("%f %f: %f\n",X,Y,d[i]);
		//for(int j=0;j<p;j++)printf("%f %f\n",x[j],y[j]);
	}
	if(!chk()){
		printf("NG\n");return 0;
	}
	for(int i=0;i<b;i++){
		for(int j=0;j<a;j++){
			if(d[i]-eps>r[j])continue;
			if(used[j])continue;
			ret[i]=j+1;
			used[j]=1;
			if(chk()){
				break;
			}
			used[j]=0;
		}
	}
	for(int i=0;i<b;i++)printf("%d\n",ret[i]);
}

Measured memory_bytes: 1256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N = 10**5

Q = int(input())
L = [list(map(int, input().split())) for i in range(Q)]

prime = [1]*N
prime[0] = prime[1] = 0

for i in range(2,N):
    if prime[i]:
        tmp = i*2
        while tmp < N:
            prime[tmp] = 0
            tmp += i

r_sum = [0]*N
for i in range(3,N):
    if prime[i] and prime[(i+1)//2]:
        r_sum[i] = r_sum[i-1]+1
    else:
        r_sum[i] = r_sum[i-1]

for l in L:
    print(r_sum[l[1]]-r_sum[l[0]-1])

Measured memory_bytes: 38792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


int main(){
  int m,n;
  int i,j;
  int N;
  scanf("%d",&N);

  char w[N][256];
  for(i=1; i<=N; i++){
    scanf("%s",w[i-1]);
  }

  int l=0;
  i=1;
  for(i=0; i<=N-1; i++){
    for(j=i; j<=N-1;j++){
      if(strcmp(w[i-1],w[j])==0){
        l = l+1;
      }
    }
  }
  for(i=1; i<=N-1; i++){
    m = strlen(w[i-1]);
    n = strlen(w[i]);
    if(w[i-1][m-1]==w[i][0]){
      l = l;
    }else{
      l = l+1;
    }
  }
  if(l==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }


  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()
	root := make([]int, N + 2)

	for i := 1; i <= N; i++ {
		root[i] = nextInt()
	}

	originalCost := 0
	for i := 0; i <= N; i++ {
		originalCost += distance(root[i], root[i+1])
	}

	for i := 1; i <= N; i++ {
		fmt.Println(originalCost + distance(root[i-1], root[i+1]) - distance(root[i-1], root[i]) - distance(root[i], root[i+1]))
	}
}

func distance(a, b int) int {
	if a > b {
		return a - b
	} else {
		return b - a
	}
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> table(h);
    for (auto& v : table)
    {
        cin >> v;
    }

    vector<int> dx = { 0, 1, 0, -1 };
    vector<int> dy = { 1, 0, -1, 0 };

    bool success = true;

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (table[i][j] == '#')
            {
                bool is_black_any = false;
                for (int k = 0; k < 4; k++)
                {
                    const int ny = i + dy[k];
                    const int nx = j + dx[k];
                    if (0 <= ny && ny < h && 0 <= nx && nx < w)
                    {
                        if (table[ny][nx] == '#')
                        {
                            is_black_any = true;
                            break;
                        }
                    }
                }
                if (!is_black_any)
                {
                    success = false;
                }
            }
        }
    }

    cout << (success ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
const main =(standardInput) =>{
  const s = standardInput;
  var start=-1,end=0,i=0;
  while(s[i]){
    if(s[i]=='A' && start ==-1){
    start=i;
    }else if(s[i]=='Z'){
    end=i;
    }
    i++;
  }
  var out=end+1-start;
  console.log(out);
  
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));

Measured memory_bytes: 7372
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000
#define MAX 200000

// sieve of Eratosthenes (prime num)
bool p[MAX+1]; //prime number=true
void prime(int n){
  rep(i,n+1) p[i]=true;
  p[0]=p[1]=false;
  for(int i=2;i<=n;i++){
    if(p[i]){
      for(int j=i*2; j<=n; j+=i){
	p[j]=false;
      }
    }
  }
}


int main(){
  prime(MAX);
  int n,P;
  while(scanf("%d %d", &n, &P), (n!=-1)||(P!=-1)){
    int nums[100];
    vector<int> adds;

    // take P prime number bigger than n
    int cnt=0, idx=n+1;
    while(cnt<P){
      if(p[idx]){
	nums[cnt]=idx;
	cnt++;
	rep(i,cnt){
	  adds.pb(nums[i]+idx);
	}
      }
      idx++;
    }

    sort(all(adds));

    cout << adds[P-1] << endl;

  }
  return 0;
}

Measured memory_bytes: 1480
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, a, b, dl, h[N], mx;
bool isval(int cnt) {
	long long ps = 1ll * cnt * b, nd = 0;
	for (int i = 0; i < n; i++) {
		long long x = 1ll * h[i] - ps;
		if (x > 0) 
			nd += 1ll * (x + dl - 1) / dl;
	}
	return nd <= cnt;
}
int findAns() {
	int up = mx, dw = 0;
	while (up - dw > 1) {
		long long md = 1ll * (up + dw) / 2;
		if (isval(md)) 
			up = md;
		else
			dw = md;
	}
	return up;
}
int main() {
	cin >> n >> a >> b;
	dl = a - b;
	for (int i = 0; i < n; i++)
		cin >> h[i], mx = max(mx, h[i]);
	cout << findAns();
	return 0;
}	


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    vector<vector<int>> x(n);
    vector<vector<int>> y(n);
    int ans=-1;
    rep(i,n){
        int m;
        cin >> m;
        rep(j,m){
            int a,b;
            cin >> a >> b;
            a--;
            x[i].push_back(a);
            y[i].push_back(b);
        }
    }
    rep(bit,1<<n){
        int cnt=0;
        bool ok=true;
        rep(i,n){
        if(bit>>i&1){
            rep(j,x[i].size()){
                if((bit>>x[i][j]&1) != y[i][j]) ok=false;
            }
            cnt++;
        }
    }
    if(ok)ans = max(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int main() {
    ll n; cin >> n;
    string ans;
    while(n) {
        n--;
        ans += 'a' + n%26;
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 3568
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7

N = int(input())
AB = []
for _ in range(N):
    AB.append((int(input()), 0))
for _ in range(N):
    AB.append((int(input()), 1))
AB.sort(reverse=True)

ans = 1
Aset = 0
Bset = 0

while AB:
    _, x = AB.pop()
    if x:
        if Bset:
            ans *= Bset
            ans %= mod
            Bset -= 1
        else:
            Aset += 1
    else:
        if Aset:
            ans *= Aset
            ans %= mod
            Aset -= 1
        else:
            Bset += 1

print(ans)

Measured memory_bytes: 24524
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		Long A = sc.nextLong();
		Long B = sc.nextLong();
		Long K = getK(A,B) ;
		if(K == null) {
			System.out.println("IMPOSSIBLE");
		}else {
			System.out.println(K);
		}
	}

	public Long getK(Long A, Long B) {

		Long K = null ;
		if((A+B)%2 == 0 ) {
			K = (A + B)/2 ;
		}

		return K ;
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep2(i,a,n) for(int i = (a);i < (n);i++)
#define rep(i,n) rep2(i,0,n)
#define INF (1LL << 60)

vector<ll> a;
ll n;

ll solve(ll x,ll y,ll z){
    ll sum = (x*x+y*y+z*z+x*y+y*z+z*x);
    if(sum > n)return 0;
    return sum;
}

int main(void){
    cin >> n;
    a.resize(n+n,0);
    
    for(ll i = 1;i <= n;i++){
        for(ll j = i;i*j <= n;j++){
            for(ll l = j;j*l <= n;l++){
                if(i == j && j == l)a[solve(i,j,l)]++;
                else if(i != j && j != l && j != l)a[solve(i,j,l)]+=6;
                else a[solve(i,j,l)]+=3;
            }
        }
    }
    
    for(int i = 1;i <= n;i++)cout << a[i] << endl;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 1e9 + 1
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

int n, A[100010];

int partition(int p, int r) {
    int x = A[r];
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

int main() {
    cin >> n;
    REP(i, n) cin >> A[i];
    int q = partition(0, n - 1);
    REP(i, n) {
        if (i) cout << " ";
        if (i == q) cout << "[";
        cout << A[i];
        if (i == q) cout << "]";
    }
    cout << endl;
}


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

namespace _ {
	bool rEOF = 1;//为0表示文件结尾
	inline char nc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return p1 == p2 && rEOF && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? (rEOF = 0, EOF) : *p1++;
	}
	template<class _T>
	inline bool read(_T &num) {
		char c = nc(), f = 1; num = 0;
		while (c<'0' || c>'9')c == '-' && (f = -1), c = nc();
		while (c >= '0'&&c <= '9')num = num * 10 + c - '0', c = nc();
		return (bool)(num *= f);
	}
	inline bool need(char &c) { return c >= 'a'&&c <= 'z' || c >= '0'&&c <= '9' || c >= 'A'&&c <= 'Z'; }//读入的字符范围
	inline bool read_str(char *a) {
		while ((*a = nc()) && need(*a) && rEOF)++a;
		*a = '\0'; return rEOF;
	}
}using namespace _;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	}
}

int n, m, p;

struct Edge {
	int u, v, c;
}edge[5000 + 5];
int cnt = 0;

void add(int u, int v, int c)
{
	edge[cnt].u = u;
	edge[cnt].v = v;
	edge[cnt].c = c-p;
	cnt++;
}

long long dist[2500 + 5];

bool bellman(int n)
{
	for (int i = 1; i <= n; i++)dist[i] = -0x3f3f3f3f3f3f3f3f;
	dist[1] = 0;
	for (int i = 1; i < n; i++)
	{
		bool flag = 0;
		for (int j = 0; j < cnt; j++)
		{
			int u = edge[j].u;
			int v = edge[j].v;
			int c = edge[j].c;
			dist[v] = max(dist[v], dist[u] + c);
		}
	}
	bool flag = 0;
	for (int i = 1; i <= n; i++)
	{
		long long mini = dist[n];
		for (int j = 0; j < cnt; j++)
		{
			int u = edge[j].u;
			int v = edge[j].v;
			int c = edge[j].c;
			dist[v] = max(dist[v], dist[u] + c);
		}
		if (dist[n] != mini)return 0;
	}
	return 1;
}

int main()
{
	file(1);
	scanf("%d%d%d", &n, &m, &p);
	for (int i = 1; i <= m; i++)
	{
		int u, v, c;
		scanf("%d%d%d", &u, &v, &c);
		add(u, v, c);
	}
	if (bellman(n))
	{
		printf("%lld\n", max(0ll, dist[n]));
	}
	else
		printf("-1\n");
	return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    p = N// (A + B)
    ans = p * A
    mod = N % ( A + B )
    if mod >= A:
        ans += A
    else:
        ans += mod

    print(ans)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))

for i in range(n):
  a[i]-=(i+1)
  
a.sort()

if n%2==0:
  tmp=(a[n//2]+a[n//2-1])//2
else:
  tmp=(a[n//2])
  
ans=0
for aa in a:
  ans+=abs(aa-tmp)
#print(tmp)
#print(a)
print(ans)

  
  



Measured memory_bytes: 94436
#include <bits/stdc++.h>
using namespace std;
#define f(i,j,k)=for(int i=j;i<=k;i++)  
#define f2(i,j,k)=for(int i=j;i>=k;i--)  
int main(){
    long long a,b,c,k;
    cin>>a>>b>>c;
    cin>>k;
    long long ans=0;
    while(a>=b){
        b*=2;
        ans++;
    }
    while(b>=c){
        c*=2;
        ans++;
    }
    if(ans<=k){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
N = int(input())
a1, b1, c1 = map(int, input().split())
dp = [[0, 0, 0] for _ in range(N)]
dp[0][0] = a1
dp[0][1] = b1
dp[0][2] = c1
for i in range(1, N):
    a, b, c = map(int, input().split())
    dp[i][0] = a + max(dp[i-1][1], dp[i-1][2])
    dp[i][1] = b + max(dp[i-1][0], dp[i-1][2])
    dp[i][2] = c + max(dp[i-1][0], dp[i-1][1])

print(max(dp[-1]))


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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    REP(i, n) cin >> d[i];
    int ans = 0;
    for(int i = 0; i < n - 1; i++) {
        for(int j = i + 1; j < n; j++) {
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define brep(i,n) for(int i=n-1;i>=0;i--)
#define brep1(i,n) for(int i=n;i>=1;i--)
#define rep1(i,n) for(int i=1;i<n;i++)
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
#define ll long long
 
unsigned const int MOD = 1e9+7;
 
 
 
int main(void){
    int n;
    cin >> n;
    vector<ll> a;
    rep(i,n){
        int input;
        cin >> input;
        a.emplace_back(input);
    }
    sort(a.begin(),a.end());
    ll ans = a[(n/2)]-a[(n/2)-1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <complex>
#include <vector>
#include <cmath>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

typedef complex<double> P;
typedef vector<P> VP;
const double EPF = 1e-10;

#define X real()
#define Y imag()
#define EQ(x,y) (abs(x-y) < EPF)

double dot(P a, P b) {
  return (conj(a)*b).X;
}
double cross(P a, P b) {
  return (conj(a)*b).Y;
}
double distPP(P a, P b) {
  return sqrt(dot(a-b,a-b));
}
P crosspoint(P a, P b, P c, P d) {//ac , bd
  double d1 = cross(d-b,b-a);
  double d2 = cross(d-b,c-a);
  if(EQ(d1,0) & EQ(d2,0)) return a;
  if(EQ(d2,0)) return a;
  return a + (c-a)*d1/d2;
}
P normal_vector(P a) {
  P b(-a.Y, a.X);
  return b;
}
P polar(double r, double theta) {
  P a(r*cos(theta),r*sin(theta));
  return a;
}

int main() {
  int n;
  scanf("%d",&n);
  REP(i,n) {
    double x,y;
    P a,b,c,d;
    scanf("%lf %lf", &x, &y);
    a = P(x,y);
    scanf("%lf %lf", &x, &y);
    b = P(x,y);
    scanf("%lf %lf", &x, &y);
    c = P(x,y);
    scanf("%lf %lf", &x, &y);
    d = P(x,y);
    
    if(EQ(cross(a-b, c-d),0))printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

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

using namespace std;

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

	int B, i = 1, ans = 0;
	float A, T;

	cin >> A >> B >> T;

	T += 0.5;

	while (A * i < T) {
		ans += B;
		i++;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<string> s(n);
  vector<int> a(n);
  string x;
  for(int i=0;i<n;++i)cin>>s[i]>>a[i];
  cin>>x;
  bool f=false;
  int c=0;
  for(int i=0;i<n;++i){
    if(f)c+=a[i];
    if(x==s[i])f=true;
  }
  cout<<c;
}

Measured memory_bytes: 256
use std::io;


fn main() {
    let (a, b, c) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };
    let ans = (a..b + 1).filter(|&i| c % i == 0).count();
    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 5032
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;
const int mod = 1000000007;


int64_t combi(int n, int k) {
  int64_t a,b;
  if(n%2==0){ a=n/2,b=n-1;}
  else{ a=(n-1)/2,b=n;}
  return a*b;
}
int main() {

  int64_t N,ans=0;
  cin>>N;
  vector<int> A(N);
  unordered_map<int,int>map;
  for(int i=0; i<N; i++){
    int k; cin>>k;A[i]=k;
   if(!map.count(k))map[k]=1;
    else map[k]++;
  }
  for (auto i = map.begin(); i != map.end(); ++i) {
    if(i->second>1) ans+=combi(i->second,2);
}
      int64_t k=ans;
  for(int i=0; i<N; i++){
    int tmp=map[A[i]];
    if(tmp>1)ans-=combi(tmp,2);
    if(tmp>2)ans+=combi(tmp-1,2);
    cout<<ans<<endl;
    ans=k;
  }

}


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

int main() { 
    int a, b;
    cin >> a >> b;
    
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

// n の素因数を (素因数, 個数) のペアで列挙して返す。O(sqrt(N))
map<i64, int> primeFactorize(i64 n)  // {{{
{
    map<i64, int> pf;
    for (i64 i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            pf[i] += 1;
            n /= i;
        }
    }
    if (n != 1) pf[n] = 1;
    return pf;
}  // }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(i64, N);
    if (N == 1) {
        print(0);
        return 0;
    }

    i64 ans = 0;
    for (const auto [p, cnt] : primeFactorize(N)) {
        repr(i, 64, 0) {
            if (i * (i + 1) / 2 <= cnt) {
                dump(p, cnt, i);
                ans += i;
                break;
            }
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
const int maxn=1e5+5;
int main()
{
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    if(s[k-1]>='A'&&s[k-1]<='Z') s[k-1]+=32;
    cout<<s<<"\n";
}


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


int main()
{
    ll n;cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
      if(i%3 !=0 && i%5!=0)
        sum+=i;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <bitset>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <memory.h>
#include <algorithm>
using namespace std;
typedef long long ll;
string s;
int k;
int main()
{
	cin>>s>>k;
	for(int i=0;i<s.size();++i){
		if(s[i]=='a')
			continue;
		int need=26-(s[i]-'a');
		if(k<need)
			continue;
		k-=need;
		s[i]='a';
	}
	s[s.size()-1]=(s[s.size()-1]-'a'+k)%26+'a';
	puts(s.c_str());
	return 0;
}

Measured memory_bytes: 512
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<queue>

using namespace std;
deque<int> ans;
int m, k;
int main()
{
    cin >> m >> k;
    int mx = (1 << m) - 1;
    int n = (1 << (m + 1));
    if (mx < k || (m == 1 && k == 1)) {
        cout << -1 << endl;
        return 0;
    }
    if (k == 0) {
        for (int i = 0; i < n - 1; ++i) {
            cout << i / 2 << " ";
        }
        cout << (n - 1) / 2 << endl;
        return 0;
    }
    ans.push_back(k);
    int pad = k == 0 ? mx : 0;
    for (int i = 0; i <= mx; ++i) {
        if (i == k || i == pad) continue;
        ans.push_back(i);
        ans.push_front(i);
    }
    for (int i = 0; i < ans.size(); ++i) {
        cout << ans[i] << " ";
    }
    cout << pad << " " << k << " " << pad << endl;
}

Measured memory_bytes: 2816
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stack>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
printf("%d",min(min(min(a+c,a+d),b+c),b+d));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
using namespace std;

signed main(){
    while(1){
        int n;
        cin>>n;
        if(!n)break;
        int a[n];
        rep(i,n)cin>>a[i];
        int s=0;
        rep(i,n)s+=a[i];
        s/=n;
        int ans=0;
        rep(i,n)ans+=(a[i]<=s);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 10000000
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;
char snake[256]={0};
int check(int len){
	if(len % 2 == 1)return INF;
	if(snake[0] == '>'){
		if(snake[1] == 39){
			if(snake[len-1] != '~')return INF;
			int cnt = 0;
			int x = 0;
			rep(i,len){
				if(snake[i] == '#'){
					cnt++;
					x = i;
				}
			}
			if(cnt != 1)return INF;
			if(snake[2] != '=')return INF;
			reps(i,3,x){
				if(snake[i] != '=')return INF;
			}
			reps(i,x+1,len-1){
				if(snake[i] != '=')return INF; 
			}
			return (x-2 == len-x-2) ? 1 : INF; 
		}
		else if(snake[1] == '^'){
			if(snake[len-1] != '~' || snake[len-2] != '~')return INF;
			if(snake[2] != 'Q' || snake[3] != '=')return INF;
			for(int i = 4; i < len-2; i += 2){
				if(snake[i] != 'Q' || snake[i+1] != '=')return INF;
			}
			return 0;
		}
	}
	return INF;
}
int main(){
	int n;
	scanf("%d",&n);
	rep(q,n){
		memset(snake,0,sizeof(snake));
		scanf("%s",snake);
		int len = strlen(snake);
		int res = check(len);
		(res == 1) ? puts("A") : (res == 0) ? puts("B") : puts("NA");
	}
	return 0;
}

Measured memory_bytes: 1172
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0034
public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (sc.hasNext()) {
			String[] ss = sc.next().split(",");
			int v1 = new Integer(ss[10]), v2 = new Integer(ss[11]), L = 0;
			int[] ls = new int[10];
			for (int i = 0; i < 10; i++) {
				ls[i] = new Integer(ss[i]);
				L += ls[i];
			}
			double d = (double)v1 * L / ((double)(v1 + v2)); 
			int j = 0;
			do {
				d -= (double)ls[j++];
			} while (d > 0);
			System.out.println(j);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>

using namespace std;

using ll = long long;

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

	vector<int> ts(n);
	ll sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> ts[i];
		sum += ts[i];
	}

	int m;
	cin >> m;

	for (int i = 0; i < m; i++)
	{
		int p, x;
		cin >> p >> x;
		cout << (sum - ts[p - 1] + x) << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i,m,n) for(int i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
int main() {
    lli A,B,C;
    cin >> A;
    Out(A*A*A);
}


Measured memory_bytes: 3100
#from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n = ii()
    cnt = 0
    for i in range(1,n+1):
        if not i%2:
            continue
        tmp = 0
        for j in range(1,i+1):
            if not i%j:
                tmp+=1
        if tmp == 8:
            cnt+=1
    print(cnt)


main()




Measured memory_bytes: 3700
N = int(input())
A = [int(input()) for i in range(N)]
a_max = int(max(A))
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max or count >= 2:
		print(a_max)
	else:
		b_max = 0
		for j in range(N):
				if A[j] == a_max:
					continue
				if A[j] > b_max:
					b_max = A[j]
		print(b_max)


Measured memory_bytes: 12568
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;

int n;

int main() {
	cin >> n;
	int x = n*(n + 1) / 2;
	cout << x << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NKL (int64 *n, int64 *k, int64 *l)
{
  int cnt;
  
  cnt = scanf("%lld %lld %lld", n, k, l);

  return;
}

void omit_LF (void)
{
  char c;
  
  scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

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

//  if (NULL == fgets(buf, sizeof(buf), stdin)) {
//    return NULL;
//  }
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = malloc((size_t)(n * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

int main()
{
  int64 N,K,L;
  char *str;

  get_NKL(&N, &K, &L);

  if ((N+K+L) >= 22) {
    printf("bust");
    return 0;
  }
  printf("win");

  return 0;
}



Measured memory_bytes: 128
import Control.Applicative
import Data.List
toInt::String->Int
toInt = read
format::[Int]->String
format [x] = show x
format (x:xs) = show x ++ " " ++ format xs
sub2::[Int]->[[Int]]->[String]
sub2 [] [ys] = [format ys]
sub2 xs'@(x:xs) (ys:yss) = (format ys ++ " " ++ format xs') : sub2 xs yss
sub (x:xs) (y:ys) = sub2 xs ys
main::IO ()
main = do
  getLine
  a <- (map toInt).words <$> getLine
  (putStr.unlines.(sub a).(scanl (flip insert) [])) a


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N, P;
  cin >> N >> P;
  string S;
  cin >> S;
  if(P != 2 && P != 5){
  reverse(S.begin(),S.end());
  vector<int> ten(N+1,10%P);
  for(int i=1; i<N+1; i++){
    ten[i] = (ten[i-1]*10)%P;
  }
  int64_t dp[N+1];
  for(int i=0; i<N+1; i++){
    dp[i] = 0;
  }
  for(int i=0; i<N; i++){
    int x = S.at(i) - '0';
    if(i == 0){
      dp[i] = x%P;
    }
    else{
      dp[i] = (dp[i-1] + x*ten[i-1])%P;
    }
    //cout << dp[i] << endl;
  }
  
  map<int64_t,int64_t> mp;
  for(int i=0; i<N+1; i++){
    if(mp.count(dp[i])){
      mp[dp[i]]++;
    }
    else{
      mp[dp[i]] = 1;
    }
  }
  
  int64_t ans = 0;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    ans += (itr->second)*(itr->second-1)/2;
  } 
  cout << ans << endl;
  }
  else{
    int64_t cnt = 0;
    for(int i=0; i<S.size(); i++){
      int x = S.at(i) - '0';
      if(x %P == 0){
        cnt += i+1;
      }
    }
    cout << cnt << endl;
  }
}



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n;
	cin >> n;
	vector<int> l(n);
	for(int i = 0; i < n; ++i)
	{
		cin >> l[i];
	}

	sort(l.begin(), l.end());
	
	ll ans = 0;
	for(int i = 0; i < n - 2; ++i)
	{
		for(int j = i + 1; j < n - 1; ++j)
		{
			vector<int>::iterator iter = lower_bound(l.begin(), l.end(), l[i] + l[j]);
			ll size = iter - l.begin();
			// cout << "(" << i << ", " << j << ") " << size << " " << size - j - 1 << endl;
			ans += size - j - 1;
		}
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007ll
#define INF (1 << 28)    // for x <= 10^9
#define INFL (1ll << 60) // for x <=10^19
#define EPS (1e-10)

using namespace std;

using ll = long long;

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

  if (a == b && b == c) {
    if (a % 2 == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  int ans = 0;
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    int tmp1 = a;
    int tmp2 = b;
    a = (b + c) / 2;
    b = (tmp1 + c) / 2;
    c = (tmp1 + tmp2) / 2;
    ans++;
  }

  cout << ans << endl;
}


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

void  solve(){
unordered_map<int,int> cnt;
int n;
cin>>n;
vector<int> v(n);
long long s=0;
for(int i=0;i<n;i++){
	cin>>v[i];
	s=s^v[i];
}
for(auto i:v){
	cout<<(s^i)<<" ";
}


}

int  main(){

	
		solve();


 
}


Measured memory_bytes: 3980
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int a[3], count=0;
  for (int i = 0; i < 3; i++) cin >> a[i];
  sort(a, a+3);
  while (a[1] < a[2]) {
    a[0] += 1;
    a[1] += 1;
    count += 1;
  }
  if ((a[1] - a[0]) % 2 == 0) {
    count += int((a[1] - a[0]) / 2);
  }
  else count += int((a[1] + 1 - a[0]) / 2) + 1;
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 256