akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(),(x).end()
using namespace std;

int a[1000000];

vector<int>zx1,zx0;

int main (){
    multiset<int>mul;
    int n;cin>>n;
    int x,y;


    for(int i=0;i<n;i++)  {
        cin>>a[i];
        if(a[i]>=0) zx1.push_back(a[i]);
        else zx0.push_back(a[i]);
        mul.insert(a[i]);
    }
    vector<pair<int,int> >vec;
    sort(a,a+n);
    int sz1=zx1.size();
    int sz0=zx0.size();
    if(sz1==0) {//全小于０的情况
        reverse(a,a+n);
        int now=a[0];
        for(int i=1;i<n;i++){
            if(i==n-1) vec.push_back({now,a[n-1]}),now-=a[i];
            else vec.push_back({now,a[i]}),now-=a[i];
        }
        cout<<now<<endl;
        for(auto &x:vec) cout<<x.first<<" "<<x.second<<endl;
        return 0;
    }
    else if(sz0==0){//全部大于０的情况
        int now=a[0];
        for(int i=1;i<n;i++){
            if(i==n-1) vec.push_back({a[i],now}),now=a[i]-now;
            else vec.push_back({now,a[i]}),now-=a[i];

        }
        cout<<now<<endl;
        for(auto &x:vec) cout<<x.first<<" "<<x.second<<endl;
        return 0;
    }
    else {
        sort(all(zx1)),sort(all(zx0));
        int now=zx0[0];
        for(int i=0;i<sz1-1;i++) {
            vec.push_back({now,zx1[i]});
            now-=zx1[i];
        }
        vec.push_back({zx1[sz1-1],now});
        now=zx1[sz1-1]-now;
        for(int i=1;i<sz0;i++) {
            vec.push_back({now,zx0[i]});
            now-=zx0[i];
        }

        cout<<now<<endl;
        for(auto &x:vec) cout<<x.first<<" "<<x.second<<endl;
        cout<<endl;
    }
    return 0;
}
/**
8
-3 -2 -1 0 0 2 3 6

6
1 3 5 6 7 9

6
-1 -2 -3 -4 -5 0

6
-1 -2 -3 -4 -5 -6




*/


Measured memory_bytes: 8308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<int> t;
    int now = 1;
    int cnt = 0;
    rep(i, 0, n) {
        if (s[i] == (char)(now + '0')) cnt++;
        else {
            t.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    t.push_back(cnt);
    if ((int)t.size() % 2 == 0) t.push_back(0);

    int ans = 0;
    int len = t.size();
    int left = 0, right = 0;
    int sum = t[0];
    for (int i = 0; i < len; i += 2) {
        int nextleft = i;
        int nextright = min(i + 2 * k, len - 1);
        while (nextright > right) {
            right++;
            sum += t[right];
        }
        while (nextleft > left) {
            sum -= t[left];
            left++;
        }
        ans = max(ans, sum);
    }

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


Measured memory_bytes: 1020
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない




int main() {

	int n, a, m; m = 0;
	int x[51] = { 0 };
	ull d[51][51][2501] = {0};//d[a][b][c] aまでにb枚選んで合計cにする通り
	
	cin >> n >> a;

	for (int i = 1; i <= n; i++) {
		cin >> x[i];
		m = max(m, x[i]);
	}

	sort(x, x + n);

	d[0][0][0] = 1;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k <= m*j; k++) {
				if (i != 0 || j != 0 || k != 0) {
					if (x[i] > k&&i - 1 >= 0) {
						d[i][j][k] = d[i - 1][j][k];
					}
					else if (x[i] <= k&&i - 1 >= 0 &&j-1>=0) {
						d[i][j][k] = d[i - 1][j][k] + d[i - 1][j - 1][k - x[i]];
					}
					else {
						d[i][j][k] = 0;
					}
				}
			}
		}
	}

	ull ans = 0;
	for (int i = 1; i <= n;i++) {
		ans += d[n][i][a*i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 51072
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);

        while(true){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();

            if(m == -1 && f == -1 && r == -1) break;

           if(m == -1 || f == -1 ){
                System.out.println("F");
            }else if(m+f >= 80){
                System.out.println("A");
            }else if(m+f >=65){
                System.out.println("B");
            }else if(m+f >=50){
                System.out.println("C");
            }else if(m+f >=30){
                if(r >=50){
                    System.out.println("C");
                }else{
                    System.out.println("D");
                }
            }else{
                System.out.println("F");
            }

        }
    }
}


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

int main(){

  int D;
  cin >> D;

  if(D == 25)
    cout << "Christmas" << endl;
  else if(D == 24)
    cout << "Christmas Eve" << endl;
  else if(D == 23)
    cout << "Christmas Eve Eve" << endl;
  else
    cout << "Christmas Eve Eve Eve" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)



using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}


int main() {

    int n;
    int a[200000];
    int count = 0;
    int cur = 1;
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
    }

    for(int i = 0; i < n; i ++){
        if(a[i] == cur){
            cur ++;
        }else{
            count ++;
        }
    }
    if(count == n) cout << -1;
    else cout << count;
    return 0;
}











Measured memory_bytes: 4400
import sys

f_i = sys.stdin

n = int(f_i.readline())

adj = [[]] * n
for x in f_i:
    x = list(map(int, x.split()))
    adj[x[0]] = (c_v for c_v in zip(x[3::2], x[2::2]))

import heapq

def dijkstra():
    PQ = [(0, 0)]
    isVisited = [False] * n
    distance = [999900001] * n

    distance[0] = 0
    
    while PQ:
        uc, u = heapq.heappop(PQ)

        if uc > distance[u]:
            continue

        isVisited[u] = True
        
        for vc, v in adj[u]:
            if isVisited[v] == True:
                continue
            
            t_cost = distance[u] + vc
            if t_cost < distance[v]:
                distance[v] = t_cost
                heapq.heappush(PQ, (t_cost, v))

    for v, d in enumerate(distance):
        print(v, d)


dijkstra()

Measured memory_bytes: 42124
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<deque>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")
#define ret return 0

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

	string s, t;
	cin >> s >> t;
	int cnt = 0;

	for (int i = 0; i < s.size(); i++)
	{
		for (int j = 0; j < s.size(); j++)
		{
			if (s[j] == t[(i + j) % s.size()])
			{
				cnt++;
			}
			else
			{
				break;
			}
		}
		if (cnt == s.size())
		{
			cout << "Yes" << endl;
			ret;
		}
		cnt = 0;
	}
	cout << "No" << endl;

	return 0;
}

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

using namespace std;

int main() {
    int N, M;
    cin >> N;
    cin >> M;
    priority_queue <long> A;
    for (int i = 0; i < N; ++i) {
        long a;
        cin >> a;
        A.push(a);
    }
    for (int i = 0; i < M; ++i) {
        A.push(A.top() / 2);
        A.pop();
    }
    long sum = 0;
    while (!A.empty()) {
        sum += A.top();
        A.pop();
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1400
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      String S = sc.next();
      int K = sc.nextInt();
      String str=S;
      for(int i=0;i<N;i++){
        if(S.charAt(i)!=S.charAt(K-1)){
          str = str.substring(0,i)+"*"+str.substring(i+1);
        }
      }
      System.out.println(str);
    }
}

Measured memory_bytes: 38768
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    int cnt = ((N + 1) / 2);
    if (cnt < K) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
	double x, y;
	Point(double x = 0.0, double y = 0.0) :
			x(x), y(y) {
	}

	Point operator +(Point p) {
		return Point(x + p.x, y + p.y);
	}
	Point operator -(Point p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator *(double k) {
		return Point(x * k, y * k);
	}
	Point operator /(double k) {
		return Point(x / k, y / k);
	}

	double norm() {
		return x * x + y * y;
	}
	double abs() {
		return sqrt(norm());
	}

	bool operator <(Point p) {
		return x != p.x ? x < p.x : y < p.y;
	}
	bool operator ==(Point p) {
		return equals(x, p.x) && equals(y, p.y);
	}
};
typedef Point Vector;

class Segment {
public:
	Point p1, p2;
	Segment(Point p1 = Point(), Point p2 = Point()) :
			p1(p1), p2(p2) {
	}
};
typedef Segment Line;

double dot(Vector v1, Vector v2) {
	return v1.x * v2.x + v1.y * v2.y;
}
double cross(Vector v1, Vector v2) {
	return v1.x * v2.y - v1.y * v2.x;
}
bool isOrthogonal(Vector v1, Vector v2) {
	return equals(dot(v1, v2), 0.0);
}
bool isOrthogonal(Segment s1, Segment s2) {
	return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool isOrthogonal(Point l1, Point l2, Point m1, Point m2) {
	return isOrthogonal(l2 - l1, m2 - m1);
}
bool isParallel(Vector v1, Vector v2) {
	return equals(cross(v1, v2), 0.0);
}
bool isParallel(Segment s1, Segment s2) {
	return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool isParallel(Point l1, Point l2, Point m1, Point m2) {
	return isParallel(l1 - l2, m1 - m2);
}

double distancePP(Point p1, Point p2) {
	return (p1 - p2).abs();
}
double distanceLP(Line l, Point p) {
	return cross(l.p2 - l.p1, p - l.p1) / dot(l.p2, l.p1);
}
double distanceSP(Segment s, Point p) {
	if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
		return distancePP(s.p1, p);
	else if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
		return distancePP(s.p2, p);
	else
		return distanceLP(s, p);
}
//double distanceSS(Segment s1, Segment s2) {
//	if (intersect(s1, s2))
//		return 0.0;
//	else {
//		return min(
//				{ distanceSP(s1, s2.p1), distanceSP(s1, s2.p2), distanceSP(s2,
//						s1.p1), distanceSP(s2, s1.p2) });
//	}
//}

enum PositionSP {
	COUNTER_CLOCKWISE = -1,
	CLOCKWISE = 1,
	ONLINE_BACK = 2,
	ONLINE_FRONT = -2,
	ON_SEGMENT = 0
};
PositionSP ccw(Point p1, Point p2, Point p) {
	Vector a = p2 - p1, b = p - p1;
	if (cross(a, b) > EPS)
		return COUNTER_CLOCKWISE;
	else if (cross(a, b) < -EPS)
		return CLOCKWISE;
	else if (dot(a, b) < -EPS)
		return ONLINE_BACK;
	else if (a.norm() < b.norm())
		return ONLINE_FRONT;
	else
		return ON_SEGMENT;
}

bool intersect(Point p1, Point p2, Point p3, Point p4) {
	return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0
			&& ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment s1, Segment s2) {
	return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

int main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		Segment s1, s2;
		cin >> s1.p1.x >> s1.p1.y;
		cin >> s1.p2.x >> s1.p2.y;
		cin >> s2.p1.x >> s2.p1.y;
		cin >> s2.p2.x >> s2.p2.y;
		cout << intersect(s1, s2) << endl;
	}
	return 0;
}



Measured memory_bytes: 3232
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  int n; cin >> n;
  vector<vector<int> > kind(n, vector<int> (n, -1));
  for (int a = 0; a < n; a++) {
    int at; cin >> at;
    for (int b = 0; b < at; b++) {
      int id, k; cin >> id >> k;
      kind[a][a] = 1;
      kind[a][id-1] = k;
    }
  }
  int ans = 0;
  for (int i = 0; i < 1<<n; i++) {
    int tmp = i, id=0;
    vector<int> taken;
    vector<int> want(n, 0);
    // DEBUG(i);
    while (tmp != 0) {
      if (tmp&1) {
        taken.push_back(id);
        want[id] = 1;
      }
      id++; tmp >>= 1;
    }
    // for (int i : taken) cout << i << " ";
    // cout << endl;
    vector<int> v(n, -1);
    bool stop = false;
    // cout << "check" << endl;
    for (int t : taken) {
      for (int j = 0; j < n; j++) {
        // cout << v[j] << " " << kind[t][j] << endl;
        if (v[j] == -1) v[j] = kind[t][j];
        if ((v[j] != kind[t][j] || kind[t][j] != want[j])&& kind[t][j] != -1) {
          // cout << "stop" << endl;
          stop = true; break;
        }
      }
      if (stop) break;
    }
    if(!stop) {
      ans = max(ans, (int) taken.size());
      // for (int i : taken) cout << i << " ";
      // cout << endl;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	for(int n; cin >> n && n;) {
		vector<int> a(n);
		for(auto &e : a) cin >> e;
		sort(begin(a), end(a));

		int ans = INT_MAX;
		for(int i = 1; i < n; ++i) {
			ans = min(ans, abs(a[i] - a[i - 1]));
		}
		cout << ans << endl;
	}
	return EXIT_SUCCESS;
}

Measured memory_bytes: 3148
H, N = map(int, input().split())

A = [0] * (N+1)
B = [0] * (N+1)
#magic = np.zeros((N+1, 2), dtype=int)

for i in range(1, N+1):
    A[i], B[i] = map(int, input().split())

# print(magic)
# print(A)
# print(B)

INF = 100000010  # 10^4 * 10^4 + spare

#dp = np.full((N+1, H*2+1), INF)
#dp[0][0] = 0

dp = [INF]*(H+1)
#dp = np.full(H+1, INF, dtype=int)
dp[0] = 0

for i in range(1, N+1):
    for j in range(H + 1):
        # 貰うDP
        if j-A[i] >= 0:
            dp[j] = min(dp[j - A[i]] + B[i], dp[j])
        else:
            dp[j] = min(dp[0] + B[i], dp[j])

#        print(dp[i])
#    print(dp)

print(dp[H])


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

void solve(){
    string a, b; cin >> a >> b;
    int n, m; n = a.length(); m = b.length();
    
    vector<vector<int>>dp(n+1, vector<int>(m+1, 0));
    for(int i = 1; i < n+1; i++){
        for(int j = 1; j < m+1; j++){
            if(a[i - 1] == b[j - 1]){
                dp[i][j] = 1 + dp[i - 1][ j - 1];
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    int result = dp[n][m];
    int i = n; int j = m;
    string s = "";
    while(result != 0){
        if(result > dp[i-1][j] and result > dp[i][j-1]){
            s += a[i-1];
            result = result - 1;
            i = i-1;
            j = j-1;
        }
        else if(result == dp[i-1][j]){
            i = i-1;
        }
        else{
            j = j-1;
        }
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    //cout << dp[n][m] << endl;

} 

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


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    string S;
    int count=0;
    cin >> N >> S ;
      
    if(N%2==1)
        cout << "No" << endl;

    else  {
        for(int i=0; i<N/2; i++) {
            if(S.at(i)!=S.at(i+N/2)){
                cout << "No" << endl;
                break;
              }
            else
              count++;           
            }
            
        }
    if (N!=1 && count==N/2)
       cout << "Yes" << endl;
        
    
    
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2147483640
using namespace std;
int main()
{
	//freopen("out.txt","w",stdout);
	long long a,ans=0,b=0;
	string k;
	cin >> a >> k;
	for(int i=0; i<4; i++)
		if(i!=1)
		{
			b*=10;
			b+=(k[i]-'0');
		}
	cout << (a*b)/100<<'\n';
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 400100;
const ll INF = 1e15;
const ll MOD =  998244353;
ll N,M,W,a,b,c,d,e,K;
ll A[MAXN];

ll qexp(ll a, ll b){
    if(b==0)return 1;
    ll h=qexp(a,b/2);
    h=h*h%MOD;
    if(b%2)h=h*a%MOD;
    return h;
}

ll qinv(ll a){
    return qexp(a,MOD-2);
}

ll fact[MAXN], finv[MAXN];
ll ans;

ll choose(ll x, ll y){
    return fact[x]*finv[y]%MOD*finv[x-y]%MOD;
}

int main(){
    cin>>N>>M>>K;
    fact[0]=1;
    for(int i=1;i<400000;++i)fact[i]=fact[i-1]*i%MOD;        
    for(int i=0;i<400000;++i)finv[i]=qinv(fact[i]);
    for(int k=0;k<=K;++k){
        ll n=N-k;
        ll p=choose(n+k-1,k);
        ll m=M*qexp(M-1,n-1)%MOD;
        ans=(ans+p*m)%MOD; 
    }
    cout<<ans;
}

Measured memory_bytes: 9884
n,x,m=map(int,input().split())
p=[0]*(m+1)
a=x
t=0
s=0
for i in range(2*m):
    if p[a]==1:
        p[a]=2
        break
    else:
        p[a]=1
        a=a**2%m
a=x
S=0
for i in range(2*m):
    if p[a]==1:
        s+=1
        S+=a
        a=a**2%m
    else:
        s+=1
        S+=a
        break
T=0
A=0
for i in range(2*m):
    a=a**2%m
    t+=1
    T+=a
    if p[a]==2:
        A=a
        break
a = x
if n <= s:
    ans=0
    for i in range(n):
        ans+=a
        a=a**2%m
    print(ans)
else:
    ans=S
    a=A
    n-=s
    ans+=(n//t)*T
    n=n%t
    for i in range(n):
        a=a**2%m
        ans+=a
    print(ans)

Measured memory_bytes: 66664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll a;cin >> a;
    ll d=log10(a)+1;
    vl v(d);
    for(int i=d-1;i>=0;i--){
        v[i]=a%10;
        a/=10;
    }
    ll ans=0;
    rep(bit,1<<(d-1)){
        ans+=v[d-1];
        ll dcnt=0;
        rep(i,d-1){
            if(bit&(1<<i))dcnt=0;
            else dcnt++;
            ans+=v[d-2-i]*(ll)pow(10,dcnt);
        }
    }
    cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()

typedef long long ll;

template <class T = int>
T in() { T x; cin >> x; return x; }
#define output(e) cout << e << '\n'

#ifdef LOCAL
    #define dr(x) cout << "L" << __LINE__ << ": " << #x << " -> " << x << "\n"
#else
    #define dr(x)
#endif

//
// Implementation
//

int grid[3][3];
int a[3];
int b[3];

void absetup() {
    a[1] = grid[1][0] - b[0];
    a[2] = grid[2][0] - b[0];
    b[1] = grid[0][1] - a[0];
    b[2] = grid[0][2] - a[0];
}

bool iscorrect() {
    rep(i, 3) {
        rep(j, 3) {
            if (grid[i][j] != a[i] + b[j]) return false;
        }
    }
    return true;
}

int main() {
    rep(i, 3) {
        rep(j, 3) {
            grid[i][j] = in();
        }
    }
    rep(i, 100 + 1) {
        rep(j, 100 + 1) {
            a[0] = i;
            b[0] = j;
            absetup();

            if (iscorrect()) {
                output("Yes");
                return 0;
            }
        }
    }
    output("No");
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String tmp = br.readLine();
			
			if(tmp == null){
				break;
			}
			
			String[] tmpArray = tmp.split(",");
			
			int[] cards = new int[5];
			int[] appears = new int[13];
				for(int i = 0; i < 5; i++){
				cards[i] = Integer.parseInt(tmpArray[i]);
				appears[cards[i] - 1]++;
			}
			
			Arrays.sort(cards);
			
	
			boolean fourcards = false;
			boolean threecards = false;
			int pair = 0;
			//4cards
			for(int i = 0; i < 13; i++){
				if(appears[i] >= 4 ){
					fourcards = true;
					break;
				}
				if(appears[i] == 3){
					threecards = true;
				}
				if(appears[i] == 2){
					pair++;
				}
			}
			
			boolean straight = false;
			if(cards[0]==1 && cards[1] == 10 && cards[2] == 11 && cards[3] == 12 && cards[4] == 13){
				straight = true;
			}
			else {
				straight = true;
				for(int j = 1; j < 5; j++){
					if(cards[j] != cards[0] + j){
						straight = false;
						break;
					}
				}
			}
			
			if(fourcards){
				System.out.println("four card");
			}
			else if(threecards && pair == 1){
				System.out.println("full house");
			}
			else if(straight){
				System.out.println("straight");
			}
			else if(threecards){
				System.out.println("three card");
			}
			else if(pair == 2){
				System.out.println("two pair");
			}
			else if(pair == 1){
				System.out.println("one pair");
			}
			else {
				System.out.println("null");
			}
			
		}
	}

}

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

int main(void){
	int l = 100000;
	float tl = 0.0;
	int n = 0;
	scanf("%d", &n);
	for(int i=0;i<n;i++){
		l = (int)(ceilf(l * 1.05f / 1000) * 1000);
	}
	printf("%d\n", l);
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
int main()
{
    char a[110],b[55]={0},c[55]={0};
    int n,mid,l,i,j;
    scanf("%d",&n);
    scanf("%s",&a);
    l=strlen(a);
    if(l%2!=0)
    {
        printf("No\n");
    }
    else
    {
        mid=l/2;
        for(i=0;i<mid;i++)
        {
            b[i]=a[i];
        }
        for(j=0,i=mid;i<l;i++,j++)
        {
            c[j]=a[i];
        }

        if(strcmp(b,c)==0)
            printf("Yes\n");
        else
            printf("No\n");
    }

}


Measured memory_bytes: 128
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 2e5 + 10;
int a[maxN];
ll dp[maxN];
int x[maxN];
ll pref[maxN];
map < ll, ll > mp[maxN];
ll solve(ll cur, int c) {
    if (c == 1) return cur;
    if (mp[c].count(cur)) return mp[c][cur];
    if (cur >= -pref[2]) return cur;
    int it = lower_bound(pref + 2, pref + c + 1, -cur) - pref;
    it -= 1;
    assert(-pref[it] >= cur);
    cur = -2 * pref[it] - cur;
    return mp[c][cur] = solve(cur, it - 1);

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n - 1; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n - 1; i++) pref[i] = pref[i - 1] + a[i];
    int m;
    cin >> m;
    while (m--) {
        ll cur;
        cin >> cur;
        cur -= pref[n - 1];
        cur = solve(cur, n - 2);
        cout << a[1] + pref[1] + cur << '\n';
    }
    /*for (int i = 1; i <= m; i++) {
        cin >> x[i];
    }
    dp[n - 1] = a[n - 1] - a[n];
    ll mn = -pref[n - 2] - dp[n - 1];
    for (int i = n - 2; i >= 1; i--) {
        dp[i] = a[i] + pref[i] + mn;
        mn = max(mn, -pref[i - 1] - dp[i]);
    }
    cout << dp[1];*/
    return 0;
}

Measured memory_bytes: 73544
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<map>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const int z = 1000000007;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
int main() {
    int n,q;
    cin >> n;
    map<int,int> ma;
    int tmp;
    llong sum=0;
    REP(i, n) {
        cin >> tmp;
        ma[tmp]++;
        sum += tmp;
    }
    cin >> q;
    vector<llong> anss(q);
    int b, c;
    REP(i, q) {
        cin >> b >> c;
        anss[i] = sum = sum + (c-b) * ma[b];
        ma[c] += ma[b];
        ma[b] = 0;
    }
    REP(i, q) {
        cout << anss[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 8308
import sys
input = sys.stdin.readline
n = int(input())
memo = [0 for i in range(n)]
for i in range(n):
  memo[int(input())-1] = i
cand = 0
tmp = 0
for n1, n2 in zip(memo[:], memo[1:]):
  if n2 > n1:
    tmp += 1
    if tmp > cand:
      cand = tmp
  else:
    tmp = 0
print(n - cand - 1)


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

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

int main()
{
    int n;
    scanf("%d", &n);

    for (int i = 0; i <= 50000; i++) {
        int x = floor(1.0 * i * 1.08);
        if (x == n) {
            printf("%d\n", i);
            return 0;
        }
    }

    printf(":(\n");

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <sstream>
#include <cassert>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <ctime>

using namespace std;

#define en '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const ll INFLL = 1e18;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int MAX_SIZE = 5e5;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

bool IS_ONE_TEST = 1;
ld START_TIME, TIME;

void fast_in_out() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void solve() {
    int n, q;
    cin >> n;
    vector<ll> a(n);
    map<ll, int> mp;
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ++mp[a[i]];
        sum += a[i];
    }
    cin >> q;
    while (q--) {
        int b, c;
        cin >> b >> c;
        sum -= mp[b] * b;
        sum += mp[b] * c;
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << en;
    }
}

int main() {
    START_TIME = clock();
    fast_in_out();
    int TESTS = 1;
    if (!IS_ONE_TEST) cin >> TESTS;
    while (TESTS--) { solve(); }
#ifdef __APPLE__
    TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    cerr << en << TIME * 1000 << " ms." << en;
#endif
    return 0;
}

/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


Measured memory_bytes: 9416
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
ll dp[51][51][2501];
int main(){
  int n,a;
  cin >> n >> a;

  vector<int> x(n+1);

  x[0] = 0;

  for(int i = 1;i <= n;i++)cin >> x[i];

  int X = max(a,*max_element(x.begin(),x.end()));

  for(int j = 0;j <= n;j++){
    for(int k = 0;k <= n;k++){
      for(int s = 0;s <= n*X;s++){
        if(j == 0 && k == 0 && s == 0)dp[j][k][s] = 1;
        else{
          if(j >= 1 && s < x[j])dp[j][k][s] = dp[j-1][k][s];
          else if(j >= 1 && k >= 1 && s >= x[j])dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j]];
          else dp[j][k][s] = 0;
        }
      }
    }
  }

  ll ans = 0;
  for(int k = 1;k <= n;k++){
    ans += dp[n][k][k*a];
  }

  cout << ans << endl;
}


Measured memory_bytes: 51072
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

int main() {
	//七日目

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

	string a, b, c;
	cin >> a >> b >> c;
	cout << 'A' << b[0] << 'C' << endl;
	
	return 0;
}

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

void to_int(char x, int &n) {
  
  if (x == '0') n = 0;
  else if (x == '1') n = 1;
  else if (x == '2') n = 2;
  else if (x == '3') n = 3;
  else if (x == '4') n = 4;
  else if (x == '5') n = 5;
  else if (x == '6') n = 6;
  else if (x == '7') n = 7;
  else if (x == '8') n = 8;
  else if (x == '9') n = 9;
  else cout << "error 'to_int' x different int" << endl;
}

long many_formulas(int i, long a, long b, vector<int> number_sequence) {
  long ans, n = number_sequence.at(i);

  if (i + 1 >= number_sequence.size()) return a + n + b;
  
  b += n;
  ans = many_formulas(i + 1, a, b * 10, number_sequence);
  
  a += b;
  return ans + many_formulas(i + 1, a, 0, number_sequence);
}

int main() {
  string X;
  char x;
  
  cin >> X;
  
  vector<int> number_sequence(X.size());
  for (int i = 0; i < number_sequence.size(); i++) {
  	x = X.at(i);
    
    to_int(x, number_sequence.at(i));
  }
  
  
  
  cout << many_formulas(0, 0, 0, number_sequence) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

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

	int R, C, K; cin >> R >> C >> K;
	vector<vector<ll>> item(R);
	vector<vector<vector<ll>>> dp(R);
	for (int i = 0; i < R; i++) {
		item[i].resize(C);
		dp[i].resize(C);
		for (int j = 0; j < C; j++) {
			item[i][j] = 0;
			dp[i][j].resize(4, 0);
		}
	}

	for (int i = 0; i < K; i++) {
		ll r, c, v; cin >> r >> c >> v;
		r--; c--;
		item[r][c] = v;
	}

	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			if (i > 0) {// 上から来る場合
				for (int k = 0; k < 4; k++) {
					chmax(dp[i][j][0], dp[i - 1][j][k]);
				}
			}
			if (j > 0) {// 左から来る場合
				for (int k = 0; k < 4; k++) {
					chmax(dp[i][j][k], dp[i][j - 1][k]);
				}
			}
			if (item[i][j] > 0) {// アイテムを拾う場合
				for (int k = 3; k > 0; k--) {
					chmax(dp[i][j][k], dp[i][j][k - 1] + item[i][j]);
				}
			}
		}
	}

	ll ans = 0;
	for (int k = 0; k < 4; k++) {
		chmax(ans, dp[R - 1][C - 1][k]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 706724
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include <utility>
#include<cstdlib>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<functional>
#include<algorithm>
#define ms0(a) memset(a,0,sizeof(a))
#define ms1(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
using namespace std;
typedef long long  ll;
//typedef __int64  ll;
const double Eps = (double)0.5;
const int M = 1e9 + 7;
const int N = 1e5 + 5;
const double PI = acos(-1.0);
int a[N];
bool b[N];
int main()
{
    int n;
    cin >> n;
    for(int i=1; i <= n; i++)
        cin>>a[i];
    int asr = 0;
    for(int i=1; i<= n ; i++)
    {
        if(!b[i])
        {
            int j = a[i];
            int k = a[j];
            if(i == k)
            {
                asr++;
                b[j] = true;
            }
        }
    }
    cout<<asr<<endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
typedef pair<int,int> P;
typedef pair<int,P> PP; 
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1e9+7;

int dp[100010][2];

signed main(){
  string l;
  cin>>l;
  dp[0][0]=1;
  for(int i=0;i<sz(l);i++){
    if(l[i]=='1'){
	 dp[i+1][0]+=(2*dp[i][0])%MOD;
	 dp[i+1][0]%=MOD;
	 dp[i+1][1]+=dp[i][0];
	 dp[i+1][1]%=MOD;
    }else{
	 dp[i+1][0]+=dp[i][0];
    }
    dp[i+1][1]+=(3*dp[i][1])%MOD;
    dp[i+1][1]%=MOD;
  }
  cout<<(dp[sz(l)][0]+dp[sz(l)][1])%MOD<<endl;
  return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String t = sc.next();
		for(int i = 0 ; i < n ; i++) {
			if(s.substring(i).equals(t.substring(0, n - i))) {
				System.out.println(i + n);
				return;
			}
		}
		System.out.println(s.length() + t.length());
	}
}


Measured memory_bytes: 21844
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    hq = [(-A[-1], -A[-1])]
    A.pop()

    ans = 0
    while A:
        a = A.pop()
        p, q = heappop(hq)
        p, q = -p, -q
        ans += p
        if a < p:
            heappush(hq, (-a, -p))
        else:
            heappush(hq, (-p, -a))
        if a < q:
            heappush(hq, (-a, -q))
        else:
            heappush(hq, (-q, -a))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 109300
import 'dart:io';
import 'dart:math';

void main(List<String> args) {
  final ABHM = stdin
      .readLineSync()
      .split(' ')
      .map(
        (x) => int.parse(x),
      )
      .toList();
  final A = ABHM[0];
  final B = ABHM[1];
  final H = ABHM[2];
  final M = ABHM[3];
  final Hx = 360 / 12 * H + 30 * M / 60;
  final Mx = 360 / 60 * M;
  final angle = (Hx - Mx).abs();
  final ans = sqrt(pow(A, 2) + pow(B, 2) - 2 * A * B * cos(angle * pi / 180));
  print(ans);
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	while(n != 0){
		int max, min;
		int ans,t;
		ans = 0;
		max = 0; min = 1000;
		for(int i = 0; i < n; i++){
			cin >> t;
			if(t > max) max = t;
			if(t < min) min = t;
			ans += t;
		}
		ans -= (max + min);
		ans /= n - 2;
		cout << ans << endl;
		cin >> n;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<cstdint>

int const MAXN = 1e5;

int64_t p[MAXN+1], q[MAXN+1], r[MAXN];
int64_t x[MAXN*2+1];
int X, Y, A, B, C;

int main() {
  std::cin >> X >> Y >> A >> B >> C;
  for(int i = 0; i < A; ++i) std::cin >> p[i];
  for(int i = 0; i < B; ++i) std::cin >> q[i];
  for(int i = 0; i < C; ++i) std::cin >> r[i];
  std::sort(p, p+A);
  std::sort(q, q+B);
  std::sort(r, r+C);
  std::merge(p+(A-X), p+A, q+(B-Y), q+B, x); x[X+Y] = 1e10;
  int ix = 0;
  for(int ic = C-1; ic >= 0; --ic) {
    if(x[ix] >= r[ic]) break;
    x[ix++] = r[ic];
  }
  int64_t ans = 0;
  for(int i = 0; i < X+Y; ++i) ans += x[i];
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 3968
def toggling_string(string):

    dummy = string.lower()
    res = list()
    
    for i in range(len(dummy)):
        if dummy[i] == string[i]:
            res.append(dummy[i].upper())
        else:
            res.append(dummy[i].lower())

    print("".join(res))

if __name__ == "__main__":
    
    sentence = input()
    toggling_string(sentence)



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

using ll=long long;

int main() {
  int N,i;
  ll f=0, l=0;
  cin >> N;
  vector<int> a(N*3);
  vector<ll> s(N+1,0);
  priority_queue<ll, vector<ll>, greater<ll>> pqf;
  priority_queue<ll> pql;
  
  for(i=0; i<N*3; i++) {
    cin >> a.at(i);
    if(i<N) {
      pqf.push(a.at(i));
      f += a.at(i);
    }
    if(i>=N*2) {
      pql.push(a.at(i));
      l += a.at(i);
    }
  }
  
  for(i=N; i<=N*2; i++) {
    s.at(i-N) +=  f;
    s.at(N*2-i) -= l;
    pqf.push(a.at(i));
    f += a.at(i)-pqf.top();
    pqf.pop();
    pql.push(a.at(N*3-i-1));
    l += a.at(N*3-i-1)-pql.top();
    pql.pop();
  }

  cout << *max_element(s.begin(), s.end()) << endl;
}

Measured memory_bytes: 4468
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import qualified Data.Vector.Unboxed as VU
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS

main :: IO ()
main = do
  [h, w] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    encode :: (Int, Int) -> Int
    encode (i, j) = i * w + j
    decode :: Int -> (Int, Int)
    decode = (`divMod` w)
    inside :: (Int, Int) -> Bool
    inside (i, j) = 0 <= i && i < h && 0 <= j && j < w
    neighbors :: VU.Vector Bool -> Int -> [Int]
    neighbors v k = filter (v VU.!) . map encode . filter inside $ [(i, j - 1), (i, j + 1), (i - 1, j), (i + 1, j)]
      where
        (i, j) = decode k
    search :: VU.Vector Bool -> Int -> Bool -> Int
    search _ _  False = 0
    search v k0 _     = snd . last $ queue
      where
        queue = (k0, 0) : walk 1 (IS.singleton k0) queue
        walk :: Int -> IntSet -> [(Int, Int)] -> [(Int, Int)]
        walk 0 _ _ = []
        walk l u ((k, d) : q) = map (flip (,) (d + 1)) ns ++ walk (l - 1 + length ns) u' q
          where
            ns = filter (`IS.notMember` u) $ neighbors v k
            u' = foldl (flip IS.insert) u ns
  bs <- VU.fromList . map ('.' ==) . concat . lines <$> getContents :: IO (VU.Vector Bool)
  print . VU.maximum . VU.imap (search bs) $ bs

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 5256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    bool jdg = true;
    if (N % 2 == 1) {
        if(A[0] != 0)jdg = false;
        for(int i = 1; i < N; i++){
            if(i % 2 == 0){
                if(A[i] != i)jdg = false;
            }else{
                if(A[i] != i + 1)jdg = false;
            }
        }
    }else{
        for(int i = 0; i < N; i++){
            if(i % 2 == 0){
                if(i + 1 != A[i])jdg = false;
            }else{
                if(i != A[i])jdg = false;
            }
        }
    }
    
    if(jdg){
        long long ans = 2;
        for(int i = 1; i < N / 2; i++){
            ans *= 2;
            ans %= MOD;
        }
        if(N == 1)ans = 1;
        cout << ans % MOD << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);
ll dx[8]={0,0,-1,1,-1,1,-1,1};
ll dy[8]={1,-1,0,0,1,1,-1,-1};
vector<vector<ll> > c(10,vector<ll>(10,0));

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,K; cin>>N>>K;
    vector<ll> minus;
    vector<ll> plus;
    vector<ll> zero;
    rep(i,N){
        ll x; cin>>x;
        if(x<0) minus.pb(x);
        else if(x==0) zero.pb(x);
        else plus.pb(x);
    }
    ll m=sz(minus),p=sz(plus),need=K-sz(zero);
    minus.pb(0);
    plus.pb(0);
    sort(all(minus),greater<ll>());
    sort(all(plus));
    
    ll ans=INF;
    rep(i,min(need,m)+1){
        if(need-i > p) continue;
        ll X=-minus[i];
        ll Y=plus[need-i];
        
        chmin(ans,max(X,Y)+min(X,Y)*2);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4556
// dile a la jardinera que traigo flores
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define tm1 ff
#define tm2 ss.ff
#define tm3 ss.ss
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define all(v) (v).begin(),(v).end()
#define FER(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define IFR(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 100005
#define M 27
#define N1 150005
#define N2 200005
#define MAXN 4353546332
//#define mod 1000000007
using namespace std;
typedef int ll;
typedef pair<ll,ll> ii;
typedef pair<ll, ii> tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
 
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif

int main(){
  fastio;
  ll n,k; cin>>n>>k;
  vi v1,v;
  FER(i,0,n){
    ll a; cin>>a;
    v.pb(a);
  }
  sort(all(v));
  ll ts1=upper_bound(all(v), k)-v.begin(),ini;
  //ll ts2=lower_bound(all(v), k)-v.begin();
  //cout<<ts1<<endl;
  FER(i,0,sz(v)) {
    if(i==0) ini=v[i];
    else v1.pb(v[i]-ini), ini=v[i];
  }
  //for(auto xd: v1) cout<<xd<<" "; cout<<endl;
  if(v[ts1]>k) v1.pb((v[ts1]-k));
  if(ts1>0) v1.pb(abs(v[ts1-1]-k));
  //for(auto xd: v1) cout<<xd<<" "; cout<<endl;
  ll ans=0;
  for(auto xd: v1){
    //cout<<xd<<endl;
    ans=__gcd(ans,xd);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1400
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()
b = N - 2
mi = A * b
ma = B * b
print(max(ma - mi + 1, 0))



Measured memory_bytes: 10628
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long min = 1000000000L;
        for(int i = 0; i < N; i++){
            long A = sc.nextLong();
            int cnt = 0;
            while(A % 2 == 0){
                cnt++;
                A /= 2;
            }
            if(min > cnt){
                min = cnt;
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 23252
import java.util.*;
public class Main
{
  public static void main(String args[])throws java.lang.Exception
  {
    Scanner in=new Scanner(System.in);
    int N=in.nextInt();
    int R=in.nextInt();
    if(N>=10)
      System.out.println(R);
    else
      System.out.println(R+100*(10-N));
  }
}

Measured memory_bytes: 21588
N, M = map(int, input().split())
D = dict()

for i in range(M):
    k, v = input().split()
    k = int(k)
    if k in D:
        if D[k] != v:
            print(-1)
            exit()
    else:
        D[k] = v

ans = list('0' * N)

if 1 in D and N != 1:
    if D[1] == '0':
        print(-1)
        exit()

for k, v in D.items():
    ans[k - 1] = v

if N != 1 and ans[0] == '0':
    ans[0] = '1'

print("".join(ans))

Measured memory_bytes: 3064