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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll n;
  cin >> n;
  vector<ll> v(n);
  ll s = 0, count = 0, m = INF;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    count += (v[i] < 0);
    m = min(m, abs(v[i]));
    s += abs(v[i]);
  }
  cout << ((count % 2 == 0) ? s : s - m * 2) << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
ll gcd(ll s, ll t){
    if(t == 0) return s;
    return gcd(t, s % t);
}

int main(){
    ll n, k;
    cin >> n >> k;
    int a[n], mx = 0;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    ll g = a[0];
    for(ll i = 1; i < n; i++){
        g = gcd(g, a[i]);
    }
    if(mx >= k && k%g == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    vector<int> X(N);
    map<int,int> m;
    rep(i,N){
        cin >> X[i];
        m[i]=X[i];
    }
    sort(X.begin(),X.end());
    int a=X[N/2-1],b=X[N/2];
    rep(i,N){
        if (m[i]>a){
            cout << a << endl;
        }
        else {
            cout << b << endl;
        }
    }
}

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

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

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

int gcd(int a,int b);

int main(void)
{
  int n,i;
  scanf("%d%d",&n,&i);
  printf("%d",n-i+1);
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n);

    int min, ret = 1;
    std::cin >> min;
    for (int i = 1; i < n; i++) {
        int in;
        std::cin >> in;
        if (min > in) {
            ret++;
            min = in;
        }
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n;
    cin >> n;
    map<string, lli> d;
    rep(i, n){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        d[s]++;
    }
    lli sum = 0;
    for(auto p: d) sum += p.second*(p.second-1)/2;
    cout << sum << endl;
}

Measured memory_bytes: 11264
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
using namespace std;

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3, y3, x4, y4;
    x4 = y1 - y2 + x1;
    y4 = x2 - x1 + y1;
    x3 = x4 + x2 - x1;
    y3 = y4 + y2 - y1;
    printf("%d %d %d %d\n", x3, y3, x4, y4);
}
    

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

int N, M;

int main() {
  cin >> N >> M;
  vector<string> board(N);

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

  int ans = N*M;
  for(int r=1; r<=N-2; r++) {
    for(int b=1; b<=N-2; b++) {
      for(int w=1; w<=N-2; w++) {
        if(r + b + w != N) continue;
        vector<string> comp(N);
        int idx = 0;

        for(int i=0; i<w; i++) {
          comp[idx++] = string(M, 'W');
        }
        for(int i=0; i<b; i++) {
          comp[idx++] = string(M, 'B');
        }
        for(int i=0; i<r; i++) {
          comp[idx++] = string(M, 'R');
        }

        int cnt = 0;
        for(int i=0; i<N; i++) {
          for(int j=0; j<M; j++) {
            cnt += (board[i][j] != comp[i][j]);
          }
        }
        ans = min(ans, cnt);
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define loop(x,n) for(int x = 0; x < n; ++x)
#define ed end()  
#define bg begin()
#define ft first
#define sc second
# define ld long double
#define ll long long
#define ub(v,a) upper_bound(all(v),a)
#define lb(v,a) lower_bound(all(v),a)
#define sz(a) (int)(a.size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define tr(v,it) for(auto it=v.begin();it!=v.end();it++)
#define present(v,x) (v.find(x)!=v.end()) //set/map etc.
#define vpresent(v,x) (find(all(v),x)!=v.end()) // vector
#define M_PI 3.14159265358979323846
#define bs(v,x) binary_search(all(v),x)
typedef vector< int > vi;
typedef vector< long long > vll;
typedef vector<pair<ll,ll>> vp;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
const long long max_sz = 1e5 + 1;
const long long mod = 1e9 + 7;
char flip(char k){ if(k=='0') return '1'; return '0'; }
ll sum_digit(ll n){ ll a=0,i; for(i=n;i>0;i=i/10){ a+=(i%10);} return a; }
ll gcd(ll a, ll b){
	if(b == 0) return a;
	return gcd(b, a%b);
}
int main(){
                   // ios_base::sync_with_stdio(false);
                    //cin.tie(NULL);
                    //cout.tie(NULL);
 
                     ll t;
                   //  cin >> t;
                     t=1;
                     while (t--){
                        ll n,d;cin>>n>>d;
                        ll jhc=0;
                        for(ll i=0;i<n;i++){
                            ll x,y;cin>>x>>y;
                            if(x*x + y*y <=d*d)jhc++;
                        }
                      cout<<jhc<<endl;
                     }
                      return 0;
}


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

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

    int A, B;
    char op;
    cin >> A >> op >> B;

    if(op == '+')
        cout << A + B << endl;
    if(op == '-')
        cout << A - B << endl;

    return 0;
}

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

using namespace std;

const int maxn = 50010;
const int maxm = 100010;

int n, m, T;
vector<int> vec[maxn], G[maxm];
int ex[maxm], ey[maxm];
char str[maxm];

namespace Subtask1 {
	int vis[maxn];
	bitset<maxn> dp[maxm];
	void solve() {
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j + 1 < vec[i].size(); j++) {
				G[vec[i][j+1]].push_back(vec[i][j]);
			}
		}
		for (int i = 1; i <= m; i++) {
			dp[i][ex[i]] = dp[i][ey[i]] = 1;
		}
		int ok = 0;
		for (int i = 1; i <= m; i++) {
			for (int j = 0; j < G[i].size(); j++) {
				int v = G[i][j];
				dp[i] |= dp[v];
			}
			if (dp[i].count() == n) {
				ok = i;
			}
		}
		if (!ok) {
			puts("-1");
			exit(0);
		}
		vis[ex[ok]] = vis[ey[ok]] = ok;
		for (int i = ok - 1; i >= 1; i--) {
			int x = ex[i], y = ey[i];
			if (vis[x] && !vis[y]) {
				vis[y] = i;
				str[i] = '^';
			} else if (vis[y] && !vis[x]) {
				vis[x] = i;
				str[i] = 'v';
			}
		}
		for (int i = 1; i <= m; i++) {
			if (str[i] == '\0') {
				if (vis[ex[i]] < vis[ey[i]]) {
					str[i] = 'v';
				} else str[i] = '^';
			}
		}
		puts(str+1);
	}
}

namespace Subtask2 {
	void solve() {
		if (n == 2) {
			puts("-1");
			exit(0);
		}
		int to[4];
		to[1] = 1, to[2] = 2, to[3] = 3;
		for (int i = m; i >= 1; i--) {
			int x = ex[i], y = ey[i];
			if (x <= 3 && y > 3) {
				str[i] = '^';
			} else if (x > 3 && y <= 3) {
				str[i] = 'v';
			} else if (x > 3 && y > 3) {
				str[i] = '^';
			} else {
				if (to[x] == to[y]) {
					str[i] = '^';
				} else {
					int z = 0;
					for (int j = 1; j <= 3; j++) {
						if (j != x && j != y) {
							z = j;
						}
					}
					if (to[x] == to[z]) {
						str[i] = 'v';
						to[x] = to[y];
					} else {
						str[i] = '^';
						to[y] = to[x];
					}
				}
			}
			puts(str + 1);
		}
	}
}

int main() {
	scanf("%d%d%d", &n, &m, &T);
	for (int i = 1; i <= m; i++) {
		scanf("%d%d", &ex[i], &ey[i]);
		vec[ex[i]].push_back(i), vec[ey[i]].push_back(i);
	}
	if (T == 1) Subtask1::solve();
	else Subtask2::solve();
	return 0;
}

Measured memory_bytes: 621048
#include <stdio.h>

int get_gcd(int x, int y);

int main(void)
{
	int x, y, gcd, lcm;
	while(scanf("%d %d", &x, &y)==2)
	{
		gcd = get_gcd(x, y);
		
		lcm = x / gcd * y;
		
		printf("%d %d\n", gcd, lcm);
		//printf("%d\n", gcd);
		
	}
	return 0;
}

int get_gcd(int x, int y)
{
	if(x<y)
	{
		y = y % x;
	}
	while(x >= 1 && y >= 1)
	{
		x = x % y;
		if(x == 0)
			break;
		
		y = y % x;
	}

	return (x + y);
}

Measured memory_bytes: 596
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=[0]
tmp=0
for i in A:
  tmp+=i
  B.append(tmp)

d = {}
for i in B:
  i %= M
  if i not in d:
    d[i] = 0
  d[i] += 1

ans = 0
for i in d.values():
  ans += i*(i-1)//2
print(ans)

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

#define o cout<<"Hello did you expect this?"<<endl;
#define ll long long
#define pb push_back
#define mp make_pair//with Z
#define F first
#define S second

using namespace std;

const int N = 2e5 + 100;
const int mod = 1e9 + 7;

void hey ()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int main ()
{
	hey();
	ll a, b, n;
	cin >> a >> b >> n;
	ll k = min(n, b - 1);
	ll ans = (a * (k)) / b;
	cout << ans;
}




Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int n, k; scanf("%d%d", &n, &k);
	int r, s, p; scanf("%d%d%d", &r, &s, &p);
	std::string t; cin >> t;

	// 0: r
	// 1: s
	// 2: p
	auto calc = [&](char c, int x) {
		if(c == 'r') return (x == 2 ? p : 0);
		if(c == 's') return (x == 0 ? r : 0);
		if(c == 'p') return (x == 1 ? s : 0);
	};

	int ans = 0;
	for(int offset = 0; offset < k; offset++) {
		int add = 0, tmp = n / k + 5;
		auto dp = make_v<int>(tmp, 3);
		for(int i = 0; offset + i * k < n; i++) {
			int idx = offset + i * k;

			for(int j = 0; j < 3; j++) {
				int from = dp[i][j];

				for(int k = 0; k < 3; k++) {
					if(j == k) continue;

					dp[i + 1][k] = std::max(dp[i + 1][k], from + calc(t[idx], k));
					add = std::max(add, dp[i + 1][k]);
				}
			}
		}

		ans += add;
	}
	
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 5760
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

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


Measured memory_bytes: 3592
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val s = next().toList()
    println(700 + 100*s.count { it == 'o' })
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33732
MOD = 998244353

def main(argv)
  n = gets.chomp.to_i
  d = gets.chomp.split(' ').map(&:to_i)

  unless d[0] == 0 then
    puts 0.to_s
    return
  end

  c = Hash.new
  d.each do |x|
    if c.has_key?(x) then
      c[x] += 1
    else
      c[x] = 1
    end
  end

  unless (c.has_key?(0) and (c[0] == 1)) then
    puts 0.to_s
    return
  end

  m = c.keys.max

  s = 1
  h = 0
  while h < m do
    unless (c.has_key?(h) and c.has_key?(h + 1)) then
      puts 0.to_s
      return
    end

    t = (c[h] ** c[h + 1]) % MOD
    s = (s * t) % MOD

    h += 1
  end

  puts s.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (long long)1e18 + 1;

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

    vector<int> v(3);
    REP(i, 3) {
        std::cin >> v[i];
    }

    SORT(v);

    std::cout << v[2] * 10 + v[1] + v[0] << std::endl;

    return 0;
}


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

int const MAX =1100;
struct expect{

  std::vector<double> ev;
  expect(){
    ev.resize(MAX);
    std::vector<int> ex(MAX,0);
    for (int i = 1; i < MAX; i++) {
      ex[i]+=ex[i-1]+i;
    }
    for (int i = 1; i < MAX; i++) {
      ev[i]=(double)ex[i]/i;
    }
  }

  double get(int n){
    return ev[n];
  }

};

int main(){
  int n,k;
  std::cin >> n>>k;
  std::vector<int> p(n);
  rep(i,n)std::cin >> p[i];

  expect e;

  double now=0;
  rep(j,k){
    now +=e.get(p[j]);
  }

  double ans=0;
  for (int i = 1; i <n-k+1; i++) {
    now -= e.get(p[i-1]);
    now += e.get(p[i+k-1]);
    ans = max(now,ans);
  }
  ans = max(now,ans);

  printf("%.20f\n",ans);


}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
//#include <string.h>
using namespace std;
int main(){
	char alpha[] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
	string str;
	while( 1 ){
		if( getline( cin, str ).eof() ) break;
		for( int a = 0; a < 26; a++ ){
			for( size_t i = 0; i < str.length(); i++ ){
				for( size_t j = 0; j < sizeof(alpha); j++ ){
					if( str[i] == alpha[j] ){
						str[i] = alpha[j + 1];
						break;
					}
				}
			}
		/*char word = strtok( str.c_str(), " " );
		if( word == "the" || word == "that" || word == "this" ) break;
		while( word == NULL ){
			word = strtok( NULL, ' ' );
			if( word == "the" || word == "that" || word == "this" ) goto end;
		}*/
			if( str.find("the") != string::npos || str.find("this") != string::npos || str.find("that") != string::npos ){
				break;
			}
		}
		cout << str << endl;
	}
}

Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
long long N,A;
cin>>N;
vector<long long> HAM,HAP;
for(long long i=0;i<N;++i){
    cin>>A;
    HAM.push_back(i+1-A);
    HAP.push_back(i+1+A);
}
sort(HAM.begin(), HAM.end());
sort(HAP.begin(), HAP.end());
long long tmp_num=0;
long long ans=0;
long long mc,pc,num1,num2,tmp1,tmp2;
mc=0;
pc=0;

    HAM.push_back(0);
    HAP.push_back(0);

while(mc<N && pc<N){
num1=HAM[mc];
num2=HAP[pc];
tmp1=0;
tmp2=0;
if(num1>num2){
    pc+=1;
}
else if(num1<num2){
    mc+=1;
}
else if(num1==num2){
tmp_num=num1;
while(HAM[mc]==tmp_num){
    tmp1+=1;
    mc+=1;
}
while(HAP[pc]==tmp_num){
    tmp2+=1;
    pc+=1;
}
ans+=tmp1*tmp2;

}
}

cout<<ans<<"\n";

return 0;
}


Measured memory_bytes: 6572
#include <iostream>
using namespace std;
bool t[60000] = {false};
int main()
{
	int n, c, i, j, a, b;
	t[0] = true;
	for (i = 2; i * i <= 60000; i++)
	{
		if (!t[i-1])
		{
			for (j = i+i; j <= 60000; j+=i)
				t[j-1] = true;
		}
	}
	while (cin >> n)
	{
		if (cin.eof()) break;
		for (i = n-1; i >= 2; i--)
			if (!t[i-1])
			{
				a = i;
				break;
			}
		for (i = n+1; i < 60000; i++)
			if (!t[i-1])
			{
				b = i;
				break;
			}
		cout << a << " " << b << endl;
	}
}

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

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

   a = N/1000;
   b = (N-a*1000)/100;
   c = (N-a*1000-b*100)/10;
   d = N- a*1000-b*100-c*10;
   if(a == b && b == c){
       cout << "Yes" <<endl;
   }
   else if(b == c && c == d){
       cout << "Yes" <<endl;
   }
   else{
       cout << "No" <<endl;
   } 
}

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

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; }
const ll INF = 1LL << 60;

//---main---------------------------------------------
int main(){
    //main
    int x,y;
    cin >> x >> y;
    if(y%2==1){
        cout << "No" << endl;
        return 0;
    }
    int t = (y-2*x)/2;
    if( 0 <= t && t<=x ) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

//ループ
#define rep(i, n) for(int i = 0; i < n; i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ

//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;

using namespace std;

//#include "./lib/generic/search.h"

int main(){
    int n;
    cin >> n;
    vector<ll> cnt(MX); //分布を集計する。余裕をもって100005にしている。100001でも問題はない。
    rep(i,n){
        int a;
        cin >> a;
        cnt[a]++; //初期状態の分布を集計していく
    }
    ll tot = 0; //総和
    rep(i, MX) tot += i*cnt[i]; //この時点での総和を求める

    int q;
    cin >> q;
    rep(i, q){
        int b, c;
        cin >> b >> c;
        tot -= b*cnt[b]; //B⇒Cへ分布を移動させるので、b×bの数分だけ総和から引く
        tot -= c*cnt[c]; //Cの数が変更されるので、c×cの数分だけ総和から引く
        cnt[c] += cnt[b]; //B⇒Cへ分布を移動
        cnt[b] = 0; //Cへ分布を移動させたので0に
        tot += b*cnt[b]; //B⇒Cへ分布を移動させたあとの、b×bの数を総和に反映
        tot += c*cnt[c]; //B⇒Cへ分布を移動させたあとの、c×cの数を総和に反映
        cout << tot << endl;
    }
    return 0;
}

Measured memory_bytes: 4016
import sys
from collections import deque

n, m = map(int, input().split())

path = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    path[a].append(b)
    path[b].append(a)

ans = [0] * (n+1)
alr = [0] * (n+1)
que = deque([1])
while len(que) > 0:
    idx = que.popleft()
    for i in path[idx]:
        if alr[i] == 0:
            que.append(i)
            ans[i] = idx
            alr[i] = 1
        else:
            pass

print('Yes')
for i in range(2, n+1):
    print(ans[i])


Measured memory_bytes: 34792
h, w = list(map(int, input().split()))
d = {".":0, "#":1}
ss = [list(input()) for _ in range(h)]
ss = [[d[x] for x in s] for s in ss]

ws = [[0 for _ in range(w)] for _ in range(h)]
hs = [[0 for _ in range(w)] for _ in range(h)]

i = 0
while i < h:
	j = 0
	while j < w:
		if ss[i][j] == 0:
			end = w
			for k in range(j + 1, w):
				if ss[i][k] == 1:
					end = k
					break
			for l in range(j, end):
				ws[i][l] = end - j
			j = end + 1
		else:
			j += 1
	i += 1

j = 0
while j < w:
	i = 0
	while i < h:
		if ss[i][j] == 0:
			end = h
			for k in range(i + 1, h):
				if ss[k][j] == 1:
					end = k
					break
			for l in range(i, end):
				hs[l][j] = end - i
			i = end + 1
		else:
			i += 1
	j += 1

ans = max([max([ws[j][i] + hs[j][i] for i in range(w)]) for j in range(h)])
print(max(ans - 1, 0))


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

using namespace std;

vector<int> findNext(vector<int> a) {
    int n = a.size();
    for (int i = n-1; i >= 0; i--) {
        if (a[i] < 9 && (i == 0 || abs(a[i-1] - (a[i]+1)) <= 1)) {
            a[i]++;
            for (int j = i+1; j < n; j++) {
                a[j] = max(a[j-1] - 1, 0);
            }
            return a;
        }
    }
    a.assign(n+1, 0);
    a[0] = 1;
    return a;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vector<int> cur = {0};
    for (int i = 0; i < n; i++) {
        cur = findNext(cur);
    }
    for (int v: cur) {
        cout << v;
    }
    cout << endl;
}



Measured memory_bytes: 256
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=int(input())
    e=n//2
    o=n-e
    print(o/(n))  
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
 
public class Main{
	
	int N;
	int M;
	public void solve(){
		N = nextInt();
		M = nextInt();
		int[] memo = new int[N + 1];
		for(int i = 0; i < M; i++){
			memo[nextInt()]++;
			memo[nextInt()]--;
		}
		
		int ans = 0;
		int cnt = 0;
		for(int i = 0; i <= N; i++){
			cnt += memo[i];
			ans++;
			if(cnt > 0) ans+=2;
		}
		out.println(ans);
	}
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

Measured memory_bytes: 24860
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                  cerr<<#x<<": "<<x<<endl
#define trace2(x, y)              cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)              cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)          cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    cin >> a >> b;
    cout << (a+b)%24;
    return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#ifndef ONLINE_JUDGE
//#  define LOG(x) (cerr << #x << " = " << (x) << endl)
//#else
//#  define LOG(x) 0
//#endif
#define pb push_back
#define mod 1000000007
#define endl '\n'
typedef int integer;
#define int long long
using namespace std;

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = 200005;
int ar[NN];
int n, m, k;
vector<int> adj[NN];


integer main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        cin >> ar[i];
    }
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++){
        bool f = true;
        for (auto v : adj[i]){
            if (ar[v] >= ar[i]){
                f = false;
                break;
            }
        }
        ans += (f);
    }
    cout << ans << endl;

}


Measured memory_bytes: 12596
#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);

    LL n;
    cin >> n;
    set<LL> st;
    vector<LL> div = Div(n - 1);
    for(int i = 0; i < div.size(); ++i) {
        st.insert(div[i]);

    }
    vector<LL> nd = Div(n);

    for(int i = 1; i < nd.size(); ++i) {
        LL t = n;
        while(t % nd[i] == 0 && t > 0) {
            t /= nd[i];

        }
        if(t % nd[i] == 1) st.insert(nd[i]);
    }
    cout << st.size() - 1 << endl;
    return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<queue>
#include<algorithm>
#include<utility>
#include<vector>
#include<list>
using namespace std;
int main() {
	double t, v, y,n,in;
	while (cin >> v) {
		t = v / 9.8;
		y = 4.9*pow(t, 2);
		n = (y + 5) / 5;
		in = (int)n;
		if (in == n)cout << n << endl;
		else cout << (int)n+1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3136
import java.util.Scanner

object Main{
  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    val n: Int = scanner.nextInt
    val words: List[String] = List.fill(n)(scanner.next)


    println(check(n, words))
  }

  def check(n: Int, words: List[String]): String ={
    // すでに出た単語を格納していく
    val already: List[String] = List(words.head)
    isEstablish(n, words.head, words.tail, already)
  }

  /**
    * しりとりが成立するか調べる
    * rule -> 未発言の単語　かつ　直前の単語の末尾とその単語の先頭が一致する
    * @return "Yes" or "No"
    */
  def isEstablish(n:Int, head:String, tail:List[String], already: List[String]) :String ={
    n match {
      case 1 => "Yes"
      case _ =>
        (head.last == tail.head.head) match {
          case false => "No"
          case true =>
            already.contains(tail.head) match {
              case true => "No"
              case false => isEstablish(n-1, tail.head, tail.tail, tail.head :: already)
            }
        }
    }
  }
}

Measured memory_bytes: 25424
import scala.math._

object Main {
  def main(args: Array[String]): Unit = {
    val lines = io.Source.stdin.getLines().toSeq
    println(solve(lines))
  }

  def solve(lines: Seq[String]): String = {
    val (_even, _odd) = lines.head.split("").filter(_.length > 0).map(_.toInt).zipWithIndex.partition(_._2 % 2 == 0)
    val even = _even.map(_._1)
    val odd = _odd.map(_._1)

    val evenBlackCount = even.count(_ == 0)
    val evenWhiteCount = even.count(_ == 1)
    val oddBlackCount = odd.count(_ == 0)
    val oddWhiteCount = odd.count(_ == 1)

    min(evenBlackCount + oddWhiteCount, evenWhiteCount + oddBlackCount).toString
  }
}


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

int n, w;

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

    int value[n+1], weight[n+1];

    for(int i = 1; i <= n; i++){
        cin >> value[i] >> weight[i];
    }

    int dp[w+1];

    for(int i = 0; i <= w; i++){
        dp[i] = 0;
    }

    for(int i = 1; i <= w; i++){
        for(int j = 1; j <= n; j++){
            if(weight[j] <= i){
                dp[i] = max(dp[i], dp[i-weight[j]]+value[j]);
            }
        }
    }

    printf("%d\n", dp[w]);
    return 0;

}


Measured memory_bytes: 3252
n = int(input())
h = list(map(int, input().split())) [::-1]


for i in range(n-1):
    if h[i] < h[i + 1]:
        h[i + 1] -= 1
        if h[i] < h[i + 1]:
            print('No') 
            exit()
print('Yes')

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




int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int>> dp(n,vector<int>(n,0));
    for(int i = 0; i < n-1; i++){
        for(int j = i + 1; j < n; j++){
            if(s[i] != s[j]){
                dp[i][j] = 0;
            }else if(i == 0){
                dp[i][j] = 1;
            }else{
                dp[i][j] = dp[i-1][j-1] + 1;
                if(j - dp[i][j] + 1 <= i) dp[i][j] = 0;
            }
        }
    }
    int ans = 0;
    rep(i,n){
        rep(j,n){
            if(dp[i][j] > ans) ans = dp[i][j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 98176
if __name__ == "__main__":
    n, k = map(int, input().split())
    p = 10**9 + 7

    answer = 0
    nCi = 1
    n_1Ci = 1
    for i in range(min(k + 1, n)):
        answer += nCi * n_1Ci
        answer %= p
        deno = pow(i + 1, p - 2, p)
        nCi *= (n - i) * deno
        nCi %= p
        n_1Ci *= (n - i - 1) * deno
        n_1Ci %= p

    print(answer)


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    char s[20];
    cin >> s;
    imfor(i, strlen(s)) {
        if (s[i] == ',') {
            s[i] = ' ';
        }
        cout << s[i];
    }
    cout << endl;
}

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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

LL res, cur;

int n, k, s[17];

int main(){
	scanf("%d %d", &n, &k);
	FI(i, 1, n) scanf("%d", &s[i]);
	res = (1LL << 44);
	FI(i, 0, (1 << n) - 1){
		int cnt = 0;
		FI(j, 0, n - 1) if(i & (1 << j)) cnt++;
		if(cnt == k){
			cur = 0;
			int necess = 0;
			FI(j, 0, n - 1){
				if(i & (1 << j)){
					if(s[j + 1] <= necess){
						necess++;
						cur += necess - s[j + 1];
					}
					else necess = s[j + 1];
				}
				else necess = max(necess, s[j + 1]);
			}
			res = min(res, cur);
		}
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	vi c(26);
	rep(i, n) {
		rep(j, 26) {
			if (s[i] == (char)('a' + j)) c[j]++;
		}
	}
	int k = -1;
	rep(i, 26) {
		if (c[i] == 0) {
			k = i;
			break;
		}
	}
	if (k == -1) cout << "None" << endl;
	else cout << (char)('a' + k) << endl;
}

Measured memory_bytes: 512
N = int(input())
act = [[int(item) for item in input().split()] for _ in range(N)]

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

for i in range(N):
    for j in range(3):
        temp_hp = []
        for k in range(3):
            if k != j:
                temp_hp.append(dp[i-1][k] + act[i][j])
        dp[i][j] = max(temp_hp)
# print(dp)
print(max(dp[N-1]))

Measured memory_bytes: 75224
class Facts:
  
  def __init__(self, mod=10**9+7, n_max=1):
    self.mod     = mod
    self.n_max   = n_max
    self.fact    = [1, 1]
    self.inv     = [0, 1]
    self.factinv = [1, 1]
    if 1 < n_max:
      setup_table(n_max) 
  
  def cmb(self, n, r):
    if r < 0 or n < r:
      return 0
    if self.n_max < n:
      self.setup_table(n)
    return self.fact[n] * (self.factinv[r] * self.factinv[n-r] % self.mod) % self.mod
  
  def setup_table(self, t):
    for i in range(self.n_max+1,t+1):
      self.fact.append( self.fact[-1] * i % self.mod )
      self.inv.append( -self.inv[mod % i] * (mod // i) % self.mod )
      self.factinv.append( self.factinv[-1] * self.inv[-1] % self.mod )
    self.n_max = t

mod = 998244353

n, m, k = map(int, input().split())

ans = 0
f = Facts(mod)
t = m * pow(m-1, n-1-k, mod)

for i in range(k,-1,-1):
  ans += f.cmb(n-1,i) * t % mod
  t = t * (m-1) % mod

print(ans % mod)

Measured memory_bytes: 32888
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()
	c := nextInt()

	colors := make([]int, 101)
	colors[a]++
	colors[b]++
	colors[c]++

	if colors[a] == 1 && colors[b] == 1 && colors[c] == 1 {
		fmt.Println(3)
	} else if colors[a] == 2 || colors[b] == 2 || colors[c] == 2 {
		fmt.Println(2)
	} else {
		fmt.Println(1)
	}
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll a[1000000];
ll b[1000000];
ll c[1000000];
ll t[1000000];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
int main() {
	cin>>N;
	rep(i,0,N){
		cin>>t[i];
	}
	sort(t,t+N);
	vector<ll> v;
	rep(i,1,t[N-1]+1){
		if(t[N-1]%i==0)
			v.push_back(i);
	}
	ans=0;
	rep(i,0,N-1){
		ans+=*lower_bound(v.begin(),v.end(),t[i])-t[i];
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3960
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			long[] p = new long[n], q = new long[n];
			IntStream.range(0, n).forEach(i -> {
				long x = scanner.nextLong(), y = scanner.nextLong();
				p[i] = x + y;
				q[i] = x - y;
			});
			System.out.println(Math.max(Arrays.stream(p).max().getAsLong() - Arrays.stream(p).min().getAsLong(),
					Arrays.stream(q).max().getAsLong() - Arrays.stream(q).min().getAsLong()));
		}
	}
}


Measured memory_bytes: 64132
#include <iostream>
#include <vector>
#include <queue>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
using namespace std;

using ope_pair = pair<int,int>;
bool operator>(const ope_pair a,const ope_pair b){return a.first > b.first;};
bool operator<(const ope_pair a,const ope_pair b){return a.first < b.first;};


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

    priority_queue<int, std::vector<int>, std::greater<int>> sorted_queue;
    rep (i, n) {
        int val;
        cin >> val;
        sorted_queue.push(val);
    }

    priority_queue<ope_pair, vector<ope_pair>, less<ope_pair>> operation_queue;
    rep (i, m) {
        int changing_max_card_nums, replace_value;
        cin >> changing_max_card_nums >> replace_value;

        ope_pair p = make_pair(replace_value, changing_max_card_nums);
        operation_queue.push(p);
    }

    while(!operation_queue.empty() && operation_queue.top().first >= sorted_queue.top() ) {
        int value = operation_queue.top().first;
        int cards = operation_queue.top().second;

        rep(j, cards) {
            if (sorted_queue.top() >= value) {
                break;
            }
            sorted_queue.pop();
            sorted_queue.push(value);
        }
        operation_queue.pop();
    }

    ll total = 0;
    while(!sorted_queue.empty()) {
        total += sorted_queue.top();
        sorted_queue.pop();
    }

    cout << total << endl;
    return 0;
}


Measured memory_bytes: 1784
#!/usr/bin/env python3

def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = S[0]
    fcnt = 0
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
    if fcnt == 0:
        fcnt = cnt
    ans += cnt // 2
    ans *= K
    if len(S) == fcnt:
        ans = (len(S) * K) // 2
    elif S[0] == S[-1]:
        ans -= (fcnt // 2 + cnt // 2 - (fcnt + cnt) // 2) * (K - 1)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8904
#include <bits/stdc++.h>
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
#define ll long long
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    string s;
    cin>>s;
    rep(i,0,1000){
        int a3=i/100,a2=(i/10)%10,a1=i%10;
        int ok1=0,ok2=0,ok3=0;
        rep(j,0,n){
            int d=s[j]-'0';
            if(ok2&&a1==d)ok1=1;
            else if(ok3&&a2==d)ok2=1;
            else if(a3==d)ok3=1;
        }
        if(ok1)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	int n;
	cin >> n;

	int a, b;
	int max_highest = 0, score = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		if (a > max_highest) {
			score = b;
			max_highest = a;
		}
	}

	cout << max_highest + score << "\n";

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using PL = pair<ll,ll>;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
constexpr int INF = (1 << 29);
constexpr ll INF_ = (1LL << 58);
constexpr ld EPS = (1e-10);
constexpr ld PI_ = 3.141592653589793238;//46264338327950288
constexpr ld E_ = 2.71828182845904523;//5360287471352
constexpr ll MOD = 1000000007;
//// functions (integer)_________________________________
ll modpow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a % m;
		a = a * a%m; n >>= 1;
	}
	return res;
}
long long modinv(long long a, long long p, long long mod){
  return modpow(a,p-2,mod);
}
////-----------------------------------------------------



int main(){
  int N;vector<ll> A; set<ll>P; map<ll,ll> B;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  RPT(i,0,N){
    ll a; cin >> a;
    A.push_back(a);
  }
  sort(A.begin(),A.end());

  FOR(i,2,1000003){
    bool ynprime = true;
    for(auto x : P){
      if(i % x == 0){ ynprime = false; break; }
      if( x*x > i ) break;
    }
    if(ynprime) P.insert(i);
  }

  RPT(i,0,N){
    ll ttl = A[i];
    set<ll>::iterator it = P.find(A[i]);
    if(it!=P.end()){
      ttl = 1;
      if(B[A[i]]<1) B[A[i]] = 1;
    }
    for(auto &xx : P){
      auto x = xx;
      ll cnt = 0;
      if(x > A[i] || ttl == 1) break;
      while(ttl % x == 0){
        ttl /= x;
        cnt++;
      }
      if(cnt){
        if(B[x]<cnt) B[x] = cnt;
      }
    }
    if(ttl != 1) {
      P.insert(A[i]);
      B[A[i]] = 1;
    }
  }

  ll L=1, Ainv = 0;
  for(auto x : P){
    L = ((L * (modpow(x,B[x],MOD))%MOD)) % MOD;
  }
  RPT(i,0,N){
    Ainv = (Ainv + ((modpow(A[i],MOD-2,MOD)%MOD)%MOD) ) % MOD;
  }
  ll ans = (Ainv * L) % MOD;
  //ll ans = (Ainv % MOD);
  cout << ans << endl; 
  //cout << L << endl << Ainv << endl;for(auto x: P) if(B[x]) cout << x << "^" << B[x] << " ";
  return 0;
}

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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int main(){
    long N;
    cin >> N;
    long A[N];
    long sum = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum += A[i];
    }
    if(N == 1){
        YES(1);
        return 0;
    }else if(sum % (N * (N + 1) / 2)){
        YES(0);
        return 0;
    }
    sum /= N * (N + 1) / 2;
    for(int i = 0; i < N - 1; i++){
        if((A[i] - A[i + 1] + sum) % N || A[i] - A[i + 1] + sum < 0){
            YES(0);
            return 0;
        }
    }
    YES((A[N - 1] - A[0] + sum) % N == 0 && A[N - 1] - A[0] + sum >= 0);
}




Measured memory_bytes: 1024