akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    // 人数入力
    int num;
    cin >> num;

    // 教室にいた人数を保存
    vector<int> vecNum(num);
    for(int i=0; i<num; i++){
        cin >> vecNum.at(i);
    }
    
    // 順番を探索
    vector<int> vecAns(num);
    for(int i=0;i<num; i++){
        vecAns.at(vecNum[i]-1) = i + 1;
    }

    // 出力
    for(int i=0; i<num; i++){
        cout << vecAns[i] << " ";

        if(i==num-1){
            cout << endl;
        }
    }

    return 0;
}

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

long long int comb(int n,int r){
    long long int res = 1;
    int i;
    for (i=0;i<r;i++){
        res = res * (n-i)/(i+1);
    }
    return res;
}

int main(void){
    int N,P;scanf("%d %d",&N,&P);
    
    int i,j,odds=0,evens=0;
    for (i=0;i<N;i++){
        int a;scanf("%d",&a);
        if (a%2)odds++; else evens++;
    }

    long long int res = 0;

    for (i=P;i<=odds;i+=2){
        res += comb(odds,i);
    }
    res*= pow(2,evens);
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <iostream>
#include <string>

using namespace std;
int main(int argc,char **argv){
	vector<string> inputs;

	while(true){
		string line;
		getline(cin,line);
		if(line == "."){ break; }
		inputs.push_back( line );
	}

	for(auto it=inputs.begin();it!=inputs.end();++it){
		stack<char> st;
		bool isok=true;
		for(auto cit=it->begin();cit!=it->end();++cit){
			char c = *cit;
			if(c=='('||c=='['){ st.push(c); }
			else if(c==')'){
				if(st.size()==0){isok=false;break;}
				if(st.top()=='('){ st.pop(); }
				else{ isok=false; break; }
			}
			else if(c==']'){
				if(st.size()==0){isok=false;break;}
				if(st.top()=='['){ st.pop(); }
				else{ isok=false; break; }
			}
		}
		isok = isok && st.empty();
		cout << (isok?"yes":"no") << endl;
	}

}

Measured memory_bytes: 1688
#include <iostream>
using namespace std;
int main()
{
	int s;
	cin >> s;
	int m = 0;
	while (s != 1 && s != 2 && s != 4)
	{
		if (s % 2 == 0)
		{
			s = s / 2;
		}
		else
		{
			s = 3 * s + 1;
		}
		m++;
	}
	cout << (m + 4) << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] rate = new int[9];
        for (int i = 0; i < n; i++) {
            int tmp = sc.nextInt();
            if (tmp < 400) {
                rate[0]++;
            } else if (tmp < 800) {
                rate[1]++;
            } else if (tmp < 1200) {
                rate[2]++;
            } else if (tmp < 1600) {
                rate[3]++;
            } else if (tmp < 2000) {
                rate[4]++;
            } else if (tmp < 2400) {
                rate[5]++;
            } else if (tmp < 2800) {
                rate[6]++;
            } else if (tmp < 3200) {
                rate[7]++;
            } else {
                rate[8]++;
            }
        }
        int count = 0;
        for (int i = 0; i <= 7; i++) {
            if (rate[i] > 0) {
                count++;
            }
        }
        System.out.println(Math.max(count, 1) + " " + (count + rate[8]));
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <numeric>
#include <complex>
using namespace std;

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

char field[200][200];

int main() {
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    if (unique(S.begin(), S.end()) == S.end())cout << "yes" << endl;
    else cout << "no" << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")

#define int128 __int128

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

int const maxn = 3e5 + 5;

struct Line {
	ll k, b;
	mutable const Line* nx;
	bool operator<(ll x) const {
		if (!nx) return 0;
		return b - nx->b < (nx->k - k) * x;
	}
	bool operator<(const Line& rhs) const {
		return k < rhs.k;
	}
};
// will maintain upper hull for maximum
struct HullDynamic : multiset<Line, less<>> {
	bool bad(iterator y) {
		auto z = next(y);
		if (y == begin()) {
			if (z == end()) return 0;
			return y->k == z->k && y->b <= z->b;
		}
		auto x = prev(y);
		if (z == end()) return y->k == x->k && y->b <= x->b;
		return (x->b - y->b) * (int128)(z->k - y->k) >= (y->b - z->b) * (int128)(y->k - x->k);
	}
	void insert_line(ll k, ll b) {
		auto y = insert({ k, b, 0 });
		if (bad(y)) { erase(y); return; }
		auto z = next(y);
		while (z != end() && bad(z)) z = erase(z);
		if (z != end()) y->nx = &*z;
		while (y != begin() && bad(z = prev(y))) erase(z);
		if (y != begin()) z->nx = &*y;
	}
	ll eval(ll x) {
		auto l = *lower_bound(x);
		return l.k * x + l.b;
	}
};

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

	ll n, C; cin >> n >> C;

	vector<ll>h(n);
	for (ll i = 0; i < n; i++) cin >> h[i];

	ll cur = 0;
	

	for (ll i = 0; i < n; i++) {
		if (i)cur = C + h[i] * h[i] - cht.eval(h[i]);
		else cur = 0;
		cht.insert_line(2 * h[i], -(h[i] * h[i] + cur));
	}

	cout << cur << endl;

	return 0;
}

/*
5
2 6 15 5 10

4
2 6 15 5

*/

Measured memory_bytes: 14336
import itertools, heapq, bisect
from collections import defaultdict as ddic, deque, Counter

rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())
MOD = 10 ** 9 + 7

###

def solve(N, T, A, graph):
    if T == A: return 0
    stack = [(A, None)]
    seen = {A}
    back = {}
    while stack:
        node, par = stack.pop()
        back[node] = par
        for nei in graph[node]:
            if nei != par:
                if nei not in seen:
                    stack.append((nei, node))
                    seen.add(nei)

    path = [T]
    while back[path[-1]] is not None:
        path.append(back[path[-1]])

    def bfs(source, par):
        queue = deque([(source, par, 0)])
        d=  0
        while queue:
            node, par, d = queue.popleft()
            for nei in graph[node]:
                if nei != par:
                    queue.append((nei, node, d+1))
        return d
    
    ans = 0
    i = 0
    j = len(path) - 1
    while i + 2 < j:
        i += 1
        j -= 1
        ans += 1
    # now T goes away from A
    #print "!", path[i], path[i+1], ans
    ans += j-i-1
    ans += bfs(path[i], path[i+1])
    return ans


N, T, A = rrm()
T -= 1; A -= 1
graph = [[] for _ in xrange(N)]

for _ in xrange(N-1):
    a, b = rrm()
    a -= 1; b -= 1
    graph[a].append(b)
    graph[b].append(a)

print solve(N, T, A, graph)


Measured memory_bytes: 75036
d = int(input())

c = list(map(int,input().split()))

s = []

for _ in range(d):
    temp = list(map(int,input().split()))

    s.append(temp)

choices = []

for _ in range(d):
    temp = int(input())

    choices.append(temp)

def calc_point(point_list, interval, choice):
    point = 0

    for i, day in enumerate(interval):
        point -= c[i] * day

    point += point_list[choice - 1]

    return point

interval = [0] * 26

result = 0

for i in range(d):
    choice = choices[i]

    interval = [x + 1 for x in interval]

    interval[choice - 1] = 0

    result += calc_point(s[i], interval, choice)

    print(result)
    
    

Measured memory_bytes: 68548
#include <bits/stdc++.h>
using namespace std;
int main() {
  double N,D,X,Y,a,K,S,d;
  cin >> N >> D;
  a = 0;
  d = D * D;
  for(int i = 0;i < N;i++) {
    cin >> X >> Y;
    K = X * X;
    S = Y * Y;
    if((K + S) <= d) {
      a++;
    }
  }
  cout<<a<<endl;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repr(i, n) for(int i = n; i>=0; i--)
#define all(x) (x).begin(), (x).end()
#define INF 100100100
typedef long long ll;
typedef pair<int, int> p;
 
int main(void) {
	int n, q, d[100002];
	ll t, a[100002], stop[100002];
	scanf("%d%lld%d", &n, &t, &q);
	for (int i = 1; i <= n; i++) {
		scanf("%lld%d", &a[i], &d[i]);
	}
	a[0] = -3000000000000000000LL;
	d[0] = 1;
	a[n + 1] = 3000000000000000000LL;
	d[n + 1] = 2;
	for (int i = 0; i <= n; i++) {
		if (d[i] == 1 && d[i + 1] == 2) {
			ll tmp = (a[i] + a[i + 1]) / 2;
			for (int j = i; j >= 0 && d[j] == 1; j--) {
				if (a[j] + t >= tmp) stop[j] = tmp;
				else stop[j] = a[j] + t;
			}
			for (int j = i + 1; j <= n + 1 && d[j] == 2; j++) {
				if (a[j] - t <= tmp) stop[j] = tmp;
				else stop[j] = a[j] - t;
			}
		}
	}
	for (int i = 0; i < q; i++) {
		int x;
		scanf("%d", &x);
		printf("%lld\n", stop[x]);
	}
	
	return 0;
}

Measured memory_bytes: 5156
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	long long  m,n,i,sum=0;
	long long  a[200010];
	scanf("%lld %lld",&m,&n);
	for(i=0;i<m;i++)
	{
		scanf("%lld",&a[i]);
		//printf("%d",a[i]);
	}
	sort(a,a+m);
	for(int k=0;k<i-n;k++)
	{//printf("%d",a[k]);
		sum+=a[k];
	}
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;

int main(){


	int N; std::cin >> N;
	std::map<std::string, int> m;
	rep(i, N){
		std::string s; std::cin >> s;
		m[s]++;
	}
	int M; std::cin >> M;
	rep(i, M){
		std::string t; std::cin >> t;
		m[t]--;
	}

	int ans = INT_MIN;

	for(const auto& v : m){
		ans = std::max(ans, v.second);
	}

	if(ans < 0)ans = 0;
	std::cout << ans;

	return 0;
}

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

int main(){

    int N; cin >> N;
    int h[N];for(int i = 0; i < N; i++){cin >> h[i];}
    int cost[N];

    for(int i = 0; i < N; i++){
        
        if(i == 0){cost[i] = 0;}
        else if(i == 1){cost[i] = abs(h[1]-h[0]);}
        else{
            cost[i] = min(cost[i-2] + abs(h[i]-h[i-2]), cost[i-1] + abs(h[i]-h[i-1]));
        }
    }

    cout << cost[N-1] << endl;
}

Measured memory_bytes: 1024
from collections import deque

def solve(N, children, weights):
    ret = [0 for _ in range(N + 1)]
    stack = deque()
    stack.append([0, 1])
    used = [False for _ in range(N + 1)]
    used[1] = True
    while stack:
        weights_sum, node = stack.pop()
        weights_sum += weights[node]
        ret[node] = weights_sum

        if not children[node]:
            continue

        for c in children[node]:
            if used[c]:
                continue
            stack.append([weights_sum, c])
            used[c] = True

    for idx in range(1, N + 1):
        print(ret[idx], end=" ")

if __name__ == "__main__":
    N, Q = map(int, input().split())
    children = [[] for _ in range(N + 1)]

    for _ in range(1, N):
        a, b = map(int, input().split())
        children[a].append(b)
        children[b].append(a)

    weights = [0 for _ in range(N + 1)]

    for _ in range(Q):
        p, x = map(int, input().split())
        weights[p] += x

    solve(N, children, weights)

Measured memory_bytes: 120436
#include <iostream>
using namespace std;
#define FOR(i,n) for(i=0;i<n;++i)
int i,j;
int main(void){
    
    int n;
    string s;
    cin>>n>>s;
    
    int x=0,xmax=0;
    FOR(i,n){
        if(s[i]=='I')x++;
        else x--;
        
        if(x>xmax)xmax=x;
    }
    
    cout<<xmax;
    
    return 0;
}


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

typedef map<char, int> State;

bool finished(State &m){
  for(char c = '1' ; c <= '9' ; c++){
    if(m[c]) return false;
  }
  return true;
}

bool bfs(string s){
  State start;
  for(int i = 0 ; i < (int)s.size() ; i++){
    start[s[i]]++;
    if(start[s[i]] > 4) return false;
  }
  queue<State> que;
  for(char c = '1' ; c <= '9' ; c++){
    if(start[c] >= 2){
      State nex = start;
      nex[c] -= 2;
      que.push(nex);     
    }
  }
  
  while(!que.empty()){
    State q = que.front(); que.pop();
    
    if(finished(q)) return true;
    
    for(char c = '1' ; c <= '9' ; c++){
      if(q[c] >= 3){
	State nex = q;
	nex[c] -= 3;
	que.push(nex);
      }
    }
    for(char c = '1' ; c <= '7' ; c++){
      if(q[c] >= 1 && q[c+1] >= 1 && q[c+2] >= 1){
	State nex = q;
	nex[c] -= 1, nex[c+1] -= 1, nex[c+2] -= 1;
	que.push(nex);
      }
    }
  }
  return false;
}

int main(){
  string s;
  while(cin >> s){
    vector<char> ans;
    for(char c = '1' ; c <= '9' ; c++){
      if(bfs(s + c)) ans.push_back(c);
    }
    if(ans.size() == 0) cout << 0 << endl;
    else{
      for(int i = 0 ; i < (int)ans.size() ; i++){
	cout << ans[i];
	if(i == (int)ans.size()-1) cout << endl;
	else cout << ' ';
      }
    }
  }
  
  return 0;
}

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;

  if(a == b)
    cout << c;
  else if(a == c)
    cout << b;
  else if(b == c)
    cout << a;
    
}


Measured memory_bytes: 3616
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    B = sorted(il())
    print(sum(B[:2]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1000100;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
char s[N];
int n,i,ans,k;
int main(){
	//freopen("1.out","w",stdout);
	scanf("%s",s+1);
	n=strlen(s+1);
	for(i=1;i<=n;i++)
	if(s[i]=='T'){
		if(k)k--;
		else ans++;
	}else k++;
	printf("%d\n",ans+k);
	return 0;
}

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

int main() {
string S;
cin >> S;
string a, b;
int L =S.size();
a = S.substr(0, (L-1)/2);
b = S.substr((L+3)/2-1, (L-1)/2);
string sinv=S, ainv=a, binv=b;
reverse(S.begin(), S.end());
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
if(a==ainv && S==sinv && b == binv) cout << "Yes" << endl;
else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3584
#pragma region

#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

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

  string S;
  cin >> S;
  rep(i,S.length()) {
    if (S[i] == 'U' || S[i] == 'D') continue;
    if (i % 2 == 0 && S[i] == 'R') continue;
    if (i % 2 == 1 && S[i] == 'L') continue;
    out("No");
    return 0;
  }
  out("Yes");
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    int q, w, e;

    q = a + b;
    w = a + c;
    e = b + c;

    if(q <= w){
        if(q <= e){
            cout << q << endl;
        }else{
            if(e <= w){
                cout << e << endl;
            }else{
                cout << w << endl;
            }
        }
    }else{
        if(e <= w){
            cout << e << endl;
        }else{
            cout << w << endl;
        }
    }

}

Measured memory_bytes: 256
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    s = IS()
    if 'a' in s and 'b' in s and 'c' in s: print('Yes')
    else: print('No')

if __name__ == '__main__':
    main()


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

ll A,B,C,D;
map<ll,ll>memo;
ll solve(ll N){
    if(N==0) 
		return 0;
    if(N == 1) 
		return D;
    if(memo.count(N)) 
		return memo[N];
    ll l2=(N/2)*2;
    ll r2=((N+1)/2)*2;
    ll l3=(N/3)*3;
    ll r3=((N+2)/3)*3;
    ll l5=(N/5)*5;
    ll r5=((N+4)/5)*5;
    ll res=1e18;
    if(N<res/D) 
		res=N*D;
    res=min(res,llabs(l2-N)*D+A+solve(l2/2));
    res=min(res,llabs(r2-N)*D+A+solve(r2/2));
    res=min(res,llabs(l3-N)*D+B+solve(l3/3));
    res=min(res,llabs(r3-N)*D+B+solve(r3/3));
    res=min(res,llabs(l5-N)*D+C+solve(l5/5));
    res=min(res,llabs(r5-N)*D+C+solve(r5/5));
    memo[N]=res;
    return res;
}
int main(){
    int T;
    cin>>T;
    for(int t=0;t<T;t++){
        memo.clear();
        ll N;
        cin>>N;
        cin>>A>>B>>C>>D;
        cout<<solve(N)<<"\n";
    }
    return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	int res = 0;
	for (int i = 1; i <= n; i *= 100) {
		res += min(n, i * 10 - 1) - i + 1;
	}
	cout << res << endl;
}


Measured memory_bytes: 3632
inp = lambda cast=int: list(map(cast, input().split()))
# printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)
n, = inp()
A = [0.0] + inp(float)
dp = [[0.0 for _ in range(n + 1)] for _ in range(n + 1)]
res = 0.0
for i in range(n + 1):
    for j in range(n + 1):
        if i == 0:
            dp[i][j] = 1 if j == 0 else 0
        elif j == 0:
            dp[i][j] = dp[i-1][j] * (1 - A[i])
        else:
            dp[i][j] = dp[i-1][j] * (1 - A[i]) \
                       + dp[i-1][j-1] * A[i]
        if i == n and j > n/2:
            res += dp[i][j]
print(res)

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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

void solve()
{
    ll n,m,k;
    cin>>n>>m>>k;
    
    ll mx1=0,mx2=0;
    map<ll,ll> row,col;
    set<pair<ll,ll>> s;
    ll rr,cc;
    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        row[x]++;
        col[y]++;
        s.insert({x,y});
        
        if(mx1<row[x])
        {
            mx1=row[x];
            rr=x;
        }
        if(mx2<col[y])
        {
            mx2=col[y];
            cc=y;
        }
    }
    ll flag=0;
    
    vector<ll> vr,vc;
    for(auto it:row) if(it.second==mx1) vr.push_back(it.first);
    for(auto it:col) if(it.second==mx2) vc.push_back(it.first);
    
    for(ll i=0;i<vr.size();i++)
    {
        for(ll j=0;j<vc.size();j++)
        {
            ll t1=vr[i];
            ll t2=vc[j];
            if(s.find({t1,t2})==s.end()) flag=1;
            if(flag==1) break;
        }
        if(flag==1) break;
    }
    if(flag==1) cout<<mx1+mx2;
    else cout<<mx1+mx2-1;
}

int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}


Measured memory_bytes: 67848
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
	string s,t;
	cin >> s>>t;
	if (s.length()+1!=t.length())
	{
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i]!=t[i])
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
const int mo=1000000007;
int f[3005],a[3005];
char s[3005];
void dp(int i,int &R){
	R=i>R?i:R;
	for (int j=i;j>=0;j--)
		if (j<a[R]-R+i || j>a[R]) f[j]=0;
			else if (j) (f[j]+=f[j-1])%=mo;
}
int main(){
	int n,m;
	scanf("%d%d\n%s",&n,&m,s+1);
	for (int i=1;i<=n;i++) a[i]=a[i-1]+s[i]-'0';
	int L=1,R=0;f[0]=1;
	for (int i=1;i<=m;i++){
		int l,r;
		scanf("%d%d\n",&l,&r);
		for (int j=L;j<l;j++) dp(j,R);
		L=l;R=r>R?r:R;
	}
	for (int i=L;i<=n;i++) dp(i,R);
	printf("%d\n",f[a[n]]);
}

Measured memory_bytes: 128
import java.util.*;
// import java.io.*;
class Main{
  public static void main(String args[])throws Exception{
    // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    Scanner sc = new Scanner(System.in);
    int count = 0;
    int number = 0;
    // int n = Integer.parseInt(br.readLine());
    int n = sc.nextInt();
    // String [] S = br.readLine().split("\\s+");
    long [] array_s = new long[n];
    for(int i =0; i<n; i++){
      array_s[i] = sc.nextLong();
    }

    // int q = Integer.parseInt(br.readLine());
    int q = sc.nextInt();
    // String [] T = br.readLine().split("\\s+");
    long [] array_t = new long[n];
    long t;
    for(int i = 0; i<q; i++){
      t = sc.nextLong();
      for(int j = 0; j<n; j++){
        if(t == array_s[j]){
          count++;
          break;
        }
      }
    }

    System.out.println(count);
  }
}


Measured memory_bytes: 39600
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
int nax = 1e3 + 5;
int mod = 1e9 + 7;
void add_self(int &a, int b){
	a += b;
	if( a >= mod){
		a -= mod;
		}
	}
int main(){
	int h,w;
	char row[nax][nax];
	scanf("%d%d",&h,&w);
	for(int i = 0; i < h; ++i){
		scanf("%s", row[i]);
		}
	vector<vector<int>> dp(h,vector<int>(w));
	dp[0][0] = 1;
	for(int i = 0 ; i < h; ++i){
		for(int j = 0; j < w; ++j){
			for(int r : {i, i+ 1}){
				int c = j;
				if(r == i){
					c++;
					}
				if( r < h && c < w && row[i][j] == '.'){
					add_self(dp[r][c] , dp[i][j]);
					}
				}
		}
	}
	printf("%d\n", dp[h-1][w-1]);
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main() {
  string u,j;
  int deff = 0;
  cin >> u;
  j = "7";
  for (int i = 0; i < 3; ++i)
  {
    if (string(1,u[i]) == j) {
      if (deff == 0) {
        cout << "Yes";
        deff = 1;
      }
    }
  }
  if (deff == 0) {
    cout << "No";
  }
}

Measured memory_bytes: 3628
import java.util.Scanner;
import java.util.ArrayList;

class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    while(n>0) {
      ArrayList<String> input_arr = new ArrayList<>();
      for(int i = 0; i < n; i++) input_arr.add(scan.next());

      int[][] arr = new int[input_arr.size()][2];
      for(int i = 0; i < input_arr.size(); i++) {
        char[] _in = input_arr.get(i).toCharArray();
        int count = 0;
        int cursor = 0;
        while(_in[cursor]=='.') {
          count++;
          cursor++;
        }

        int num = 0;
        if(_in[cursor]=='+') num=-1;
        else if(_in[cursor]=='*') num=-2;
        else num=(int)(_in[cursor]-'0');
        arr[i][0] = count;
        arr[i][1] = num;
      }

      AbstractExpression ae;
      if(AbstractExpression.isTerminal(arr,0)) {
        ae = new TerminalExpression();
      }else {
        ae = new NonterminalExpression();
      }
      ae.interpret(arr,0);
      System.out.println(ae.calc());

      n = scan.nextInt();
    }
  }
}

abstract class AbstractExpression{
  AbstractExpression() {

  }
  abstract int interpret(int[][] _arr,int num);
  abstract int calc();
  static boolean isTerminal(int[][] _arr,int num) {
    return _arr[num][1]>=0;
  }
}

class TerminalExpression extends AbstractExpression{
  int term;
  TerminalExpression() {

  }
  @Override
  int interpret(int[][] _arr,int num) {
    term = _arr[num][1];
    return 1;
  }
  @Override
  int calc() {
    return term;
  }
}

class NonterminalExpression extends AbstractExpression{
  ArrayList<AbstractExpression> aeArray;
  int mark = 0;
  NonterminalExpression() {
    aeArray = new ArrayList<>();
  }
  @Override
  int interpret(int[][] _arr,int num) {
    int startDepth = _arr[num][0];
    mark = _arr[num][1];
    int startNum = num;
    num++;
    while(num<_arr.length && _arr[num][0]>startDepth) {
      AbstractExpression _ae = null;
      if(isTerminal(_arr,num)) {
        _ae = new TerminalExpression();
      }else {
        _ae = new NonterminalExpression();
      }
      aeArray.add(_ae);
      num += _ae.interpret(_arr,num);
    }
    return num-startNum;
  }
  @Override
  int calc() {
    int result = 0;
    if(mark==-1) {
      for(AbstractExpression _ae : aeArray) result += _ae.calc();
    }else if(mark==-2) {
      result = 1;
      for(AbstractExpression _ae : aeArray) result *= _ae.calc();
    }
    return result;
  }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  string s; cin >> s;
  int red = 0, blue = 0;
  for(int i = 0; i < s.length(); ++i) {
    if(s[i] == '0') red++;
    else blue++;
  }
  cout << 2 * min(red, blue) << endl;

  return 0;
}

Measured memory_bytes: 512
def solve():
    N = int(input())
    A = input()
    B = input()
    C = input()

    ans = 0
    for i in range(N):
        a = A[i]
        b = B[i]
        c = C[i]

        s = {a, b, c}
        if len(s) == 3:
            ans += 2
        elif len(s) == 2:
            ans += 1

    return ans


def main():
    ans = solve()
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3068
// D - Road to Millionaire
#include <bits/stdc++.h>
using namespace std;
int in(){int x;cin>>x;return x;}

int main(){
	int N; cin>>N;
	int64_t yen = 1000;
	for(int nxt, now=in(), i=0; i<N-1; ++i, now=nxt)
		yen += max(0L, yen/now * ((nxt=in()) - now));
	cout<< yen <<endl;
}


Measured memory_bytes: 3660
#include<iostream>
#include<string>
using namespace std;
int main() 
{
	string a;
	int k;
	cin>>k>>a;
	int t=a.length();
	if(k<t)
	{
		for(int i=0;i<=k-1;i++)
		{
			cout<<a[i];
		}
		cout<<"...";
	}
	else{
		for(int i=0;i<=t-1;i++)
		{
			cout<<a[i];
		}
	}
	return 0;
}

Measured memory_bytes: 3136
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
    int x,y,a,b;

	while(1){
		 cin>>x>>y;
		a=x;
		b=y;

		 if( a>y)a=y,b=x;
		 if( x==0&&y==0)break;
         cout<<a<<" "<<b<<endl;

	}
    return 0;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200020
#define lim9 1000000002

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
	in(k);
	int ans = 0;
	for(int a = 1; a <= k; a++) {
		for(int b = 1; b <= k; b++) {
			for(int c = 1; c <= k; c++) {
				ans += gcd(a, gcd(b, c));
			}
		}
	}
	out(ans);
	return 0;
}


Measured memory_bytes: 3580
#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(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int M;
ll d, c;

int main() {
	cin >> M;
	ll cnt = 0, sum = 0;
	REP(i, M) {
		scanf("%lld %lld", &d, &c);
		cnt += c;
		sum += d * c;
	}
	
	ll ans = cnt - 1 + sum / 9 - (sum % 9 == 0);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>S;
    N = S.size();
    ll ans = 0;
    reps(i,1,N/2){
        bool ok = true;
        rep(j,i) if(S[j] != S[j + i]) ok = false;
        if(ok) ans = i*2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int n, m, l;
	std::cin >> n >> m >> l;

	int *matrixA = new int[n*m];
	int *matrixB = new int[m*l];

	int readValue;
	for (int i = 0; i < n*m; i++) {
		std::cin >> readValue;
		matrixA[i] = readValue;
	}
	for (int i = 0; i < m*l; i++) {
		std::cin >> readValue;
		matrixB[i] = readValue;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			long sum = 0;
			for (int k = 0; k < m; k++) {
				sum += matrixA[i*m + k] * matrixB[k*l + j];
			}
			std::cout << sum;
			if (j < l - 1)
				std::cout << " ";
		}
		std::cout << "\n";
	}

	delete[] matrixA;
	delete[] matrixB;
    return 0;
}




Measured memory_bytes: 3188
#include <stdio.h>

int main(){
	char s[4];
	scanf("%s",s);
	int i,j;
	for(i = 0;i<4;i++)
		s[i] -= 0x30;

	for(i = 0;i<(1<<(4-1));i++){
		int tmp[3] = {0};
		int sum = s[0];
		for(j = 0;j<=2;j++){
			if(i&(1<<j)){
				sum -= s[j+1];	
				tmp[j] = 1;
			}else
				sum += s[j+1];
		}
		if(sum == 7){
			for(j = 0;j<=2;j++){
				printf("%d",s[j]);
				if(tmp[j] == 1)
					printf("-");
				else
					printf("+");
			}
			printf("%d=7\n",s[3]);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		int ans;

		if (s.equals("RRR")) {
			ans = 3;
		} else if (s.equals("RRS") || s.equals("SRR")) {
			ans = 2;
		} else if (s.equals("SSS")) {
			ans = 0;
		} else {
			ans = 1;
		}

		System.out.println(ans);

		sc.close();
	}

}

Measured memory_bytes: 35552
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;cin>>x;
  if(x>3){
    y=sqrt(x);
    vector<int>a(y);
    for(int i=1;i<y;i++){
      int k=i+1;
      while(true){
        k*=i+1;
        if(k>x){
          a.at(i)=k/(i+1);
          break;
        }
      }
    }
    sort(a.begin(),a.end());
    cout<<a.at(a.size()-1)<<endl;
  }
  else cout<<1<<endl;
}


Measured memory_bytes: 256
#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<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef 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
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e17+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(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(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

///2009~
int main(void){
	int n,K,i,j;cin>>n>>K;
	if(K>(n-2)*(n-1)/2){cout<<"-1"<<endl;return 0;}
	cout<<n-1+(n-2)*(n-1)/2-K<<endl;
	for(i=2;i<=n;i++){cout<<"1 "<<i<<endl;}
	for(i=2;i<=n;i++){
		for(j=i+1;j<=n;j++){
			if(K>0){K--;continue;}
			cout<<i<<" "<<j<<endl;
		}
	}
	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int s, e;
    s = h1 * 60 + m1;
    e = h2 * 60 + m2;
    cout << max(0, (e - k) - s) << endl;
    return 0;
}



Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if(B>=1&&B<=20&&A>=B&&A<=20&&C>=1&&C<=20)
    {
        int a,b;
        a=A-B;
        b=C-a;
        if(b<=0)
        {
            printf("0\n");
        }
        else
        {
            printf("%d",b);
        }

    }
}


Measured memory_bytes: 2120
#include<bits/stdc++.h>
#include <boost/math/common_factor_rt.hpp>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
using namespace boost::math;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    CIN(N);
    I vec;
    REP(a,N*3){
        CIN(b);
        vec.pb(b);
    }
    priority_queue<int> quemin;
    priority_queue<int, vector<int>, greater<int> > quemax;
    LL ma = 0;
    LL mi = 0;
    for(int a = 0;a < N;a++){
        quemax.push(vec.at(a));
        ma += vec.at(a);
        quemin.push(vec.at(a+2*N));
        mi += vec.at(a+2*N);
    }
    LL mass[100010];
    LL mass1[100010];
    LL ins_ma = ma;
    LL ins_min = mi;
    int s = 0;
    for(int a = 0;a < N;a++){
        int ins = vec.at(a+N);
        quemax.push(ins);
        int w = quemax.top();
        quemax.pop();
        ma -= w;
        ma += ins;
        mass[a]=ma;

    }
    for(int a = N*2-1;a >= N;a--){
        int ins = vec.at(a);
        quemin.push(ins);
        int w = quemin.top();
        quemin.pop();
        mi -= w;
        mi += ins;
        mass1[a-N]=mi;
        s++;
    }
    LL ans = -LINF;
    ans = max(ans,ins_ma-mass1[0]);
   // cout<<ins_ma<<" "<<mass1[0]<<endl;
    for(int a = 0;a < N-1;a++){
     //   cout<<mass[a]<<" "<<mass1[a+1]<<endl;
        ans = max(ans, mass[a]-mass1[a+1]);
    }
    ans = max(ans,mass[N-1]-ins_min);
    COUT(ans);
    return 0;
}


Measured memory_bytes: 4208
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

vector<long long> Divisor(long long n) {
    vector<long long> ret;
    for(long long i=1; i*i<=n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i*i!=n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

vector<vector<long long>> yakusuz;

void init_yakusuz(int K) {
    yakusuz.resize(K+1);
    for (int i = 1; i <= K; i++) {
        yakusuz[i] = Divisor(i);
    }
}

int main(void) {
    int N, K; cin >> N >> K;
    // int ans_debug = 0;
    // for (int i = 1; i <= K; i++) {
    //     for (int j = 1; j <= K; j++) {
    //         for (int k = 1; k <= K; k++) {
    //             ans_debug += gcd(gcd(i, j), k);
    //         }
    //     }
    // }
    // cout << ans_debug << endl;

    init_yakusuz(K);
    vector<long long> minus(K+1);
    long long ans = 0;
    
    for (int i = K; i >= 1; i--) {
        long long tmp = K/i;
        tmp = mod_pow(tmp, N);
        tmp -= minus[i];
        tmp = (tmp + MOD) % MOD;
        ans += tmp*i;
        ans %= MOD;
        for (int j = 0; j < yakusuz[i].size(); j++) {
            minus[yakusuz[i][j]] += tmp;
            minus[yakusuz[i][j]] %= MOD;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 18600
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */


int main() {
    int n;
    cin >> n;
    vector<int> V(n);
    rep(i, n) cin >> V[i];
    sort(ALL(V));
    vector<double> ans(n);
    ans[0] = V[0];
    rrep(i, n - 1) {
        ans[i] =  (ans[i - 1] + V[i]) / 2;
    }
    cout << fixed << setprecision(10) << ans[n - 1] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;

    string s; cin >> s;
    vector<vector<ll>> dp(s.size()+1,vector<ll>(13,0));
    dp[0][0] = 1;
    for(ll i=0;i<s.size();i++){
        for(ll j=0;j<13;j++){
            if(s[i] == '?'){
                for(ll k=0;k<10;k++){
                    dp[i+1][(j*10+k)%13] += dp[i][j];
                    dp[i+1][(j*10+k)%13] %= mod;
                }
            }else{
                int k = s[i]-'0';
                dp[i+1][(j*10+k)%13] += dp[i][j];
                dp[i+1][(j*10+k)%13] %= mod;
            }
        }
    }

    cout << dp[s.size()][5] << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

ll h[100100];

int main(void)
{
    ll K, N;
    cin >> N >> K;
    REP(i, N) cin >> h[i];
    sort(h, h+N);
    ll mi = INF;
    REP(i, N - K + 1) {
        ll d = h[i + K - 1] - h[i];
        mi = min(mi, d);
    }
    cout << mi << endl;

}


Measured memory_bytes: 1024
from collections import Counter

N = int(input())
S = []
for i in range(N):
    S.append(input())

S.sort() #l = sorted(S)と同義 *Sは変化させたくないときはsorted使う◎
counted = Counter(S)
l = counted.most_common()
m = l[0][1]
l.sort()
for i in l:
    if m == i[1]:
        print(i[0])

Measured memory_bytes: 46900
#include<stdio.h>
int main(void)
{
	int a[5],i,ans=0,max=0;
	for(i=0;i<5;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<5;i++)
	{
		if(a[i]%10==0){
			ans+=a[i];
		}
		else
		{
			ans+=a[i]+10-(a[i]%10);
			if(max<10-(a[i]%10))
			max=10-(a[i]%10);
		}
	}
	printf("%d\n",ans-max);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

/**
 * Created by Harry on 3/31/20.
 */
//https://atcoder.jp/contests/dp/tasks/dp_b
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] height = new int[n];
        for(int i=0; i<n; i++){
            height[i] = scanner.nextInt();
        }
        System.out.print(findMinCost(n,k,height));
    }

    public static long findMinCost(int n, int k, int[] height){
        long[] dp = new long[n];
        dp[0] = 0;
        for(int i=1; i<n; i++){
            dp[i] = Integer.MAX_VALUE;
            for(int j=i-1; j>=Math.max(0, i-k); j--){
                dp[i] = Math.min(dp[i], dp[j]+Math.abs(height[i]-height[j]));
            }
        }
        return dp[n-1];
    }
}


Measured memory_bytes: 52588
S = input()
N = len(S)
for i in range(N):
    if (i + 1) % 2 == 1:
        if S[i] in ("R", "U", "D"):
            continue
        else:
            print("No")
            exit()
    else:
        if S[i] in ("L", "U", "D"):
            continue
        else:
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 61880