akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<"!"<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  vi ori;
  for(auto &a:A){cin>>a;ori.pb(a);}
  sort(ALL(A));
  double mid=((double)A[n/2-1]+A[n/2])/2;
  for(auto a:ori){
    //  cout<<a<<" "<<mid<<endl;
    if((double)a<mid){
      cout<<A[n/2]<<endl;
    }else{
      cout<<A[n/2-1]<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 5488
N, K, Q = map(int, input().strip().split())
# A=[0]*Q
score=[K]*N
for i in range(Q):
    A=int(input().strip())
    score[A-1]+=1
score=list(map(lambda x: x-Q,score))

for i in range(N):
    if score[i]>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 52056
N, K = map(int, input().split())
a = [0] * N
b = [0] * N

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

a, b = zip(*sorted(zip(a, b)))

count = 0
while K > 0:
    K -= b[count]
    count += 1

print(a[count - 1])

Measured memory_bytes: 25972
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[] a = new String[H];
		for(int i = 0; i < H; i++) {
			a[i] = sc.next();
		}
		StringBuilder buf = new StringBuilder();
		for(int i = 0; i < W+2; i++) {
			buf.append("#");
		}
		String frame = buf.toString();
		System.out.println(frame);
		for(int i = 0; i < H; i++) {
			System.out.println("#" + a[i] + "#");
		}
		System.out.println(frame);
	}
}


Measured memory_bytes: 30432
N,K=map(int,input().split())
n = []
for i in range(1 , N +1):
  n.append(i)


for i in range(K):
  di = int(input())
  arr= list(map(int,input().split()))
  for j in arr:
    if(j in n):
      n.remove(j)

print(len(n))

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

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

    dsu d(n);

    for (int i = 0; i < q; i++) {
        int w, a, b;
        cin >> w >> a >> b;
        if (w == 0) {
            d.merge(a, b);
        } else {
            if (d.same(a, b)) {
                cout << 1 << '\n';
            } else {
                cout << 0 << '\n';
            }
        }
    }
}


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

int main() {
  int n,l;
  cin>>n>>l;
  vector<string> s(n);
  for (int i=0;i<n;i++) cin>>s.at(i);
  sort(s.begin(),s.end());
  for (int i=0;i<n;i++) cout<<s.at(i);
  cout<<endl;
}

Measured memory_bytes: 256
def judge(p, r, l):
    rowBorder = r
    highBorder = l -r
    ret = False
    if p <= highBorder and p >= rowBorder:
        ret = True
    
    return ret

def circleinRec(w, h, x, y, r):
    #W
    retW = judge(x, r, w)

    #H
    retH = judge(y, r, h)

    if retW == True and retH == True:
        return True

    else:
        return False

def main():
    val = input().split()
    val = [int(n) for n in val]
    ret = circleinRec(val[0], val[1], val[2], val[3], val[4])
    if ret == True:
        print('Yes')

    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 5604
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
using namespace std;
const ll MAX=1e9+7;

ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}

int main(){
  ll N;
  cin >> N;
  vector<ll> a(N);
  rep(i,N){
    cin >> a[i];
  }
  ll sum=a[0];
  for(ll i=1;i<N;i++){
    sum=gcd(sum,a[i]);
  }
  cout << sum << endl;
}

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

int c[10][10];

void warshall_floyd(){
	REP(k,10){
		REP(i,10){
			REP(j,10){
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
}

int main(){
	int h,w;
	cin >> h >> w;
	REP(i,10){
		REP(j,10){
			cin >> c[i][j];
		}
	}
	warshall_floyd();
	int a[h][w];
	REP(i,h){
		REP(j,w){
			cin >> a[i][j];
		}
	}
	int res = 0;
	REP(i,h){
		REP(j,w){
			if(a[i][j] != -1){
				res += c[a[i][j]][1];
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k; cin >> n >> k;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]--;
	}
	vector<int> s(n+1);
	for(int i=0;i<n;i++){
		s[i+1]=(s[i]+a[i])%k;
	}
	map<int,int> mp;
	queue<int> q;
	ll ans=0;
	for(int i=0;i<=n;i++){
		ans+=mp[s[i]];
		mp[s[i]]++;
		q.push(s[i]);
		if(q.size()==k){
			mp[q.front()]--;
			q.pop();
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 12032
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
# mod = 998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
INF = 1<<32-1
# INF = 10**18

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

def main():
    n,k = map(int,ipt().split())
    ssm = SegTree([0]*300002,max,0)
    for i in range(n):
        a = int(ipt())
        sma = ssm.query(max(0,a-k),min(300001,a+k+1))
        ssm.update(a,sma+1)

    print(ssm.query(0,300001))


    return None

if __name__ == '__main__':
    main()


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

int main(void){
    int h, w;
    cin >> h >> w;

    char s[h+2][w+2];
    rep(i, h + 2){
        rep(j, w + 2){
            if(i == 0 || j == 0 || i == h + 1 || j == w + 1)
                s[i][j] = '.';
            else
                cin >> s[i][j];
        }
    }

    for(int i = 1; i < h + 1; i++){
        for(int j = 1; j < w + 1; j++){
            bool check = false;
            if(s[i][j] == '#'){
                s[i][j] = '+';
                if(s[i+1][j] != '.'){
                    s[i+1][j] = '+';
                    check = true;
                }
                if(s[i-1][j] != '.'){
                    s[i-1][j] = '+';
                    check = true;
                }
                if(s[i][j+1] != '.'){
                    s[i][j+1] = '+';
                    check = true;
                }
                if(s[i][j-1] != '.'){
                    s[i][j-1] = '+';
                    check = true;
                }

                if(check == false){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int n,a,b;
    cin>>n>>a>>b;
    long long int ans=(n/(a+b))*a;
    n%=a+b;
    ans+=min(a,n);
    cout<<ans<<"\n";
	return 0;
}

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

const int MAXN = 100010;

typedef long long ll;
const int mod = 1e9 + 7;

#define X first
#define Y second

vector<pair<int, int> > E[MAXN];
bool flag = true;
bool vis[MAXN];
int d[MAXN];

void dfs(int x)
{
	for (auto e: E[x])
	{
		int y = e.X, z = e.Y;
		if (!vis[y])
		{
			vis[y] = true;
			d[y] = d[x] + z;
			dfs(y);
		}
		else if (d[y] != d[x] + z) flag = false;
	} 
}

int main()
{
	//freopen("input", "r", stdin);

	int n, m, x, y, z;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; ++i)
	{
		scanf("%d %d %d", &x, &y, &z);
		E[x].push_back(make_pair(y, z));
		E[y].push_back(make_pair(x, -z));
	}
	
	for (int i = 1; i <= n; ++i)
		if (!vis[i]) vis[i] = true, d[i] = 0, dfs(i);
	
	puts(flag? "Yes":"No");

    return 0;
}

Measured memory_bytes: 11136
n = int(input())
t_score, h_score = 0, 0
for i in range(n):
    t, h = input().split()
    if t > h:
        t_score += 3
    elif t < h:
        h_score += 3
    else:
        t_score += 1
        h_score += 1
print(t_score, h_score)

Measured memory_bytes: 6720
a,b = list(map(int, input().split()))
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

c = set(make_divisors(a))
d = set(make_divisors(b))
e = list(c & d)

f = []
for i in range(len(e)):
        if is_prime(e[i]):
            f.append(e[i])
print(len(f) + 1)

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

#define ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
        
        
    int n, m;
    cin >> n >> m;
    m = (m * (m - 1)) / 2; 
    n = (n * (n - 1)) / 2;
    cout <<m + n<< endl;

    return 0;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	int count[n+1];
	memset(count,0,sizeof(count));
	for(int i=0;i<n-1;i++){
		int a;
		cin >> a;
		count[a]++;
	}
	for(int i=1;i<=n;i++){
		cout << count[i] << "\n";
	}
}

Measured memory_bytes: 4380
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){c=Getchar();rev|=c=='-';if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const ll inf=0x3f3f3f3f3f3f3f;
const int N=100005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,pw[3];
ll ans,dp[N][3];

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	pw[0]=1;pw[1]=-1;
	read(n,ans);n--;
	for(int i=1;i<=2;i++) dp[0][i]=-inf;
//	dp[0][0]=0;
	for(int i=1;i<=n;i++){
		char tmp[5];
		int opt,x;reads(tmp);read(x);
		opt=tmp[0]=='-'?1:0;
		for(int j=0;j<=2;j++) dp[i][j]=-inf;
		for(int j=0;j<=2;j++){
			gmax(dp[i][j],dp[i-1][j]+pw[opt^(j&1)]*x);
			if(j) gmax(dp[i][j-1],dp[i-1][j]+pw[opt^(j&1)]*x);
			if(opt&&j<2) gmax(dp[i][j+1],dp[i-1][j]+pw[opt^(j&1)]*x);
		}
	}
	print(ans+max(dp[n][0],max(dp[n][1],dp[n][2])));
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> M;
    vector<ll> a(N);
    cin >> a;
    priority_queue<int> pq;
    REP(i, N)
    pq.push(a[i]);
    ll m = 0;
    while (m < M) {
        X = pq.top();
        X /= 2;
        m++;
        pq.pop();
        pq.push(X);
    }
    while (!pq.empty()) {
        ans += pq.top();
        pq.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 4704
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
typedef  pair<int,int> P;

//union findで実装してあげて、最大個数所属している山を探す

int par[200005];
int ranking[200005];
int number[200005];
int n,m;
int a;
int b;
void init(int n) {
for (int i = 0; i < n; i++) {
par[i] = i;
ranking[i] = 0;
number[i]=1;
}
}

int find(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}

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

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



int main()
{
cin>>n>>m;
init(n+5);
rep(i,m)
{cin>>a>>b;
a--;b--;
if(!same(a,b))
unite(a,b);
}
int ans=0;
rep(i,n)
{
ans=max(ans,number[i]);
}


cout <<ans;
}


Measured memory_bytes: 5956
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int N;
	int T,A,k;
	cin>>N>>T>>A;
	int H[N+1];
	double Temp[N+1];
	double tt;
	for(int i=1;i<=N;i++)cin>>H[i];
	double min=10000;
	for(int i=1;i<=N;i++)
	{
		Temp[i]=T-0.006*H[i]-A;
		tt=Temp[i];
		//cout<<Temp[i]<<endl;
		if(Temp[i]<=0) tt=-1*Temp[i];
		if(tt<min) 
		{
			k=i;
			min=tt;
		}
	}
	cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;
using Graph = vector<vector<int>>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

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

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

ll ans = 0;

void Main()
{
  ll n, m; cin >> n >> m;
  ll S = 0;
  rep(i, n)
  {
    S += pow(2, i);
  }
  vll k(m);
  vvll X(m);
  vll p(m);
  rep(i, m)
  {
    cin >> k[i];
    rep(j, k[i])
    {
      ll K;
      cin >> K;
      K--;
      X[i].pb(K);
    }
  }
  rep(i, m)
  {
    cin >> p[i];
  }
  S++;
  while(S)
  {
    S--;
    ll s = S;
    vll F(m, 0);
    vb flag(n, false);
    ll now = 0;
    while(s)
    {
      if(s % 2 == 1) flag[now] = true;
      now++;
      s /= 2;
    }
    ll L = 0;
    rep(i, m)
    {
      ll J = 0;
      rep(j, k[i])
      {
        ll K = X[i][j];
        if(flag[K] == true) J++;
      }
      if(J % 2 == p[i]) L++;
    }
    if(L == m) ans++;
  }
  fin(ans);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#include <string.h>
#define COUNTOF(x) (sizeof(x) / sizeof(*(x)))



int main() {
	int r=0, x,y;
	char s[100];


	scanf("%s", s);



	for (int i = 0; i < strlen(s); ++i) {

		if (s[i] != s[strlen(s)-i-1]) {
			r++;
	
		}


	}

	printf("%d", r/2);

}

Measured memory_bytes: 128
N, M, K = map(int, input().split())
A = [0]+list(map(int, input().split()))
B = [0]+list(map(int, input().split()))
import itertools
A_cs = list(itertools.accumulate(A))
B_cs = list(itertools.accumulate(B))

total = 0
j = len(B)-1
for i in range(len(A_cs)):
    while (j >= 0):
        if A_cs[i] + B_cs[j] <= K:
                total = max(total,i + j)
                break
        j -= 1

print(total)


Measured memory_bytes: 130152
import sys
from collections import Counter
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a_cnt = sorted(list(Counter(a).values()))
    s = set(a)
    t = max(0, len(s) - k)
    print(sum(a_cnt[0:t]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 37420
#MLE注意！ not は使わず !=
#0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    a,b,c,d = map(int, input().split())
    while a>0 and c>0:
        c -= b
        if c<=0:
            print('Yes')
            break
        a -= d
        if a<=0:
            print('No')
            break

if __name__ == '__main__':
    main()

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

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

int func(int v) {
	if (v == 1 || v == 3 || v == 5 || v == 7 || v == 8 || v == 10 || v == 12) {
		return 0;
	} else if (v == 2) {
		return 1;
	} else {
		return 2;
	}
}

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

	int x, y;
	cin >> x >> y;

	int a = func(x);
	int b = func(y);

	cout << (a == b ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define fori(x, y) for(int i = x; i<y; i++)
typedef long long ll;
using namespace std;
int main() { 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll s, cont =1;
	cin >> s;
	bool arr[10000];
	fori(0, 10000) arr[i]=false;
	while(arr[s]==0){
		//cout << s << " ";
		cont++;
		arr[s]=1;
		if(s%2==0) s = s/2;
		else s=3*s+1;
	}
	//printf("%d\n", s);
	//cout << endl << cont << endl;
	cout << cont << "\n";
	
	return 0; 
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    --p[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  long long ans = -1e18;
  for (int si = 0; si < n; si++) {
    int x = si;
    vector<int> s;
    long long tot = 0;
    while (1) {
      x = p[x];
      s.push_back(c[x]);
      tot += c[x];
      if (x == si) break;
    }
    int l = s.size();
    long long t = 0;
    for (int i = 0; i < l; i++) {
      t += s[i];
      if (i + 1 > k) break;
      long long now = t;
      if (tot > 0) {
        long long e = (k - (i + 1)) / l;
        now += tot * e;
      }
      ans = max(ans, now);
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <deque>
using namespace std;

int main() {
    deque<int> v;
    long int n;
    int q;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> q;
        long long int x, d;
        if(q == 0){
            cin >> d >> x;
            if(d==0){
                v.insert(v.begin(), x);
                //front--;
                //v.pop_front();
            }
            else {
                v.push_back(x);
            }
        }
        else if(q == 1){
            cin >> x;
            cout << v[x] << endl;
        }
        else {
            cin >> d;
            if(d == 0){
                v.pop_front();
                //v.erase(v.begin());
            }
            else {
                v.pop_back();
            }
        }
    }
}


Measured memory_bytes: 4676
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

bool f(pair<int,int> a, pair<int,int> b)
{
    if (a.first > b.first)
        return true;
    else 
        if (a.first == b.first)
            if (a.second <= b.second)
                return true;
            else 
                return false;
        else 
            return false;
}

signed main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v(n);
    rep(i, 0, n)
    {
        int a, b;
        cin >> a >> b;
        v[i] = {b, a};
    }
    sort(begin(v), end(v), f);
    int ans = 0;
    set<int> s;
    rep(i, 0, m+1)
        s.insert(i);
    rep(i, 0, n)
    {
        auto x = s.lower_bound(v[i].second);
        if (x == s.end())
            continue;
        else 
        {
            s.erase(*x);
            ans += v[i].first;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 9576
#include<bits/stdc++.h>
#define int int64_t
using namespace std;

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

	int n , x;
	cin >> n;
	set<int> s;
	for(int i = 0; i < n; i++) cin >> x , s.insert(x);
	if(s.size() == n) cout << "YES\n";
	else cout << "NO\n";
	
    return 0;
}


Measured memory_bytes: 9728
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define maxn 100000 * 2 + 10
using namespace std;
int main()
{
    int n;
    cin>>n;
    int mid = n*n;
    cout<<mid<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
    int a,b;
    char op;
      while(1){
    cin>>a>>op>>b;
  
        
    if(op=='?') break;
    if(op=='+') cout<<a+b;
    if(op=='-') cout<<a-b;
    if(op=='*') cout<<a*b;
    if(op=='/') cout<<a/b;
    cout<<endl;
}
    
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#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)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

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

  cout << (k / 2) * ((k + 1) / 2) << endl;

  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
void put(int n)
{
  if(n==0) printf("A");
  if(n==1) printf("B");
  if(n==2) printf("C");
  if(n==3) printf("D");
  if(n==4) printf("E");
}

int main(void)
{
  int s1,s2;
  int m,s,t;
  int i;
  while(1){
    m=0;
    for(i=0;i<5;i++){
      scanf("%d %d",&s1,&s2);
      if(s1==0&&s2==0)
	goto END;
      s=s1+s2;
      if(s>m){
	m=s;
	t=i;
      }
    }
    put(t);
    printf(" %d\n",m);
  }END:

  return 0;
}

Measured memory_bytes: 604
using System;

class FiftyFifty
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        int yes = 0;
        int no = 0;
        
        for (var i = 0; i <= 3; i++)
        {
            var count = 0;
            for (int j = 1; j <= 3; j++)
            {
                if (input[i] == input[j])
                {
                    count++;
                }
            }

            if (count == 1)
            {
                yes++;
            }
            //同じ字が3文字か1文字の場合
            if (count == 2 || count == 0)
            {
                no++;
            }
        }

        if(yes == 2)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
        
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const int INFI = 1000000000;
 const ll INFL = (1LL << 60);

 bool isPrime(int n) {
   for (int i = 2; i * i <= n; i++) {
     if (n % i == 0) return false;
   }
   return true;
 }

 int main() {
   int N; cin >> N;
   vector<int> ans;

   rep(i, 6, 55556) {
     if (isPrime(i) && i % 5 == 1) ans.push_back(i);
     if (ans.size() == N) break;
   }

   rep(i, 0, N - 1) cout << ans.at(i) << " ";
   cout << ans.back() << endl; 
 }


Measured memory_bytes: 256
#include <iostream>

bool isSameGroupe(int x, int y) {
  if (x == y)
    return true;
  if (x == 2 || y == 2)
    return false;
  if (x % 2 == y % 2) {
    if ((x < 8 && y < 8) || (x >= 8 && y >= 8))
      return true;
    else
      return false;
  } else {
    if ((x < 8 && y >= 8) || (x >= 8 && y < 8))
      return true;
    else
      return false;
  }
}

int main() {
  int x, y;
  std::cin >> x >> y;
  if (isSameGroupe(x, y))
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}


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

int solve(int n, int p){

  if(!n) return 1;
  if(n < 0) return 0;

  int res = 0;
  return res += solve(n-p, p+1);
}

int main(){

  int n;
  while(cin >> n, n){
    int ans = 0;
    for(int i=1;i<n;i++) ans += solve(n, i);
    cout << ans << endl;
  }

}

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int p,c,w,s;
string l;

int main(){
	while(cin>>p && p){
        cin>>c>>w>>s;
        vs col;
        getline(cin,l);
        while(getline(cin,l) && l!="?"){
            if(l==""){
                col.pb(string(w,'.'));
            }else{
                while(l.sz%w!=0)l+='.';
                rep(i,l.sz/w){
                    string t;
                    rep(j,w)t+=l[i*w+j];
                    col.pb(t);
                }
            }
        }
        while(col.sz%(p*c)!=0){
            col.pb(string(w,'.'));
        }
        rep(i,col.sz/(p*c)){
            vs ans(p,"");
            rep(j,c){
                rep(h,p){
                    ans[h]+=col[i*p*c+j*p+h];
                    if(j<c-1)ans[h]+=string(s,'.');
                }
            }
            rep(j,p)cout<<ans[j]<<endl;
            cout<<"#\n";
        }
        cout<<"?\n";
    }
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <ctime>
#include <deque>
using namespace std;

long long n, a;
long long ans;

bool can(long long sum, int k) {
	long long now = n;
	for (int i = 0; i < k; i++) {
		long long q = sum / k + (i < sum % k);
		if (q >= now)
			return true;
		now = (now - 1) / q + 1;
		// cout << q << ' '<< now << endl;
	}
	return false;
}

int main() {
	cin >> n >> a;
	ans = n;
	// cout << can(6, 2) << endl;
	// return 0;
	for (int i = 1; i < 64; i++) {
		long long l = i, r = n, mid;
		while (l < r - 1) {
			mid = (l + r) / 2;
			if (can(mid, i + 1))
				r = mid;
			else
				l = mid;
		}
		ans = min(ans, i * a + r);
	}
	cout << ans << endl;
}


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

#define be begin
#define en end
#define pb push_back
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++) 

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;

int main(){
    int n;
    cin>>n;
    Vll l(n);
    REP(i,n){
        cin>>l[i];
    }
    sort(ALL(l),greater<int>());

    LL total = 0;
    REP(i,n){
        REP2(j,i+1,n){
            REP2(k,j+1,n){
                if( l[i]<l[j]+l[k] &&
                    l[j]<l[i]+l[k] &&
                    l[k]<l[i]+l[j]){
                        total++;
                    }
            }
        }
    }
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long X, D, N, r, cnt; 
long long A[200010], L[200010], R[200010], res[200010]; 
map<long long, bool> seen; 
map<long long, vector<pair<long long, long long>>> M; 
int main(){
	cin >> N >> X >> D; 
	if(D == 0 && X == 0){
		cout << 1 << endl; return 0; 
	}
	else if(D == 0){
		cout << N + 1 << endl; return 0; 
	}
	if(D < 0){
		X *= -1; D *= -1; 
	}
	r = (X + D * 100000000) % D; 
	for(int i = 1; i <= N; i++) A[i] = X + D * (i-1); 
	for(int i = 1; i <= N; i++) L[i] = L[i-1] + A[i]; 
	for(int i = 1; i <= N; i++) R[i] = R[i-1] + A[N+1-i]; 
	for(int i = 0; i <= N; i++){
		res[i] = (r * i) % D; 
		M[res[i]].push_back(make_pair(L[i], R[i])); 
	}
	for(int i = 0; i <= N; i++){
		if(seen[res[i]]) continue; 
		sort(M[res[i]].begin(), M[res[i]].end()); 
		seen[res[i]] = true; 
		long long right = -1e18; 
		for(auto p : M[res[i]]){
			long long x = p.first, y = p.second; 
			if(right < x){
				cnt += (y - x) / D + 1; right = y; 
			}
			else if(right <= y){
				cnt += (y - right) / D; right = y; 
			} 
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 40832
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();

		List<String> list1 = new ArrayList<>(3);
		for (int i = 0; i < 3; i++) {
			list1.add(S.substring(i,i+1));
		}
		int l1 = list1.size();

		List<String> list2 = new ArrayList<>(new HashSet<>(list1));
		int l2 = list2.size();

		/*
		for (String s : list1) {
			System.out.println("list1" + s);
		}
		for (String s : list2) {
			System.out.println("list2" + s);
		}
		System.out.println("l1：" +l1 + "l2：" + l2);
		*/
		if (l1 == l2) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int N,C[10000],D[5010][2],i,j;

main(){
    scanf("%d",&N);for(i=0;i<N-1;i++)scanf("%d",C+i);
    fill_n(*D,10020,1e9);D[0][1]=D[1][0]=0;
    for(i=0;i<N-1;i++)
        for(j=N/2;~j;j--){
            D[j+1][0]=min(D[j][0],D[j][1]+C[i]);
        D[j][1]=min(D[j][0]+C[i],D[j][1]);
    }
    printf("%d\n",min(D[N/2][0],D[N/2][1]));
}

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

using namespace std;

int main(){

    int n, m;
    cin >> n >> m;

    int l[m], r[m];
    for(int i=0; i<m; i++){
        cin >> l[i] >> r[i];
    }

    int l_prime = *max_element(l, l+m);
    int r_prime = *min_element(r, r+m);

    if(l_prime > r_prime){
        cout << '0' << endl;
        return 0;
    }

    cout << r_prime - l_prime + 1 << endl;

    return 0;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
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++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e12
typedef long long ll;


int main() {
    ll A,B,Q; cin >> A >> B >> Q;
    vector<ll> S(A+2); FOR(i,1,A+1) cin >> S[i];
    vector<ll> T(B+2); FOR(i,1,B+1) cin >> T[i];
    vector<ll> x(Q); REP(i,Q) cin >> x[i];
    S[0] = -INF; S[A+1] = INF;
    T[0] = -INF; T[B+1] = INF;

    REP(i,Q){
        ll sl,sr,tl,tr;
        auto s_itr = lower_bound(ALL(S), x[i]);
        sr = *s_itr;
        sl = *(--s_itr);
        
        auto t_itr = lower_bound(ALL(T), x[i]);
        tr = *t_itr;
        tl = *(--t_itr);
        
        //cout << sl << ", " << sr << " " << tl << ", " << tr << " " << x[i] << endl;

        ll ans = 1e15;
        ans = min(ans, max(x[i]-sl, x[i]-tl));
        ans = min(ans, max(sr-x[i], tr-x[i]));

        ans = min(ans, 2*(x[i]-sl) + tr-x[i]);
        ans = min(ans, 2*(tr-x[i]) + x[i]-sl);

        ans = min(ans, 2*(x[i]-tl) + sr-x[i]);
        ans = min(ans, 2*(sr-x[i]) + x[i]-tl);

        cout << ans << endl;
    }

    


    return 0;
}

Measured memory_bytes: 5604
#include <iostream>
using namespace std;
int swap(int a[],int N);
int swap(int a[],int N) {
	int sw;
	int i, j;
	for (i = 0; i < N; ++i) {
		for (j = i + 1; j < N; ++j) {
			if (a[i] > a[j]) {
				sw = a[i];
				a[i] = a[j];
				a[j] = sw;
			}
		}
	}
	return 0;
}
int main()
{
	int a[1000];
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> a[i];
	 swap(a, N);

	 cout << a[N-1] - a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
ab=[list(map(int,input().split())) for i in range(n)]
import math
from collections import defaultdict
d = defaultdict(int)
zerozero=0
azero=0
bzero=0
for tmp in ab:
    a,b=tmp

    if a==0 and b==0:
        zerozero+=1
        continue
    if a==0:
        azero+=1
        continue
    if b==0:
        bzero+=1
        continue

    absa=abs(a)
    absb=abs(b)
    gcd = math.gcd(absa,absb)

    absa//=gcd
    absb//=gcd

    if a*b >0:
        d[(absa,absb)]+=1
    else:
        d[(absa,-absb)]+=1

found = defaultdict(int)
d[(0,1)]=azero
d[(1,0)]=bzero

ans=1
mod=1000000007
for k in list(d.keys()):
    num = d[k]
    a,b=k

    if b>0:
        bad_ab = (b,-a)
    else:
        bad_ab = (-b,a)

    if found[k]!=0:
        continue
    found[bad_ab] = 1

    bm=d[bad_ab]

    if bm == 0:
        mul = pow(2,num,mod)
    if k==bad_ab:
        mul = num+1
    else:
        mul = pow(2,num,mod) + pow(2,bm,mod) -1
    ans*=mul

ans+=zerozero
ans-=1
print(ans%mod)

Measured memory_bytes: 188552
for _ in range(int(input())):
    p,q=map(int,input().split())
    c=0
    for i in range(142):
        for j in range(142):
            if (i>0 or j>0)and(j*p+i*q)%(j*j+i*i)==0 and (j*q-i*p)%(j*j+i*i)==0:c+=1
    print('P' if c<5 else 'C')

Measured memory_bytes: 7684
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

const double PI=(acos(-1));

int main(){
    int yy,mm,dd;
    scanf("%d/%d/%d",&yy,&mm,&dd);
    if(yy>2019){
        cout<<"TBD"<<endl;
        return 0;
    }else if(yy==2019){
        if(mm>4){
            cout<<"TBD"<<endl;
            return 0;
        }else{
            cout<<"Heisei"<<endl;
            return 0;
        }
    }else{
        cout<<"Heisei"<<endl;
        return 0;
    }
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define plint pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    string s, t;
    cin >> s >> t;
    int ans=0;
    REP(i,3){
        if(s[i]==t[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main (void)
{
    long long a,b,t;
    int i,j;
    long long k;
    scanf("%lld%lld",&a,&b);
    if(a<b)
    {
        t=a;
        a=b;
        b=t;
    }
    for(i=1;;i++)
    {
        k=a*i;
        if(k%b==0)
            break;
    }
    printf("%lld\n",k);
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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

D.sort()
mid = N//2

if D[mid-1] == D[mid]:
    print(0)
    exit()

count = 0
for i in range(D[mid-1]+1, D[mid]+1):
    count += 1

print(count)

Measured memory_bytes: 14016
#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 MOD 1000000007
#define ll long long int
#define pair <ll, ll> pi
#define vector <ll> vi
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define SQ(a) (a) * (a)
#define ordered_set tree<ll, null_type, greater_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> //greater_equal<ll> or less<ll>
// find_by_key()   order_of_key()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/*bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen('input.txt', 'r', stdin);
    //freopen('output.txt', 'w', stdout);
    ll i, j, k, n, m, b, d, t, ans = 0,x,y,sum=0;
    cin>>n>>k;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,greater<ll>());
    for(i=0;i<k;i++){
        sum+=a[i];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, k;
	cin >> n >> k;
	
	vector<int> h(n);
	for(int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	
	sort(h.begin(), h.end());
	
	int ans = 1e9 + 10;
	for(int i = 0; i < n - k + 1; ++i) {
		ans = min(ans, h[i + k - 1] - h[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll popcount(ll x){
  ll res=0;
  for(ll i=0; i<=20; i++){
    if(x>>i&1) res++;
  }
  return res;
}

ll f(ll x){
  if(x==0) return 0;
  ll cnt=popcount(x);
  return 1+f(x%cnt);
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  string s; cin>>s;
  
  ll cnt=0;
  rep(i,n) if(s[i]=='1') cnt++;
  
  vll t1(n+1,1), t2(n+1,1);
  for(ll i=1; i<n; i++){
    t1[i]=t1[i-1]*2%(cnt+1);
    if(cnt>1) t2[i]=t2[i-1]*2%(cnt-1);
  }
  
  ll f1=0, f2=0;
  for(ll i=0; i<n; i++){
    f1=f1*2+(s[i]=='1');
    f1%=(cnt+1);
    if(cnt>1){
      f2=f2*2+(s[i]=='1');
      f2%=(cnt-1);
    }
  }
  
  // 1度cntのmodを取ってしまえば、その桁数は20未満なので、2回目以降modを取る計算量は定数と見て良い
  // 各iについて、1回目の操作がO(n)となるので、これを高速化する
  // 元のpopcountをcntとするとbit反転後のpopcountはcnt+1かcnt-1のいずれかになる
  // これを利用して、s mod (cnt+1), s mod (cnt-1) を予め求めておき、反転して立つ or 消えるbitを足し引きすることでO(1)で計算する
  // 例えばi bit目が立つならmod cnt+1となるので、(s+1<<i)%(cnt+1) つまり s%(mod+1)+(1<<i)%(cnt+1) が計算できれば良い
  // s%(mod+1)は上で求めたf1である
  // (1<<i)%(mod+1)は上で求めたt1[n-1-i]である
  // NOTE: t1について
  // iは最大2*10^5になるので、これを単にbitシフトするとオーバーフローする
  // そのため各桁ごとにmod cnt+1を求めていく
  // 2進数において今見ている桁の値は前の桁の値*2で求まるので、これに対してmod cnt+1を計算してt1に格納していく
  // t1はt[0]がs[n-1]の値、t[n-1]がs[0]の値に対応している
  
  for(ll i=0; i<n; i++){
    if(s[i]=='1'){
      if(cnt==1) cout<<0<<endl;
      else{
        ll tmp=f2-t2[n-1-i];
        tmp%=(cnt-1);
        if(tmp<0) tmp+=cnt-1;
        ll ans=f(tmp)+1;
        cout<<ans<<endl;
      }
    }else{
      ll tmp=f1+t1[n-1-i];
      tmp%=(cnt+1);
      ll ans=f(tmp)+1;
      cout<<ans<<endl;
    }
  }
  
}

Measured memory_bytes: 6768
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int n;
    cin >> n;
    double v;
    priority_queue<double, vector<double>, greater<double> > que;
    rep(i, n) {
        cin >> v;
        que.push(v);
    }
    rep(i, n - 1){
        double a = que.top();
        que.pop();
        double b = que.top();
        que.pop();
        que.push((a + b) / 2);
    }

    cout << que.top() << endl;
}


Measured memory_bytes: 256