akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    #cost[i]:i日後に報酬が貰える仕事の報酬
    cost = [[] for _ in range(10**5+10)]
    for _ in range(n):
        a,b = map(int, input().split())
        cost[a].append(b)

    res = 0
    hq = [0]
    heapq.heapify(hq)
    for i in range(1, m+1):
        for c in cost[i]:
            heapq.heappush(hq, -c)
        if not hq:
            continue
        res -= heapq.heappop(hq)
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 18704
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, c;
  cin >> a >> b >> c;
  if (a + b == c || a + c == b || b + c == a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main()
{
	int N, L;
	cin >> N >> L;
	int sum = 0;
	if (L + N - 1 < 0)
	{
		for (int i = 0; i < N - 1; ++i)
		{
			sum += L + i;
		}
	}
	else if (L > 0)
	{
		for (int i = 1; i < N; ++i)
		{
			sum += L + i ;
		}
	}
	else
	{
		for (int i = 0; i < N; ++i)
		{
			sum += L + i;
		}
	}
	cout << sum;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int K;
    cin >> K;

    vector<i64> A(K);
    rep(i,0,K) cin >> A[i];

    i64 l=2,r=2;
    for(int i=K-1; i>=0; --i){
        l=(l+A[i]-1)/A[i]*A[i];
        r=r/A[i]*A[i];
        if(l>r){
            cout << -1 << endl;
            return;
        }
        r=r+A[i]-1;
    }

    cout << l << " " << r << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

using namespace std;

int main(){
string s;
cin >> s;
string s1 = s.substr(0, 5);  
string s2 = s.substr(6, 7); 
string s3 = s.substr(14, 5); 
string ans = s1 + " " + s2 + " " + s3;  
cout << (ans) << endl;
return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(input())
b = list(input())
c = list(input())
counter = 0
for i in range(n):
    if a[i] == b[i] == c[i]:
        counter += 0
    elif a[i] == b[i] or b[i] == c[i] or a[i] == c[i]:
        counter += 1
    else:
        counter += 2
print(counter)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

#define pii pair<int, int>

const int N = 5e4 + 5;
const int M = 1e5 + 5;

int n, m, type;
char ans[M];
int us[M], vs[M];

namespace subtask1 {

	bitset<N> f[M];
	boolean vis[M];
	int h[N], A[M], B[M];

	void F(int p, int x) {
		if (!p || vis[p]) {
			return;
		}
		vis[p] = true;
		if (x == us[p]) {
			F(A[p], x);
			F(B[p], vs[p]);
		} else {
			ans[p] = 'v';
			F(B[p], x);
			F(A[p], us[p]);
		}
	}

	void solve() {
		for (int i = 1, u, v; i <= m; i++) {
			u = us[i], v = vs[i];
			if (!h[u]) {
				f[i].set(u);	
			} else {
				f[i] = f[h[u]]; 
			}
			swap(u, v);
			if (!h[u]) {
				f[i].set(u);	
			} else {
				f[i] |= f[h[u]]; 
			}
			swap(u, v);
			A[i] = h[u], B[i] = h[v];
			h[u] = h[v] = i;
		}
		for (int i = 1; i <= m; i++)
			ans[i] = '^';
		for (int i = 1; i <= m; i++) {
			if ((signed) f[i].count() == n) {
				F(i, us[i]);
				puts(ans + 1);
				return;
			}
		}
		puts("-1");
	}

}

namespace subtask2 {
	
	const int C = 451;

	set<pii> S;
	int h[C];
	int nxt[M][C];
	bitset<C> vis[M][2];

	boolean dfs(int p, int x, int y) {
		if (x == y) {
			return false;
		}
		if (p == m + 1) {
			return true;
		}
		int sx = -1, sy = -1;
		if (x == us[p] || y == us[p]) {
			sx = 0, sy = x ^ y ^ us[p];
		} else {
			sx = 1, sy = x ^ y ^ vs[p];
		}
		if (vis[p][sx].test(sy))
			return false;
		vis[p][sx].set(sy);

		// down
		int nx = (x == us[p]) ? vs[p] : x;
		int ny = (y == us[p]) ? vs[p] : y;
		if (dfs(min(nxt[p][nx], nxt[p][ny]), nx, ny)) {
			ans[p] = 'v';
			return true;
		}

		nx = (x == vs[p]) ? us[p] : x;
		ny = (y == vs[p]) ? us[p] : y;
		if (dfs(min(nxt[p][nx], nxt[p][ny]), nx, ny)) {
			ans[p] = '^';
			return true;
		}
		return false;
	}

	void solve() {
		for (int i = 1; i <= m; i++) {
			S.insert(pii(us[i], vs[i]));
		}
		if ((signed) S.size() < 1ll * n * (n - 1) / 2) {
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					if (!S.count(pii(i, j))) {
						for (int k = 1; k <= m; k++) {
							if (us[k] == i || us[k] == j) {
								ans[k] = '^';
							} else {
								ans[k] = 'v';
							}
						}
						puts(ans + 1);
						return;
					}
				}
			}
			assert(false);
			return;
		}
		assert(n < C);
		for (int i = 1; i <= m; i++)
			ans[i] = 'v';
		for (int i = 1; i <= n; i++)
			h[i] = m + 1;
		for (int i = m; i; i--) {
			memcpy(nxt[i], h, sizeof(h));
			h[us[i]] = h[vs[i]] = i;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				if (dfs(min(h[i], h[j]), i, j)) {
					puts(ans + 1);
					return;
				}
			}
		}
		puts("-1");
	}

}

int main() {
	scanf("%d%d%d", &n, &m, &type);
	for (int i = 1; i <= m; i++) {
		scanf("%d%d", us + i, vs + i);;
	}
	if (type == 1) {
		subtask1::solve();
	} else {
		subtask2::solve();
	}
	return 0;
}


Measured memory_bytes: 614272
import collections
N = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A)
C = [i[0] for i in B.items() if i[1] >= 2]
D = [i[0] for i in B.items() if i[1] >= 4]
C.sort(reverse=True)
D.sort(reverse=True)
if len(C)==0 or len(C)==1 and len(D)==0:
    print(0)
elif len(C)>1 and len(D)==0:
    print(C[0]*C[1])
elif len(C)==0 and len(D)>0:
    print(D[0]*2)
elif len(C)==1 and len(D)>0:
    print(max(C[0]*D[0],D[0]*2))
else:
    print(max(D[0]*2,C[0]*C[1],C[0]*D[0]))

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

int main() {
    int N;
    cin >> N;
    map<string, int> map_;
    for(int i=0; i<N; i++) {
        string S;
        cin >> S;
        map_[S]++;
    }

    int max_ = 0;
    for(const auto i : map_) 
        if(max_ < i.second) max_ = i.second;

    for(const auto i : map_) 
        if(max_ == i.second) cout << i.first << endl;
}


Measured memory_bytes: 25216
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
int kaijo(int n){
	int ans = 1;
	if (n != 0){
		for (int i = 0; i < n; i++){
			ans *= (n - i);
		}
	}
	else{
		ans = 1;
	}
	return ans;
}

int main(){
	int a[10000];
	string s="";
	int cnt = 1;
	int cnt2 = 0;
	int b;
	int c = 1;
	int q;
	int m = 0;
	int flag = 0;
	int h,w;
	cin >> h;
	cin >> w;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	//for (int i1 = 0; i1 < w; i1++){
	q = a[0];
	while (1){
		
		if (c>n){
			break;
		}
		
		q = q-m;
		//cout << q <<"あ"<< endl;
		b = cnt2 / 2;
		if (b * 2 == cnt2){
			for (int i2 = 0; i2 < q; i2++){
				if (cnt == w) {
					cout << c << endl;
					flag = 1;
					cnt = 1;
					m = i2 + 1;
					cnt2++;
					break;
				}
				else{
					cout << c<<" ";
					cnt++;
				}
			}
		}
		else{
			for (int i2 = 0; i2 < q; i2++){
				if (cnt == w) {
					//cout << c << endl;
					s = to_string(c)+" " + s;
					s.pop_back();
					cout << s << endl;
					flag = 1;
					cnt = 1;
					m = i2 + 1;
					cnt2++;
					s = "";
					break;
				}
				else{
					//cout << c;
					s = to_string(c)+" " + s;
					cnt++;
				}
			}
		}
		if (flag == 0){
			c++;
			m = 0;
			q = a[c - 1];
			//cnt = 1;
		}
		flag = 0;
		
		
	}
	//cout << c << endl;
	//}
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

int n,A,B,L,R;

bool solve() {
	REPE(nplus,n) {
		int nmin=n-nplus;
		ll l=A+(ll)L*nplus-(ll)R*nmin,r=A+(ll)R*nplus-(ll)L*nmin;
		if(l<=B&&B<=r) return true;
	}
	return false;
}

void run() {
	scanf("%d%d%d%d%d",&n,&A,&B,&L,&R); if(A>B) swap(A,B); --n;
	printf("%s\n",solve()?"YES":"NO");
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

int main() {
  string s;
  cin >> s;
  vv(ll) dp(s.size()+1,v(ll)(2,0));
  dp[0][0] = 1;
  dp[0][1] = 0;
  for(ll i = 0;i < s.size();i++) {
    dp[i+1][1] = (dp[i][1] * 3 )% MOD;
    if(s[i] == '0') {
      dp[i+1][0] = dp[i][0];
    } else {
      dp[i+1][0] = dp[i][0] * 2;
      dp[i+1][1] += dp[i][0];
    }
    dp[i+1][0] %= MOD;
    dp[i+1][1] %= MOD;
  }
  cout << (dp[sz(s)][0] + dp[sz(s)][1]) % MOD << endl;
  return 0;
}

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

int main(){
int A,B,C;
double D; 
  cin >> A >> B;
  D=(A+B)*0.5;
  C=(A+B)/2;
  if(D>C){
  cout<<C+1<<endl;
  }else{
  cout<<C<<endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}

int modpow(int N, int M){return M ? modpow(N * N % MOD, M / 2) * (M % 2 ? N : 1) % MOD : 1;}
int modcomb(int N,int M){ int x = 1, y = 1; for(int i = 1; i <= M; i++) {x = x * (N-i+1) % MOD; y = y * i % MOD;} return x * modpow(y, MOD-2) % MOD;}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int X, Y;
    cin >> X >> Y;
    int x = 2*Y-X, y = 2*X-Y;
    if (x % 3 != 0 || y % 3 != 0) {
        cout << ans << endl;
        return 0;
    }
    x /= 3;
    y /= 3;
    ans = min(modcomb(x+y,x),modcomb(x+y,y));
    cout << ans << endl;

    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc145/abc145_d && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc145/abc145_d && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc145/abc145_d && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define N 1000005
#define ll long long
#define debug(a) cout<<#a<<": ";for(auto i:a)cout<<i<<" ";cout<<'\n';
#define trace(a) cout<<#a<<": "<<a<<"\n"
#define int ll
int a[N];
ll ps[N];
int n;
vector< vector<ll> > poss;
signed main() {
	ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
	int i,j,k,l,m,t;
	cin >> n;
	ll sum = 0;
	for(i = 1;i <= n;i++) {
		cin >> a[i];
		ps[i] = ps[i-1] + a[i];
		sum += a[i];
	}
	ll ans = 1e18;
	for(i = 2;i <= n-2;i++) {
		ll sum1 = ps[i];
		int lid[2],rid[2];
		int id = lower_bound(ps,ps+n,(sum1+1)/2) - ps;
		lid[0] = id;
		lid[1] = id-1;
		id = lower_bound(ps+i,ps+n,(ps[n] - ps[i])/2 + ps[i]) - ps;
		rid[0] = id;
		rid[1] = id-1;
		for(int j = 0;j < 2;j++) {
			for(int k = 0;k < 2;k++) {
				if(lid[j] < i && lid[j] > 0 && rid[k] > i && rid[k] < n) {
					vector<ll> v = {ps[lid[j]],ps[i] - ps[lid[j]], ps[rid[k]] - ps[i],ps[n] - ps[rid[k]]};
					sort(v.begin(),v.end());
					// trace(i);
					// debug(v);
					ans = min(ans,v[3] - v[0]);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5888
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define	PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vll vector<ll>
#define vbl vector<bool>
#define vpll vector<pll>
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(),x.end()
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define mod 1000000007
#define INF 1000000000000000
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set_pll;
#define ook order_of_key
#define fbo find_by_order
/*  
	Query 1 - order_of_key(k) : Number of items strictly smaller than k.
	Query 2 - find_by_order(k) : K-th element in the set (counting from zero).
	less<ll> means Query 1 will return numbers strictly less than k.
	greater<ll> means Query 1 will return numbers strictly greater than k.
*/
ll powmod(ll x, ll n){
	ll res = 1;
	while(n){
		if(n & 1){
			res *= x;
			res %= mod;
		}
		x *= x;
		x %= mod;
		n >>= 1;
	}
	return res;
}
ll invmod(ll a){
	return powmod(a, mod - 2);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int res = 0;
	for(int i = 1; i < n - 1; i++){
		if(s[i - 1] == 'A' and s[i] == 'B' and s[i + 1] == 'C'){
			res++;
		}
	}
	cout << res;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    int cnt = 0, n;
    cin >> n >> s;
    for (int i = 0; i < n - 2; i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
 
 
int main() {
int s,w ;
cin >> s>>w;
if (w>=s) cout <<"unsafe" << endl;
else cout<< "safe" <<endl;
}

Measured memory_bytes: 3600
#include <cstdio>
using namespace std;
int A[30], n;

int solve(int i, int m)
{
    bool res;
    if (m == 0)
    {
        return true;
    }
    else if (i >= n)
    {
        return false;
    }
    res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main()
{
    int q, q_i;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%d", &q_i);
        if (solve(0, q_i) == true)
        {
            printf("yes\n");
        }
        else
            printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>  
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N = 1e5 + 10;  
ll Lft[3*N], Rit[3*N];
int num[3*N];
int main()  
{  
 //  freopen("in.txt", "r", stdin);
    int n;
    while (~scanf("%d", &n))
    {
        for (int i = 1; i <= 3*n; i++)
            scanf("%d", num + i);
        priority_queue<int, vector<int>, greater<int> >qmin; 
        priority_queue<int> qmax;
        ll sum = 0;
        // qmin.push(num[0]);
 
        for (int i = 1; i <= n; i++)
        {
            sum += num[i];
            qmin.push(num[i]);
        }
        int m = n<<1;
        Lft[n] = sum;
        for (int i = n + 1; i <= m; i++)
        {
         /*   if (qmin.top() < num[i])
            {
                sum += num[i];
                sum -= qmin.top();
                qmin.pop();
                qmin.push(num[i]);
            }*/
            qmin.push(num[i]);
            sum += num[i] - qmin.top();
            qmin.pop();
            Lft[i] = sum;
        }
 
        sum = 0;
        for (int i = 3*n; i >= m + 1; i--)
        {
            sum += num[i];
            qmax.push(num[i]);
        }
        Rit[m+1] = sum;
        for (int i = m; i >= n + 1; i--)
        {
           /* if (num[i] < qmax.top())
            {
                sum += num[i];
                sum -= qmax.top();
                qmax.pop();
                qmax.push(num[i]);
            }*/
            qmax.push(num[i]);
            sum += num[i] - qmax.top();
            qmax.pop();   
            Rit[i] = sum;
        }
        ll ans = Lft[n] - Rit[n + 1];
        for (int i = n; i <= m; i++)
        {
            ans = max(Lft[i] - Rit[i+1], ans);
        }
        cout<<ans<<endl;
    }
 
   return 0;  
}  

Measured memory_bytes: 5240
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include<queue>
#include<map>
using namespace std;

int main() {
	long int N,a;
	int one = 0;
	int four = 0;
	int W = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		if (a % 4 == 0)four ++;
		if (a % 4 != 0 && a % 2 == 0)W++;
		if (a % 2 == 1)one++;
	}
	if (N % 2 == 0) {
		if (four >= one)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else {
		if (four+1 >= one)cout << "Yes" << endl;
		else cout << "No" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
# 2020/05/31
# AtCoder Beginner Contest 169 - C (AfterCase)

# Input
a, b = input().split()

# Calc
bint = int(b[0:len(b)-3])
bfloat = int(b[len(b)-2:len(b)])
ans = int(a) * (bint * 100 + bfloat) // 100

# Output
print(ans)


Measured memory_bytes: 9096
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
typedef long long ll;
const ll mod = 1e9 + 7;

int main() {
    int X, t;
    cin >> X >> t;
    cout << max(0, X - t) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

from collections import deque

def main():
	n=II()
	G=[[] for _ in range(n+1)]
	
	for _ in range(n-1):
		a,b=MI()
		G[a].append(b)
		G[b].append(a)
	#print(G)
	
	Q=deque()
	Q.append([1,0])
	l=0
	v=0
	sumi=set()
	
	while Q:
		#print(Q)
		now,d=Q.popleft()
		sumi.add(now)
		if d>l:
			v=now
			l=d
		for i in G[now]:
			if i not in sumi:
				Q.append([i,d+1])
	#print(v,l)
	
	Q=deque()
	Q.append([v,0])
	l=0
	sumi=set()
	while Q:
		#print(Q)
		now,d=Q.popleft()
		sumi.add(now)
		if d>l:
			l=d
		for i in G[now]:
			if i not in sumi:
				Q.append([i,d+1])
	#print(l)
	
	if l%3==1:
		print("Second")
	else:
		print("First")

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	









if __name__ == "__main__":
	main()


Measured memory_bytes: 64620
#include <stdio.h>
int main(void)

{

	int H,W;

	int i,j;


	while(1){
		scanf("%d %d",&H,&W);

		if(H==0 && W==0){

			break;
		}

		for(i=1;i<=H;i++){
			for(j=1;j<=W;j++){
				if((j==1 || j==W)||(i==1 || i==H)){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}

		printf("\n");

	}

	return 0;

}


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

#define ll long long

int main()
{
    int n;
    cin>>n;
    map<string, int> mp;
    string s;
    while(n--)
    {
        cin>>s;
        mp[s]++;
    }
    cout<<"AC"<<" x "<<mp["AC"]<<endl;
    cout<<"WA"<<" x "<<mp["WA"]<<endl;
    cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
    cout<<"RE"<<" x "<<mp["RE"]<<endl;
    return 0;
}

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

using namespace std;

int a[2009], b[2009];

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

    long long ans, cost = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cost += a[i];
        b[i] = a[i];
    }

    ans = cost;
    for (int i = 1; i < n; i++) {
        cost = 0;
        for (int j = 0; j < n; j++) {
            int p = j - i;
            if (p < 0) p += n;
            b[j] = std::min(b[j], a[p]);
            cost += b[j];
        }
        ans = std::min(ans, cost + 1LL * i * x);
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200010


int main() {
	char a[30][30];
	bool b[30][30];
	int c[30][30];
	queue<pair<int, int> >q;
	f(i, 30) {
		f(j, 30) {
			a[i][j] = 0;
			b[i][j] = false;
		}
	}
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d", &n, &k);
	f(i, n) {
		scanf("%s", a[i]);
		f(j, k) {
			if (a[i][j] == '.')b[i + 1][j + 1] = true;
		}
	}
	s = 0;
	f(i, n) {
		f(j, k) {
			if (b[i + 1][j + 1]) {
				f(ii, n + 2) {
					f(jj, k + 2)c[ii][jj] = -1;
				}
				c[i + 1][j + 1] = 0;
				q.push(make_pair(i + 1, j + 1));
				while (!q.empty()) {
					x = q.front().first;
					y = q.front().second;
					s = max(s, c[x][y]);
					q.pop();
					f(ii,3) {
						f(jj, 3) {
							if ((abs(ii - 1) + abs(jj - 1)) == 1) {
								if (b[x + ii-1][y + jj-1] && (c[x + ii-1][y + jj-1] == -1)) {
									c[x + ii-1][y + jj-1] = c[x][y] + 1;
									q.push(make_pair(x + ii-1, y + jj-1));
								}
							}
						}
					}
				}
			}
		}
	}
	printf("%d\n", s);


	return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<vector<int>> S(100, vector<int> (N));
	for (int i = 0; i < N; i++) {
		char c;
		cin >> c;
		S.at(c - 'a').at(i)++;
	}
	
	int ttl = 0;
	int cntX, cntY;
	for (int i = 1; i < N; i++) {	
		int subttl = 0;
		for (int k = 0; k < 26; k++) {
			cntX = cntY = 0;
			for (int j = 0; j < i; j++) {
				cntX += S.at(k).at(j);
			}
			for (int j = i; j < N; j++) {
				cntY += S.at(k).at(j);
			}
			if (cntX > 0 && cntY > 0) subttl++;
		}
		ttl = max(ttl, subttl);
	}
	cout << ttl << endl;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
long long n,x,y,z,q,root,d[N],up[31][N],sz,tin[N],tout[N],timer;
vector<pair<long long,long long> >g[N];

void dfs(int v,int pr){
    tin[v]=timer++;
    up[0][v]=pr;
    for(int i=1;i<=sz;i++){
        up[i][v]=up[i-1][up[i-1][v]];
    }
    for(auto to:g[v]){
        if(to.first!=pr){
            d[to.first]=d[v]+to.second;
            dfs(to.first,v);
        }
    }
    tout[v]=timer++;
}
inline bool upper(int a,int b){
    return tin[a]<=tin[b] && tout[a]>=tout[b];
}
inline int lca(int a,int b){
    if(upper(a,b)){
        return a;
    }
    if(upper(b,a)){
        return b;
    }
    for(int i=sz;i>=0;i--){
        if(!upper(up[i][a],b)){
            a=up[i][a];
        }
    }
    return up[0][a];
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    while((1<<sz)<=n){
        sz++;
    }
    for(int i=1;i<n;i++){
        cin>>x>>y>>z;
        g[x].push_back(make_pair(y,z));
        g[y].push_back(make_pair(x,z));
    }
    cin>>q>>root;
    dfs(root,root);
    while(q--){
        cin>>x>>y;
        z=lca(x,y);
        if(z!=x && z!=y){
            cout<<d[x]-d[z]+d[y]-d[z]+2*d[z]<<"\n";
        }
        else{
            cout<<d[y]+d[x]<<"\n";
        }
    }
}


Measured memory_bytes: 31872
#include<stdio.h>
int main(void){
    int x,a,b;
    scanf("%d%d%d",&x,&a,&b);
    a-=x;b-=x;
    if(a<0)
    a*=-1;
    if(b<0)
    b*=-1;
    if(a<b)
    printf("A");
    else
    {
        printf("B");
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second  
#define endl '\n'
#define pb push_back
#define t_case ll tt; cin>>tt; while (tt--)
#define all(v) v.begin(),v.end()
#define ub(a,x) upper_bound(all(a),x)-a.begin()
#define lb(a,x) lower_bound(all(a),x)-a.begin()
#define fr(a,b,c) for (ll a=b;a<c;a++)
#define take(xx,n) for (int i=0;i<n;i++) cin>>xx[i];
#define take1(xx,n) for (int i=1;i<=n;i++) cin>>xx[i];
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
int main() 
{
	fastio
	//t_case
	{
		ll sum=0,ans=0,f=1,n,m,k,x,y,z  ;cin>>n;
		if (n>=400 && n<600) cout<<8;
		if (n>=600 && n<800) cout<<7;
		if (n>=800 && n<1000) cout<<6;
		if (n>=1000 && n<1200) cout<<5;
		if (n>=1200 && n<1400) cout<<4;
		if (n>=1400 && n<1600) cout<<3;
		if (n>=1600 && n<1800) cout<<2;
		if (n>=1800 && n<2000) cout<<1;
		cout<<endl;
	}
	return 0;
}
 

Measured memory_bytes: 3648
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>  vll;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;

  vll a(n),b(n);
  map<ll,ll> m;

  rep(i,n) cin >> a[i] >> b[i];

  rep(i,n)
  {
    m[b[i]] += a[i];
  }

  ll work = 0;
  for(auto it:m)
  {
    work += it.second;
    if(work > it.first)
    {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

int main() {
    int n;
    while(true){
        cin >> n;
        if(n == 0)break;
        string vote[n];
        rep(i,n) cin >> vote[i];
        vector< pair<int ,string> > voted; 
        voted.push_back(make_pair(1, vote[0]));
        if(n == 1) {
            cout << voted[voted.size() - 1].second << " " << 1 << endl;
            continue;
        }

        int nokori = n - 2;

        for(int i = 1; i < n; i++, nokori--) {
            bool tuika = false;
            rep(j,voted.size()) {
                if(voted[j].second == vote[i]){
                    voted[j].first++;
                    tuika = true;
                    break;
                }
            }
            if(!tuika) voted.push_back(make_pair(1, vote[i]));

            sort(voted.begin(),voted.end());

            if(voted[voted.size() - 1].first > n / 2) {
                cout << voted[voted.size() - 1].second << " " << i + 1 << endl;
                break;
            }
            if(voted.size() > 2){
                if(voted[voted.size() - 1].first > voted[voted.size() - 2].first + nokori) {
                    cout << voted[voted.size() - 1].second << " " << i + 1 << endl;
                    break;
                }
            }
        }
        if(voted[voted.size() - 1].first == voted[voted.size() - 2].first) {
            cout << "TIE" << endl;
        }
    }
}


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

int main(void) {
    int N;
    cin>>N;
    vector<int> A,B,C;
    A.push_back(0);
    B.push_back(0);
    C.push_back(0);
    int score = 0;
    REP(i, N) {
        int a;
        cin>>a;
        A.push_back(a);
    }
    REP(i, N) {
        int b;
        cin>>b;
        B.push_back(b);
    }
    REP(i, N - 1) {
        int c;
        cin>>c;
        C.push_back(c);
    }
    int before = -1;
    REP(i, N) {
        int a = A.at(i);
        score += B.at(a);
        if (before == a - 1) score += C.at(a - 1);
        before = a;
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define F(i,n,a) for(int i=a;i<n;i++)
#define vi vector<int>
#define pb push_back
#define lli long long int
#define mod 1000000007
//realfuhrer10
using namespace std;


int main(){
   lli a,b,c,d; cin>>a>>b>>c>>d;
   lli x,y;
   cout<<max(max(a*c,b*c),max(a*d,b*d));
}

Measured memory_bytes: 3192
//#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=2*1e5+5;
int n,m,hd[maxn],k,in[maxn],vis[maxn],num[maxn];
int tt,cnt,tax[maxn];
struct edd{
	int nt,v;
}e[maxn*2];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline void add(int a,int b){
	e[k].v=b; e[k].nt=hd[a]; hd[a]=k++;
	e[k].v=a; e[k].nt=hd[b]; hd[b]=k++;
}

void dfs(int x,int efa){
	//if(num[x] > tt) return ;
	if(num[x] == tt){ cnt++; num[x]++; return ; }
	num[x]=tt;
	for(rg int i=hd[x];i!=-1;i=e[i].nt){
		int v=e[i].v;
		if(i == (efa^1) || vis[i]) continue;
		dfs(v,i);
		if(num[v] == tt+1){
			vis[i]=tt+1; vis[i^1]=tt+1; 
			num[x]++;
			return ;
		}
	}
}

int main(){
	#ifndef ONLINE_JUDGE
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	#endif
	memset(hd,-1,sizeof(hd)); k=0;
	n=rd(); m=rd(); int x,y;
	go(i,m+1,1){
		x=rd(); y=rd(); add(x,y);
		in[x]++; in[y]++;
	}
	int fl=0;
	go(i,n+1,1){
		if(in[i]%2 != 0){ fl=1; break; }
		tax[in[i]]++;
	}
	if(fl){ puts("No"); return 0; }
	go(i,n+1,1){
		if(in[i] >= 6){
			puts("Yes"); return 0;
		}
	}
	if(tax[4] >= 3){
		puts("Yes"); return 0;
	}
	for(rg int i=0;i<k;i+=2){
		if(vis[i]) continue ;
		tt+=5;
		num[e[i^1].v]=tt;
		dfs(e[i].v,i);
		if(num[e[i].v] == tt+1){ 
			vis[i]=vis[i^1]=tt; 
		}
		if(cnt >= 3){
			fl=1; break;
		}
	}
	puts(fl ? "Yes" : "No");
	return 0;
}//Faze


Measured memory_bytes: 9856
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifndef U_L_LONG
typedef unsigned long long ULLONG;
#endif
#ifndef L_LONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}


static void ABC106D_AtCoderExpress2();

#if 1
int main()
{
	ABC106D_AtCoderExpress2();
	fflush(stdout);
	return 0;
}
#endif

static void ABC106D_AtCoderExpress2()
{
	int N, M, Q;
	get3int(N, M, Q);

	auto pqStat = new int[N][501];
	memset(pqStat, 0, sizeof(int) * N * 501);
	for (int i = 0; i < M; i++) {
		int l, r;
		get2int(l, r); l--; r--;
		pqStat[l][r]++;
	}

	auto pqSum = new int[N][501];
	memset(pqSum, 0, sizeof(int) * N * 501);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int l = i; l <= j; l++) {
				for (int r = l; r <= j; r++) {
					pqSum[i][j] += pqStat[l][r];
				}
			}
		}
	}

	auto ans = new int[Q];
	for (int i = 0; i < Q; i++) {
		int p, q;
		get2int(p, q); p--; q--;
		ans[i] = pqSum[p][q];
	}

	for (int i = 0; i < Q; i++) {
		printf("%d\n", ans[i]);
	}

	delete[] ans;
	delete[] pqStat;
	delete[] pqSum;
}


Measured memory_bytes: 3328
#include <cstdio>
int main(){
 int i,j,w,h;
 while(true) {
  scanf("%d %d",&h,&w);
  if ((h==0)&&(w==0)) break;
  while(h>0){
   for(i=0;i<w;i++){
    printf("#");
   };
   printf("\n");
   --h;
  }
  printf("\n");
 };
 return 0;
};

Measured memory_bytes: 1000
package main

import (
  "fmt"
)

func main() {
  var N int
  fmt.Scan(&N)
  var S string
  fmt.Scan(&S)
  cnt := 0
  for i := 0; i < 2 << uint(N - 1); i++ {
    c := i
    RB := make([]string, 2)
    for j := 0; j < N; j++ {
      RB[c % 2] += string(S[j])
      c /= 2
    }
    r := len(RB[0])
    b := len(RB[1])
    DP := make([][]int, N + 1)
    for i := range DP {
      DP[i] = make([]int, N + 1)
    }
    DP[0][0] = 1
    for k := 0; k < N; k++ {
      for l := 0; l < k + 1; l++ {
        if l < r && RB[0][l] == S[2 * N - 1 - k] {
          DP[k + 1][l + 1] += DP[k][l]
        }
        if k - l < b && RB[1][k - l] == S[2 * N - 1 - k] {
          DP[k + 1][l] += DP[k][l]
        }
      }
    } 
    for _, d := range DP[N] {
      cnt += d
    }
  }
  fmt.Println(cnt)
}

Measured memory_bytes: 7552
N,M=list(map(int, input().split()))
src=[i+1 for i in range(M*2+1)]
if M%2==0:
  for m in range(M//2):
    a=src[m]
    b=src[M-m]
    print('{} {}'.format(a,b))
  for m in range(M//2):
    a=src[M+1+m]
    b=src[-(m+1)]
    print('{} {}'.format(a,b))
else:
  for m in range(M//2):
    a=src[m]
    b=src[M-1-m]
    print('{} {}'.format(a,b))
  for m in range(M-(M//2)):
    a=src[M+m]
    b=src[-(m+1)]
    print('{} {}'.format(a,b))

Measured memory_bytes: 15820
import java.util.*;
import java.io.*;

public class Main {

	public static void main (String[] args) {
	   Scanner sc = new Scanner(System.in) ;
	   char s[] = sc.nextLine().toCharArray();
	   long k = sc.nextLong();
	   for(int i = 0; i<Math.min(s.length, k); i++) {
		   if(s[i] != '1' ) {
			   System.out.println(s[i]);
			   return; 
		   }
	   }
	   System.out.println('1'); 
	}
}


Measured memory_bytes: 21972
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long start = sc.nextLong();
        long end = sc.nextLong();
        long num;
        if (end - start == 1) {
            num = start ^ end;
        } else if (end - start == 0) {
            num = start;
        } else {
            num = 0;
            for (long i = start - (start % 4) + 3; i >= start; i--) {
                num ^= i;
            }
            for (long i = end - (end % 4); i <= end; i++) {
                num ^= i;
            }
        }
        // 455 none
        // 456 456
        // 457 456 457
        // 458 456 457 458
        // 121 121 122 123
        // 122 122 123
        // 123 123
        // 124 none
        // 3 - 9 -> 3 (4 - 7) ^8-9
        // 1 - 15 -> 1-3 (4 - 15)
        // 20 - 60 -> 4-7 8-11
        // 123 - 456 -> 124- 455
        // 000 0
        // 001
        // 010 2
        // 011
        // 100 4
        // 101
        // 110
        // 111
        // 1000 8
        // 1001
        // 1010
        // 1011
        // 1100
        // 1101
        // 1110
        // 1111
        // 10000
        // 10001
        // 16 32 64
        
        System.out.println(num);
    }
}

Measured memory_bytes: 23124
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;

string itos(int target){
  if(target<=9){
    char add='0'+target;
    return string{'0','0',add};
  }else if(target<=99){
    char add2='0'+(target%10);
    target/=10;
    char add1='0'+target;
    return string{'0',add1,add2};
  }else{
    char add3='0'+(target%10);
    target/=10;
    char add2='0'+(target%10);
    target/=10;
    char add1='0'+target;
    return string{add1,add2,add3};
  }
}

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

  int n;
  cin>>n;
  string s;
  cin>>s;

  int result=0;
  for(int target=0;target<=999;target++){
    string ts=itos(target);
    int pos=0;
    for(int i=0;i<n;i++){
      if(ts[pos]==s[i]){
        pos++;
        if(pos>=3){
          result++;
          break;
        }
      }
    }
  }

  cout<<result<<endl;




  return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int A, B, C;

int main() {

	cin >> A >> B >> C;

	if (A == B || B == C || C == A) {
		if (A != B || B != C || C != A) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
  int n; //??????????????°
  int num; 
  char mark;
  char marks[4] = {'S', 'H', 'C', 'D'};
  int cards[4][13] = {0};

  cin >> n;
  
  for(int i = 0; i < n; i++){
    cin >> mark >> num;
    for(int j = 0; j < 4; j++){
      if(mark == marks[j]){
	cards[j][num-1] = 1;
	break;
      }
    }
  }
  for(int i = 0; i < 4; i++){
    for(int j = 0; j < 13; j++){
      if(!cards[i][j] == 1){
	cout << marks[i] << " " << j+1 << "\n";
      }
    }
  }
  return 0;
}

      

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int n=s.size(),g=0,p=0;
	rep(i,n){
		if(s.at(i)=='g') g++;
		else p++;
	}
	cout << (g-p)/2 << endl;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
#ABC43 C

n = int(input())
a = list(map(int,input().split()))

mi = float('inf')

for i in range(-100,101):
    cost = 0
    for j in range(n):
        cost += (i - a[j])**2
    mi = min(mi,cost)
print(mi)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define MAGIC cin.tie(NULL); ios_base::sync_with_stdio(false)
#define endl '\n'
//#define ll long long
#define mod (1000000007)
//#define NCONS 100001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
//#define MCONS 2001
//#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
#define int long long
//#define double long double
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;

int gcd(int a, int b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

#define YYYY cout << "YES" << endl
#define NNNN cout << "NO" << endl
#define yyyy cout << "Yes" << endl
#define nnnn cout << "No" << endl
int dx[]{0, 1, 0, -1};
int dy[]{1, 0, -1, 0};

const int NCONS = 100001;
//const int MCONS = 101;

int32_t main()
{
    MAGIC;
    int r; cin >> r;
    cout << r * r;
    
    
    return 0;
}



Measured memory_bytes: 888
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N=1e4+10;
int val(int a,int b){
    int temp=b;
    while(temp){
        a*=10;
        temp/=10;
    }
    return a+b;
}
int min(int a,int b){return a>b?b:a;}
int main(){
    int n,a[N],p[100],now=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    sort(a,a+n);
    a[n]=10000;
    for(int i=0;i<4;i++)for(int j=0;j<4;j++)if(i!=j)p[now++]=val(a[i],a[j]);
    sort(p,p+now);
    printf("%d\n",p[2]);
}


Measured memory_bytes: 2796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  ll n,k;
  cin >> n >> k;
  if(k%2)
    cout << (n/k)*(n/k)*(n/k) << endl;
  else{
    ll a=2*n/k;
    ll b=a/2;
    ll c=a-b;
    cout << b*b*b+c*c*c << endl;
  }
}

Measured memory_bytes: 256
import math
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    n = sc.intarr()[0]
    ns = int(math.sqrt(n)) + 1
    minimum = n
    for i in range(1, ns):
        if n % i == 0:
            cost = (n//i) + i - 2
            if cost < minimum:
                minimum = cost
    print(minimum)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	ll a = 2, b = 1, c = 3;
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}
	else if (N == 2) {
		cout << 3 << endl;
		return 0;
	}
	repe(i, 3, N) {
		a = b;
		b = c;
		c = a + b;
	}
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	a1 := make([]int, n)
	a2 := make([]int, n)
	for i := range a1 {
		fmt.Scan(&a1[i])
	}
	for i := range a2 {
		fmt.Scan(&a2[i])
	}

	var a1sum, max int
	for i := 0; i < n; i++ {
		a1sum += a1[i]
		sum := a1sum
		for j := i; j < n; j++ {
			sum += a2[j]
		}
		if sum > max {
			max = sum
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 512