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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

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

    vector<lint> f(n);
    vector<vector<lint>> p(n,vector<lint>(10));
    REP(i,n){
        REP(j,10){
            lint tmp;
            cin >> tmp;
            f[i] += tmp*pow(2, 9 - j);
        }
    }
    REP(i, n)
    {
        REP(j, 11)
        {
            cin >> p[i][j];
        }
    }
    lint INF = 1000000000;

    lint max_benefit = -INF;
    for (lint bit = 1; bit < (1 << 10); ++bit)
    {
        lint benefit = 0;
        REP(i,n){
            lint tmp=(bit &f[i]);
            lint c=0;
            IREP(j,10){
                c += tmp /(1<<j);
                tmp %= (1<< j);
            }
            benefit += p[i][c];
        }
        max_benefit = max(max_benefit, benefit);
    }
    /*
    REP(i,n){
       //cout << f[i] << "\n";
        std::stringstream ss;
        ss << std::bitset<10>(f[i]);
        std::string s = ss.str();
        //cout << s << "\n";
        //REP(j,11)cout << p[i][j]<<" ";
    }
    //lint ans;
    */

    cout << max_benefit <<"\n";

    return 0;
}

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

int main(){
    int N,K;
    cin >> N >> K;
    int p;
    vector<int> vec;
    int i;
    for(i=0; i<N; i++){
        cin >> p;
        vec.push_back(p);
    }
    sort(vec.begin(),vec.end());
    int sum=0;
    for(i=0; i<K; i++){
        sum+=vec[i];
    }
    cout << sum << endl;
    system("pause");
    return 0;
}

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e9
#define F first
#define S second


const int MAX = 402;

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;


int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> G(n,vector<int>(n,0));
    Rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a][b] = 1;
      	G[b][a] = 1;
    }
    vector<int> vec(n-1);
    Rep(i,n-1)vec[i] = i+1;
    int v = 0;
    int ans = 0;
    do{
      	v = 0;
        Rep(i,n-1){
            int next = vec[i];
            if(G[v][next] == 1){
                v = next;
            }else break;
            if(i == n-2)ans++;
        }
    }while(next_permutation(vec.begin(),vec.end()));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int S;
  scanf("%d", &S);
  int T=S/100;
  S%=100;
  int c=0,d=0;
  if(1<=T && T<=12) c=1;
  if(1<=S && S<=12) d=1;
  if(c*d==1) printf("AMBIGUOUS\n");
  else if(c==1) printf("MMYY\n");
  else if(d==1) printf("YYMM\n");
  else printf("NA\n");
  return 0;
}

Measured memory_bytes: 1624
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

vector<int> topolSort(vector< vector<int> > e) {
    vector<int> indeg(e.size()), ans;
    ans.reserve(e.size());
    queue<int> q;
    for (int i = 0; i < e.size(); ++i) for (int j = 0; j < e.at(i).size(); ++j) ++indeg.at(e.at(i).at(j));
    for (int i = 0; i < e.size(); ++i) if (indeg.at(i) == 0) q.push(i);
    while (!q.empty()) {
        ans.push_back(q.front());
        q.pop();
        for (int i : e.at(ans.back())) if (--indeg.at(i) == 0) q.push(i);
    }
    return ans;
}

int main() {
    int n, m, a, b;
    scanf("%d%d", &n, &m);
    vector< vector<int> > e(n + 1);
    for (int i = 1; i < n + m; ++i) {
        scanf("%d%d", &a, &b);
        e.at(a).push_back(b);
    }
    vector<int> t = topolSort(e), ans(n + 1);
    for (int i = 1; i <= n; ++i) for (int j : e.at(t.at(i))) ans.at(j) = t.at(i);
    for (int i = 1; i <= n; ++i) printf("%d\n", ans.at(i));
    return 0;
}


Measured memory_bytes: 12032
#include <iostream>
using namespace std;
int main()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a)
	{
		cout << k << endl;
	}
	else if (a < k && k <= a + b)
	{
		cout << a << endl;
	}
	else if (a + b < k && k <= +a + b + c)
	{
		cout << a - (k - a - b) << endl;
	}
	return 0;
}

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

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

    int count = 0;
    int min = INT_MAX;
    for (int i=0; i<N; i++) {
        int p;
        cin >> p;
        if (p < min) {
            count += 1;
            min = p;
        }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  ll n;
  cin >> n;
  for (ll h = 1; h <= 3500; h++)
  {
    for (ll i = 1; i <= 3500; i++)
    {
      if (4*h*i-n*h-n*i>0 && (n*h*i)%(4*h*i-n*h-n*i)==0) {
        ll j = (n*h*i)/(4*h*i-n*h-n*i);
        cout << h << " " << i << " " << j << endl;
        return 0;
      }
    }
    
  }
  
    return 0;
}

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

using namespace std;

int main(int argc, char *argv[])
{
    // input from txt （提出時にこの箇所は削除すること）
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
    
    
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    int a,b, c;
    cin >> a >> b >> c;
    if (a < b && b < c) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


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


int main() {
  long long N,n,M,m;
  long double s;
  cin>>N;
  vector<long double> a(N);
  vector<long long> b(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    b.at(i)=a.at(i);
  }
  sort(a.begin(),a.end());
  n=N/2;
  s=(a.at(n)+a.at(n-1))/2;
  M=a.at(n);
  m=a.at(n-1);
  //cout<<s;
  for(int i=0;i<N;i++){
    if(b.at(i)>=s){
      cout<<m<<endl;
    }
    else{
      cout<<M<<endl;
    }
  }
    return 0;
}


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

A.sort()
S = set(A)
M = max(A)

preA = 0
for i in A :
  if preA == i :
    S.discard(i)
  if i in S :
    num = i * 2
    while num <= M :
      S.discard(num)
      num += i    
  preA = i
  
print(len(S))

Measured memory_bytes: 32272
import scala.io.StdIn._
import scala.math._

object Main extends App with StdInHelper {
  val Array(x, y) = readInts

  if (x * 2 <= y && y <= x * 4 && y % 2 == 0) println("Yes")
  else println("No")
}

trait StdInHelper {
  def readStrings = readLine.split(" ")
  def readInts = readStrings.map(_.toInt)
  def readLongs = readStrings.map(_.toLong)
  def readDoubles = readStrings.map(_.toDouble)
  def readBigInts = readStrings.map(BigInt.apply(_))
  def readBigDecimals = readStrings.map(BigDecimal.apply(_))
}


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

void countup_island(int h, int w){
  int graph[51][51];
  rep(i,h)rep(j,w){
    cin >> graph[i][j];
    if(graph[i][j]) graph[i][j] = -1;
  }
  int cnt = 0;
  rep(i,h)rep(j,w){
    if(graph[i][j] == -1){
      cnt++;
      stack<pair<int,int>> stk;
      stk.emplace(make_pair(i,j));
      while(!stk.empty()){
        int now_h = stk.top().first;
        int now_w = stk.top().second;
        stk.pop();
        graph[i][j] = cnt;
        for(int k=-1;k<=1;k++){
          for(int l=-1;l<=1;l++){
            int next_h = now_h + k;
            int next_w = now_w + l;
            if(0<=next_h && next_h<h && 0<=next_w && next_w<w && graph[next_h][next_w]==-1){
              graph[next_h][next_w] = cnt;
              stk.emplace(make_pair(next_h,next_w));
            }
          }
        }
      }
    }
  }
  cout << cnt << endl;
}

int main(){
  while(true){
  int h,w;
  cin >> w >> h;
  if(h !=0 && w != 0) countup_island(h, w);
  else break;
  }
  return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }
 
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 
inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
 
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int N,A,B,C;
vi L;
int rec(int i, int a, int b, int c){
  if(i==N){
    if(!a||!b||!c) return INF;
    return abs(A-a)+abs(B-b)+abs(C-c);
  }
  int res=rec(i+1,a,b,c);
  
  chmin(res,rec(i+1,a+L[i],b,c)+(a?10:0));
  chmin(res,rec(i+1,a,b+L[i],c)+(b?10:0));
  chmin(res,rec(i+1,a,b,c+L[i])+(c?10:0));
  
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int a,b,c,d; cin>>a>>b>>c>>d;
  bool ok=false;
  if(abs(a-c)<=d) ok=true;
  if(abs(a-b)<=d&&abs(b-c)<=d) ok=true;
  if(ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))

while n > 1:
	list = []
	for i in range(n-1):
		for j in range(i+1, n):
			sum = (v[i] + v[j])/2
			for k in range(n):
				if k != i and k != j:
					sum += v[k]
			list.append([i, j, sum])
	list.sort(key=lambda x : x[2])
	list.reverse()
	v[list[0][0]] = (v[list[0][0]]+v[list[0][1]])/2
	v[list[0][1]] = v[n-1]
	n -= 1
print(v[0])


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  ll n, k; cin >> n >> k;
  vector<ll> x(n);
  rep(i, n) cin >> x[i];

  vector<ll> l, r;
  r.push_back(0);
  rep(i, n) {
    if (x[i] < 0) l.push_back(-x[i]);
    if (x[i] > 0) r.push_back(x[i]);
    if (x[i] == 0) k--;
  }
  l.push_back(0);
  reverse(ALL(l));

  ll ans = INFLL;
  for (int i = 0; i <= k; i++) {
    if (i >= r.size()) break;
    if (i == k) {
      chmin(ans, r[i]);
      break;
    }
    if (k-i >= l.size()) continue;
    chmin(ans, r[i] * 2 + l[k-i]);
  }

  for (int i = 0; i <= k; i++) {
    if (i >= l.size()) break;
    if (i == k) {
      chmin(ans, l[i]);
      break;
    }
    if (k-i >= r.size()) continue;
    chmin(ans, l[i] * 2 + r[k-i]);
  }

  cout << ans << endl;

  return 0;
}


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

struct data 
{
	int checked;
	int num;
};

int main(void)
{
	int happy_num=0;
	int N,x;
	struct data okasi[101];
	scanf("%d %d",&N,&x); //N:人数 x:お菓子の数
	for(int i=0;i<N;i++)
	{
		scanf("%d",&okasi[i].num);
		okasi[i].checked = 0;
	}
	while(true)
	{
		int min;
		int min_num;
		int fin=0;
		for(int i=0;i<N;i++)
		{
			if(okasi[i].checked == 0)
			{
				min = okasi[i].num;
				min_num = i;
				fin = 1;
				break;
			}

		}

		for(int i=min_num;i<N;i++)
		{
			if(okasi[i].checked == 0 && min > okasi[i].num)
			{
				min = okasi[i].num;
				min_num = i;
			}
		}
		okasi[min_num].checked = 1;

		//printf("%d %d\n",min,min_num);

		if(fin ==0 || x<min)
		{
			if(x != 0 && happy_num > 0 && fin == 0) happy_num -=1;
			printf("%d\n",happy_num);
			break;
		}else
		{
			x = x - min;
			happy_num++;
		}
	}
return 0;

}

Measured memory_bytes: 128
"""
# 標準入力取得
## 文字列
     = sys.stdin.readline().rstrip()
     = list(sys.stdin.readline().rstrip())

## 数値
     = int(sys.stdin.readline())
     = map(int, sys.stdin.readline().split())
     = list(map(int, sys.stdin.readline().split()))
     = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

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

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

import copy

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007
# sortedと比較
# 
if __name__ == "__main__":
     N = int(sys.stdin.readline())
     L = list(map(int, sys.stdin.readline().split()))

     cnt = 0
     
     for i, e in enumerate(L):
          if e != i + 1:
               cnt += 1

     if cnt == 0 or cnt == 2:
          print("YES")
     else:
          print("NO")

Measured memory_bytes: 5072
from numba import jit
N = int(input())

"""nを素因数分解"""
"""2以上の整数n => [(素因数, 指数), ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            arr.append((i, cnt))
    if temp != 1:
        arr.append((temp, 1))
    if arr == []:
        arr.append((n, 1))
    return arr

li = factorization(N)
ans = 0
for i in li:
    k = i[1]
    loop = 1
    while True:
        k -= loop
        if k>=0:
            ans += 1
        else:
            break
        loop += 1
if N==1:
    print(0)
else:
    print(ans)
        

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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> c(N,0);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    c[a]++;
    c[b]++;
  }
  for(int i=0;i<N;i++) cout<<c[i]<<endl;
}
    
  

Measured memory_bytes: 256
import math
while True:
    a, op, b = input().split()
    a, b = map(int, (a, b))
    if op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '*':
        print(a*b)
    elif op == '/':
        print(math.floor(a/b))
    elif op == '?':
        break



Measured memory_bytes: 5660
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int i,j,n,K;cin>>n>>K;
	vector<int>A(n);
	for(i=0;i<n;i++){
		cin>>A[i];
		if(i>=K){
			cout<<(A[i-K]<A[i]?"Yes":"No")<<endl;
		}
	}
	
	return 0;
}

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

int main(int argc, char const *argv[]) {
    /* code */
    string A,B,C;
    cin >> A >> B >> C;
    if(A.back()==B.front() && B.back()==C.front()) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
H = INT()
W = INT()

H2 = N - H + 1
W2 = N - W + 1
print(H2 * W2)


Measured memory_bytes: 5220
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807

int main(){
    iostream::sync_with_stdio(false);
    
    int H, W;
    cin >> H >> W;
    int height[1000][1000];
    pair<int, int> sorted[1000000];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> height[i][j];
            height[i][j]--;
            sorted[height[i][j]] = make_pair(i, j);
        }
    }

    int point[1000][1000] = {};//そこから流したときに溜まる箇所がいくつあるか
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if((i==0 || height[i-1][j] > height[i][j]) && (i==H-1 || height[i+1][j] > height[i][j])
            && (j==0 || height[i][j-1] > height[i][j]) && (j==W-1 || height[i][j+1] > height[i][j])){
                //ここはくぼみ
            }
            else continue;
            bool already[1000][1000] = {};//全部false
            queue<pair<int, int>> que;
            point[i][j] = 1;
            already[i][j] = true;
            que.push(make_pair(i, j));
            while(!que.empty()){
                int i = que.front().first;
                int j = que.front().second;
                if(i!=0 && already[i-1][j]== false && height[i-1][j] > height[i][j]){
                    point[i-1][j]++;
                    already[i-1][j] = true;
                    que.push(make_pair(i-1, j));
                }
                if(i!=H-1 && already[i+1][j]== false && height[i+1][j] > height[i][j]){
                    point[i+1][j]++;
                    already[i+1][j] = true;
                    que.push(make_pair(i+1, j));
                }
                if(j!=0 && already[i][j-1]== false && height[i][j-1] > height[i][j]){
                    point[i][j-1]++;
                    already[i][j-1] = true;
                    que.push(make_pair(i, j-1));
                }
                if(j!=W-1 && already[i][j+1]== false && height[i][j+1] > height[i][j]){
                    point[i][j+1]++;
                    already[i][j+1] = true;
                    que.push(make_pair(i, j+1));
                }
                que.pop();
            }
        }
    }

    int ans = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(point[i][j] > 1) ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 11956
#if !defined(ONLINE_JUDGE)
    #include "prettyprint.hpp" 
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 1729
    #define cer(x) 13
#endif
const bool testcase=0;
typedef long long int ll;
#define INF LONG_MAX
#define MINF LONG_MIN 
#define MAXR 111111
const ll mod1 = 1000000007;
const ll mod2 = 998244353;



//loop 
#define loop(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define loope(i,L,R) for (int i = L; i <= R; i++)
#define rloop(i,L,R) for (int i = L; i > R; i--)
#define rloope(i,L,R) for (int i = L; i >= R; i--)
#define nl cout<<'\n'



//misc
#define sz(x) ((int)((x).size()))
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL) 
#define checkbit(n,b) ( (n >> b) & 1)
#define test int _T_=1;if(testcase){cin>>_T_;}while(_T_--)



//vector
#define lastEle(vec) vec[vec.size()-1]
#define all(ve) ve.begin(),ve.end()
#define rall(x) x.rbegin(),x.rend()
#define fi first
#define se second



template<typename T>inline T mmod(T a,T b,T mod){return ((a%mod)*(b%mod))%mod;}
template<typename T>inline T smod(T a,T b,T mod){return ((a%mod)+(b%mod))%mod;}
template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}
template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a){in>>a.fi>>a.se;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a){for(auto &x : a)in>>x;return in;}

ll lcm(ll a,ll b){return (max(a,b)/__gcd(a,b))*min(a,b);} 

// MAIN
void solve();
int main(){
    std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
    start = std::chrono::high_resolution_clock::now();
    fast;
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
        // for debug in error.txt
        freopen("error.txt", "w", stderr);
    #endif
    test {
        solve();
    }
    end = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
    cerr << "\nElapsed Time: " << elapsed_time << "ms\n";
    return 0;
}


// SOLVE 

void solve() {
    ll n;
    cin >> n;
    std::vector<ll> v(n);    
    cin >> v;
    ll cnt = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            for(int k = j+1; k < n; k++) {
                int x = v[i] + v[j];
                int y = v[j] + v[k];
                int z = v[i] + v[k];
                d(i,j,k);
                if(x > v[k] && y > v[i] && z > v[j]  && (v[i]!=v[j]) && (v[j]!=v[k]) && (v[i]!=v[k])) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << '\n';
}



Measured memory_bytes: 3660
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		
		for(int i=1; i<=n; i++){
			int a = i;
			while(a % 10 != 3 && a >= 10){
				a /= 10;}
			if(i%3==0){
				System.out.print(" "+i);}
			else if(a % 10==3){
				System.out.print(" "+i);}}
		System.out.print("\n");
	}
}


Measured memory_bytes: 28564
// 2020-09-19 20:16:20
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
// using namespace atcoder;

// clang-format on
const int MX = 100010;
int in[MX], dp[MX];
vector<int> G[MX];
void dfs(int u, int p) {
  if (p == -1) {
    dp[u] = 0;
  } else {
    in[u]--;
    chmax(dp[u], dp[p] + 1);
  }
  if (in[u] == 0) {
    for (auto v : G[u]) dfs(v, u);
  }
}
void answer() {
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    in[b]++;
  }
  memset(dp, -1, sizeof dp);
  rep(i, n) if (in[i] == 0 && dp[i] == -1) dfs(i, -1);
  int ans = 0;
  rep(i, n) chmax(ans, dp[i]);
  cout << ans << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 12888
#include<stdio.h>
int isprime(int n){
        for(int i = 2; i * i <= n; i++){
                if(n % i == 0) return 0;
        }
        return 1;
}
int main(){
        int n, i;
        for(;;){
                scanf("%d", &n);
                if(n == 0) break;
                for(i = n - 2; i >= 2; i--){
                        if(isprime(i) == 1 && isprime(i + 2) == 1){
                                printf("%d %d\n", i, i + 2);
                                break;
                        }
                }
        }
        return 0;
}

Measured memory_bytes: 1752
class UnionFind:
    def __init__(self, N):
        self.root = [-1 for _ in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        while self.root[x] >= 0:
            x = self.root[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.root[x] = y
            self.size[y] += self.size[x]
        else:
            self.root[y] = x
            self.size[x] += self.size[y]

N, M = [int(_) for _ in input().split()]
uf = UnionFind(N)

for i in range(M):
    X, Y, Z = [int(_) for _ in input().split()]
    uf.union(X-1, Y-1)

ans = set()
for i in range(N):
    ans.add(uf.find(i))
print(len(ans))


Measured memory_bytes: 19132
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b,c;
  cin >> a >> b;
  c = a * b;
  
  if (c % 2 == 0) {
    cout << "Even";
  }
  
  else {
    cout << "Odd";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int 
#define endl '\n'
#define INF 1000000000
#define MOD 1000000007
#define MAX 100000000 
#define mp make_pair
#define pb push_back
using namespace std;
int parent[200001],s[200001],vis[200001];
void make_set(int v) {
    parent[v] = v;
    s[v]=1;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return find_set(parent[v]);
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (s[a] < s[b])
            swap(a, b);
        parent[b] = a;
        s[a] += s[b];
    }
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,u,v;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	make_set(i);
    }
    for(int i=1;i<=m;i++)
    {
    	cin>>u>>v;
    	union_sets(u,v);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
    	//cout<<size[i]<<" ";
    	u=find_set(i);
    	if(!vis[u])
    	{
    		ans=max(ans,s[u]);
    		vis[u]=1;
    	}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5840
s = gets.chomp.chars

ans = s.size - 1

("a".."z").each do |c|
  count = 0
  t = s.dup

  until t.uniq.size == 1
    (t.size - 1).times do |i|
      t[i] = [t[i], t[i + 1]].include?(c) ? c : t[i]
    end

    count += 1
    t.pop
  end

  ans = count if count <= ans
  break if ans == 0
end

puts ans


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

int main()
{
	while (true) {
		int a, b;
		string str;

		cin >> a >> str >> b;

		if (str == "?") {
			break;
		}

		if (str == "+") {
			cout << a + b << endl;
		}
		else if (str == "-") {
			cout << a - b << endl;
		}
		else if (str == "*") {
			cout << a*b << endl;
		}
		else {
			cout << a / b << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n];
    for(int i=0;i<n;i++)cin >> a[i] >> b[i] >> c[i];

    vector<vector<int> >dp(n,vector<int>(3));
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i=1;i<n;i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + c[i];
    }

    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}

Measured memory_bytes: 9852
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll res = 0;
	res += min(a, k);
	k -= res;
	a -= res;
	k -= b;
	k = max(0ll, k);
	cout << res - k << '\n';
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

ll gcd(ll a,ll b){
	if(a<b){
		swap(a,b);
	}

	while(ll r=(a%b)){
		a = b;
		b = r;
	}
	return b;
}

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

	int N=in(),X=in();
	vector<int> p(N);
	REP(i,N){
		int x=in();
		p[i] = abs(x-X);
	}
	ll gc = p[0];
	REP(i,N-1){
		gc = gcd(gc,p[i+1]);
	}

	cout << gc << endl;
	return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

vector<Vi> out, in;
Vi col;
ll cnt[3];
bool bad;
int edges;

void dfs(int i, int c) {
	if (col[i]) {
		if (col[i] != c+1) bad = 1;
		return;
	}
	col[i] = c+1;
	cnt[c]++;
	edges += sz(out[i]);
	each(e, out[i]) dfs(e, (c+1)%3);
	each(e, in[i]) dfs(e, (c+2)%3);
}

void run() {
	int n, m; cin >> n >> m;
	out.resize(n);
	in.resize(n);
	col.resize(n);

	rep(i, 0, m) {
		int a, b; cin >> a >> b;
		out[a-1].pb(b-1);
		in[b-1].pb(a-1);
	}

	ll ans = 0;

	rep(i, 0, n) if (!col[i]) {
		cnt[0] = cnt[1] = cnt[2] = 0;
		edges = 0;
		bad = 0;
		dfs(i, 0);

		if (bad) {
			ll k = cnt[0]+cnt[1]+cnt[2];
			ans += k*k;
		} else if (cnt[0] && cnt[1] && cnt[2]) {
			ans += cnt[0]*cnt[1] + cnt[1]*cnt[2] + cnt[0]*cnt[2];
		} else {
			ans += edges;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 16256
#include<iostream>
using namespace std;
 
int main(){
 
  string s;
 
  cin>>s;
 
  int f=0, cnt=0;
  for(int i=0;i<s.size();i++){
    if(f==0){
      if(s[i]=='A') f++;
    }
    if(f==1){
      if(s[i]=='Z'){
    cout<<"AZ";
    f--;
    cnt++;
      }
    }
  }
  if(cnt) cout<<endl;
 
  if(cnt==0) cout<<-1<<endl;
   
  return 0;
}

Measured memory_bytes: 3212
import java.util.*;

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

        String str = sc.nextLine();
        int n = Integer.parseInt(str);

        int h_point = 0,t_point = 0;

        for(int i = 0;i < n;i++){
            String taro = sc.next();
            String hanako = sc.next();
            if(taro.compareTo(hanako) > 0)  t_point += 3;
            else if(taro.compareTo(hanako) < 0) h_point += 3;
            else{
                t_point++;
                h_point++;
            }
        }
        System.out.println(t_point+" "+h_point);
    }
}


Measured memory_bytes: 29684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	String s=sc.next();
	char c[]=s.toCharArray();

	for(int i=0;i<=s.length()-1;i++){
		if(i%2==0){
			System.out.print(c[i]);
		}
	}
	System.out.println();

	}}

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

using namespace std;

int n, a[10], s;
int ret;

void rec(bool data[10], int cnt, int deep)
{
	if (deep == 10){
		if (cnt == n){
			int sum = 0;
			for (int i = 0; i < 10; i++){
				if (data[i]) {
					sum += a[i];
					// cout << a[i] << " " ;
				}
			}
			// cout << " -> " << sum << endl;
			if (sum == s) ret++;
		}
		return;
	}
	rec(data, cnt, deep + 1);
	data[deep] = true;
	rec(data, cnt + 1, deep + 1);
	data[deep] = false;
	return;
}

int main(void)
{
	for (int i = 0; i < 10; i++){
		a[i] = i;
	}
	while (cin >> n >> s, n || s) {
		ret = 0;
		
		bool data[10];
		fill(data, data + 10, false);
		rec(data, 0, 1);
		data[0] = true;
		rec(data, 1, 1);
		

		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
// https://atcoder.jp/contests/abc145/tasks/abc145_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    REP(i, n) { cin >> v[i].first >> v[i].second; }
    double sum = 0, cnt = 0;
    REP(i, n) {
        FOR(j, i + 1, n) {
            int t = (v[i].first - v[j].first) * (v[i].first - v[j].first) +
                    (v[i].second - v[j].second) * (v[i].second - v[j].second);
            sum += sqrt(t);
            cnt++;
        }
    }
    double ave = (double)(n - 1) * sum / cnt;
    printf("%.10f\n", ave);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

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

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int b[100];

bool a[100];
int d[100];

void update(){
	d[0] = 1;
	rep(i, N - 1){
		d[i + 1] = d[i] + a[i];
	}
}
void solve(){
	rep(i, N){
		if(i + 1 < b[i]){
			cout << -1 << endl;
			return;
		}
	}
	rep(i, N) d[i] = 1;
	int n = N;
	repr(i, N){
		if(!a[i] and d[i] == b[i]){
			cout << b[i] << endl;
			a[i] = true;
			update();
			n--;
			if(n == 0) break;
			i = N;
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) {
		cin >> b[i];
	}
		solve();
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
q = [list(map(int, input().split())) for i in range(m)]
p= list(map(int, input().split()))
ans = 0
 
for s in range(2**n): #スイッチのon/offの状態の総当たり（2**n通り）
    judge = True
    for i in range(m): #電球1つずつに対して
        cnt=0
        for j in range(1,len(q[i])): #sの総当たりでqに当てはまるものを探す。kはforを1からにすれば無視できる。
            w=q[i][j]
            if s >> (w-1) &1 ==1: #sをw-1回シフトさせて(w-1)個目のスイッチがonか判定
                cnt+=1 #onになっているスイッチの個数をカウント
        if cnt % 2 != p[i]: #スイッチの個数を2で割った余りがpiに等しいか判定
            judge = False
    if judge:
        ans += 1
 
print(ans)

Measured memory_bytes: 9040
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr ll mod = 1e9+7;
constexpr ll md = mod;
constexpr ll inf = 1e15;
int main(){
    int n;
    cin>>n;
    vector<int> l(n+1),r(n+1);
    vector<int> v(n);
    for(auto &a : v) cin>>a;
    for(int i=0;i<n;++i){
        l[i+1] = __gcd(l[i],v[i]);
    }
    for(int i=n-1;i>=0;--i){
        r[i] = __gcd(r[i+1],v[i]);
    }
    ll ma = 0;
    for(int i=0;i<n;++i){
        ma = max(ma,1LL*__gcd(l[i],r[i+1]));
    }
    cout << ma << endl;
    return 0;
}



Measured memory_bytes: 1536
#include<stdio.h>
void insertSort (int[],int );
int main(){
  int i,N=0,v,l;
  int A[100];
  scanf("%d",&N);
  if(N<1 || N>100) return 0;
  for(i=0;i<N;i++){
    scanf(" %d",&A[i]);
  }
  insertSort (A,N);
  return 0;
}

void insertSort(int A[],int N){
 int i,j,v,l;
 
    for(j=1;j<N;j++){
      v=A[j];
      i=j-1;
             printf("%d",A[0]);
       for(l=1;l<N;l++){
	printf(" %d",A[l]);
       }
      printf("\n");
       
      while(i>=0 && A[i]>v){
	A[i+1]=A[i];
	i--;
	A[i+1]=v;
	
      }

 

    }
    printf("%d",A[0]);
       for(l=1;l<N;l++){
	printf(" %d",A[l]);
       }
       printf("\n");
   
}
  




Measured memory_bytes: 2072
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int qq;
  cin >> qq;
  priority_queue<int> lo;
  priority_queue<int, vector<int>, greater<int>> hi;
  long long sum = 0, sum_lo = 0, sum_hi = 0;
  while (qq--) {
    int x;
    cin >> x;
    if (x == 2) {
      long long t = lo.top();
      cout << lo.top() << " " << sum + t * (int) lo.size() - sum_lo + sum_hi - t * (int) hi.size() << '\n';
    } else {
      int a, b;
      cin >> a >> b;
      sum += b;
      if (lo.empty() || a <= lo.top()) {
        lo.push(a);
        sum_lo += a;
        if ((int) lo.size() > (int) hi.size() + 1) {
          int t = lo.top();
          lo.pop();
          sum_lo -= t;
          sum_hi += t;
          hi.push(t);
        }
      } else {
        sum_hi += a;
        hi.push(a);
        if ((int) hi.size() > (int) lo.size()) {
          int t = hi.top();
          hi.pop();
          sum_lo += t;
          sum_hi -= t;
          lo.push(t);
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
long long MOD=1000000007;
int main(){
  int N,M;
  cin>>N>>M;
  vector<bool> unsafe(N+1,true);
  for(int i=0;i<M;i++){
    int a;
    cin>>a;
    unsafe[a]=false;
  }
  vector<long long int>DP(N+1,0);
  DP[0]=1;
  if(unsafe[1])DP[1]=1;
  for(int i=2;i<=N;i++){
    if(unsafe[i-1])DP[i]+=DP[i-1];
    if(unsafe[i-2])DP[i]+=DP[i-2];
    DP[i]%=MOD;
  }
  cout<<DP[N]<<endl;
}

Measured memory_bytes: 1024
using System;

namespace ABC046
{
    class B
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);

            double res = K * Math.Pow(K - 1, N - 1);
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13140
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 2000010
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-9
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, m, cnt, k, ans;
const ll mod = 1e9 + 7;
ll a[SIZE];
ll pre[SIZE];
ll qpow(ll a, ll b, ll mod) { //快速幂 a ^ b % mod
	ll ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ans;
}

void init(int n) { // 预处理阶乘
	pre[0] = pre[1] = 1;
	rep(i, 2, n) pre[i] = 1ll * i * pre[i - 1] % mod;
}
ll sol(ll n, ll m) {
	ll ans = 1;
	rep(i, (n - m + 1ll), n) {
		ans = (ans * 1ll * i) % mod;
	}
	return ans;
}
ll C(ll n, ll m) { // 求组合数 nCm
	return sol(n, m) *qpow(pre[m], mod - 2ll, mod) % mod;
}
void debug() {
	ll tp = 1;
	for (ll i = 0; i < m; i++)tp = 1ll * tp * (n - i) % mod * qpow(i + 1ll, mod - 2ll, mod) % mod;
	ans -= tp; tp = 1;
	for (ll i = 0; i < k; i++)tp = 1ll * tp * (n - i) % mod * qpow(i + 1ll, mod - 2ll, mod) % mod;
	ans -= tp;
}
int main() {
	init(200000);
	io(); cin >> n >> m >> k;
	ans = qpow(2ll, n, mod) - 1ll;
	debug();
	cout << (ans % mod + mod) % mod;
}

Measured memory_bytes: 1792
//#include<bits/stdc++.h> using namespace std;
#include<iostream>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue> //priority_queue inside queue
#include<deque>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl '\n'
typedef long long ll;
typedef unsigned long long ull;
#define f(i,start,end) for(i=start;i<=end;i++)
#define min_heap priority_queue<int, vector<int>, greater<int> >
#define max_heap priority_queue<int>
#define eb emplace_back

struct Point
{
    ll x, y;
};
/// compare function for sorting the points
bool cmp(Point p1, Point p2)
{
    if(p1.x!=p2.x) return p1.x<p2.x;
    return p1.y<p2.y; //p1.x==p2.x
}

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

ll sum(ll x)
{
    ll res = 0;
    if(x%2==0){
        res = x/2;
        res *= (x+1);
    }
    else{
        res = (x+1)/2;
        res *= x;
    }
    return res;
}

int binary_search(int a[], int n, int x)
{
    int l = 0, r = n-1, m = 0;
    while(l<=r)
    {
        m = l + (r-l)/2;
        if(a[m]==x) return m;
        if(a[m]>x){ r = m-1; }
        else if(a[m]<x){ l = m+1; }
    }
    return -1;
}
/*
/// Quick Sort ///
int swap(int *a, int *b)
{
    int t = *a;
    *a = *b;
    *b = t;
}
int partition(int arr[], int low, int high)
{
    int pivot = arr[high]; // pivot
    int i = low - 1; // index fixed at -1 for low=0
    
    for(int j=low; j<=high-1; j++)
    {
        if(arr[j]<pivot)
        {
            i++;
            swap(&arr[i], &arr[j]);
        }
    }
    swap(&arr[i+1], &arr[high]);
    return (i+1);
}
int quickSort(int arr[], int low, int high)
{
    if(low<high)
    {
        int pi = partition(arr, low, high);
        
        quickSort(arr, low, pi-1);
        quickSort(arr, pi+1, high);
    }
}
/// Quick Sort ///
*/


int main()
{
    fast;
    //int t=0,tc=0; cin >> tc; f(t,1,tc) //testcases
    {
        int i,j;
        int n; cin >> n;
        int ans = 0;
        ans += (n/500)*1000;
        n%=500;
        ans += (n/5)*5;
        cout << ans << nl;
    }
    return 0;
}

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

int main()
{
  string str[100];
  int n;
  int l;

  cin >> n >> l;

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

  sort(str, str + n);

  for (int i = 0; i < n; i++){
    cout << str[i];
  }
  cout << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long const MAX=1e5+2;
long long dp[MAX]={0};
int main()
{long long i,j,x,n,r,k,p,t,w,y;
cin>>n>>w;
for(i=0;i<n;i++)
{cin>>x>>y;
for(j=w;j>0;j--)
{if(j-x<0)
break;
else 
dp[j]=max(dp[j-x]+y,dp[j]);}
}
cout<<dp[w]<<"\n";
return 0;}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  
  int count = 0;
  rep(i,N) {
    if (i == 0) count++;
    else {
      if (S[i] != S[i-1]) {
        count++;
      }
    }
  }

  cout << count << endl;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < 1000; i++) {
    S = S.at(S.size() - 1) + S;
    S.pop_back();
    if (S == T) return cout << "Yes" << "\n", 0;
  }
  cout << "No" << "\n";
}

Measured memory_bytes: 3628
from math import ceil
def resolve():
    def chick(k):
        cnt = 0
        for i in range(N):
            h = ceil((H[i] - B * k) / (A - B))
            cnt += max(0, h)
        return cnt <= k

    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]

    # 最小の攻撃回数を求める
    # 魔法攻撃の回数をkとした時、すべての魔物は少なくともkBの体力が削られている
    # H[i] - kB > 0 であるような各iについて、その敵に対してA-Bの攻撃を何回当てれば体力が0になるかが算出される。
    # 上記の計算：(H[i] - kB) / (A-B) (ただし切り上げ)を計算して和を取る
    ok = 10 ** 10
    ng = 0
    while ok - ng > 1:
        k = (ok + ng) // 2
        if chick(k):
            ok = k
        else:
            ng = k

    print(ok)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 12968