akhauriyash/Code-Regression huggingface dataset:
mod prime_number {

use std::iter::Iterator;

pub struct PrimeFactorization {
    n: usize,
    cur: usize,
    limit: usize,
}

///素因数分解
impl PrimeFactorization {
    ///素因数を計算するイテレータを返す。
    pub fn calc(n: usize) -> PrimeFactorization {
        PrimeFactorization {
            n: n,
            cur: 1,
            limit: (n as f64).sqrt() as usize + 1,
        }
    }
}

impl Iterator for PrimeFactorization {
    type Item = usize;
    fn next(&mut self) -> Option<Self::Item> {
        loop {
            if self.cur == 0 || self.cur > self.n {
                return None;
            }

            self.cur += 1;

            if self.cur > self.limit {
                if self.n != 1 {
                    self.cur = 0;
                    return Some(self.n);
                }
                return None;
            }
            if self.n % self.cur == 0 {
                self.n /= self.cur;
                self.cur -= 1;
                return Some(self.cur + 1);
            }
        }
    }
}

}

use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};

use prime_number::*;
use std::collections::HashMap;

#[fastout]
fn main() {
   input! {
      mut n:usize
   }

   if n == 1 {
      println!("0");
      return;
   }

   let mut v = PrimeFactorization::calc(n).collect::<Vec<_>>();
   let mut map = HashMap::new();
   for i in v {
      *map.entry(i).or_insert(0) += 1;
   }
   let mut ans = 0;
   for (_, mut x) in map {
      let mut k = 1;
      loop {
         if x < k {
            break;
         }
         x -= k;
         ans += 1;
         k += 1;
      }
   }
   println!("{}", ans);
}



Measured memory_bytes: 2216
#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];
  for(int i = 1; i < N; i++) {
    if(H[i] - H[i - 1] > 0) H[i] -= 1;
    else if(H[i] - H[i - 1] == 0) continue;
    else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	while (true) {
		C -= B;
		if (C <= 0) {
			cout << "Yes";
			break;
		}
		A -= D;
		if (A <= 0) {
			cout << "No";
			break;
		}
	}

}

Measured memory_bytes: 3104
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
using namespace std;
int main() {
	long long n, q,ans=0;
	cin >> n >> q;
	vector<long long>question(q),numbers(n);
	for (int i = 0; i < n; ++i) cin >> numbers[i];
	for (int i = 0; i < q; ++i)cin >> question[i];
	long long sum=0;
	for (int i = 0; i < q; ++i) {
		int right = 0;
		for (int left = 0; left < n; ++left) {
			while (right < n&&sum+numbers[right] <= question[i]) {
				sum += numbers[right++];
			}
			ans += right - left;
			if (right == left)++right;
			else sum -= numbers[left];
		}
		cout << ans << endl;
		ans = 0;
	}
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  
  	int l,r,d;
  	cin>>l>>r>>d;
  	int ans = 0;
  	for(int i=l;i<=r;i++){
    	if(i%d==0) ans++;
    }
  	cout<<ans;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




int main() {
    ll n;
    cin >> n;
    
    ll ans = INF;
    for(ll i = 1; i < n; i++){
        ll a = i, b = n - a;
        ll sum = 0;
        while(a){
            sum += a % 10;
            a /= 10;
        }
        while(b){
            sum += b % 10;
            b /= 10;
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int X;
    cin >> X;
    int p = X / 500, q = X % 500, r = q / 5;
    cout << p * 1000 + r * 5;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <functional>

int main(void) {
  int k, n, ans = 0, i;
  scanf("%d%d", &n, &k);
  int l[n];
  for(i = 0; i < n; ++i) scanf("%d", &l[i]);
  std::sort(l, l + n, std::greater<int>());
  for(i = 0; i < k; ++i) ans += l[i];
  printf("%d", ans);
  return 0;
}

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

const int MOD = 1e5;

int conv[256];
int k2b[10946], b2k[1 << 19];

int n, m;
int g[20][20];
int dp[2][10946][2];

int main()
{
	for (int i = 0; i < 4; i++){
		conv["JOI?"[i]] = i;
	}
	
	cin >> n >> m;
	int u = 1;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			char c;
			cin >> c;
			g[i][j] = conv[c];
			if (c == '?') u = (u * 3) % MOD;
		}
	}
	
	int tm = 0;
	for (int i = 0; i < (1 << (m - 1)); i++){
		bool f = true;
		for (int j = 0; j < m - 2; j++){
			if (((i >> j) & 1) & ((i >> (j + 1)) & 1)) f = false;
		}
		if (f){
			k2b[tm] = i;
			b2k[i] = tm;
			tm++;
		}
	}
	
	auto &src = dp[0];
	auto &dst = dp[1];
	int mask = (1 << (m - 1)) - 1;
	src[0][0] = 1;
	for (int i = 0; i < n * m; i++){
		memset(dst, 0, sizeof(dst));
		for (int j = 0; j < tm; j++){
			for (int k = 0; k < 2; k++){
				int x = i / m, y = i % m;
				if (g[x][y] == 0 || g[x][y] == 3){
					int nj = b2k[(k2b[j] << 1) & mask];
					int nk = y < m - 1;
					dst[nj][nk] = (dst[nj][nk] + src[j][k]) % MOD;
				}
				if (g[x][y] == 1 || g[x][y] == 3){
					int nj = b2k[((k2b[j] << 1) & mask) | k];
					int nk = 0;
					dst[nj][nk] = (dst[nj][nk] + src[j][k]) % MOD;
				}
				if (g[x][y] == 2 || g[x][y] == 3){
					if (((~k2b[j]) >> (m - 2)) & 1){
						int nj = b2k[(k2b[j] << 1) & mask];
						int nk = 0;
						dst[nj][nk] = (dst[nj][nk] + src[j][k]) % MOD;
					}
				}
			}
		}
		swap(src, dst);
	}
	
	int res = 0;
	for (int i = 0; i < tm; i++){
		for (int j = 0; j < 2; j++){
			res = (res + src[i][j]) % MOD;
		}
	}

	cout << (u - res + MOD) % MOD << endl;
}

Measured memory_bytes: 3668
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

char mp[2000][2000];
vector<int> sh[2000], sw[2000];
void solve() {
	int h, w; cin >> h >> w;
	rep(i, h)rep(j, w) {
		cin >> mp[i][j];
		if (mp[i][j] == '#') {
			sh[i].push_back(j);
			sw[j].push_back(i);
		}
	}
	rep(i, h) {
		sh[i].push_back(-1); sh[i].push_back(w);
		sort(sh[i].begin(), sh[i].end());
	}
	rep(i, w) {
		sw[i].push_back(-1); sw[i].push_back(h);
		sort(sw[i].begin(), sw[i].end());
	}
	int ma = 0;
	rep(i, h) {
		rep(j, w) {
			if (mp[i][j] == '#')continue;
			int sum = 1;
			int id = lower_bound(sh[i].begin(), sh[i].end(),j) - sh[i].begin();
			sum += sh[i][id] - sh[i][id - 1] - 2;
			id = lower_bound(sw[j].begin(), sw[j].end(), i) - sw[j].begin();
			sum += sw[j][id] - sw[j][id - 1] - 2;
			ma = max(ma, sum);
		}
	}
	cout << ma << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(9);
	//init();
	//while (cin >> n>>m>>l,n)solve();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 38272
#include<bits/stdc++.h>
using namespace std;
struct Node{
	   int father,left,right,child,id;
};
struct Node T[100001];
int n,k,id,x,y;
int getheight(Node u){
	 int h1,h2;
	 h1=h2=0;
	 if (u.right!=-1)
	    h1=getheight(T[u.right])+1;
	 if (u.left!=-1)
	    h2=getheight(T[u.left])+1;
	 return max(h1,h2);
}
int getdepth(Node u){
	int d=0;
	while (u.father!=-1){
		  u=T[u.father];
		  d++;
	}
	return d;
}
string check(Node u){
	   if (u.father==-1)
	      return "root";
	   if (u.child==0)
	      return "leaf";
	   return "internal node";
}
int main(){
    cin>>n;
    for (int i=0; i<n; i++){
    	T[i].father=T[i].left=T[i].right=-1; 
	}
    int l;
	for (int i=0; i<n; i++){
		cin>>id>>x>>y;
		T[id].left=x; T[id].right=y;
		T[id].id=id;  T[id].child=2;
 	    if (T[id].left!=-1)
		   T[T[id].left].father=id; 
		if (T[id].right!=-1)
		   T[T[id].right].father=id; 
	    if (T[id].left==-1) T[id].child--;
	    if (T[id].right==-1) T[id].child--;
	}
	Node u;
	for (int i=0; i<n; i++){
		u=T[i];
		cout<<"node "<<i<<":"<<" parent = "<<u.father;
		cout<<", sibling = ";
		if (T[u.father].left!=u.id){
			if (u.father!=-1)
			   cout<<T[u.father].left;
			else
			   cout<<-1;
		}
		else{
			if (u.father!=-1)
			   cout<<T[u.father].right;
			else
			   cout<<-1;
	    }
	    cout<<", degree = ";
	    int tot=2;
	    if (u.left==-1) tot--;
	    if (u.right==-1) tot--;
		cout<<tot<<", depth = "<<getdepth(T[i]);
		cout<<", height = "<<getheight(u)<<", "<<check(T[i])<<endl;

		
	}	
	return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main() {
    
    ll a, p;
    cin >> a >> p;
    
    ll r = 0;
    
    r = (a * 3 + p) / 2;
    
    
    cout << r;

}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  ll bb=0;
  vll a(n),b(n);
  vll ab(n);
  rep(i,n){
    cin>>a[i]>>b[i];
    ab[i]=a[i]+b[i];
    bb-=b[i];
  }
  sort(rall(ab));
  rep(i,n){
    bb+=ab[i];
    i++;
  }
  COUT(bb);
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  vector<ll> d;
  ll ans=0;
  for(ll i=1;i*i<=n;i++){
    ll t=(n+i-1)/i-1;
    if(t!=0){
      if(n%t==n/t){
        ans+=t;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, n, a) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, n, 0)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b, c;
    cin >> a >> b >> c;
    if (a + b >= c)
    {
        cout << b + c << endl;
    }
    else
    {
        cout << 2 * b + a + 1 << endl;
    }
}

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

int main()
{
	int n;
	int a[210];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int res = 0;
	while (true) {
		bool odd = false;
		for (int j = 0; j < n; j++) {
			if (a[j] % 2 != 0) {
				odd = true;
			}
		}
		if (odd) {
			break;
		}
		for (int k = 0; k < n; k++) {
			a[k] /= 2;
		}
		res++;
	}
	cout << res << endl;
}

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

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

    int ans = n;
    for (int i = 1; i < n; i++) {
        int sum=0, tmp_i=i, tmp_n=n-i;
        while (tmp_i) {
            int dig = tmp_i % 10;
            sum += dig;
            tmp_i /= 10;
        }
        while (tmp_n) {
            int dig = tmp_n % 10;
            sum += dig;
            tmp_n /= 10;
        }

        ans = min(ans, sum);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int n, ans=0;
	string a, b, c;
	cin >> n;
	cin >> a >> b >> c;
	for(int i=0; i<n; i++){
		if(a[i]!=b[i] && b[i]!=c[i] && c[i]!=a[i]){
			ans+=2;
		} else if(a[i]==b[i] && b[i]==c[i]){
			ans+=0;
		} else {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 888
n,m = map(int,input().split())
py = [list(map(int,input().split())) for i in range(m)]
c = [0]*n
sort_py = sorted(py,key=lambda x:x[1])
ans = dict()
for p,y in sort_py:
    c[p-1] += 1
    ans[p,y] = str(p).zfill(6)+str(c[p-1]).zfill(6)

for p,y in py:
    print(ans[p,y])

Measured memory_bytes: 48528
#include<bits/stdc++.h>
 
using namespace std;
 
int const size = 21;
int dp[1<<size];
int arr[30][30];
int mod = 1e9 + 7;
 
int countbits(int x){
	int count = 0 ;
	while(x){
		count++;
		x = x&x-1;
	}
	return count;
}
 
long long int solve(int x, int n){
	if(x == (1<<n) -1) return 1;
	if(x >= (1<<n)) return 0;
	if(dp[x] != -1) return dp[x];
	int ans = 0;
	int count = countbits(x);
	// cout<<x<<" "<<n<<"\n";
 
	for(int i=0;i<n;i++){
		if(!(x&(1<<i)) && arr[count][i] == 1) ans += solve(x | (1<<i), n)%mod;
		ans%=mod;
	}
	dp[x] = ans;
	return dp[x];
}
 
int main(){
	int n;
	scanf("%d",&n);
	for(int x=0;x<n;x++){
		for(int i=0;i<n;i++) scanf("%d",&arr[x][i]);
	}
	for(int x=0;x<(1<<n);x++) dp[x] = -1;
 
	cout<<solve(0,n);
	return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

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

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N;
    string S;
    cin >> N >> S;

    char c = S[0];
    int ans = 1;
    for (int i = 0; i < N; i++) {
        if (c != S[i]) {
            ans++;
            c = S[i];
        }
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> a(N);
    rep(i, N) cin >> a.at(i);
    vector<ll> b(M);
    rep(i, M) cin >> b.at(i);
    vector<ll> ans = convolution(a, b);
    rep(i, N+M-2){
      cout << ans.at(i) << " ";
    }
    cout << ans.at(N+M-2) << endl;
}

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

def solve():
    N = int(input())
    Cs = input()

    ans = 0
    left, right = 0, N-1
    while left <= right:
        if Cs[left]=="W" and Cs[right]=="R":
            ans += 1  # 石を入れ替える
            left, right = left+1, right-1
            continue
        elif Cs[left]=="W" and Cs[right]=="W":
            right -= 1
            continue
        elif Cs[left]=="R" and Cs[right]=="R":
            left += 1
            continue
        else:
            left, right = left+1, right-1
            continue


    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 9392
#include<bits/stdc++.h>
using namespace std;
int main(void){
  char S[100000];
  scanf("%s",S);
  int count0=0,count1=0,count=0;
  char *p;
  p=S;
  while(*p!='\0'){
    if(S[count]=='1'){
      count1++;
    }
    else{
      count0++;
    }
    p++;
    count++;
  }
  cout << 2*min(count0,count1) << endl;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Abc166D
    {
        public static void Main()
        {
            var x = long.Parse(Console.ReadLine());
            var afoot = (long)Math.Ceiling(Math.Pow(x, 1.0 / 4));

            for (long a = 1; a <= afoot; a++)
            {
                var a5 = (long)Math.Pow(a, 5);
                for (long b = 0; b < a; b++)
                {
                    long y = a5 - (long)Math.Pow(b, 5);
                    if (x == y)
                    {
                        Console.WriteLine($"{a} {b}");
                        return;
                    }
                    else if (x > y)
                        break;
                }
            }

            afoot = (long)Math.Ceiling(Math.Pow(x, 1.0 / 5));
            for (long a = 0; a <= afoot; a++)
            {
                var a5 = (long)Math.Pow(a, 5);
                for (long b = 0; b <= a; b++)
                {
                    long y = a5 + (long)Math.Pow(b, 5);
                    if (x == y)
                    {
                        Console.WriteLine($"{a} {-b}");
                        return;
                    }
                    else if (x < y)
                        break;
                }
            }
        }
    }
}


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

int main() {
  int w,h;
  cin >> w>>h;
  vector<vector<int>>pq(w+h,vector<int>(2));
  vector<int>p(w);
  rep(i,w){
    cin>>p.at(i);
    pq.at(i).at(0)=p.at(i);
    pq.at(i).at(1)=1;
  }
  vector<int>q(h);
  rep(i,h){
    cin>>q.at(i);
    pq.at(i+w).at(0)=q.at(i);
    pq.at(i+w).at(1)=2;
  }
  sort(pq.begin(),pq.end());
  long ans=0;
  long a=w+1;
  long b=h+1;
  rep(i,w+h){
    if(pq.at(i).at(1)==1){
      ans+=pq.at(i).at(0)*b;
      a--;
    }
    else{
      ans+=pq.at(i).at(0)*a;
      b--;
    }
  }
  
  cout<<ans<<endl;
}



Measured memory_bytes: 12032
#include<stdio.h>

int main(){
  
  int x,y,n;
  scanf("%d%d",&x,&y);
  if(x>=y){
    n=x%y;
    while(n!=0){
      x=y;
      y=n;
      n=x%y;
    }
    printf("%d\n",y);
  }
  else{
    n=y%x;
    while(n!=0){
      y=x;
      x=n;
      n=y%x;
    }
    printf("%d\n",x);
  }
  return 0;
}

Measured memory_bytes: 592
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        String S=  sc.next();

        List<Integer> list = new ArrayList<>();
        List<Character> list01 = new ArrayList<>();
        char prev = S.charAt(0);
        int count =1;
        for (int i = 1; i < S.length(); i++) {
            char c = S.charAt(i);
            if(prev==c){
                count++;
            }else{
                list.add(count);
                list01.add(prev);
                count=1;
            }
            prev=c;
        }
        list.add(count);
        list01.add(prev);

        if(list01.get(0)=='0'){
            list.add(0,0);
        }
        if(list01.get(list01.size()-1)=='0'){
            list.add(0);
        }
        int ans=0;
        int width = 2*K+1;

        //TLE  n^2
//        for (int i = 0; i < list.size() ; i=i+2) {
//            int len = 0;
//            for (int j = i; j <= Math.min( width+i-1,list.size()-1) ; j++) {
//                len += list.get(j);
//            }
//            ans = Math.max(ans,len);
//        }

        //尺取り

        int len = 0;
        for (int j = 0; j <= Math.min( width-1,list.size()-1) ; j++) {
            len += list.get(j);
        }
        ans = Math.max(ans,len);

        for (int i = 2; i < list.size() ; i=i+2) {
            int left = list.get(i-2) +list.get(i-1);
            int right = 0;
            if(i+width-1<list.size()){
                right = list.get(i+width-2) +list.get(i+width-1);
            }
            len = len - left + right;
            ans = Math.max(ans,len);
        }

        System.out.println(ans);
    }
}


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

int n;
pair<pair<string, int> , int> v[111];

int main() {
	cin>>n;
	for(int i=0;i<n;i++) {
		cin>>v[i].first.first>>v[i].first.second;
		v[i].first.second*=-1;
		v[i].second = i+1;
	}
	sort(v, v+n);
	for(int i=0;i<n;i++) 
		cout<<v[i].second<<endl;
	
	return 0;
}

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

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

int N;
vector<ll> A;
vector<ll> sum;

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

    cin >> N;
    A.resize(N);
    sum.resize(N+1);
    rep(i, N) cin >> A[i];
    rep(i, N) sum[i+1] = sum[i] + A[i];

    ll res = 1LL << 60;
    reps(i, N) {
        // P < Qの境を求める。lowはP < Q, highはP >= Q
        int low = 0, high = i;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] >= sum[i] - sum[mid]) high = mid;
            else low = mid;
        }
        ll p = sum[low], q = sum[i] - sum[low];
        ll p2 = sum[high], q2 = sum[i] - sum[high];
        ll left_min = min(p, q), left_max = max(p, q);
        if (abs(p2 - q2) < abs(p - q)) {
            left_min = min(p2, q2), left_max = max(p2, q2);
        }
        low = i, high = N;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] - sum[i] >= sum[N] - sum[mid]) high = mid;
            else low = mid;
        }
        ll r = sum[low] - sum[i], s = sum[N] - sum[low];
        ll r2 = sum[high] - sum[i], s2 = sum[N] - sum[high];
        ll right_min = min(r, s), right_max = max(r, s);
        if (abs(r2 - s2) < abs(r - s)) {
            right_min = min(r2, s2), right_max = max(r2, s2);
        }
        ll tmp = max(left_max, right_max) - min(left_min, right_min);
        res = min(res, tmp);
    }
    cout << res << endl;
    return 0;
}

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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	double W, H, x, y;
	
	cin >> W >> H >> x >> y;
	
	if(x*2 == W && y*2 == H){
		printf("%.10f %d", W*H/2, 1);
	}else
		printf("%.10f %d", W*H/2, 0);
	
	return 0;
}

Measured memory_bytes: 256
class AdjacentGraph:
    """Implementation adjacency-list Graph.
    Beware ids are between 1 and size.
    """
    def __init__(self, size):
        self.size = size
        self._nodes = [[0] * (size+1) for _ in range(size+1)]

    def set_adj_node(self, id_, adj_id):
        self._nodes[id_][adj_id] = 1

    def __iter__(self):
        self._id = 0
        return self

    def __next__(self):
        if self._id < self.size:
            self._id += 1
            return (self._id, self._nodes[self._id][1:])

        raise StopIteration()


def run():
    n = int(input())
    g = AdjacentGraph(n)

    for i in range(n):
        id_, c, *links = [int(x) for x in input().split()]
        for n in links:
            g.set_adj_node(id_, n)

    for id_, nodes in g:
        print(" ".join([str(x) for x in nodes]))


if __name__ == '__main__':
    run()



Measured memory_bytes: 5688
// ?????¬???????????¬?????? (define int long long ?????????)

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)

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

typedef pair<int, int> pii;
typedef long long ll;

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


const int INF = 1 << 25;

int H, W, N;
char board[1010][1010];
int dist[1010][1010];
int x[10], y[10];

int bfs(int sx, int sy, int tx, int ty) {
    rep(i,0,H) rep(j,0,W) dist[i][j] = INF;
    dist[sx][sy] = 0;

    queue<pii> que;
    que.push(make_pair(sx, sy));

    while(que.size()) {
        pii cur = que.front(); que.pop();
        int cx, cy;
        tie(cx, cy) = cur;

        rep(k,0,4) {
            int nx = cx + dx[k], ny = cy + dy[k];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if(board[nx][ny] == 'X') continue;
            if(dist[nx][ny] > dist[cx][cy] + 1) {
                dist[nx][ny] = dist[cx][cy] + 1;
                que.push(make_pair(nx, ny));
            }
        }
    }

    return dist[tx][ty];
}

int main() {
    cin >> H >> W >> N;
    rep(i,0,H) rep(j,0,W) {
        cin >> board[i][j];
        if(board[i][j] == 'S') board[i][j] = '0';
        if(isdigit(board[i][j])) {
            int val = board[i][j] - '0';
            x[val] = i, y[val] = j;
        }
    }

    int ans = 0;
    rep(i,0,N) {
        ans += bfs(x[i], y[i], x[i+1], y[i+1]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
	int i;
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]){
		cout<<"YES";
	}
	else cout<<"NO";
}

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

int main(){
  vector<int>a(3);
  for(int i = 0; i<3; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  cout << a.at(0) << " " << a.at(1) << " " << a.at(2) << endl;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> A(N);
    rep(i, N) {
        int a;
        cin >> a;
        A[i] = {a, i + 1};
    }
    
    vector<int> ans;
    while (A.size()) {
        int k = -1;
        for (int i = A.size() - 1; i >= 0; --i) {
            if (A[i].first == A[i].second) {
                k = i;
                break;
            }
        }
        if (k == -1) {
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(A[k].first);
        A.erase(A.begin() + k);
        rep(i, A.size()) A[i].second = i + 1;
    }
    reverse(ans.begin(), ans.end());
    rep(i, N) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N, M;
	cin >> N >> M;

	vector<pair<int, int>> h(N);
	vector<int> ans(N);
	vector<int> min(N, INF32);

	for (int i = 0; i < N; i++)
	{
		int x, y;
		cin >> x >> y;
		h[i].first = x;
		h[i].second = y;
	}

	for (int i = 0; i < M; i++)
	{
		int x, y;
		cin >> x >> y;

		for (int j = 0; j < N; j++)
		{
			int dis = abs(h[j].first - x) + abs(h[j].second - y);
			if (dis < min[j])
			{
				min[j] = dis;
				ans[j] = i + 1;
			}
		}
	}

	for (auto out : ans)
	{
		cout << out << endl;
	}
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>

using namespace std;

#define MAX_H 30
#define MAX_W 30

#define DIR_UP 0
#define DIR_RIGHT 1
#define DIR_DOWN 2
#define DIR_LEFT 3

#define INST_STRAIGHT 0
#define INST_RIGHT 1
#define INST_BACK 2
#define INST_LEFT 3

#define REP(i,a,e) for(int i = (int)(a); i < (int)(e); ++i)

const int inv = -1;
const int infty = 1<<27;
const int di[] = {0,1,0,-1};
const int dj[] = {-1,0,1,0};

int h,w;
int map[MAX_H][MAX_W];
bool G[MAX_H][MAX_W][MAX_H][MAX_W];
int W[MAX_H][MAX_W][4];
int C[4];

void ResetGraph(){
  h=0;
  w=0;
  C[0]=C[1]=C[2]=C[3]=0;
  REP(i,0,MAX_H){
    REP(j,0,MAX_W){
      REP(k,0,MAX_H){
	REP(l,0,MAX_W){
	  G[i][j][k][l] = false;
	}
      }
      map[i][j] = inv;
      REP(k,0,4)
	W[i][j][k]=infty;
    }
  }
}

bool isInside(int i, int j){
  return 0<=i&&i<h&&0<=j&&j<w;
}

struct state{
  int i,j;
  int dir;
  int cost;
  bool operator<(const state &t)const{
    return cost > t.cost;
  }
};

bool isGoal(int i, int j){ return i==h-1&&j==w-1; }

pair<int,int> proceed(int i, int j, int dir){
  switch(dir){
  case DIR_UP: return make_pair(i-1,j);
  case DIR_RIGHT: return make_pair(i,j+1);
  case DIR_DOWN : return make_pair(i+1,j);
  case DIR_LEFT: return make_pair(i,j-1);
  }
  return make_pair(-1,-1);
}

int Dijkstra(){
  priority_queue< state > pq;
  state st;

  st.i = 0;
  st.j = 0;
  st.dir = DIR_RIGHT;
  st.cost = 0;

  pq.push(st);
  while(!pq.empty()){
    st = pq.top();
    pq.pop();

    if( W[st.i][st.j][st.dir] <= st.cost ) continue;
    if( W[st.i][st.j][st.dir] > st.cost ) W[st.i][st.j][st.dir] = st.cost;
    if( isGoal( st.i, st.j ) ) return st.cost;
    // if( map[st.i][st.j] == 4 ) continue;

    // cout << "I:"<<st.i << " J:"<<st.j<<" DIR : " << st.dir << " COST : " << st.cost<<endl;

    for(int d=0;d<4;++d){
      state next=st;
      next.dir = (st.dir+d)%4;
      pair<int,int> np = proceed( st.i, st.j, next.dir );
      
      // cout << " NEXT : " << np.first << " , " << np.second << endl;
      if( isInside( np.first, np.second ) ){
	next.i = np.first;
	next.j = np.second;
	
	if( d != map[st.i][st.j] )
	  next.cost += C[ d ];
	pq.push( next );
      }
    }
  }
  return -1;
}

int main(){

  while(true){
    ResetGraph();

    cin >> w >> h;
    if(w==0&&h==0)break;

    REP(i,0,h){
      REP(j,0,w){
	cin >> map[i][j];
      }
    }

    cin >> C[0] >> C[1] >> C[2] >> C[3];

    cout << Dijkstra() << endl;

    //break;
  }
  return 0;
}

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

int main()
{
  	string s;
  	cin >> s;
  	if (s[0] >= '2') {
      	if (s[2] >= '1' && s[3] >= '9' && (s[5] == '1' || s[6] >= '5'))
         	cout << "TBD" << endl;
      	else
          	cout << "Heisei" << endl;
    }
  	else {
    	 cout << "Heisei" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * 0066 Tic Tac Toe
 */
public class Main {

	public static void main(String[] args) throws IOException {
		List<TicTacToe> ticTacToeList = readTicTacToe();
		for (TicTacToe ticTacToe : ticTacToeList) {
			// System.out.println(ticTacToe);
			System.out.println(ticTacToe.judge());
		}
	}

	private static List<TicTacToe> readTicTacToe() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		List<TicTacToe> ticTacToeList = new ArrayList<>();
		String line = null;
		while ((line = reader.readLine()) != null) {
			ticTacToeList.add(new TicTacToe(line));
		}
		return ticTacToeList;
	}

	// Tic Tac Toe
	private static class TicTacToe {

		// Win pattern
		private static final List<Pattern> WIN_PATTERN = Arrays.asList(Pattern.compile(".*1.*4.*7.*"),
				Pattern.compile(".*2.*5.*8.*"), Pattern.compile(".*3.*6.*9.*"), Pattern.compile(".*1.*2.*3.*"),
				Pattern.compile(".*4.*5.*6.*"), Pattern.compile(".*7.*8.*9.*"), Pattern.compile(".*1.*5.*9.*"),
				Pattern.compile(".*3.*5.*7.*"));

		// position
		private Map<Character, String> positionMap = new HashMap<>();

		// Constructor
		public TicTacToe(String input) {
			// Init map
			positionMap.put('o',  "");
			positionMap.put('x',  "");

			// Set positions
			for (int i = 0; i < input.length(); i++) {
				char name = input.charAt(i);
				if (name == 'o' || name == 'x') {
					positionMap.put(name, positionMap.get(name) + (i + 1));
				}
			}

		}

		// Judge
		private char judge() {
			// If position matches win pattern, the player win
			for (Character key : positionMap.keySet()) {
				for (Pattern p : WIN_PATTERN) {
					if (p.matcher(positionMap.get(key)).matches()) {
						return key;
					}
				}
			}
			// If none win, this game is draw
			return 'd';
		}

		@Override
		public String toString() {
			final StringBuilder result = new StringBuilder();
			positionMap.forEach((k, v) -> result.append(k + ":" + v + ", "));
			return result.toString();
		}
	}
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    cout << (n+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let w: f64 = scan(tokens);
    let h: f64 = scan(tokens);
    let x: f64 = scan(tokens);
    let y: f64 = scan(tokens);
    let ans = w * h / 2.0;
    if x == w / 2.0 && y == h / 2.0 {
        println!("{} 1", ans);
    } else {
        println!("{} 0", ans);
    }
}


Measured memory_bytes: 4352
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	io_init;
	int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vector<int> p(A), q(B), r(C);
	for (int i = 0; i < A; i++)cin >> p[i];
	for (int i = 0; i < B; i++)cin >> q[i];
	for (int i = 0; i < C; i++)cin >> r[i];
	sort(p.begin(), p.end(), greater<>());
	sort(q.begin(), q.end(), greater<>());
	sort(r.begin(), r.end(), greater<>());
	ll s = 0;
	priority_queue<int> que;
	for (int i = 0; i < X; i++) {
		s += p[i];
		que.push(-p[i]);
	}
	for (int i = 0; i < Y; i++) {
		s += q[i];
		que.push(-q[i]);
	}
	ll ans = s;
	for (int i = 0; i < min(C, X + Y); i++) {
		auto a = que.top(); que.pop();
		s += a + r[i];
		ans = max(ans, s);
	}
	cout << ans << endl;
}


Measured memory_bytes: 2552
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;
using ll  = long long;
template <typename T> T In() {
    T t;
    cin >> t;
    return t;
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(i, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}


int main() {
    ll A = In<ll>();
    ll B = In<ll>();
    if((A+B)%2==0){
        cout << (A + B) / 2 << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int S(long int x){
	int r=0;
	while(x>0){r+=x%10;x/=10;}
	return r;
}

int main(){
  long int n,i,j,x=1,y,r,s;
  double m,o;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    printf("%ld\n",x);
    r=++x;
  	m=(double)x/S(x);
  	for(j=0,s=10;j<15;j++,s*=10L){
  		y=s*(x/s+1)-1;o=(double)y/S(y);
  		if(o<m){m=o;r=y;}
  	}
    x=r;
  }
}


Measured memory_bytes: 1688
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;


void solve()
{
   
    int n;
    cin>>n;
    int ans=power(10,n,hell);
    ans=(ans-(2*power(9,n,hell))%hell+hell)%hell;
    ans=(ans+(power(8,n,hell)))%hell;
    cout<<ans<<endl;
    
    
    
}

int32_t main()
{
    IOS;
    
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}







Measured memory_bytes: 3624
n=int(input())
s=input()
l=len(s)
u=[]
for i in range(l):
  u.append(s[i])
alp=[]
d="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for j in range(26):
  alp.append(d[j])
for k in range(l):
  for h in range(26):
    if u[k]==alp[h]:
      u[k]=alp[(h+n)%26]
      break

for b in range(l):
  print(u[b], end="")


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,L;
    cin >> N >> L;
    ll ans = INF, ans_val = -1;
    rep(i,0,N){
        ll v1 = L + i;
        ll v2 = 0;
        rep(j,0,N){
            if(i == j) continue;
            v2 += L+j;
        }
        if(ans > abs(L+i)){
            ans = abs(L+i);
            ans_val = v2;
        }
    
    }
    print(ans_val);
    
}

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

int N, Y;
int x, y, z;

int main(void) {
  cin >> N >> Y;
  
  for (int i = N; i >= 0; i--) {
    for (int j = 0; j + i <= N; j++) {
      int ans = Y - (i * 10000 + j * 5000);
      if (ans >= 0 && i + j + ans / 1000 == N) {
        cout << i << " " << j << " " << ans / 1000 << endl;
        exit(0);
      }
    }
  }

  cout << "-1 -1 -1" << endl;
  return 0;
}


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

const int MAX = 200000;
const int MAX2 = 28;

int binarySearch(int *b, int check, int max) {
	int min = -1;
	for (int mid = max >> 1;max - min > 1;mid = min + (max - min >> 1)) {
		if (b[mid] >= check) max = mid;
		else min = mid;
	}
	return max;
}
int main() {
	static int N, a[MAX], b[MAX];
	cin >> N;
	for (int i = 0;i < N;++ i) cin >> a[i];
	for (int i = 0;i < N;++ i) cin >> b[i];
	
	int ans = 0, tmp;
	for (int i = 1 << MAX2;i > 0;i >>= 1) {
		for (int j = 0;j < N;++ j) {
			a[j] &= (i << 1) - 1;
			b[j] &= (i << 1) - 1;
		}
		sort(b, b+N);
		tmp = 0;
		for (int j = 0;j < N;++ j) {
			tmp += binarySearch(b, (i << 2) - a[j], N) - binarySearch(b, (i | i << 1) - a[j], N) + binarySearch(b, (i << 1) - a[j], N) - binarySearch(b, i - a[j], N);
		}
		ans |= (tmp & 1) == 0 ? 0 : i;
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

解説AC、これは無理でした
*/

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


int main(){ 
    char x;
	int a,b,c;

	cin>>a>>x>>b;
	if(x=='+'){
		c = a + b;
		cout<<c;
	}
	else if(x=='-')
	{
		c = a - b;
		cout<<c;
	}
} 

Measured memory_bytes: 256
import java.util.Scanner;
import java.io.PrintWriter;
import java.util.Deque;
import java.util.ArrayDeque;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int N = Integer.parseInt(sc.next());
        String[] allN = new String[N];
        int[][] town = new int[N][2];
        Deque<String> q = new ArrayDeque<String>();
        for (int i = 0; i < N; i++){
            town[i][0] = Integer.parseInt(sc.next());
            town[i][1] = Integer.parseInt(sc.next());
            allN[i] = Integer.toString(i);
            q.addLast(Integer.toString(i));
        }
        
        int perm = N;
        String order;
        for (int i = 1; i < N; i++){
            for (int j = 0; j < perm; j++){
                order = q.pollFirst();
                for (int k = 0; k < N; k++){
                    if (!order.contains(allN[k])){
                        q.addLast(order+allN[k]);
                    }
                }
            }
            perm *= (N - i);
        }

        double Dist = 0;
        double currDist;
        int a, b;
        for (int j = 0; j < perm; j++){
            order = q.pollFirst();
            //out.println(order);
            currDist = 0;
            for (int i=0; i < N -1; i++){
                a = Integer.valueOf(order.substring(i, i+1));
                b = Integer.valueOf(order.substring(i+1, i+2));
                currDist += Math.sqrt(Math.pow((town[a][0] - town[b][0]), 2) + Math.pow((town[a][1]-town[b][1]), 2));
            }
            Dist += currDist;
        }
        out.println(Dist / perm);

        //テンプレ
        sc.close();
        out.flush();
    }
}

Measured memory_bytes: 62448