akhauriyash/Code-Regression huggingface dataset:
class PriorityQueue
  MIN = -(1 << 60)

  attr_reader :size

  def initialize(&block)
    @size = 0
    @heap = Array.new
    @get_key = block || :itself.to_proc
  end
def empty?
    size == 0
  end

  def pop
    return nil if @size <= 0
    max = @heap[1]
    @heap[1] = @heap[@size]
    @size -= 1
    max_heapify(1)
    max
  end

  def push(x)
    @size += 1
    i = @size
    @heap[i] = x
    while i > 1 && (@get_key.call(@heap[i / 2]) <=> @get_key.call(@heap[i])) < 0
      t = @heap[i / 2]
      @heap[i / 2] = @heap[i]
      @heap[i] = t
      i = i / 2
    end
  end

  def top
    return nil if @size <= 0
    @heap[1]
  end

  def to_a
    return [] if @size == 0
    @heap[1..@size]
  end

  private

  def max_heapify(i)
    l = 2 * i
    r = 2 * i + 1
    largest =
      l <= @size && (@get_key.call(@heap[l]) <=> @get_key.call(@heap[i])) > 0 ? l : i
    largest = r \
      if r <= @size && (@get_key.call(@heap[r]) <=> @get_key.call(@heap[largest])) > 0
    unless largest == i
      t = @heap[i]
      @heap[i] = @heap[largest]
      @heap[largest] = t
      max_heapify(largest)
    end
  end
end

N, M = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

pq = PriorityQueue.new { |(a, _)| a }
as.each do |a|
  pq.push([a, a.to_f])
end

rest_count = M
while rest_count > 0
  a, raw = pq.pop
  pq.push([(raw / 2).to_i, raw / 2])
  rest_count -= 1
end
ans = pq.to_a.reduce(0) { |acc, (a, _)| acc + a }
puts ans


Measured memory_bytes: 17940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;


vector<int> find_all(const string s) {
	string search[] = {"A", "C", "G", "T"};
	vector<int> v;
	for (int i = 0; i < 4;++i) {
		int pos = s.find(search[i]);
		while  (pos != string::npos) {
			v.push_back(pos);
			pos = s.find(search[i], pos + 1);
		}
	}
	sort(v.begin(), v.end());
	return v;
}

int main() {
	string s;
	cin >> s;
	auto result = find_all(s);
	if (result.size() == 0) {
		cout << 0 << endl;
		return 0;
	}
	int max_l = 1;
	int tmp = 1;
	for (size_t i = 1; i < result.size(); ++i) {
		if (result[i] == result[i-1] + 1) {
			++tmp;
		} else {
			if (tmp > max_l) max_l = tmp;
			tmp = 1;
		}
	}
	if (tmp > max_l) max_l = tmp;
	cout << max_l << endl;
	return 0;
}

Measured memory_bytes: 256
const main = input => {
  const args = input.split(/\n\n|\r|\n/)
  const s = args[0].split('')
  const r = args[1].split('')
  const num = s.reduce((a, b, i) => {
    if (b === r[i]) a++
    return a
  }, 0)
  console.log(num)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

const ll coe[] = {1007, 1009};
const ll mod[] = {(ll)1e9+7, (ll)1e9+9};

ll add(ll a, ll b, ll m) {
	return (a + b) % m;
}
ll mul(ll a, ll b, ll m) {
	return (a * b) % m;
}
ll power(ll x, ll n, ll m) {
	ll res = 1;
	for (ll i = 1; i <= n; i <<= 1) {
		if (i & n) res = mul(res, x, m);
		x = mul(x, x, m);
	}
	return res;
}

ll get_hash(vector<ll>& h, int l, int r, int hid) {
	return mul(add((h[r] - h[l]) % mod[hid], mod[hid], mod[hid]), power(power(coe[hid], l, mod[hid]), mod[hid]-2, mod[hid]), mod[hid]);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N, M; cin >> N >> M;
	string S; cin >> S;
	int l = 0, r = 1;
	vector<ll> h[2];
	REP(i, 2) {
		h[i] = vector<ll>(N+1, 0);
		REP(j, N) {
			h[i][j+1] = add( h[i][j], mul(S[j], power(coe[i], j, mod[i]), mod[i]), mod[i] );
		}
	}
	set<P> s;
	REP(q, M) {
		string Q; cin >> Q;
		if (Q == "R++") {
			++r;
		}
		else if (Q == "R--") {
			--r;
		}
		else if (Q == "L++") {
			++l;
		}
		else if (Q == "L--") {
			--l;
		}
		s.insert( P( get_hash(h[0], l, r, 0), get_hash(h[1], l, r, 1) ) );
	}
	// cout << get_hash(h[0], 0, 1, 0) << endl;
	// cout << get_hash(h[0], 1, 2, 0) << endl;
	// cout << get_hash(h[0], 2, 3, 0) << endl;
	// cout << get_hash(h[0], 3, 4, 0) << endl;
	// cout << get_hash(h[0], 4, 5, 0) << endl;
	cout << s.size() << endl;
}

Measured memory_bytes: 26532
/**
 * A
 */
import java.io.*;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        InputStream in = System.in;
        Scanner scanner = new Scanner(in);
    
        int next = scanner.nextInt();
        int left = 1000 - (next % 1000);
        System.out.println(left == 1000 ? 0 : left);
        scanner.close();
    }

}

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

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

  vector<string> a(h);
  rep(i,h) cin >> a.at(i);

  rep(i,w+2) cout << '#';
  cout << endl;
  rep(i,h){
    cout << '#';
    cout << a.at(i);
    cout << '#' << endl;
  }
  rep(i,w+2) cout << '#';
  cout << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

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

    string s;
    cin >> s;
    int n = int(s.size());

    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            if (s[i] == 'L') {
                cout << "No" << endl;
                return 0;
            }
        } else {
            if (s[i] == 'R') {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    dbg(cnt);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#define INF 2147483647
#define MAX_N 100001
using namespace std;
int tree[(1<<18)];
int n,q;

//Segment_tree
void update(int i,int x) {//i = site , x = value
  i+=(n-1);
  tree[i] = x;
  while(i!=0){
    i=(i-1)/2;
    tree[i] = min(tree[i*2+1],tree[i*2+2]);
  }
}

int find(int a ,int b,int M,int L,int R){ 
  if(R<=a || b<=L) return INF;
  if(a<=L && R<=b) return tree[M];
  int nx = (R+L)/2;
  return min(find(a,b,M*2+1,L,nx),find(a,b,M*2+2,nx,R));
}

/*void init(){
  for(int i=0;i<n;i++) update(i,INF);
  }*/

// Union Find
int par[MAX_N]; //parenat
int rank[MAX_N]; //deep

void init(int n){
  for(int i=0;i<n;i++) par[i]=i, rank[i]=0;
}

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

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

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

int main(){
  cin >> n >>q;
  init(n);
  while(q--){
    int com,x,y;
    cin >>com >> x >> y;
    if(com == 0) unite(x,y);
    if(com == 1) cout << same(x,y) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1252
#include <cstdio>
#define MAX 10000
#define NIL -1
struct Node { int parent, left,right;};
Node T[MAX];
int n,D[MAX],H[MAX];
void setDepth(int u,int d){
  if(u==NIL) return;
  D[u] =d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL) h1=setHeight(T[u].left)+1;
  if(T[u].right!=NIL) h2=setHeight(T[u].right)+1;
  return H[u]=(h1>h2?h1:h2);
}

int getSibling(int u){
  if(T[u].parent==NIL) return NIL;
  if(T[T[u].parent].left!=u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
  if(T[T[u].parent].right!=u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left!=NIL) deg++;
  if(T[u].right!=NIL) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent == NIL){
    printf("root\n");
  }else if(T[u].left==NIL && T[u].right==NIL){
    printf("leaf\n");
  }else {
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++) T[i].parent = NIL;
  for(int i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL) T[l].parent=v;
    if(r!=NIL) T[r].parent=v;
  }
  for(int i=0;i<n;i++) if(T[i].parent ==NIL) root=i;
  setDepth(root,0);
  setHeight(root);
  for(int i=0;i<n;i++){
    print(i);
  }
  return 0;
}


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

void yugu(int g,int h);

int main() {
  int x,y;
  scanf("%d%d",&x,&y);
  if(1<=x && y<=pow(10,9)){
    yugu(x,y);
  }
  return 0;
}

void yugu(int g,int h) {
  int a1,a2,b;
  if(g>h) {
    a1=g;
    a2=h;
  }
  else {
    a1=h;
    a2=g;
  }
  while(1) {
    b=a2;
    a2=a1%a2;
    if(a2==0) break;
    a1=b;
  }
  printf("%d\n",b);
}
  



Measured memory_bytes: 2104
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

const MOD: usize = 1_000_000_000 + 7;

fn main() {
    let (n, k) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };

    let a: Vec<usize> = read_vec();

    let mut dp = vec![vec![0; k+1]; n+1];

    // init
    dp[0][0] = 1;

    for i in 0..n {
      // 累積和
      let sum = cum_sum(&dp[i]);

      for j in 0..k+1 {
        dp[i+1][j] = sum[j+1] - sum[j - min(j, a[i])];
        dp[i+1][j] %= MOD;
      }
    }
    
    println!("{}", dp[n][k]);
}

fn cum_sum(v: &Vec<usize>) -> Vec<usize> {
    let n = v.len();
    let mut sum = vec![0; n + 1];

    for i in 0..n {
        sum[i + 1] = sum[i] + v[i];
    }

    sum
}

Measured memory_bytes: 108796
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		int f=0;
		int ans=0;
		n=sc.nextInt();
		String test;
		String A = "A";
		String Un = "Un";
		for(int i=0;i<n;i++) {
			test=sc.next();
			if(test.equals(A))ans++;
			else if(test.equals(Un))ans--;


			if(ans<0) {
				f=1;
				break;
			}
		}

		if(f==1||ans>=1)System.out.println("NO");
		else System.out.println("YES");
		
		
		
		sc.close();
	}
}




Measured memory_bytes: 26480
s = input()

def check(s):
  if(s==s[::-1]):
    return True
  else:
    return False
  
n = len(s)
if(check(s[:(n-1)//2])):
  if(check(s[((n+3)//2)-1:])):
    if(check(s)):
    	print('Yes')
    else:
      print('No')
  else:
    print('No')
else:
     print('No')

Measured memory_bytes: 3060
using System;

class _169C
{
    static void Main()
    {
        long A;
        double B;
        string str;
        string[] str_array;
        int B_int;
        double B_sho;

        str = Console.ReadLine();
        str_array = str.Split(' ');

        A = long.Parse(str_array[0]);

        B = double.Parse(str_array[1]);


        //A = (long)9e+15;
        //B = 9.9;

        B_int = (int)B;

        B_sho = B - B_int;

        Console.WriteLine(A * B_int + (int)(A * B_sho));


    }
}

Measured memory_bytes: 27464
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n
# 
# s = input()

imp = "IMPOSSIBLE"
a, b = map(int, input().split())

hoge = (a + b)
ans = imp
if hoge % 2 == 0:
    ans = hoge // 2
print(ans)


Measured memory_bytes: 38256
# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
# visual studio code shortcut https://qiita.com/TakahiRoyte/items/cdab6fca64da386a690b
# delete line: Ctrl+Shift+k
# choose same words: Ctrl+Shift+l
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

from itertools import combinations, permutations # https://docs.python.org/ja/3/library/itertools.html
from math import factorial
def combinations_count(n, r):
    # faster than the following code
    # def combinations_count(n, r):
    #     return factorial(n) // (factorial(n - r) * factorial(r))
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from functools import reduce
from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)
# set the inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
    # R = lambda: map(int, input().split()) :it's fashionable, isn't it?
    # ex1) n, k = R()
    # ex2) v = list(R())
    # ex3) bc = [list(R()) for i in range(m)]

# n = 3
# ab = [[1, 3],[2, 3]]
# c = [1, 2, 3]
# c.sort(reverse=True)

R = lambda: list(map(int, input().split()))
input2 = sys.stdin.readline
R2 = lambda: list(map(int, input2().split()))

n = int(input())
ab = [R2() for i in range(n-1)]
c = R2()
c.sort(reverse=True)

# calculate
dic = {}
l = deque()
for a, b in ab:
    dic.setdefault(a, []).append(b)
    dic.setdefault(b, []).append(a)

m = sum(c) - max(c)
d = [-1] * n
l.extend(dic[1])
d[0] = c[0]
i = 1
while l:
    deq = l.popleft()
    if d[deq-1] >= 0:
        pass
    else:
        if deq in dic:
            l.extend(dic[deq])
        d[deq-1] = c[i]
        i += 1
print(m)
print(*d)



Measured memory_bytes: 9640
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
		int x,a,b;
		Scanner scan = new Scanner(System.in);
		x = Integer.parseInt(scan.next());
		a = Integer.parseInt(scan.next());
		b = Integer.parseInt(scan.next());
		if(a>=b){
			System.out.println("delicious");
		}
		if(a+x>=b && a<b){
			System.out.println("safe");
		}
		if(a+x<b){
			System.out.println("dangerous");
		}
	}
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define N 1005
using namespace std;
int n,dp[N][N],xlen,ylen;
string x,y;

int main(){
  cin>>n;
  while(n--){
    cin>>x>>y;
    xlen=x.size();
    ylen=y.size();
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=xlen;i++){
      for(int j=1;j<=ylen;j++){
	if(x[i-1]==y[j-1])dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
	dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));
      }
    }
    cout<<dp[xlen][ylen]<<endl;
  }
  return 0;
}

Measured memory_bytes: 5156
fun main() {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    lateinit var dfs: (i: Int, s: Int, p: Int) -> Unit

    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val N = sc.next()

        pw.println(if (N.toCharArray().contains('7')) "Yes" else "No")
    }
}


Measured memory_bytes: 40320
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fod(i,a,b) for(i=a;i>=b;i--)
using namespace std;
const int maxn=3e5+7;
typedef long long ll;
ll i,j,k,l,t,n,m,ans,x,v;
ll a[maxn],sum[maxn],d[maxn];
ll f[maxn],yi,er,F[maxn],G[maxn],an[maxn],p[maxn],q[maxn],e[maxn];
ll Q(ll x){return f[x]+sum[x]+(x*x-x)/2;}
ll S(ll x){return F[x]+sum[x]+(x*x-x)/2;}
void gao(){
    fo(i,1,n)sum[i]=sum[i-1]+a[i];
    memset(f,128,sizeof(f));f[0]=d[0]=0;d[++d[0]]=0;
    fo(i,1,n){
    	f[i]=f[i-1];
	    while(d[0]>1&&Q(d[d[0]])-i*d[d[0]]<Q(d[d[0]-1])-i*d[d[0]-1])d[0]--;
	    t=d[d[0]];
		f[i]=max(f[i],(f[t]+(i-t+1)*(i-t)/2-(sum[i]-sum[t])));
		while(d[0]>1){
			yi=d[d[0]-1],er=d[d[0]];
		    if((Q(er)-Q(i))*(yi-er)<(Q(yi)-Q(er))*(er-i))break;
		    d[0]--;
		}
		d[++d[0]]=i;
	}
}
void solve(int l,int r){
	int i,j,mid=(l+r)/2;
    if(l==r)return;
    d[0]=0;
    fo(i,l,mid){
	    while(d[0]>1){
		    yi=d[d[0]-1],er=d[d[0]];
		    if((S(er)-S(i))*(yi-er)<(S(yi)-S(er))*(er-i))break;
		    d[0]--;
		}
	    d[++d[0]]=i;
	}
	fo(i,mid+1,r){
	    while(d[0]>1&&S(d[d[0]])-i*d[d[0]]<S(d[d[0]-1])-i*d[d[0]-1])d[0]--;
	    t=d[d[0]];
	    e[i]=max(e[i],G[n-i]+F[t]+(i-t+1)*(i-t)/2-(sum[i]-sum[t]));
	}
	fod(i,r-1,mid+1)e[i]=max(e[i],e[i+1]);
	solve(l,mid);solve(mid+1,r);
}
int main(){
  //  freopen("fan.in","r",stdin);
  //  freopen("genocide.out","w",stdout);
    scanf("%lld",&n);
    fo(i,1,n)scanf("%lld",&a[i]);
    gao();fo(i,0,n)F[i]=f[i];
    reverse(a+1,a+1+n);
    gao();fo(i,0,n)G[i]=f[i];
    reverse(a+1,a+1+n);fo(i,1,n)sum[i]=sum[i-1]+a[i];
    memset(e,128,sizeof(e));
    solve(0,n);
    fo(i,1,n)p[i]=e[i];memset(e,128,sizeof(e));
    swap(F,G);reverse(a+1,a+1+n);fo(i,1,n)sum[i]=sum[i-1]+a[i];
    solve(0,n);
    fo(i,1,n)p[i]=max(p[i],e[n-i+1]);
    swap(F,G);reverse(a+1,a+1+n);
    fo(i,1,n)p[i]=max(p[i],F[i-1]+G[n-i]+1-a[i]);
    scanf("%d",&m);
    fo(i,1,m){
	    scanf("%d%d",&x,&v);
	    ans=max(F[x-1]+G[n-x],p[x]+a[x]-v);
	    printf("%lld\n",ans);
	}
}

Measured memory_bytes: 25984
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
	int r, g, b, n;
	cin >> r >> g >> b >> n;
	ll ans = 0;
	for(int i=0; i*r <= n; i++){
		for(int j=0; j*g+i*r <= n; j++){
			if((n-(j*g+i*r))%b == 0) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n,m,nsum=0,msum=0;
  cin>>n>>m;
  if(n<=1&&m<=1){cout<<"0"; return 0;}
  if(n==2) nsum+=1;
  if(n==3) nsum+=3;
  if(m==2) msum+=1;
  if(m==3) msum+=3;

  for(int i=1;i<n;i++){
      if(i==1&&0<nsum) break;
      nsum+=i;
  }
  for(int i=1;i<m;i++) {
     if(i==1&&0<msum) break;
     msum+=i;
  }   
  cout<<nsum+msum;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

const int MAX_N = 1005;

int c[MAX_N][MAX_N];

int main()
{
	string X,Y;
	cin >> X;
	cin >> Y;
	for(int i=0;i<=X.length();i++){
		c[i][0] = i;
	}
	for(int j=0;j<=Y.length();j++){
		c[0][j] = j;
	}
	for(int i=1;i<=X.length();i++){
		for(int j=1;j<=Y.length();j++){
			int p,q,r;
			if(X[i-1] == Y[j-1]){
				p = c[i-1][j-1];
			}else{
				p = c[i-1][j-1] + 1;
			}
			q = c[i][j-1] + 1;
			r = c[i-1][j] + 1;
			c[i][j] = min(min(p,q),r);
		}
	}
	cout << c[X.length()][Y.length()] << "\n";
}

Measured memory_bytes: 7092
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(s,i,n) for(int i=(s);i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int gold[1000001];
int n,x;

bool sosu(int x){
	if( x == 1 || x == 2 || x == 3){
		return true;
	}
	for(int i=2;i*i<=x;i++){
		if(x%i==0){
			return false;
		}
	}
	return true;
}

int main(){
	while(true){
		cin >> n >> x;
		if(n == 0){
			break;
		}
		memset(gold,0,sizeof(gold));

		vi meshi;
		int buf;
		rep(i,n){
			cin >> buf;
			meshi.pb(buf);
			gold[buf] = 1;
		}

		rep(i,x){
			if(gold[i] == 1){
				rep(j,meshi.size()){
					if(i+meshi[j] <= x){
						gold[i+meshi[j]] = 1;
					}
				}
			}
		}

		buf = x;
		while(true){
			if(x==0){
				break;
			}
			if(gold[x] == 1){
				bool check = sosu(x);
				if(check){
					break;
				}
			}

			
			x--;
		}
		if(x==0){
			cout << "NA" << endl;
		}else{
			cout << x << endl;
		}

		
	}
}

Measured memory_bytes: 5128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

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

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

template<typename T>
void chmax(T &a, T b) {
    a = max(a, b);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> V(n + 1, 0);
    REP(i, 0, n) {
        cin >> V[i + 1];
        V[i + 1] += V[i];
    }
    int ans = 0;
    map<ll, int> m;
    REP (i, 0, n + 1) {
        if (m.count(V[i])) {
            chmax(ans, i - m[V[i]]);
        } else {
            m[V[i]] = i;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 16664
#include<stdio.h>

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

    int B[101] = {0};
    int d,i;
    for(i = 0;i < N;i++){
        scanf("%d",&d);
        B[d] += 1; 
    }

    int layer = 0;
    for(i = 0;i < 101;i++){
        if(B[i] != 0){
            layer += 1;
        }
    }
    printf("%d",layer);
    return 0;
}

Measured memory_bytes: 128
import * as fs from 'fs'
import {debug} from '../../../util'

const input = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n')
const output = (x: any) => console.log(x)

const [N, M] = input[0].split(' ').map(n => parseInt(n, 10))
const H = input[1].split(' ').map(n => parseInt(n, 10))
let ans: boolean[] = new Array(N).fill(true)

for (let i = 0; i < M; ++i) {
    const [A, B] = input[2 + i].split(' ').map(n => parseInt(n, 10))
    if (H[A-1] < H[B-1]) {
        ans[A-1] = false
    } else if (H[A-1] > H[B-1]) {
        ans[B-1] = false
    } else if (H[A-1] === H[B-1]) {
        ans[A-1] = false
        ans[B-1] = false
    }
}

let counter = 0
ans.map(a => {
    if(a) ++counter
})
output(counter)

Measured memory_bytes: 61104
n, y = map(int, input().split())
cur = 0
ok = False
for i in range(n + 1):
    if ok:
        break
    if i * 10000 > y:
        break
    if (10000 * i == y) and (i == n):
        ok = True
        print("{0} 0 0".format(i))
        break
    cur = y - (10000 * i)
    for j in range((n + 1) - i):
        if ok:
            break
        if j * 5000 > cur:
            break
        if 5000 * j == cur  and (i + j) == n:
            print("{0} {1} 0".format(i,j))
            ok = True
            break
        if ((cur - 5000 * j) % 1000) == 0:
            k = (cur - 5000 * j) / 1000
            k = int(k)
            if (i + j + k) == n:
                print("{0} {1} {2}".format(i,j, k ))
                ok = True
                break
if not ok:
    print("-1 -1 -1")


Measured memory_bytes: 42476
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(long long i=0;i<(n);i++)
#define rep2(i,m,n) for(long long i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back





//2のa乗をbで割った余り

ll amari(ll a, ll b){
    ll tmp=1%b;

    rep(i,a){
        tmp=(tmp*2)%b;
    }

    return tmp;


}




int main(){

   ll n;
   cin>>n;
   string x;
    cin>>x;

    ll cnt=0;

    rep(i,n){
        if (x.at(i)=='1'){
            cnt++;
        }
    }
  
  



  

     vector<ll> data(200001,0);

    rep(i,200001){
        ll tmp=0;
      	ll a=i;

        while (a!=0){
            bitset<20> s(a);

            ll cntone=0;
            rep(j,20){
                if (s.test(j)){
                    cntone++;
                }
            }
        
            a%=cntone;

            tmp++;
        }
      
   
  
        data.at(i)=tmp;

    }

  
  
     
                
     
  
       if (cnt==1){

        rep(i,n){
            if (x.at(i)=='1'){
                cout<<0<<endl;
            }

            else {
                if (x.at(n-1)=='0' and i!=(n-1)){
                    cout<<1<<endl;
                }
                else if (x.at(n-1)=='1' and i==n-1){
                    cout<<1<<endl;
                }
                else {
                    cout<<2<<endl;
                }

            }
        }
    }



    else if (cnt==0){
        rep(i,n){
            cout<<1<<endl;
        }
    }

  

  
  
  
    else {
      
      
        	vector<ll> minusamari(n,0);
  	vector<ll> plusamari(n,0);
  
     ll tmpminus=1%(cnt-1);
    ll tmpplus=1%(cnt+1);
  
  	minusamari.at(0)=tmpminus;
  	plusamari.at(0)=tmpplus;
  
  rep(i,n-1){
 
    
    tmpminus=(tmpminus*2)%(cnt-1);
    tmpplus=(tmpplus*2)%(cnt+1);
    
    minusamari.at(i+1)=tmpminus;
    plusamari.at(i+1)=tmpplus;
    
  }


      
      
      
      
      

        ll minusfirstamari=0;
        ll plusfirstamari=0;

        rep(i,n){
            ll tmp;
            if (x.at(i)=='1'){
                tmp=minusamari.at(n-1-i);
                minusfirstamari+=tmp;
                minusfirstamari%=(cnt-1);

                tmp=plusamari.at(n-1-i);
                plusfirstamari+=tmp;
                plusfirstamari%=(cnt+1);

            }


        }


 rep(i,n){
            if (x.at(i)=='1'){
              
                ll zantei;

                zantei=minusfirstamari-minusamari.at(n-1-i);

                if (zantei<0){
                   zantei+=cnt-1;
                }

                cout<<1+data.at(zantei)<<endl;;



            }

            else {
              
              ll zantei;
                zantei=plusfirstamari+plusamari.at(n-1-i);
                zantei%=(cnt+1);

                cout<<1+data.at(zantei)<<endl;
            }







        }



    }


                              
             












  
  



}








            






Measured memory_bytes: 8320
x, k, d = map(int, input().split())
x = abs(x)
if x > d * k:
    print(x - d * k)
else:
    re_k = x // d
    if (k - re_k) % 2 == 0:
        print(x - re_k * d)
    else:
        print((re_k + 1) * d - x)


Measured memory_bytes: 9164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;


int a, b;

int main() {
	cin >> a >> b;
	int ans = 0;
	if (a == b) ans = 2 * a;
	else {
		ans = max(a, b) * 2 - 1;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  ll N; cin >> N;
  if(N%2==1){cout << 0 << endl;return 0;}
  ll ans = 0;
  ll n = 1;
  while(pow(5,n)*2<=N){
    ans += N/((ll)(pow(5,n)*2));
    n++;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 384
import itertools
import math 
 
n,s = [int(input()) for _ in range(2)]
 
def n_base_sum(n,b):
    if(math.floor(n/b)):
        return n_base_sum(math.floor(n/b),b)+n%b
    else:
        return n%b
 
def search_p(n,s):
    for p in range(math.floor(math.sqrt(n))+1,0,-1):
        b = (n-s)//p + 1
        if b >1 :
            q = n % b
            if p+q ==s and q < b and n == p*b+q and p<b:
                return b
        
    return -1
 
ans =-1
flag = False
answers = []
if s == n:
    ans = n+1
    flag =True
    answers.append(ans)
for b in  range(2,math.ceil(math.sqrt(n))+1):
    if s== n_base_sum(n,b):
        ans = b
        flag = True
        answers.append(ans)
        break
ans = search_p(n,s)
if ans != -1:
    flag =True
    answers.append(ans)
 
if not flag:
    print(-1)
else:
    print(int(min(answers)))

Measured memory_bytes: 3188
#include <iostream>
#include<string>
#include <cassert>
#include <algorithm>
#include <functional>
#include<stdio.h>

using namespace std;

int main() {
	int N;
	string S;
	cin >> N;
	cin >> S;
	for (int i = 0; i < S.size(); ++i) {
		if(((int)S[i]+N)<=90)//A[i]をアスキーに変換すること
		S[i] += N;
		else {
			S[i] += (N - 26);

		}
	}
	cout << S << endl;
}

Measured memory_bytes: 256
import math
import heapq
from collections import Counter

#N,K=map(int, input[].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

A,B,C=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

if C-(A-B)>0:
    print(C-(A-B))
else:
    print(0)

Measured memory_bytes: 3316
import java.util.*;
import java.io.*;

public class Main {

	private static final int mod =(int)1e9+7;
	public static void main(String[] args) throws Exception  {
	      Scanner  sc=new Scanner(System.in);
	      PrintWriter out=new PrintWriter(System.out);
	      int n=sc.nextInt();
	      int a=sc.nextInt();
	      int b=sc.nextInt();
	      int c=a-b;
	      long h[]=new long[n];
	      
	      for(int i=0;i<n;i++) {
	        h[i]=sc.nextLong();
	      
	      }
	        int l=0;
	        int u=(int) 1e9;
	        while(u>=l) {
	          int k=(u+l)/2;
	          long sum=0;
	          for(long i:h) {
	            long d=i-1l*b*k;
	            if(d>0) {
	              sum+=(d+c-1)/c;
	            }
	          }
	          if(sum>k) {
	            l=k+1;
	          }else {
	            u=k-1;
	          }
	        }
	        System.out.println(u+1);
	 
	}


static long nCr(int n, int r, 
    int p) 
{ 


if (r == 0) 
return 1; 


int[] fac = new int[n + 1]; 
fac[0] = 1; 

for (int i = 1; i <= n; i++) 
fac[i] = fac[i - 1] * i % p; 

return (fac[n] * modInverse(fac[r], p) 
% p * modInverse(fac[n - r], p) 
% p) 
% p; 
} 
static long modInverse(int n, int p) 
{ 
    return pow(n, p - 2)%mod; 
} 
static long pow(long x,long y) {
  long res=1l;
  while(y!=0) {
    if(y%2==1) {
      res=x*res%mod;
    }
    y/=2;
    x=x*x%mod;
  }
  return res;
} 
}




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

int main(){
  ll n;
  cin >> n;
  vector<char> s(n);
  rep(i,n){
    cin >> s.at(i);
  }
  ll count_R=0;
  ll count_G=0;
  ll count_B=0;
  rep(i,n){
    if(s.at(i)=='R'){
      count_R++;
    }
    else if(s.at(i)=='G'){
      count_G++;
    }
    else{
      count_B++;
    }
  }
  ll answer = count_R * count_G * count_B;
  for (int i = 0; i < n - 2; i++){
    for (int j = 1; i + 2 * j < n;j++){
      if(s[i]!=s[i+j]&&s[i]!=s[i+2*j]&&s[i+j]!=s[i+2*j]){
        answer--;
      }
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	int n;
	cin >> n;
	string str;
	cin >> str;
	string s[2];
	s[0] = str.substr(0, n);
	s[1] = str.substr(n, n);
	reverse(s[1].begin(), s[1].end());
	map<pair<string,string>, LL> freq[2];
	for(int j = 0; j < 2; j++){
		for(int r = 0; r < (1<<n); r++){
			string cur[2];
			for(int z = 0; z < n; z++){
				cur[(r >> z) & 1] += s[j][z];
			}
			freq[j][{cur[0], cur[1]}]++;
		}
	}
	LL ans = 0;
	for(auto x : freq[0]){
		ans += freq[0][x.first] * freq[1][x.first];
	}
	cout << ans << '\n';
}


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

struct team{std::string name; int win; int lose;};

bool ascendingteam(const team& lteam, const team& rteam){
  if(lteam.win == rteam.win)
    return lteam.lose < rteam.lose;
  return lteam.win > rteam.win;  
}

int main(){
  int n;
  while(std::cin >> n, n){
    std::vector<team> tv;
    for(int j=0;j<n;j++){
      team t;
      t.win = 0, t.lose = 0;
      std::string name;
      std::cin >> name;
      t.name = name;
      for(int i=0;i<n-1;i++){
        int point;
        std::cin >> point;
        if(point == 0)
          t.win++;
        else if(point == 1)
          t.lose++;
      }
      tv.push_back(t);
    }

    std::sort(tv.begin(), tv.end(), ascendingteam);
    
    std::vector<team>::iterator it = tv.begin();
    while(it != tv.end()){
      std::cout << (*it).name << std::endl;
      it++;
    }
  }
}

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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

const int N = 1e5 + 2137;
int cnt[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int a;
	LL s = 0;
	for(int i=0; i<n; i++) {
		cin>>a;
		s+=a;
		cnt[a]++;
	}
	int q;
	cin>>q;
	int b, c;
	for(int i=0; i<q; i++) {
		cin>>b>>c;
		LL sx = ((LL) cnt[b]) * ((LL) b);
		LL sy = ((LL) cnt[b]) * ((LL) c);
		LL sz = sy-sx;
		s+=sz;
		cnt[c]+=cnt[b];
		cnt[b] = 0;
		cout<<s<<"\n";
	}
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

 
int main(){  
  string s;
  cin >> s;
  if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba"){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector<int> a;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb(x);
	}
	sort( a.begin(), a.end() );
	int ne = 0, po = 0;
	for(int i=0;i<n;i++){
		if( a[i] < 0 )ne++;
		else po++;
	}
	queue<int> negat, posit;
	if( ne == 0 ){
		negat.push( a[0] );
		for(int i=1;i<n;i++){
			posit.push(a[i]);
		}
	}
	else if( po == 0 ){
		for(int i=0;i<n-1;i++){
			negat.push(a[i]);
		}
		posit.push(a[n-1]);
	}
	else{
		for(int i=0;i<n;i++){
			if( a[i] < 0 )negat.push( a[i] );
			else posit.push(a[i]);
		}
	}
	vector< pair<int,int> > res;
	int final_positive = posit.front(); posit.pop();
	int cur = negat.front(); negat.pop();
	while( !posit.empty() ){
		int fr = posit.front(); posit.pop();
		res.pb( mp( cur, fr ) );
		cur = cur - fr;
	}
	res.pb( mp( final_positive, cur ) );
	cur = final_positive - cur;
	while( !negat.empty() ){
		int fr = negat.front(); negat.pop();
		res.pb( mp(cur,fr) );
		cur = cur-fr;
	}
	cout<<cur<<endl;
	for(int i=0;i<res.size();i++){
		cout<<res[i].first<<" "<<res[i].second<<endl;
	}
	return 0;
}

Measured memory_bytes: 5232
c_0 = list(map(int, input().split()))
c_1 = list(map(int, input().split()))
c_2 = list(map(int, input().split()))
c = [c_0,c_1,c_2]

for a_0 in range(100+1):
    for a_1 in range(100+1):
        for a_2 in range(100+1):
            b_0 = c[0][0] - a_0
            b_1 = c[0][1] - a_0
            b_2 = c[0][2] - a_0

            a = [a_0,a_1,a_2]
            b = [b_0,b_1,b_2]
            flag = True
            for i in range(3):
                for j in range(3):
                    if c[i][j] == a[i] + b[j]:
                        continue
                    else:
                        flag = False
            if flag:
                print('Yes')
                exit()
print('No')

Measured memory_bytes: 45124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
const int maxn=100010;
int n,m;
int l[maxn],r[maxn];
typedef long long ll;
int read(){
	char ch=getchar();
	int f=1,x=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int lowbit(int x){
	return x&(-x);
}/*
3 9
4 7
5 8
*/
int maxn1,maxn2=10000000;
int main(){
	n=read(),m=read();
	for(register int i(1);i<=m;++i) {l[i]=read(),r[i]=read();maxn1=max(maxn1,l[i]);maxn2=min(maxn2,r[i]);}
	cout<<max(maxn2-maxn1+1,0)<<endl;
	return 0;
}


Measured memory_bytes: 1024
ac=0
wa=0
tle=0
re=0

read n
for (( i = 0; i < $n; i++ )); do
  read s
  case $s in
    AC  ) ac=$(( $ac + 1 )) ;;
    WA  ) wa=$(( $wa + 1 )) ;;
    TLE ) tle=$(( $tle +1 )) ;;
    RE  ) re=$(( $re + 1 )) ;;
  esac
done

echo "AC x $ac"
echo "WA x $wa"
echo "TLE x $tle"
echo "RE x $re"

Measured memory_bytes: 3812
#include<stdio.h>

int main(){

  int n,q;
  int i,j;
  int s[100000],t[100000],c=0;

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(j=0; j < q; j++){
    scanf("%d",&t[j]);
    i=0;
    s[n]=t[j];
    while(s[i]!=t[j]){
      i++;
    }
    if(i !=n) c++;
  }

  printf("%d\n",c);

  return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,cp=0,cw=0, cg=0, cy=0;
    cin >> n;
    string s[256];
    for(int i=0;i<n;i++){
        cin >> s[i];
        if(s[i]=="P") cp++;
        if(s[i]=="W") cw++;
        if(s[i]=="G") cg++;
        if(s[i]=="Y") cy++;
    }
        
    if(cp>=1&&cw>=1&&cg>=1&&cy>=1){
        cout << "Four" << endl;
    } else {
        cout << "Three" << endl;
    }
    
}


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

#define int long long

struct Combination {
  int mod; // e.g. 1000000007
  vector<int> fact; // factorial
  vector<int> invf; // inverse factorial
  vector<vector<int> > part; // partition number

  /*
    constructor : O(sz+log(mod))   
    make factorial table (fact) and inverse factorial table (invf)
  */
  Combination(int sz, int mod) : fact(sz+1), invf(sz+1), mod(mod) {
    fact[0] = 1;
    for ( int i = 1; i < (int)fact.size(); i++ ) {
      fact[i] = fact[i-1]*i%mod;
    }
    invf[sz] = inv(fact[sz]);
    for ( int i = sz-1; i >= 0; i-- ) {
      invf[i] = invf[i+1]*(i+1)%mod;
    }
  }

  int pow(int x, int n) const {
    int ret = 1;
    while ( n > 0 ) {
      if ( n & 1 ) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return ret;
  }

  int inv(int x) const {
    return pow(x, mod - 2);
  }

  /*
    permutation
  */
  int P(int n, int r) const {
    if ( r < 0 || n < r ) return (0);
    return fact[n]*invf[n-r]%mod;    
  }

  /*
    combination
  */
  int C(int n, int r) const {
    if ( r < 0 || n < r ) return (0);    
    return fact[n]*invf[r]%mod*invf[n-r]%mod;    
  }  

  /*
    combination with repetition
  */
  int H(int n, int r) const {
    if ( n < 0 || r < 0 ) return 0;
    if ( n == 0 && r == 0 ) return 1;
    return C(n+r-1, n);    
  }

  /*
    stirling number
  */
  int S(int n, int r) const {
    int ret = 0;
    for ( int i = 1; i <= r; i++ ) {
      int add = C(r, i)*pow(i, n)%mod;      
      if ( (r-i)&1 ) ret += mod-add;
      else ret += add;
      ret %= mod;      
    }
    (ret *= invf[r]) %= mod;
    return ret;
  }

  /*
    bell number
  */
  int B(int n, int r) const {
    int ret = 0;
    for ( int i = 1; i <= r; i++ ) {
      (ret += S(n, i)) %= mod;      
    }
    return ret;
  }

  /*
    calc partition number
    return and make partition number table (part)
  */
  vector<vector<int> > built_part(int n, int r) {
    part = vector<vector<int> >(n+1, vector<int>(r+1, 0));
    part[0][0] = 1;
    for ( int i = 0; i <= n; i++ ) {
      for ( int j = 1; j <= r; j++ ) {
	if ( i-j >= 0 ) {
	  (part[i][j] = part[i][j-1]+part[i-j][j]) %= mod;	  
	} else {
	  part[i][j] = part[i][j-1];
	}
      }
    }
    return part;    
  }
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, K;
  cin >> N >> K;

  // assert(N!= 1 && K != 1);  

  const int MOD =1e9+7;  
  Combination C(2001, 1e9+7);  

  int R = N-K;
  // cout << C.C(0, 0) << endl;  
  for ( int i = 1; i <= K; i++ ) {
    int ans = 0;    
    if ( i-1 >= 0 ) ans += ((C.C(K-1, i-1) * C.C(R-1, i-1))%MOD*2)%MOD;    
    ans %= MOD;   
    if ( i-1 >= 0 ) ans += (C.C(K-1, i-1) * C.C(R-1, i))%MOD;
    ans %= MOD;
    if ( i-2 >= 0 ) ans += (C.C(K-1, i-1) * C.C(R-1, i-2))%MOD;
    ans %= MOD;

    if ( N == K && i == 1 ) cout << 1 << endl;
    else cout << (ans+MOD)%MOD << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  map<char, int> mp;
  for(int i=0;i<s.size();i++){
    mp[s[i]]++;
  }
  if(s.size()==1){
    cout << "YES\n";
    return 0;
  }
  if(abs(mp['a']-mp['b'])<=1 and abs(mp['a']-mp['c'])<=1 and abs(mp['c']-mp['b'])<=1 ){
    cout << "YES\n";
  }else{
    cout << "NO\n";
  }
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}

int main() {
    int n; cin >> n;
    std::vector<long long> a(n + 2, 0);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    long long ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans += std::abs(a[i + 1] - a[i]);
    }
    for (int i = 1; i <= n; ++i) {
        auto cur = ans;
        cur -= std::abs(a[i] - a[i - 1]);
        cur -= std::abs(a[i + 1] - a[i]);
        cur += std::abs(a[i + 1] - a[i - 1]);
        cout << cur << endl;
    }
}


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

typedef long long ll;
const int N = 2000006;



int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	ll n;
	cin>>n;
	
	long double ans = (n+1)/2;
	
	ans /= n;
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
    int a, b, d, r;
    double f;

    cin >> a >> b;

    d = a / b;
    r = a % b;
    f = 1.0 * a / b;

    printf("%d %d %.5lf", d, r, f);

    return 0;

}


Measured memory_bytes: 3228
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

ll dp[52][5020];

int main() {
	int n, a;
	cin >> n >> a;
	dp[0][2510] = 1;
	rep(i, n) {
		int x;
		cin >> x;
		x -= a;
		rep(j, 5020) {
			if (0 <= j + x && j + x < 5020) {
				dp[i + 1][j + x] += dp[i][j];
			}
			dp[i + 1][j] += dp[i][j];
		}
	}
	cout << dp[n][2510] - 1 << '\n';
}

Measured memory_bytes: 5616
#include <cstdio>
#include <cmath>
#include <limits>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdint>
#include <functional>
#include <sstream>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
using ss = stringstream;

const ll mod = 1000000000 + 7; //10^9
const ll llmax = pow(10, 18);

// bool is_integer(double x){
//     return floor(x) == x;
// }





/*逆元　あまりの割り算をするときにこいつをかける(a/b→a*modinv(b))*/
// mod. m での a の逆元 a^{-1} を計算する
// ll modinv(ll a,ll m){
//     long long b = m, u = 1, v = 0;
//     while (b) {
//         long long t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= m;
//     if (u < 0) u += m;
//     return u;
// }



// bool IsPrime(ll num)
// {
//     if (num < 2) return false;
//     else if (num == 2) return true;
//     else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
 
//     double sqrtNum = sqrt(num);
//     for (int i = 3; i <= sqrtNum; i += 2)
//     {
//         if (num % i == 0)
//         {
            // 素数ではない
//             return false;
//         }
//     }
 
    // 素数である
//     return true;
// }
 
 /*階乗*/
// ll facctorialMethod(ll k){
//     ll sum = 1;
//     for (ll i = 1; i <= k; ++i)
//     {
//         sum *= i;
        //sum%=MOD;//あまりを出力せよ問題の時はこれもやる
//     }
//     return sum;
// }

int main() {
    int x;
    cin >> x;
    if(x == 1) cout << 0 << endl;
    else cout << 1 << endl;
}


Measured memory_bytes: 3632