akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int a, b;
    cin >> a >> b;
    if(a>8||b>8){

        cout << ":(" << endl;
    }else{

        cout << "Yay!" << endl;
    }



    return 0;
}

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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

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

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<std::string> W){
  set<string> m;
  auto b = W[0];
  m.insert(b);
  for(int i=1; i<W.size(); i++) {
    if(m.find(W[i])!=m.end()){
      std::cout << NO << std::endl;
      return;
    } else {
      if(b.back() != W[i][0]) {
	std::cout << NO << std::endl;
	return ;
      } else {
	b = W[i];
	m.insert(b);
      }
    }
  }
  std::cout << YES << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<std::string> W(N);
  for(int i = 0 ; i < N ; i++){
    std::cin >> W[i];
  }
  solve(N, std::move(W));
  return 0;
}


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


int main()
{

	int a[21];
	int count=0;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}

	for (int i = 2; i <= (n-1); i++)
	{
		if (((a[i] <= a[i + 1]) && (a[i] >= a[i - 1])) || ((a[i] >= a[i + 1]) && (a[i] <= a[i - 1]))) count++;
	}

	cout << count << endl;

}

Measured memory_bytes: 764
import sys

n = int(input())
Vx = list(map(int, input().split()))
Vy = list(map(int, input().split()))
maxList = []

plist = [1, 2, 3]
for p in plist:
    Sum = 0
    for i in range(n):
        Sum += abs(Vx[i] - Vy[i])**p
        D = Sum**(1/p)
    print(D)

D = 0
for i in range(n):
    maxList.append(abs(Vx[i] - Vy[i]))
    
print(max(maxList))


Measured memory_bytes: 5668
#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 n;
    cin >> n;
    vector<int> a(n,0);
    bool can = true;
    int alpha;
    rep(i,n){
        cin >> alpha;
        if(alpha%2==0){
            if(alpha%6 != 0 and alpha%10 !=0){
                can=false;
            }
        }
    }
    if(can==true)cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
struct edge{int from,to,cost;};
vector<edge> G;
int d[2001];

int main() {
  int n,m,s;
  cin >> n >> m >> s;
  rep(i,m) {
    edge e;
    cin >> e.from >> e.to >> e.cost;
    G.pb(e);
  }
  fill(d,d+n,MAX);
  d[s]=0;
  bool ck=false;
  for(int j=0; j<n; j++) {
    bool update=false;
    for(int i=0; i<m; i++) {
      edge e=G[i];
      if(d[e.from]!=MAX && d[e.to]>d[e.from]+e.cost) {
	d[e.to]=d[e.from]+e.cost;
	update=true;
	if(j==n-1) ck=true;
      }
    }
    if(!update) break;
  }
  if(ck) pr("NEGATIVE CYCLE");
  else {
    rep(i,n) {
      if(d[i]==MAX) pr("INF");
      else pr(d[i]);
    }
  }
  return 0;
}


Measured memory_bytes: 1272
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vector<int> a(N + 1), b(M + 1);
  cin >> a[0] >> b[0];
  F0R(i, N) cin >> a[i + 1];
  F0R(i, M) cin >> b[i + 1];
  sort(rng(a));
  sort(rng(b));
  cout << (a.back() < b[0] ? "No War" : "War");
}
#endif


Measured memory_bytes: 3612
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int N, X, T;
    cin >> N >> X >> T;
    int ans = 0;
    while(N >= X)
    {
        ans += 1;
        N -= X;
    }
    if(N < X && N != 0)
        ans += 1;
    cout << ans * T << endl;
}

Measured memory_bytes: 3632
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut a: i64 = read();
    let mut b: i64 = read();
    let mut c: i64 = read();
    let mut d: i64 = read();
    let mut ans = 0;
    if d <= a {
        println!("{}", d);
        return;
    }

    if d <= a + b {
        println!("{}", a);
        return;
    }

    println!("{}", a - (d - (a + b)));
}


Measured memory_bytes: 2132
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

int main() {
    string s;
    getline(cin, s);
    int ans = 700;
    forn(i, 0, s.size()) {
        if (s[i] == 'o') ans += 100;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <cmath>
#include <map>
#include <algorithm>
#include <queue>
#include <chrono>
#include <array>
#include <random>
#include <fstream>
#include <list>


std::string yesno(bool b) {
    return b ?
        "Yes" : "No";
        // "YES" : "NO";
        // "yes" : "no";

}


int main() {
    std::cin.tie(0); std::ios::sync_with_stdio(false);
    std::array<std::array<int, 3>, 3> a;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            int tmp;
            std::cin >> tmp;
            a[i][j] = tmp;
        }
    }
    std::array<int, 3> ac{1000}, bc{1000};
    ac[0] = 0;
    bool ok = true;
    for (int i = 0; i <3 ; ++i) {
        bc[i] = a[0][i] - ac[0];
        ac[i] = a[i][0] - bc[0];
    }
    for (int i = 1; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            if(a[i][j] != ac[i] + bc[j]){
                ok = false;
            }
        }

    }
    std::cout << yesno(ok) << std::endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	int n;
	cin >> n;
	vector<pll> a(n + 1);
	for (int i = 1;i <= n;i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	ll dp[n + 1][n + 1] = {};
	sort(1 + all(a), greater<pll>());
	for (int i = 1;i <= n;i++) {
		for (int j = 0;j < i;j++) {
			dp[i][j + 1] = max(dp[i][j + 1], dp[i - 1][j] + a[i].first * abs(a[i].second - j - 1));
			dp[i][j] = max(dp[i][j], dp[i - 1][j] + a[i].first * abs(a[i].second - n + i - j - 1));
		}
	}
	ll ans = 0;
	for (int i = 0;i <= n;i++)
		ans = max(ans, dp[n][i]);
	cout << ans << '\n';
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

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

    ll n = X.size();
    stack<char> stackX;
    REP(i, n)
    {
        if (!stackX.empty())
        {
            if (X[i] == 'S')
            {
                stackX.push(X[i]);
            }
            else if (X[i] == 'T')
            {
                if (stackX.top() == 'S')
                {
                    stackX.pop();
                }
                else
                {
                    stackX.push(X[i]);
                }   
            }
        }
        else
        {
            stackX.push(X[i]);
        }
    }
    ll ans = stackX.size();

    cout << ans << endl;
}


Measured memory_bytes: 644
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun print-board (b w)
  (labels ((write-point (x)
             (if (zerop x) (write-char #\.) (write-char #\#))))
    (dotimes (i 100)
      (dotimes (j 50)
        (write-point (aref b i j)))
      (dotimes (j 50)
        (write-point (aref w i j)))
      (terpri))))

(defun main ()
  (let* ((a (- (read) 1))
         (b (- (read) 1))
         (black-board (make-array '(100 50) :element-type 'bit :initial-element 1))
         (white-board (make-array '(100 50) :element-type 'bit :initial-element 0)))
    (block white-dot
      (loop for i from 0 below 100 by 2
            do (loop for j from 0 below 49 by 2
                     do (when (zerop a)
                          (return-from white-dot))
                        (setf (aref black-board i j) 0)
                        (decf a))))
    (block black-dot
      (loop for i from 0 below 100 by 2
            do (loop for j from 1 below 50 by 2
                     do (when (zerop b)
                          (return-from black-dot))
                        (setf (aref white-board i j) 1)
                        (decf b))))
    (format t "100 100~%")
    (print-board black-board white-board)))

#-swank(main)


Measured memory_bytes: 22248
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int a,b;cin>>a>>b;
    int ans=0;
    for(int i=1;i<=b-a-1;i++){
        ans+=i;
    }
    cout<<ans-a<<endl;
}

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

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

    vector<lint> A(N+1);
    for(auto& elem : A)  cin >> elem;

    if(A[0] != 0) {
        if(N == 0 && A[0] == 1) {
            cout << 1 << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }

    if(N == 0 && A[0] == 0) {
        cout << -1 << endl;
        return 0;
    }

    reverse(A.begin(), A.end());

    vector<lint> mn(N+1), mx(N+1);
    mn[0] = mx[0] = 0;
    for(lint i=0; i+1<N+1; i++) {
        mn[i+1] = (mn[i]+A[i]+1)/2;
        mx[i+1] = (mx[i]+A[i]);
    }

    reverse(A.begin(), A.end());
    reverse(mn.begin(), mn.end());
    reverse(mx.begin(), mx.end());

    if(mn[0] != 1) {
        cout << -1 << endl;
        return 0;
    }

    lint node = 1;
    lint ans = 1;
    for(lint i=0; i+1<N+1; i++) {
        node = min((node-A[i])*2, mx[i+1]+A[i+1]);
        ans += node;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5636
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a==b)cout<<"Draw"<<endl;
  else if(a==1)cout<<"Alice"<<endl;
  else if(b==1)cout<<"Bob"<<endl;
  else if(a>b)cout<<"Alice"<<endl;
  else cout<<"Bob"<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N;
int A[200001];
int E[400001], ne[400001], he[200001];
//vector<int> V;
int V[200001], v;
void dfs(int p, int mae) {
	int itr = lower_bound(V, V + v, A[p]) - V;
	if (itr == v) {
		V[v++] = A[p];
		for (auto to = he[p]; to; to = ne[to]) {
			if (E[to] != mae) {
				dfs(E[to], p);
			}
		}
		he[p] = v--;
	}
	else {
		swap(V[itr], A[p]);
		for (auto to = he[p]; to; to = ne[to]) {
			if (E[to] != mae) {
				dfs(E[to], p);
			}
		}
		he[p] = v;
		V[itr] = A[p];
	}
}

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
inline int getintA() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}
char dn[1300000], *di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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

	N = getint();
	rep1(i, N) A[i] = getintA();
	int k = 1;
	rep(i, N - 1) {
		int u = getint(), v = getint();
		E[k] = v;
		ne[k] = he[u];
		he[u] = k++;
		E[k] = u;
		ne[k] = he[v];
		he[v] = k++;
	}

	V[v++] = 2000000000;
	dfs(1, -1);

	rep1(i, N) putint(he[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 24344
#include <stdio.h>
#include <string.h>
#include <limits.h>

#define MAX 2000000
  
int Q[MAX] = {}; 
int heapSize=0;
 
int parent(int);
int left(int);
int right(int);
void maxHeapify(int);
int extractMax(void);
void insert(int);
void increaseKey(int, int);
  
// 
int main(void)
{
  char op[10];
  int val=0;

  while (1)
  {
    scanf("%s", op);
    if (strcmp(op, "insert") == 0)
    {
      scanf("%d", &val);
      insert(val);
    }
    else if (strcmp(op, "extract") == 0)
    {
      printf("%d\n", extractMax());
    }
    else if (strcmp(op, "end") == 0)
    {
      break;
    }
  }
  return 0;
}

int extractMax(void) {
  if(heapSize < 1){
    printf("heap size is 0!");
    return 0;
  }
  int max = Q[1];
  Q[1] = Q[heapSize];
  heapSize--;
  maxHeapify(1);
  return max;
}
 
void maxHeapify(int i)
{
  int largest=0, temp=0, l=0, r=0;
 
  l = left(i);
  r = right(i);
   
  if((heapSize >= l) && (Q[l] > Q[i])){
    largest = l;
  }
  else{
    largest = i;
  }
    
  if((heapSize >= r) && (Q[r] > Q[largest])){
    largest = r;
  }
 
  if (largest != i){
    temp = Q[i];
    Q[i] = Q[largest];
    Q[largest] = temp;
    maxHeapify(largest);
  } 
 
}

void insert(int key) {
  heapSize++;
  Q[heapSize] = INT_MIN;
  increaseKey(heapSize, key);
}

void increaseKey(int i, int key) {
  Q[i] = key;
  while(i > 1 && Q[parent(i)] < Q[i]){
    int tmp = Q[i];
    Q[i] = Q[parent(i)];
    Q[parent(i)] = tmp;
    i = parent(i);
  }
}

int parent(int i) {
  return (int)(i/2);
}

int left(int i)
{
  return (2*i);
}
  
int right(int i)
{
  return (2*i + 1);
}



Measured memory_bytes: 5668
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

K=int(input())
S=input()

def COMinit(n,MOD):
    fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,(n+1)):
        fac[i]=fac[i-1]*i%MOD
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i]=finv[i-1]*inv[i]%MOD
    return fac,finv,inv

fac,finv,inv=COMinit(3*10**6,MOD)

def COM(n, k, MOD=MOD):
    if n<k or n<0 or k<0:
        return 0
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD

dp=[[0]*(K+len(S)+1) for _ in range(2)]
for i in range(len(S)-1,K+len(S)+1):
    dp[0][i]=COM(i,i-len(S)+1)*pow(25,i-len(S)+1,MOD)
dp[1][len(S)]
for i in range(K+len(S)):
    dp[1][i+1]=dp[1][i]*26+dp[0][i]
    dp[1][i+1]%=MOD
print(dp[1][-1])

Measured memory_bytes: 175272
#include<bits/stdc++.h>
using namespace std;
#define pi pair<int, int>
double S = 0;
int N;
double dist(int a, int b, vector<pi> &p){
  return sqrt((p[a].first - p[b].first)*(p[a].first - p[b].first) + (p[a].second - p[b].second) * (p[a].second - p[b].second));
}
void rec(double d, vector<pi> &p, set<int> &v, int pre){
  if(v.size() == N){
    S += d;
  }
  for(int i = 0; i < N; i++){
    if(v.count(i) == 0){
      v.insert(i);
      rec(d + dist(pre, i, p), p, v, i);
      v.erase(i);
    }
  }
}
int fac(int n){
  int res = 1;
  for(int i = 2; i <= n; i++){
    res *= i;
  }
  return res;
}
int main(){
  cin >> N;
  vector<pi> p (N);
  for(int i = 0; i < N; i++){
    cin >> p[i].first >> p[i].second;
  }
  set<int> v;
  for(int i = 0; i < N; i++){
    v.insert(i);
    rec(0.0, p, v, i);
    v.erase(i);
  }
  //cout << S << endl;
  cout << fixed << setprecision(10);
  cout << S / (double)fac(N) << endl;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
a, b = M()
if b%a ==0:
    print(a+b)
else:
    print(b-a)

Measured memory_bytes: 74600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
bool x[30];
int main(void){
    string s; cin>>s;
    for(int i=0;i<s.size();i++){
        if(x[s[i]-'a']){
            cout<<"no"<<endl;
            return 0;
        }else{
            x[s[i]-'a']=true;
        }
    }
    cout<<"yes"<<endl;
    
}


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

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int aoki = a/d + (a%d==0 ? 0 : 1);
        int takahashi = c/b + (c%b==0 ? 0 : 1);
        if(aoki >= takahashi){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35780
#include<cstdio>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int a[4];
char d[100001];
bool cmp(int a,int b){return a>b;}
int main()
{
	string s;
	cin>>s; int l=s.length();
	for (int i=0;i<l;i++)
		if (s[i]=='a') a[1]++;
		else if (s[i]=='b') a[2]++;
		else if (s[i]=='c') a[3]++;
	if (l==3) {if (a[1]==1&&a[2]==1&&a[3]==1) puts("YES"); else puts("NO"); return 0;}
	if (l==2) {if (a[1]==2||a[2]==2||a[3]==2) puts("NO"); else puts("YES"); return 0;}
	sort(a+1,a+1+3,cmp);
	for (int i=0,j=0;i<l;i++)
	{
		j=j%3+1;
		if (--a[j]<0) {puts("NO"); return 0;}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<cstring>
//int LEN=100005;
const int LEN=100005;
 struct pp{
    char name[100];
    int t;
};
struct myqueue{
    pp a[LEN];
    int head,tail;
    bool isfull(){
      if((tail+1)%LEN==head) return 1;
      return 0;
    }
    bool isempty(){
      if(head==tail)return 1;
      return 0;
    }
    void push(pp x){
        if(!isfull()){
        a[tail%LEN]=x;
        tail++;
    }
    }
    pp pop(){
     if(!isempty()){
        pp m=a[head%LEN];
        head++;
        return m;
     }

    }
} q;
int main( ){
    //myqueue q;
    int m,n;
    pp p;
    scanf("%d%d",&m,&n);
    for(int i=0;i<m;i++){
        scanf("%s%d",p.name,&p.t);
        q.push(p);
    }
    int hm=0;
    while(!q.isempty()){
        pp p1;
        p1=q.pop();
        if(p1.t<=n){
            hm=hm+p1.t;
         printf("%s %d\n",p1.name,hm);
        }else{
         hm=hm+n;
         p1.t-=n;
         q.push(p1);
        }
    }

  return 0;
}

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


int main(){
                                                                     

    long long n, i, j;

    long long m = 0;


    cin >> n;

    vector<long long> a(n + 1);



    for( i = 1 ; i <= n ; i = i + 1 ){

         cin >> a.at(i);

         }


    for( i = 1 ; i <= n ; i = i + 1 ){

         for( j = 1 ; j <= n ; j = j + 1 ){

              if( j != i && m < abs( a.at(i) - a.at(j) ) ) m = abs( a.at(i) - a.at(j) );

              }

         }

              

    cout << m << endl;


    return 0;

    }

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;


int main(){
	int sum = 0;
vector<vector<int>> a(3, vector<int>(3));//二次元配列[N][M][列][行]
for (int j = 0; j < 3 ; j++){
  for (int k = 0; k < 3; k++){
    cin >> a[j][k];
	sum += a[j][k];
  }
}
	if(3 * (a[0][0]+a[1][1]+a[2][2]) == sum)	cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		int f=0;
		int s=0;
		for(int i=0;i<3;i++){
			int a=ir.nextInt();
			if(a==5)
				f++;
			if(a==7)
				s++;
		}
		out.println(s==1&&f==2?"YES":"NO");
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string result = "";
            for(int p=0; p<S.Length; p++)
            {
                int convert = alphabet.IndexOf(S.Substring(p, 1))+N;
                if(alphabet.Length - 1<convert)
                {
                    convert = convert - alphabet.Length;
                }
                result += alphabet.Substring(convert,1);
            }
            Console.WriteLine(result);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

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

#define rep(i,n) for (int i=0;i<(n);++i)
#define rep2(i,a,b) for (int i=(a);i<(b);++i)
#define rrep(i,n) for (int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;--i)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) cout<<(#_v)<<":";for(auto(_x):(_v)){cout<<" "<<(_x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int k, s;
    cin >> k >> s;
    int ans = 0;
    rep(x, k + 1) {
        rep(y, k + 1) {
            int z = s - x - y;
            if (0 <= z && z <= k) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<int> S(n), T(m);
  rep(i, n) cin >> S[i];
  map<int, vector<int>> mp;
  rep(i, m) {
    cin >> T[i];
    mp[T[i]].push_back(i);
  }
  vector<vector<ll>> dp(n+1, vector<ll>(m+1));
  dp[0][0] = 1;
  rep(i, n) {
    rep(j, m+1) {
      (dp[i+1][j] += dp[i][j]) %= mod;
      auto itr = lower_bound(all(mp[S[i]]), j);
      if(itr != mp[S[i]].end()) (dp[i+1][*itr+1] += dp[i][j]) %= mod;
    }
    for(auto& ele: mp) {
      rep(j, ele.second.size()) {
        if(j) (dp[i+1][ele.second[j]+1] += (mod+dp[i+1][ele.second[j-1]+1]-dp[i][ele.second[j-1]+1])%mod) %= mod;
      }
    }
  }
  ll ans = 0;
  rep(i, m+1) (ans += dp[n][i]) %= mod;
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 35100
#include<iostream>
#include<algorithm>
using namespace std;
int k[15],a[101],flag,k1,vis[101];
int main(){
	int n,k2;
	cin>>n>>k2;
	for(int i=0;i<k2;i++){
		cin>>k[i];
		vis[k[i]]=true;
	}
	for(int m=1;m<=100000;m++){
		k1=0,flag=0;
		int i=m;
		while(i>0){
			a[k1++]=i%10;
			i/=10;
		}
		for(int j=0;j<k1;j++){
			if(vis[a[j]]){
			flag=1;
			continue;	
			} 
		}
		if(flag==0&&m>=n){
		cout<<m<<endl;	
		break;
		} 
		
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
signed main()
{
  int x=0,y=0,z=0,w=0,n=0,m=0;
  std::cin >> x;
  std::vector<int> v(x+1);
  std::vector<int> vv(x);
  rep(i,x+1){
    std::cin >> v[i];
  }
  rep(i,x){
    std::cin >> vv[i];
  }
  rep(i,x){
    if(v[i]<vv[i]){
      y+=v[i];
      vv[i]-=v[i];
      v[i]=0;
      if(v[i+1]<vv[i]){
        y+=v[i+1];
        v[i+1]=0;
      }else{
        y+=vv[i];
        v[i+1]-=vv[i];
      }
    }else{
      y+=vv[i];
      v[i]-=vv[i];
    }
  }
  std::cout << y << '\n';
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int t=a.at(i)-1;
    if( a.at(t)-1 == i){
      ans++;
    }
  }
  cout << ans/2;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(){
  int N, i, j, cnt=1;
  scanf("%d", &N);
  int arr[N];
  for (i=0; i<N; i++) {
    scanf("%d", &arr[i]);
  }
  i=0;
  while(cnt<N+1){
    j=arr[i];
    if (j==2) {
      printf("%d\n", cnt);
      break;
    } else {
      i=j-1;
      cnt++;
      if (cnt>=N) {
        printf("%d\n", -1);
        break;
      }
    } 
  }
  return 0;
}

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

int main(){
  int h, w;
  while(true){
    cin >> h >> w;
    if(h==0 && w==0)
      break;
    vector<string> m;
    int c[h][w];
    string s;
    for(int k=0; k<h; k++){
      cin >> s;
      m.push_back(s);
      for(int l=0; l<w; l++)
	c[k][l] = 0;
    }
    int i=0, j=0;
    bool lp = false;
    while(true){
      if(c[i][j] == 1){
	lp=true; break;
      }
      else if(m[i][j] == '.')
	break;
      else if(m[i][j] == '>'){
	c[i][j] = 1;
	j++;
      }
      else if(m[i][j] == 'v'){
	c[i][j] = 1;
	i++;
      }
      else if(m[i][j] == '<'){
	c[i][j] = 1;
	j--;
      }
      else if(m[i][j] == '^'){
	c[i][j] = 1;
	i--;
      }
    }
    if(lp){
      cout << "LOOP\n";
    }
    else
      cout << j << " " << i << endl;
  }

  return 0;
}

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

#define ll long long
// #define INF 1e9
#define fi first
#define se second

typedef pair <int, int> Pii;

vector <Pii> item;
vector <vector <ll> > knap;

ll dp(int p, int w) {
    if (p < 0 || w <= 0) return 0;
    if (knap[p][w] != 0) return knap[p][w];
    knap[p][w] = dp(p-1, w);
    if (w >= item[p].fi) knap[p][w] = max(knap[p][w], dp(p-1, w-item[p].fi) + item[p].se);
    return knap[p][w];
}

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

    item.assign(n, {0, 0});
    for (int i = 0; i < n; i++) {
        int p, w;
        scanf("%d%d", &p, &w);
        item[i] = {p, w};
    }

    knap.assign(n, vector <ll>(w+1, 0));
    printf("%lld\n", dp(n-1, w));
}


Measured memory_bytes: 79488
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = (a*b*1)%2;
        int y = (a*b*2)%2;
        int z = (a*b*3)%2;
      
      if(x!=0||y!=0||z!=0){
         System.out.println("Yes");
      }else{System.out.println("No");}
    }
}

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

#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    rep(i, s.length()){
        int tmp = s[i];
        if(i == K-1){
            tmp -= 'A' - 'a';
        }
        cout << (char)tmp;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;

namespace Tenka2019A
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = temp[0];
            var B = temp[1];
            var C = temp[2];

            if ((A < C && C < B) || (B < C && C < A))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

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

  map<ll, ll> m;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    ll v;
    scanf("%lld", &v);
    a[i] = v;
    m[v] += 1;
    // cout << v << endl;
  }

  ll tmpAnswer = 0;
  for (auto e : m) {
    if (e.second >= 2) {
      tmpAnswer += (e.second * (e.second - 1)) / 2;
    }
  }

  for (ll i = 0; i < n; i++) {
    ll v = a[i];

    ll num = m[v];
    ll num2 = num - 1;

    ll ans = tmpAnswer;

    if (num >= 2) {
      ans -= (num * (num - 1)) / 2;
    }
    if (num2 >= 2) {
      ans += (num2 * (num2 - 1)) / 2;
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 9160
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
bool compare(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.second > b.second); 
}
int findmax(int arr[], int n){
	int curr_max = -1;
	for(int i=0;i<n;i++){
		curr_max = max(curr_max, arr[i]);
		}
	return curr_max;
	}
int findmin(int arr[], int n){
	int curr_max = INT_MAX;
	for(int i=0;i<n;i++){
		curr_max = min(curr_max, arr[i]);
		}
	return curr_max;
	}
bool help(int arr[], int mid, int n, int c){
	int last_pos = arr[0];
	int cows = 1;
	for(int i=1;i<n;i++){
		if(abs(arr[i]-last_pos) >= mid){
			last_pos = arr[i];
			if(++cows == c)
				return true;
			last_pos = arr[i];
		}
	}
	return false;
}
int main() 
{ 
	ll t;
	t=1;
	while(t--){
		ll n;
		cin>>n;
		ll a[110000];
		ll b[110000];
		ll c[110000];
		ll dp[110000][3];
		for(int i=0;i<n;i++){
			cin>>a[i]>>b[i]>>c[i];
			}
		for(int i=0;i<n;i++){
			for(int j=0;j<3;j++){
				if(i==0){
					if(j==0) dp[i][j]=a[i];
					else if(j==1) dp[i][j]=b[i];
					else dp[i][j]=c[i];
					}
				else{
					for(int k=0;k<3;k++){
						if(j==k) continue;
						else if(j==0) dp[i][j]=max(dp[i][j], dp[i-1][k]+a[i]);
						else if(j==1) dp[i][j]=max(dp[i][j], dp[i-1][k]+b[i]);
						else dp[i][j]=max(dp[i][j], dp[i-1][k]+c[i]);
						}
					}
				}
			}
		cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;
	}
} 


Measured memory_bytes: 5120
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        for line in sys.stdin:
            lines.append(line.strip())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    x = int(lines[0])
    

    return (x, )


def solve(x):

    result = 'No'
    if x >= 30:
        result = 'Yes'
        
    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 62048
#include<cstdio>
#include<iostream>
#include<cmath>
#include<ctype.h>
#include<vector>
#include<cstdlib>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<time.h>

#define ll long long
#define LL long long
#define ULL unsigned long long 
#define ull unsigned long long 
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
const ll INF = -10000000000;
using namespace std;


int main()
{
	int N, K, X, Y;
	int tmp, ans = 0;
	cin >> N >> K >> X >> Y;
	tmp = N - K;
	if (tmp <= 0) ans = N*X;
	else if (tmp > 0) ans = K*X + tmp*Y;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
<>;
@y=map-$t+($t=$_),glob<>;
<>=~($/=$");
map{
	@s=$_?@s[@s]:0..$#y;
	@s[$_-1,$_]=@s[$_,$_-1]for<>;
	@y=@y[@s]if$'>>$_&1;
}0..59;
print$z+=$_,$"for@y


Measured memory_bytes: 48904
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;
    cin>>n;
    ll t,x,y;
    rep(i,n){
        cin>>t>>x>>y;
        if(t<abs(x)+abs(y)||t%2!=(abs(x)+abs(y))%2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

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

using namespace std;

int main(){
	string s; cin>>s;
	int n=s.length();
	rep(i,8) if(s.substr(0,i)+s.substr(i+n-7)=="keyence") return puts("YES"),0;
	puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int C(ll x,int  y){
  ll ans=1;
  for(int i=x;i>x-y;i--){
    ans*=i;
  }
  for(int i=1;i<=y;i++){
    ans/=i;
  }
  return ans;
}

int main(){
  int n,p;
  cin >> n >> p;
  VI a(n);
  int od=0;
  rep(i,n){
      cin >>a.at(i);
      if(a.at(i)%2==1)od++;
  }
  ll ans;
  if(od==0){
    if(p==0)ans=pow(2,n);
    else if(p==1)ans=0;
  }
  else{
    ans=pow(2,n-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3996
#include <iostream>
#include <algorithm>
#include <deque>

constexpr int MAX = 1e5 + 10;

int a[MAX];

std::deque<int> deq, deqc;

using ll = long long int;

int main()
{

    int n;
    std::cin >> n;

    for (int i = 0; i < n; ++i)
        std::cin >> a[i];

    std::sort(a, a + n);

    int x = 1, y = 1;

    deq.push_back(a[x - 1]);
    deq.push_back(a[n - y]);

    while (x + y < n)
    {

        int vf = deq.front(), vb = deq.back();

        if (vf > vb)
            deq.push_front(a[x]);
        else
        {
            deq.push_back(a[x]);
        }
        ++x;

        if (x + y >= n)
            break;

        if (vf > vb)
            deq.push_back(a[n - y - 1]);
        else
        {
            deq.push_front(a[n - y - 1]);
        }
        ++y;
    }

    ll ans = 0, re = deq.front();

    deqc = deq;

    while (!deqc.empty())
    {

        ans += std::abs((ll)deqc.front() - re);
        re = deqc.front();
        deqc.pop_front();
    }

    ll l = deq.front(), r = deq.back();
    deq.pop_front();
    ll ml = deq.front();
    deq.pop_back();
    ll mr = deq.back();

    std::cout << ans - std::abs(l - ml) - std::abs(r - mr) + std::max(std::abs(l - ml) + std::abs(r - mr), std::max(std::abs(l - ml) + std::abs(r - l), std::abs(r - mr) + std::abs(r - l))) << std::endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define int long long
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
const int N=200000+10;
const int mod=1e9+7;
const int inf=1e10;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
int X[N],Y[N],W,H,n,res;
map<int,int> Map,f;
void calc(int x,int y){
	int X1,Y1,X2,Y2;
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++){
			if(i==1&&j==1) X1=x-2,Y1=y-2,X2=x,Y2=y;
			if(i==1&&j==2) X1=x,Y1=y-2,X2=x+2,Y2=y;
			if(i==1&&j==3) X1=x-1,Y1=y-2,X2=x+1,Y2=y;
			if(i==2&&j==1) X1=x-2,Y1=y,X2=x,Y2=y+2;
			if(i==2&&j==2) X1=x,Y1=y,X2=x+2,Y2=y+2;
			if(i==2&&j==3) X1=x-1,Y1=y,X2=x+1,Y2=y+2;
			if(i==3&&j==1) X1=x-2,Y1=y-1,X2=x,Y2=y+1;
			if(i==3&&j==2) X1=x,Y1=y-1,X2=x+2,Y2=y+1;
			if(i==3&&j==3) X1=x-1,Y1=y-1,X2=x+1,Y2=y+1;
			if(X1<1||Y1<1||X2>H||Y2>W) continue;
			if(f[X1*inf+Y1]) continue;
			f[X1*inf+Y1]=1;
			int ans=0;
			res++;
			for(int i=X1;i<=X2;i++)
				for(int j=Y1;j<=Y2;j++)
					if(Map[i*inf+j])
						ans++;
			//		if(ans==0) cout<<x<<" "<<y<<" "<<X1<<" "<<Y1<<" "<<X2<<" "<<Y2<<endl;
			f[ans]++;
		}
}
main(){
	H=read(),W=read(),n=read();
	for(int i=1;i<=n;i++)
		X[i]=read(),Y[i]=read(),Map[X[i]*inf+Y[i]]=1;
	for(int i=1;i<=n;i++)
		calc(X[i],Y[i]);
	cout<<(H-2)*(W-2)-res<<endl;
	for(int i=1;i<=9;i++)
		cout<<f[i]<<endl;
}


Measured memory_bytes: 214272
#include <iostream>
#include <string>

using namespace std;

bool check(int n, string new_board, string old_board)
{
  int interval;
  bool flag;

  for(int i = 0, i_len = old_board.size(); i < i_len; i += 1){
    if(new_board[0] == old_board[i]){
      for(int j = i+1, j_len = i_len; j < j_len; j += 1){
	if(new_board[1] == old_board[j]){
	  interval = j-i;
	  flag = true;

	  for(int k = 2, k_len = new_board.size(); k < k_len; k += 1){
	    if((k-1)*interval + j > j_len || new_board[k] != old_board[(k-1)*interval + j]) {
	      flag = false;
	      break;
	    }
	  }

	  if(flag){
	    return flag;
	  }
	}
      }
    }
  }

  return false;
}

int main()
{
  int n, count = 0;
  string new_board, old_board;

  cin >> n;
  cin >> new_board;

  for(int i = 0; i < n; i += 1){
    cin >> old_board;

    if(check(n, new_board, old_board)){
      ++count;
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 1212