akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc142/tasks/abc142_e
# このナップサックdpは面白い！
# 配るdpをイメージするとわかりやすい
# dp[i][bit] ... [0,i)の鍵を考慮したときに状態bitであるための最小の費用
# bitは開けられる宝箱を2進数で示している。5(101)だったら、0,2の宝箱が開けられる。
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def as_bit(ls):
    # 開けられる宝箱をbitで示す
    ret = 0
    for l in ls:
        ret ^= 1 << (l - 1)
    return ret


from itertools import product
INF = 10**9
N, M = read_ints()
C = []
A = []
for _ in range(M):
    a, b = read_ints()
    A.append(a)
    c = read_ints()
    C.append(as_bit(c))

'''
dp[i][bit] ... [0,i)の鍵を考慮したときに状態bitであるための最小の費用
bitは開けられる宝箱を2進数で示している。5(101)だったら、0,2の宝箱が開けられる。

更新則
dp[i+1][bit|C[i]] = min(dp[i+1][bit|C[i]], dp[i][bit] + A[i]) # i番目を取る
dp[i+1][bit] = min(dp[i+1][bit], dp[i][bit]) #i番目を取らない
∵配るDP。ナンプサックDPの重さの更新がbit演算に置き換わっただけ

初期条件&境界条件
dp[i][bit]=INF
dp[i][0]=0
'''

dp = [[INF] * (2 ** N) for _ in range(M + 1)]

for i in range(M + 1):
    dp[i][0] = 0

for i, bit in product(range(M), range(2 ** N)):
    dp[i + 1][bit | C[i]] = min(dp[i + 1][bit | C[i]], dp[i][bit] + A[i])
    dp[i + 1][bit] = min(dp[i + 1][bit], dp[i][bit])

ans = dp[-1][-1]
print(ans if ans != INF else -1)


Measured memory_bytes: 75500
#include <string.h>
#include <stdio.h>

int main()
{   char s[201];
    scanf("%s",s);
    int l=strlen(s);
    for(int i=l/2-2;i>0;i--){
        int cnt=0;
        for(int j=0;j<i;j++){
            if(s[j]==s[i+j]){
                cnt++;
            }else{
                break;
            }
            if(cnt==i){
            printf("%d",i*2);
            return 0;
            }
        }
    }
    printf("2");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>//bit DP
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
priority_queue<long>p;
int main()
{
  long long n;
  cin>>n;
  long long ans=0;
  for(int i=1;i<n;i++){
    ans+=(n-1)/i;
  }
  cout<<ans<<endl;
}


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

using namespace std;

int main(void){
    
    vector<int> x, y;
    
    int count = 0;
    while(1){
        int a, b;
        cin >> a >> b;
        if(a == 0 && b == 0) break;
        count++;
        if(a < b){
            x.push_back(a);
            y.push_back(b);
        }else{
            x.push_back(b);
            y.push_back(a);
            
        }
    }

    
    for(int i = 0;i < count;i++){
        cout << x[i] << " " << y[i] << endl;
    }
    
    return 0;
}


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

int stateA,stateB;
int anum;

void inA(char arg){
	//cout << stateA << endl;
	if(stateA == 0){
		if(arg == '>'){
			stateA = 1;
		}
	}else if(stateA == 1){
		if(arg == '\''){
			stateA = 2;
		}else{
			stateA = -1;
		}
	}else if(stateA == 2){
		if(arg == '='){
			stateA = 3;
			anum++;
		}else{
			stateA = -1;
		}
	}else if(stateA == 3){
		if(arg == '='){
			anum++;
		}else if(arg == '#'){
			stateA = 4;
		}else{
			stateA = -1;
		}
	}else if(stateA == 4){
		if(arg == '='){
			anum--;
		}else{
			stateA = -1;
		}
		if(anum==0){
			stateA = 5;
		}
	}else if(stateA == 5){
		if(arg == '~'){
			stateA = 6;
		}else{
			stateA = -1;
		}
	}else if(stateA == 6){
		stateA = -1;
	}
}

void inB(char arg){
	if(stateB == 0){
		if(arg == '>'){
			stateB = 1;
		}else{
			stateB = -1;
		}
	}else if(stateB == 1){
		if(arg == '^'){
			stateB = 2;
		}else{
			stateB = -1;
		}
	}else if(stateB == 2){
		if(arg == 'Q'){
			stateB = 3;
		}else{
			stateB = -1;
		}
	}else if(stateB == 3){
		if(arg == '='){
			stateB = 4;
		}else{
			stateB = -1;
		}
	}else if(stateB == 4){
		if(arg == 'Q'){
			stateB = 5;
		}else if(arg == '~'){
			stateB = 6;
		}else{
			stateB = -1;
		}
	}else if(stateB == 5){
		if(arg == '='){
			stateB = 4;
		}else{
			stateB = -1;
		}
	}else if(stateB == 6){
		if(arg == '~'){
			stateB = 7;
		}else{
			stateB = -1;
		}
	}else if(stateB == 7){
		stateB = -1;
	}
}

main(){
	int n;
	string str;
	
	cin >> n;
	cin.ignore();
	while(n && getline(cin,str)){
		stateA=0;
		stateB=0;
		anum=0;
		bool A=false, B=false;
		
		int l = str.size();
		for(int i=0;i<l;i++){
			inA(str[i]);
			inB(str[i]);
		}
		if(stateA == 6){
			cout << "A" << endl;
		}else if(stateB == 7){
			cout << "B" << endl;
		}else{
			cout << "NA" << endl;
		}
		
		n--;
	}
}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef tuple<ll,ll,ll> ti;
typedef vector<ti> vti;
typedef vector<ii> vii;
const ll INF = 1e14;
const double PI = acos(-1.0);
const int T = 1e3 + 2;
vti v;

int main() {
    ios_base::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;

    for(int i = 0; i < n; i++) {
        ll x,y,z; cin >> x >> y >> z;
        v.eb(x,y,z);
    }

    ll ans = 0;

    for(int i = 0; i < 8; i++) {
        sort(v.begin(), v.end(), [&] (const ti &a, const ti &b) {
                ll ax,ay,az;
                ll bx,by,bz;
                tie(ax,ay,az) = a;
                tie(bx,by,bz) = b;
                if(i&1) ax = -ax, bx = -bx;
                if(i&2) ay = -ay, by = -by;
                if(i&4) az = -az, bz = -bz;
                return (ax+ay+az > bx+by+bz);

        });
        ll x = 0, y = 0, z = 0;
        for(int j = 0; j < m; j++) {
            x += get<0>(v[j]);
            y += get<1>(v[j]);
            z += get<2>(v[j]);
        }
        ans = max(ans, abs(x) + abs(y) + abs(z));
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t  i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

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

  ll n;
  std::cin>>n;

  std::cout<<(n+1)/2<<"\n";

  return 0;
}



Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0

for i in range(a+1):
    fhy = i * 500
    for j in range(b+1):
        ohy = j * 100
        for k in range(c+1):
            fty = k * 50
            if fhy + ohy + fty == x:
                ans += 1

print(ans)

Measured memory_bytes: 3064
/*
[dp] H - Grid 1
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_H = 1000;
const int MAX_W = 1000;
const ll MOD = 1e9 + 7;

int H, W;
char a[MAX_H + 1][MAX_W + 1];
int dp[MAX_H + 1][MAX_W + 1];

ll solve() {
    dp[0][1] = 1;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            dp[i][j] =
                (a[i][j] == '#') ? 0 : (dp[i - 1][j] + dp[i][j - 1]) % MOD;
        }
    }

    return dp[H][W];
}

int main() {
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> a[i][j];
        }
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 5120
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=105;
int cnt[N],flag1,flag2,flag3,m,n;
char ch[N][N];
void check()
{
	if(n&1)	flag1=m>>1;
	if(m&1)	flag2=n>>1;
	if((n&1)&&(m&1))	flag3=1;
	for(int i=1;i<=26;++i)
	{
		if(cnt[i]&1)
		{
			if(!flag3)
			{
				puts("No");
				return ;
			}
			else	flag3=0;
		}
		else
		if(cnt[i]%4!=0)
		{
			if(flag1)	flag1--;
			else	
				if(flag2)	flag2--;
				else	
				{
					puts("No");
					return ;
				}
		}
	}
	puts("Yes");
}
int main()
{
//	freopen("1.txt","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)	
	{
		scanf("%s",ch[i]+1);
		for(int j=1;j<=m;++j)
		{
			int k=ch[i][j]-'a'+1;
			cnt[k]++;
		}
	}
	check();
	return 0;
}

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

#define endl '\n'
#define int long long

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

	int a, b, c, d; cin >> a >> b >> c >> d;
	vector<int> ans;
	ans.push_back(a*d);
	ans.push_back(a*c);
	ans.push_back(b*c);
	ans.push_back(b*d);
	if((a <= 0 and b >= 0) or (c <= 0 and d >= 0))
	ans.push_back(0);
	cout << *max_element(ans.begin(), ans.end()) << endl;

	return 0;
}

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

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

  ll N; cin >> N;
  string X; cin >> X;
  vector<ll> R(N + 1, 0);
  R[0] = 0;
  for (ll i = 0; i < N; i++) {
    R[i + 1] = R[i];
    if(X[i] == 'R') R[i + 1]++;
  }
  ll total_R = R[N], toral_W = N - total_R;
  ll ans = N;
  for (ll i = 0; i < N + 1; i++) {
    ll w = i - R[i];
    ll r = total_R - R[i];
    ans = min(ans, (max(w, r)));
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 5192
#include <stdio.h>
#define MAX 500001


int A[MAX];
int heap_size;


void maxheapify(int heap[],int j){
  int largest,leftH,rightH;
    int tmp;
 

    leftH = Left(j);


    rightH = Right(j);

  if(leftH <= heap_size && heap[leftH] >heap[j]){
    largest=leftH;
  }

  else {
    largest=j;
  }

  if(rightH <= heap_size && heap[rightH] > heap[largest]){
   
 largest=rightH;

  }
  if(largest != j){

    tmp=heap[largest];

    heap[largest]=heap[j];


    heap[j]=tmp;
    maxheapify(heap,largest);
  }
}
 




void Buildmaxheap(int heap[]){

  int j,i;

  i=heap_size/2;
  for(j=i;j >= 1;j--){
    maxheapify(heap,j);
  }


}




int Left(int i){

  return 2*i;
}

int Right(int i){

  return 2*i+1;
}

int main(){

  int i;


  scanf("%d",&heap_size);

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

    scanf("%d",&A[i]);

  }

  Buildmaxheap(A);

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

    
    printf(" %d",A[i]);

  }  
      printf("\n");
  
  return 0;
}

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

int main() {
    int N, s, cnt = 0; cin >> N;
    vector<int> l;
    for (int i = 0; i < N; i++) {
        cin >> s;
        cnt += s;
        if (s % 10 != 0){
            l.push_back(s);
        }
    }

    if (cnt % 10 != 0) { 
        cout << cnt << endl;
    }
    else if (l.size() <= 0){
        cout << 0 << endl;
    }
    else {
        sort(l.begin(), l.end());
        cout << cnt - l[0] << endl;
    }
}


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

string str;
int idx;
int bitpat;


int formula(){
	char c;
	int a,b;
	c = str[idx++];
	if(c >= 'a' && c <= 'k') return (bitpat>>(c-'a'))&1;
	else if(c == 'T') return true;
	else if(c == 'F') return false;
	else if(c == '-') return !formula();

	else if(c == '('){
		a = formula();
		c = str[idx++];
		if(c == '*') b = a & formula();
		else if(c == '+') b = a | formula();
		else if(c == '-'){ idx++; b = !a | formula();}
		idx++;
		return b;
	}
}

bool eq(){
	int left,right;
	left = formula();
	idx++;
	right = formula();
	return left == right;
}

int main(void){

	while(cin >> str, str != "#"){
		for(bitpat = 0; bitpat < (1<<11); bitpat++){
			idx = 0;
			if(!eq()) break;
		}
		if(bitpat == (1<<11)) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	
	}
	return 0;
}

Measured memory_bytes: 928
//ALDS1_14_A
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

int main(){
	string T, P;

	cin>>T;
	cin>>P;
	
	if(T.length() >= P.length())
		for(int i=0;i<=T.length()-P.length();i++)
			if(T.substr(i, P.length()) == P)
				printf("%d\n", i);

	return 0;
}

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

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

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

int main(){
    ll k;
    cin >> k;
    ll ans = 0;
    rep(a, 1, k+1){
        rep(b, 1, k+1){
            rep(c, 1, k+1){
                ll g = gcd(a, b);
                ans += gcd(g, c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

vi zyoutai(int bit,int n){
    vi S;
    rep(i,n){
        if(bit & (1 << i)){
            S.pb(1);
        }
        else{S.pb(0);}
    }
    return S;
}

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

	string s;
	cin >> s;
	int n = s.size();
	vector<queue<int>> que(n);
	vi flg(n-1);
	ll sum = 0;

    for(int bit = 0;bit < (1<<n-1);++bit){
        flg = zyoutai(bit,n-1);
		int tmp = 0;
		que[0].push(s[0]-'0'); 
		rep1(i,n){
			tmp += flg[i-1];
			que[tmp].push(s[i]-'0');
		}
		rep(i,n){
			ll atai = 0;

			while(!que[i].empty()){
				atai *= 10;
				int m = que[i].front(); que[i].pop();
				atai += m;
				
			}
			sum += atai;
		}

    }
	cout << sum << endl;    

    return 0;
}


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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
//const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    vector<ll> places(n);
    rep(i, n) cin >> places[i];
    sort(places.begin(), places.end());
    ll ans = LONG_LONG_MAX;
    for (ll p = places.front(); p <= places.back(); p++) {

        ll now = 0;

        for (ll x : places) {
            ll d = abs(p - x);
            now += d * d;
        }

        cmin(ans, now);
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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; }



int main(){ 
    int n; cin >> n;
    vector<int> P(n); rep(i, n) cin >> P[i];

    int res = 0;
    if(P[0] == 1) {swap(P[0], P[1]); res++;}
    for(int i=1; i<n; i++){
        if(P[i] == i+1){
            if(i != n-1 && P[i+1] == i+2){
                swap(P[i], P[i+1]);
            }
            else swap(P[i], P[i-1]);
            res++;
        }
    }
    cout << res << ln;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
 
int main(){
 
	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
 
	long long H,W,M,cmaxR{0},cmaxC{0},cr{0}, cc{0},pr;
	cin>>H>>W>>M;
	vector<pair<long long int, long long int>> targets;
	vector<long long> rows(H+1,0), columns(W+1,0);
	while(M--){
		long long int x,y;
		cin>>x>>y;
		cmaxR=max(cmaxR,++rows[x]);
		cmaxC=max(cmaxC,++columns[y]);
		targets.push_back({x,y});
	}
	for(auto i:rows){
		if(i==cmaxR){
			++cr;
		}
	}
	for(auto i:columns){
		if(i==cmaxC){
			++cc;
		}
	}
	pr=cr*cc;
	for(auto &i:targets){
		if(rows[i.first]==cmaxR&&columns[i.second]==cmaxC){
			--pr;
		}
	}
	if(pr){
		cout<<cmaxR+cmaxC<<endl;
	}
	else{
		cout<<cmaxR+cmaxC-1<<endl;
	}
}

Measured memory_bytes: 16288
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    double a,b;
    cin >> a >> b;
    if (a == b)cout << "EQUAL" << endl;
    else if(a>b)cout << "GREATER" << endl;
    else cout << "LESS" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl;
#define STOP assert(false);
#else
#define dump(x) ;
#define LINE 	;
#define dumpV(v);
#define STOP 	;
#endif

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


vector<string> split(const string& s, char c = ' ') {
	vector<string> ret;
	stringstream ss(s);
	string t;
	while(getline(ss, t, c)) ret.push_back(t);
	return ret;
}

typedef string::const_iterator State;
const int BITS = 11;
bool minus(bool a) {return (!a);}
bool plus_(bool a, bool b) {return (a|b);}
bool muit(bool a, bool b) {return a&b;}
bool incl(bool a, bool b) {return plus_(!a, b);}

bool atom(State&, int);
bool term(State&, int);
bool formula(State&, int);

bool atom(State& now, int mask) {
	if(*now == 'T') {
		now++;
		return true;
 	}
 	if(*now == 'F') {
 		now++;
 		return false;
 	}
 	assert(*now >= 'a' && *now <= ('a'+BITS));
 	int k = *now - 'a';
 	now++;
 	return mask & (1 << k);
}
bool term(State& now, int mask) {
	bool ret = formula(now, mask);
	if(*now == '*') {
		now++;
		return muit(ret, formula(now, mask));
	}
	if(*now == '+') {
		now++;
		return plus_(ret, formula(now, mask));
	}
	if(*now == '/') {
		now++;
		return incl(ret, formula(now, mask));
	}
	assert(false);
}
bool formula(State& now, int mask) {
	if((*now >= 'a' && *now <= ('a'+BITS)) || *now == 'T' || *now == 'F') {
		return atom(now, mask);
	}
	if(*now == '-') {
		now++;
		return !formula(now, mask);
	}
	if(*now == '(') {
		now++;
		bool tmp = term(now, mask);
		now++;
		return tmp;
	}
	dump(*now);
	assert(false);
}

int main(){
	string s;
	while(cin >> s) {
		if(s == "#") break;
		auto _v = split(s, '=');
		vector<string> v(2);
		rep(i, 2) {
			rep(j, _v[i].size()) {
				if(j+1 < _v[i].size() && _v[i][j] == '-') {
					j++;
					if(_v[i][j] == '>') v[i] += '/';
					else if(_v[i][j] == '-');
					else j--, v[i]+='-';
				}
				else v[i] += _v[i][j];
			}
		}
		// dump(v[0]);
		// dump(v[1]);
		bool ans = true;
		rep(mask, 1<<BITS) {
			State it0 = v[0].begin();
			State it1 = v[1].begin();
			if(formula(it0, mask) ^ formula(it1, mask)) ans = false;
		}
		cout << (ans ? "YES" : "NO") << endl;
		
	}
	return 0;
}

Measured memory_bytes: 3216
#include <iostream>
#include<stdio.h>

using namespace std;

int main(void) {

	int k, s, z, count = 0;

	cin >> k >> s ;
	
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			z = s - x - y;	
			if (z >= 0 && x + y + z == s && z <= k) {
				count++;
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define all(x) x.begin() , x.end()
ll modular_exp(ll a , ll n)
{
	if (a == 1) return a;
	ll res = 1;
	while (n > 0)
	{
		if (n & 1) res = (res * a) % mod;
		a = (a * a) % mod;
		n >>= 1;
	}
	return res % mod;
}

void solve()
{
	ll n, k; cin >> n >> k;
	vector<ll>dp( k + 1 , 0); //it contains the count of elements
	for (ll i = 1; i <= k; ++i)
	{
		dp[i] = modular_exp( k / i , n);
	}
	for (ll i = k; i >= 1; --i)
	{
		for (ll j = (2 * i) ; j <= k ; j += i)
		{
			dp[i] -= dp[j];
		}
	}
	ll ans = 0;
	for (ll i = 1; i <= k; ++i) ans = (ans + (i * dp[i]) % mod) % mod;
	cout << ans;
}
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll t = 1; //cin >> t;
	while (t--)
		solve();
	return 0;
}



Measured memory_bytes: 3980
#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (llong (Itr) = a; (Itr) < b; (Itr) += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)

#include <iostream>
#include <vector>
using namespace std;
using llong = long long;

llong n;
vector<llong> a;

int main() {
    cin >> n;
    a.resize(n);
    for (auto &vs:a) cin >> vs;

    a.push_back(0);
    for (int i = a.size() - 1; i > 0; i--) {
        a[i - 1] += a[i];
    }

    llong mod = (llong)1e9 + 7;
    llong ans = 0;
    for (int i = 0; i < n; i++) {
        llong s = (a[i + 1] - a[n]) % mod;
        llong v = a[i] - a[i + 1];
        ans += v * s % mod;
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
};


Measured memory_bytes: 6332
#include <stdio.h>

int main(){

 int W, H, x, y, r;
 scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
 if( 0+r<=x && x<=W-r && 0+r<=y && y<=H-r ){
 printf("Yes\n");
 } else {
 printf("No\n");
 }
 

 
  
  
  return 0;
}




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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF =1000000000000000;

ll n,ans=0;
void nya(ll x,ll a,ll b,ll c){
  if(x<=n){
    if(a&&b&&c)ans++;
    nya(x*10+3,1,b,c);
    nya(x*10+5,a,1,c);
    nya(x*10+7,a,b,1);
  }
}
int main(){
  cin >> n;
  nya(0,0,0,0);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define SZ(x) ((int)(x).size())
using namespace std;
typedef pair<int,int> PII;
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FOR(i,a,b) for (int i = a; i <= b; ++i)
#define M 1000000007
#define MM 998244353
#define SZ(a) int((a).size())
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define mod 1000000007
//a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod){ int c = a + b; if(c >= p) c -= p; return c; }
inline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c; }
inline int mul(int a, int b, int p = mod){ return (a * 1ll * b) % p; }
 
using ll = long long;
using VI = vector<int>;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
using VLL = vector<ll>;
using ld = long double;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
const int MX = 2e5+10;
const int MX2 = 1e6+5;

ll INF= 4 * (ll)1e18;
int mx = 2 * (ll)1e9 + 10;

int cnt[MX];
int main(int argc, const char * argv[]) {

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0); // insert code here...
    int A,B,C;
    cin >>A >> B >> C;
    cnt[A]++;
    cnt[B]++;
    cnt[C]++;
    if (cnt[5] == 2 && cnt[7] == 1) {
        cout <<"YES"<<endl;
    }
    else {
        cout << "NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

int main() {
    ll n;
    ll a[21], b[21], c[21];
    cin>>n;
    REP(i, 0, n){
        cin>>a[i];
        a[i]--;
    }
    REP(i, 0, n) cin>>b[i];
    REP(i, 0, n-1) cin>>c[i];

    ll sum=b[a[0]];
    REP(i, 1, n){
        sum+=b[a[i]];
        if(a[i]-1 == a[i-1]){
            sum+=c[a[i-1]];
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out=new PrintWriter(System.out);
static int ans=0;

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line);
int[] a=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) a[i]=Integer.parseInt(st.nextToken());
BubbleSort(a);
getValue(a);
out.println(ans);
out.flush();
}
}

private static void swap(int[] a,int s,int t){
int tmp=a[s]; a[s]=a[t]; a[t]=tmp; ans++;
}

private static void BubbleSort(int[] a){
for(int i=0;i<a.length-1;i++){
for(int j=a.length-1;j>i;j--){
if(a[j]<a[j-1]) swap(a,j,j-1);
}
}
}

private static void getValue(int[] a){
for(int i=0;i<a.length-1;i++) out.print(a[i]+" ");
out.println(a[a.length-1]);
}
}

Measured memory_bytes: 17056
H = int(input())
#a,b = map(int,input().split())
#L = list(map(int,input().split()))
cnt = 0
cnt1 =0
num = 1
while H>1:
    H = H//2
    cnt =cnt+1
    cnt1 +=num
    num =2**(cnt)
print(cnt1 +num)

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

#define F first
#define S second
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

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


Measured memory_bytes: 3632
from collections import Counter, defaultdict
h, w, n = map(int, input().split())
ab = [[int(i)-1 for i in input().split()] for j in range(n)]

d = defaultdict(int)

for i in range(n):
    for j in range(3):
        for k in range(3):
            if ab[i][0] - j >= 0 and ab[i][1] - k >= 0 and ab[i][0] - j < (h - 2) and ab[i][1] - k < (w - 2):
                d[(ab[i][0]-j, ab[i][1]-k)] += 1

print((h-2)*(w-2)-len(d))

c = Counter(d.values())
for i in range(1, 10):
    print(c[i] if i in c else 0)

Measured memory_bytes: 185044
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { 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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<vector<ll>>A(2,vector<ll>(N));
    vector<ll>sum1(N+1);
    vector<ll>sum2(N+1);
    rep(i,N){
        cin>>A[0][i];
        sum1[i+1]=sum1[i]+A[0][i];
    }
    rep(i,N){
        cin>>A[1][i];
        sum2[i+1]=sum2[i]+A[1][i];
    }
    ll ans=0;
    rep(i,N){
        chmax(ans,sum1[i+1]+sum2[N]-sum2[i]);
    }

    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

ll dp[200010][2][3] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    ll inf = 1e18;
    for(int i=0;i<=N;i++) for(int j=0;j<2;j++) for(int k=0;k<3;k++) dp[i][j][k] = -inf;
    dp[0][0][0] = 0;
    for(int i=0;i<N;i++){
        //選ぶ
        for(int k=0;k<3;k++){
            dp[i+1][1][k] = max(dp[i+1][1][k],dp[i][0][k]+A[i]);
        }
        //選ばない
        if(i!=0){
            for(int k=0;k<3;k++){
                dp[i+1][0][k] = max(dp[i+1][0][k],dp[i][1][k]);
            }
            for(int k=0;k<2;k++) dp[i+1][0][k+1] = max(dp[i+1][0][k+1],dp[i][0][k]);
        }else {
            dp[i+1][0][1] = 0;
        }
    }
    ll ans = -inf;
    if(N%2==1) ans = max(dp[N][1][2],dp[N][0][1]);
    else ans = max(dp[N][1][1],dp[N][0][0]);
    cout << ans << "\n";
}


Measured memory_bytes: 14284
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,X,T;
    cin >> N >> X >> T;
    pr(((N/X+((N%X)==0?0:1)))*T);
}

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

int main()
{
    int a, b;
    char op = ' ';

    while(op != '?') {
        cin >> a >> op >> b;
        switch(op) {
        case '+':
            cout << a+b << endl;
            break;
        case '-':
            cout << a-b << endl;
            break;
        case '*':
            cout << a*b << endl;
            break;
        case '/':
            cout << a/b << endl;
            break;
        default:
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3092
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,l,x[300005],t[300005],top,ans;
int main()
{
	scanf("%d%d",&n,&l);
	l*=2;
	for(int i=1;i<=n;i++)scanf("%d",&x[i]);
	for(int i=1;i<=n;i++)
	{
		int ti;
		scanf("%d",&ti);
		ans+=(ti-1)/l;
		ti=(ti-1)%l+1;
		t[i]=2*(ti<=l-2*x[i])+(ti<=2*x[i]);
		if(t[i]==0)ans++,x[0]=x[i];
		else t[++m]=t[i],x[m]=x[i];
	}
	n=m;
	bool f=1;
	for(int i=1;i<=n;i++)
	{
		if(t[i]==3)top++;
		if(t[i]==2)
		{
			ans++,m--;
			if(top)m--,top--,f=1;
			else f=0;
		}
	}
	if(!m)return printf("%lld\n",1ll*(ans+f)*l),0;
	top=0,f=1;
	if(x[n]<x[0])f=0;
	for(int i=n;i>=1;i--)
	{
		if(t[i]==2)continue;
		if(t[i]==3)top++;
		if(t[i]==1)
		{
			ans++,m--;
			if(top)m--,top--;
		}
		if(!top)f=0;
	}
	if(f)m--;
	ans+=(m+3)/2;
	printf("%lld\n",1ll*l*ans);
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    int d[n];
    for(int i=0;i<n;i++){
        cin >> d[i];
    }
    sort(d, d+n);   //降順に並べる
    int counter=1;
    for(int i=0; i<n-1; i++){
        if(d[i] < d[i+1]){
            counter++;
        }
    }
    cout << counter << endl;
    return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    ll N;
    cin >> N;
    REPS(n, 1, 3500) {
        REPS(h, 1, 3500) {
            ll tmp = (ll)4*n*h - (ll)N*n - (ll)N*h;
            if (tmp == 0) continue;
            ll w = (ll)(N*h*n) / tmp;
            long double ans = (1.0 / h) + (1.0 / n) + (1.0 / w);
            if (1 <= w && abs(ans - (4.0 / N)) < 1e-15 && w <= 3500) {
                cout << n << ' ' << h << ' ' <<  w << endl;
                return 0;
            }
        }
    }
}


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

int main(){
    int a,b;
    char op;
    cin >> a >> op >>b;
    while(op != '?'){
    if(op == '+'){
        cout << a+b << endl;
    }else if(op == '-'){
        cout << a-b << endl;
    }else if(op == '*'){
        cout << a*b << endl;
    }else if(op == '/'){
        cout << a/b << endl;
    }
    cin >> a >> op >>b;
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int d[n];
    rep(i, n) cin >> d[i];
    sort(d, d+n);

    int res =0;
    res = d[n/2] - d[n/2-1];
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3936
#include <iostream>
#include<queue>
using namespace std;
priority_queue<int> pq;
int main() { 
    string s;int a;
    for (;;) {
        cin >> s;
        if (s == "end")
            break;
        if (s[0] == 'i') {
            cin >> a;
            pq.push(a);
        }
        else {
            cout << pq.top() << endl;
            pq.pop();
        }
    }
}


Measured memory_bytes: 7100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCoder
{
    class ABC173C
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int h = int.Parse(str[0]);
            int w = int.Parse(str[1]);
            int k = int.Parse(str[2]);
            int[,] c = new int[h,w];
            int[,] ansc = new int[h,w];
            int ans = 0;
            for(int i = 0; i < h; i++)
            {
                string str1 = Console.ReadLine();
                for(int j = 0; j < w; j++)
                {
                    if(str1[j]=='.')
                    {
                        c[i,j]=0;
                    }
                    else
                    {
                        c[i,j]=1;
                    }
                }
            }
            //ここまで入力
            for(int x = 0; x < (1<<h); x++)
            {
                for(int y = 0; y < (1<<w); y++)
                {
                    for(int i = 0; i < h; i++)
                    {
                        for(int j = 0; j < w; j++)
                        {
                            if(((x&(1<<i)) > 0) || ((y&(1<<j)) > 0))
                            {
                                ansc[i,j] = 0;
                            }
                            else
                            {
                                ansc[i,j] = c[i,j];
                            }
                        }
                    }
                    int count = 0;
                    for(int i = 0; i < h; i++)
                    {
                        for(int j = 0; j < w; j++)
                        {
                            count += ansc[i,j];
                        }
                    }
                    if(count == k)
                    {
                        ans++;
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}

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

int main(){
    int N;  cin >> N;
    int S = 0;
    int mod = 998244353;
    vector<int> a(N+1,0);
    for(int i=1; i<=N; i++){
        cin >> a[i];
        S += a[i];
    }

    vector<vector<ll>> dp1(N+1, vector<ll>(S+1,0));
    vector<vector<ll>> dp2(N+1, vector<ll>(S+1,0));
    dp1[1][0] = 2;
    dp1[1][a[1]] = dp2[1][0] = dp2[1][a[1]] = 1;
    for(int i=1; i<N; i++){
        for(int r=0; r<=S; r++){
            dp1[i+1][r] = 2*dp1[i][r]%mod;
            dp2[i+1][r] = dp2[i][r]%mod;

            if(r>=a[i+1]){
                dp1[i+1][r] = (dp1[i+1][r] + dp1[i][r-a[i+1]]) % mod;
                dp2[i+1][r] = (dp2[i+1][r] + dp2[i][r-a[i+1]]) % mod;
            }
        }
    }

    ll ans = 1;
    for(int i=0; i<N; i++){
        ans = (ans*3)%mod;
    }
    for(int r=S/2+1; r<=S; r++){
        ans = ans - 3*dp1[N][r];
        while(ans<0) ans += mod;
        ans%=mod;
    }
    if(S%2==0){
        ans = ans - 3*dp1[N][S/2];
    	while(ans<0) ans += mod;
    	ans = (ans + 3*dp2[N][S/2]) % mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 423744
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

//Distorted Love
public class Main{

	class B{
		int x1, y1, x2, y2;
		String s;
		public B(int x1, int y1, int x2, int y2, String s) {
			this.x1 = x1;
			this.y1 = y1;
			this.x2 = x2;
			this.y2 = y2;
			this.s = s;
		}
	}
	
	class R{
		String name;
		List<B> l;
		public R(String name) {
			this.name = name;
			l = new ArrayList<B>();
		}
		String click(int x, int y){
			for(B b:l){
				if(b.x1<=x&&x<=b.x2&&b.y1<=y&&y<=b.y2)return b.s;
			}
			return "";
		}
	}
	
	Map<String, Integer> ref;
	R[] page;
	int id;
	
	int get(String s){
		if(ref.containsKey(s))return ref.get(s);
		page[id] = new R(s);
		ref.put(s, id);
		return id++;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			sc.next();sc.next();
			page = new R[n];
			ref = new TreeMap<String, Integer>();
			id = 0;
			for(int i=0;i<n;i++){
				int x = get(sc.next());
				int k = sc.nextInt();
				while(k--!=0){
					page[x].l.add(new B(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.next()));
				}
			}
			int m = sc.nextInt();
			R[] h = new R[m];
			h[0] = page[0];
			int pos = 0;
			int t = 1;
			while(m--!=0){
				String cmd = sc.next();
				if(cmd.equals("show")){
					System.out.println(h[pos].name);
				}
				else if(cmd.equals("back")){
					pos = Math.max(0, pos-1);
				}
				else if(cmd.equals("forward")){
					pos = Math.min(t-1, pos+1);
				}
				else {
					String hit = h[pos].click(sc.nextInt(), sc.nextInt());
					if(hit.equals(""))continue;
					int x = ref.get(hit);
					h[++pos] = page[x];
					t = pos+1;
				}
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
a = int(input())
b = int(input())

if a == 1 and b == 2:
  print("3")
elif a == 2 and b == 1:
  print("3")
elif a == 1 and b == 3:
  print("2")
elif a == 3 and b == 1:
  print("2")
elif a == 2 and b == 3:
  print("1")
else:
  print("1")

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

using namespace std;

using ll=long long;

int main()
{
   int n;
   cin>>n;
   vector<int>a(n+1);
   vector<int>b(n+1);
   vector<int>c(n+1);
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
   }
   for(int i=1;i<=n;i++)
   {
       cin>>b[i];
   }
   for(int i=1;i<=n-1;i++)
   {
       cin>>c[i];
   }
   int ans=0;
   ans+=b[a[1]];
   for(int i=2;i<=n;i++)
   {
       if(a[i]-a[i-1]==1){
       ans+=b[a[i]];
       ans+=c[a[i-1]];
       }
       else
       {
           ans+=b[a[i]];
       }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc148/tasks/abc148_c
import fractions
# math.gcdは3.5からなのでAtCoderで使えない
# import math


def main():
    (a, b) = [int(i) for i in input().split(" ")]
    print(int(a * b / fractions.gcd(a, b)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12
void _main(int tc) {
  int n;
  cin >> n;
  vector<vector<int>> abc(n, vector<int>(3));
  rep(i, n) {
    cin >> abc[i][0];
    cin >> abc[i][1];
    cin >> abc[i][2];
  }

  vector<vector<int>> mem(n, vector<int>(3));
  mem[n - 1][0] = abc[n - 1][0];
  mem[n - 1][1] = abc[n - 1][1];
  mem[n - 1][2] = abc[n - 1][2];
  rrep(i, n - 1) {
    mem[i][0] = abc[i][0] + max(mem[i + 1][1], mem[i + 1][2]);
    mem[i][1] = abc[i][1] + max(mem[i + 1][0], mem[i + 1][2]);
    mem[i][2] = abc[i][2] + max(mem[i + 1][0], mem[i + 1][1]);
  }
  auto ans = max({mem[0][0], mem[0][1], mem[0][2]});
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main(){
    int h, n; cin >> h >> n;
    vector<int> a(n);
    ll sum = 0;
    rep(i,n) {
        int a; cin >> a;
        sum += a;
    }
    if(sum >= h){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}







Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cmath>

#define SQ(X) ((X)*(X))

using namespace std;

int main(void){
  int n;
  int data[1000];
  double avr,st;
  
  cout << setprecision(10);
  while(true){
    cin >> n;
    if (n==0) break;
    avr = 0;
    for (int i=0; i<n; i++){
      cin >> data[i];
      avr += data[i];
    }
    avr /= n;
    st = 0;
    for (int i=0; i<n; i++){
      st += SQ(data[i]-avr);
    }
    st /= n;
    st = sqrt(st);
    cout << st << endl;
  }
    
  return 0;
}



Measured memory_bytes: 3252
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

line = require('fs').readFileSync(config.input, 'ascii')
  .split(config.newline, 4);

S = line[1].split(' ').map(Number);
T = line[3].split(' ').map(Number);

C = T.reduce(function (p, c) {
  return p + ((S.indexOf(c) !== -1) ? 1 : 0); }, 0);

console.log(C);

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

typedef  long long ll;

int main()
{
    ll t,n,k,i,j,flag=1,sum=1,vagshes;
    cin>>n>>k;
    vagshes=n%k;
    if(abs(vagshes-k)<vagshes)
        cout<<abs(vagshes-k)<<endl;
    else
        cout<<vagshes<<endl;

}


Measured memory_bytes: 256