akhauriyash/Code-Regression huggingface dataset:
'use strict';
function Main(stdin){
  const input = stdin.trim().split('').map(str => Number(str));
  const A = input[0], B = input[1], C = input[2], D = input[3];
       if(A + B + C + D === 7){ console.log(A + '+' + B + '+' + C + '+' + D + '=7');}
  else if(A + B + C - D === 7){ console.log(A + '+' + B + '+' + C + '-' + D + '=7');}
  else if(A + B - C + D === 7){ console.log(A + '+' + B + '-' + C + '+' + D + '=7');}
  else if(A + B - C - D === 7){ console.log(A + '+' + B + '-' + C + '-' + D + '=7');}
  else if(A - B + C + D === 7){ console.log(A + '-' + B + '+' + C + '+' + D + '=7');}
  else if(A - B + C - D === 7){ console.log(A + '-' + B + '+' + C + '-' + D + '=7');}
  else if(A - B - C + D === 7){ console.log(A + '-' + B + '-' + C + '+' + D + '=7');}
  else if(A - B - C - D === 7){ console.log(A + '-' + B + '-' + C + '-' + D + '=7');}
}

// 固定
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.*;

public class Main {
	
	private static int[] list;
	
	public static void main(String[] args) {

		//input
		Scanner sc = new Scanner(System.in).useDelimiter(System.getProperty("line.separator"));
		int w = sc.nextInt();
		int n = sc.nextInt();
		w++;

		//initialization
		list = new int[w];
		for(int i=1;i<w;i++){list[i]=i;}
		
		//calculation
		String[] s;
		for(int i=0;i<n;i++){
			s = sc.next().split(",");
			swap(Integer.parseInt(s[0]),Integer.parseInt(s[1]));
		}

	    //output
		for(int i=1;i<w;i++){System.out.println(list[i]);}
	}
	
	private static void swap(int a,int b){
		list[b] = list[a] - list[b];
		list[a] -= list[b];
		list[b] += list[a];
	}
}

Measured memory_bytes: 17268
#include<bits/stdc++.h>
using namespace std;
long long int dp[100001];
int main()
{
    long long int n,k;
    cin>>n>>k;
    
    long long int h[n+1];
    h[0]=0;
    for(long long int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    //  dp[n+1];
    dp[1]=0;
    dp[0]=0;
    
    for(long long int i=2;i<=k;i++)
    {
        dp[i]=dp[i-1] + abs(h[i]-h[i-1]);
        for(long long int j=2;j<i;j++)
        {
        dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
        // curr=dp[i];
        }
    }
    
    // cout<<dp[n];
    
    for(long long int i=k+1;i<=n;i++)
    {
        dp[i]=dp[i-1] + abs(h[i]-h[i-1]);
        for(long long int j=2;j<=k;j++)
        {
        dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
        // curr=dp[i];
        }
    }
    
    cout<<dp[n];
    
    
}
    

Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int k;
  cin>>k;
  string s;
  cin>>s;
  int n = s.size();
  if(n <= k){
    cout << s << endl;
  }else{
    string ans = s.substr(0, k);
    ans += "...";
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<stack>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define drep(i,n) for(int i=((int)n)-1;i>-1;i--)
#define Rep(i,n0,n) for(int i=n0;i<((int)n);i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<((int)n);j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
#define INF2 (long long)8*(long long)INF*(long long)INF
#define mod 1000000007

typedef long long ll;

using namespace std;


int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){if(y>x)return y;else return x;}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
long long fact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i;}
int gcd(int x, int y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
ll gcd(ll x, ll y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
void say(bool x){if(x){cout<<"Yes"<<endl;}else {cout<<"No"<<endl;}return;}


int main()
{
    int n,m;
    cin >> n >>m;
    W((n-1)*(m-1))
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
const ll MOD = 2;

void solve(){
    ll n;cin>>n;
    vec a(n);rep(i,n)cin>>a[i];
    ll ans=100;
    rep(i,n)chmin(ans,(ll)__builtin_ctz(a[i]));
    cout<<ans<<endl;
}

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


Measured memory_bytes: 256
from math import log
import sys
n,k= map(int, raw_input().split())
a = map(int, raw_input().split())
if k is 0:
	ans = 0
	for i in range(n):
		ans += a[i]
	print(ans)
else:
	logk = int(log(k,2)) + 1
	num = []
	for i in range(logk):
		num.append(0)
	for i in range(n):
		memo = a[i]
		for j in range(logk):
			if memo%2 == 0:
				num[j] += 1
			else:
				num[j] -= 1
			memo = int(memo/2)
	ans = 0
	ans_m = -1
	suml = []
	suml.append(max(num[0],0))
	for i in range(logk-1):
		if num[i+1] > 0:
			suml.append(suml[i] + pow(2,(i+1))*num[i+1])
		else:
			suml.append(suml[i])
	num.reverse()
	suml.reverse()
	now = 0
	for i in range(logk):
		if k >= pow(2,(logk-1-i)):
			if i+1 < logk and ans < now + suml[i+1]:
				ans = now + suml[i+1]
			k -= pow(2,(logk-1-i))
			now += pow(2,(logk-1-i)) * num[i]
	ans = max(ans,now)
	for i in range(n):
		ans += a[i]
	print(ans)


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

void _130() {
    int n, x;
    int l[100];
    cin >> n >> x;
    for (int i = 0; i < n; ++i) { 
        cin >> l[i];
    }

    int d = 0;
    for (int i = 0; i < n; ++i) {
        d = d + l[i];
        // cout << d << endl;
        if (d > x) {
            cout << i + 1 << endl;
            return;
        }
    }
    cout << n + 1 << endl;
}


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



Measured memory_bytes: 256
import sys
from io import StringIO
import unittest


def resolve():
    N, M = [int(i) for i in input().split()]
    pp = []
    SS = []
    for _ in range(M):
        p, s = [i for i in input().split()]
        pp.append(int(p))
        SS.append(s)
    AC = 0
    WA = 0
    WAtmp = {}
    flgs = [False] * N
    for i in range(M):
        if not flgs[pp[i] - 1]:
            if SS[i] == "AC":
                AC += 1
                flgs[pp[i] - 1] = True
                if pp[i] - 1 in WAtmp.keys():
                    WA += WAtmp[pp[i] - 1]
            else:
                if pp[i] - 1 in WAtmp.keys():
                    WAtmp[pp[i] - 1] += 1
                else:
                    WAtmp[pp[i] - 1] = 1

    print(AC, WA)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 5
1 WA
1 AC
2 WA
2 AC
2 WA"""
        output = """2 2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """100000 3
7777 AC
7777 AC
7777 AC"""
        output = """1 0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """6 0"""
        output = """0 0"""
        self.assertIO(input, output)

    def test_入力例_n(self):
        input = """3 5
1 WA
1 AC
2 WA
2 AC
3 WA"""
        output = """2 2"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 22996
#include<cstdio>
#include<algorithm>
using namespace std;
int n,ans;
int l[202];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)
		scanf("%d",&l[i]);
	sort(l+1,l+2*n+1);
	for(int i=1;i<=2*n;i+=2)
		ans+=l[i];
	printf("%d",ans);
	//return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){

	int a[3],i,b,c;
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	for (i = 0; i < 2; i++){
		if (a[i] > a[i+1]){
			b = a[i];
			a[i ] = a[i+1];
			a[i+1] = b;
		}
	}
	if (a[0] > a[1]){
		c = a[0];
		a[0] = a[1];
		a[1] = c;
	}

	printf("%d %d %d\n", a[0], a[1], a[2]);

	return 0;
}

Measured memory_bytes: 596
minmp = 10000000
def main():
    def dfs(depth, pt):

        #深さmaxまでいったらMPを計算する
        if depth==n:
            mp_tmp = 0
            all_used = True
            for k in range(3):
                if pt.count(k) == 0:
                    all_used = False
                    break

                sum_tmp = 0
                mp_tmp += (pt.count(k) - 1)*10
                for l in range(n):
                    if pt[l] == k:
                        sum_tmp += moto[l]
                
                mp_tmp += abs(sum_tmp-take[k])

            if all_used == True:
                global minmp
                minmp = min(minmp,mp_tmp)
            
            return

        #次のパターンを試す
        for i in range(4):
            pt[depth] = i
            dfs(depth+1, pt)

        return

    #入力をとる
    take = [0]*3
    n,take[0],take[1],take[2] = map(int,input().split())
    moto = [int(input()) for i in range(n)]

    pt  = [3]*n
    for i in range(n):
        dfs(i,pt)

    print(minmp)

main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200001;
const ll inf=(ll)1e18;
ll n,a[N],k,num=0;

int Find(int now,ll x)
{
	int l=now+1,r=n,best=now;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(a[now]*a[mid]<=x) l=mid+1,best=mid;
		else r=mid-1;
	}
	return best;
}

int Find2(int now,ll x)
{
	int l=now+1,r=n,best=n+1;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(a[now]*a[mid]<=x) r=mid-1,best=mid;
		else l=mid+1;
	}
	return best;
}

bool check(ll x)
{
	ll ret=0;
	for(int i=1;i<n;i++)
	{
		if(a[i]>=0) ret+=Find(i,x)-i;
		else ret+=n-Find2(i,x)+1;
	}
	return ret>=k;
}

int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	ll l=-inf,r=inf,ans=-1;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(check(mid)) r=mid-1,ans=mid;
		else l=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5232
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// 2???????????????????????????????±???????
double dot(P a, P b) {
    return (a.X * b.X + a.Y * b.Y);
}

// 2???????????????????????????????±???????
double cross(P a, P b) {
    return (a.X * b.Y - a.Y * b.X);
}

int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if( cross(b,c) > EPS ) return +1;
    if( cross(b,c) < -EPS ) return -1;
    if( dot(b,c) < 0 ) return +2;
    if( norm(b) < norm(c) ) return -2;
    return 0;
}

vector<P> convexHull(vector<P> ps) {
    int n = ps.size();
    // sort(ps.begin(),ps.end(), cmp_y);
    sort(ps.begin(),ps.end());
    int k = 0;
    vector<P> convex(n*2);
    for(int i=0; i<n; i++) {
        while (k >= 2 && ccw(convex[k-2], convex[k-1], ps[i]) == -1 ) k--;
        convex[ k++ ] = ps[i];
    }
    for(int i=n-2, t=k; i>=0; i--) {
        while (k > t && ccw(convex[k-2], convex[k-1], ps[i]) == -1 ) k--;
        convex[ k++ ] = ps[i];
    }
    convex.resize(k-1);
    return convex;
}

int main() {
    int n;
    while(cin >> n) {
        if(n == 0) break;
        vector<P> ps;
        P a;
        rep(i,0,n) {
            scanf("%lf,%lf", &a.X, &a.Y);
            ps.pb(a);
        }
        vector<P> ans = convexHull(ps);
        cout << n - ans.size() << endl;
    }
    return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    for(int i=0;i<tx-sx;i++) cout << 'R';
    for(int i=0;i<ty-sy;i++) cout << 'U';
    for(int i=0;i<tx-sx;i++) cout << 'L';
    for(int i=0;i<ty-sy;i++) cout << 'D';
    for(int i=0;i<1;i++) cout << 'D';
    for(int i=0;i<tx-sx+1;i++) cout << 'R';
    for(int i=0;i<ty-sy+1;i++) cout << 'U';
    for(int i=0;i<1;i++) cout << 'L';
    for(int i=0;i<1;i++) cout << 'U';
    for(int i=0;i<tx-sx+1;i++) cout << 'L';
    for(int i=0;i<ty-sy+1;i++) cout << 'D';
    for(int i=0;i<1;i++) cout << 'R';
    return 0;
}


Measured memory_bytes: 3628
from collections import*
n,*v=map(int,open(0).read().split())
a,b=[Counter(i).most_common()+[(0,0)]for i in(v[::2],v[1::2])]
i,j=a[0][1],b[0][1]
print(min(n-i-b[1][1],n-a[1][1]-j)*(a[0][0]==b[0][0])or n-i-j)

Measured memory_bytes: 66544
#include <set>
#include <cmath>
#include <vector>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
const long long lim = 1000000000000000;
const int sublim = (int)sqrt(lim) / 3;
const vector<int> dx = { 1, 0, -1, 0 };
const vector<int> dy = { 0, 1, 0, -1 };
bool valid(vector<int> v1, vector<int> v2) {
	return (v1[0] >= v2[0] && v1[1] >= v2[1] && v1[2] >= v2[2] && v1[3] >= v2[3]) || (v1[0] <= v2[0] && v1[1] <= v2[1] && v1[2] <= v2[2] && v1[3] <= v2[3]);
}
vector<int> solve(int a, int b, int c, int d) {
	vector<vector<int> > v;
	int basemul = 1;
	int ret = 0;
	for (int i = 0; basemul <= sublim; ++i) {
		int bmul = basemul;
		for (int j = 0; bmul <= sublim; ++j) {
			int mul = bmul;
			for (int k = 0; mul <= sublim; ++k) {
				int smul = mul;
				for (int l = 0; smul <= sublim; ++l) {
					++ret;
					smul *= d;
					v.push_back({ i, j, k, l });
				}
				mul *= c;
			}
			bmul *= b;
		}
		basemul *= a;
	}
	sort(v.begin(), v.end());
	vector<bool> used(v.size());
	int cur = v.size() - 1;
	vector<vector<int> > seq;
	while (true) {
		used[cur] = true;
		seq.push_back(v[cur]);
		int ncur = -1;
		for (int i = 0; i < v.size(); ++i) {
			if (!used[i] && valid(v[cur], v[i])) {
				ncur = i;
			}
		}
		if (ncur == -1) break;
		cur = ncur;
	}
	vector<int> ans;
	for (vector<int> i : seq) {
		int mul = 1;
		for (int j = 0; j < i[0]; ++j) mul *= a;
		for (int j = 0; j < i[1]; ++j) mul *= b;
		for (int j = 0; j < i[2]; ++j) mul *= c;
		for (int j = 0; j < i[3]; ++j) mul *= d;
		ans.push_back(mul);
	}
	return ans;
}
long long gcd(long long x, long long y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
long long lcm(long long x, long long y) {
	return x / gcd(x, y) * y;
}
int main() {
	vector<int> c1 = solve(2, 7, 17, 19);
	vector<int> c2 = solve(3, 5, 11, 13);
	int n;
	cin >> n;
	set<long long> s;
	vector<vector<long long> > v(n, vector<long long>(n));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			int a = i + j, b = i - j + ((n - 1) / 2) * 2;
			if (a % 2 == 0) {
				v[i][j] = 1LL * c1[a / 2] * c2[b / 2];
				s.insert(v[i][j]);
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if ((i + j) % 2 == 1) {
				long long delta = 1;
				for (int k = 0; k < 4; ++k) {
					int tx = i + dx[k], ty = j + dy[k];
					if (0 <= tx && tx < n && 0 <= ty && ty < n) {
						delta = lcm(delta, v[tx][ty]);
					}
				}
				v[i][j] = delta + 1;
				while (s.count(v[i][j])) v[i][j] += delta;
				s.insert(v[i][j]);
				assert(v[i][j] <= lim);
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (j) cout << ' ';
			cout << v[i][j];
		}
		cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 17152
/* apple.c */
#include<stdio.h>
int main(void)
{
  int a,p,k;
  scanf("%d %d",&a,&p);
  k=a*3+p;
  if(k%2==0)
  printf("%d\n",k/2);
  if(k%2==1)
    printf("%d\n",(k-1)/2);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
 
 
using namespace std;

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

    long long n, k, q;
    cin >> n >> k >> q;
    vector<int> counts(n, 0);

    int t;
    for (int i = 0; i < q; i++) {
        cin >> t; t--;
        counts[t]++;
    }

    for (int i = 0; i < n; i++) {
        if (q - counts[i] < k) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

import heapq

n, m = map(int, input().split())
a = []
for _ in range(n):
	a.append(list(map(int, input().split())))
a.sort()
a.append([m+1, 0])

h = []
ptrA = 0
ans = 0
for i in range(m):
	while a[ptrA][0] <= i + 1:
		heapq.heappush(h, a[ptrA][1] * (-1))
		ptrA += 1
	if len(h) > 0:
		ans += heapq.heappop(h)
print(-ans)


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

int main() {
    int n;
    cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    for(int i=0;i<n;i++){
        cin >> x.at(i) >> u.at(i);
    } 
    double total=0;
    for(int i=0;i<n;i++){
        if(u.at(i)=="JPY"){
            total += x.at(i);
        }
        else{
            total += x.at(i) * 380000.0;
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    int b_4=0, e=0, o=0;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i]%4==0){
            b_4++;
        }else if(a[i]%2==0){
            e++;
        }else{
            o++;
        }
    }
    if(o==n){
        puts("No");
        return 0;
    }
    if(e+b_4==n){
        puts("Yes");
        return 0;
    }
    if(2*b_4+1>=n){
        puts("Yes");
        return 0;
    }
    if(n-2*b_4<=e){
        puts("Yes");
        return 0;
    }
    puts("No");
    return 0;
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int s;
    cin >> s;
    vector<int> a;
    a.push_back(s);
    int i = 0;
    while(1) {
        int v;
        if (a[i] % 2 == 0){
            v = a[i]/2;
        } else {
            v = 3*a[i]+1;
        }
        bool ok = false;
        for (int k = 0; k < (int)a.size(); k++){
            if (a[k] == v){
                cout << i+2 << endl;
                ok = true;
                break;
            }
        }
        if (ok){
            break;
        }
        i++;
                
        /*
        if (binary_search(all(a),v)){
            auto Iter = lower_bound(all(a),v);
            cout << Iter- a.begin() << endl;
            break;
        }
        */
        a.push_back(v);
        //sort(all(a));
    }




    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, N) cin >> h[i];

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

    int right = 0, cnt = 0;
    ll ans = 1e9;
    for(int left = 0; left < N; left++){
        ll hmin, hmax;
        while(right < N && cnt < K){
            hmin = h[left];
            hmax = h[right];
            right++;
            cnt++;
        }

        ans = min(ans, hmax - hmin);

        cnt--;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 640
// Triangle.c
// 三角形の２辺 a, b とその間の角 C から、
// その三角形の面積 S、周の長さ L, a を底辺としたときの
// 高さ h を求めるプログラムを作成して下さい。
// 【入力】
// a の長さ, b の長さ, Cの大きさ（度）（整数）が空白区切りで与えられます。
// 【出力】
// S, L, h をそれぞれ1行に出力して下さい。0.0001以下の誤差があってもよいものとします。
// 【例】
// 入力：
// 4 3 90
// 出力：
// 6.00000000
// 12.00000000
// 3.00000000
#include<stdio.h>
#include<math.h>

int main( void) {
  double a, b;
  double C;
  double PI = acos(-1);
  double rad;
  double S, L, h;

  scanf( "%lf %lf %lf", &a, &b, &C);

  rad = ( C * PI) / 180;
  h = b * sin( rad);

  S = ( a * b * sin( rad)) /2;

  L = a + b + sqrt( pow( a, 2) + pow( b, 2) - 2 * a * b * cos(rad));

  printf( "%.8lf\n", S);
  printf( "%.8lf\n", L);
  printf( "%.8lf\n", h);

  return 0;
}



Measured memory_bytes: 2108
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <cmath>     //sin, cos, tan

using namespace std;
typedef long long ll;

int main(void)
{
    ll n;
    cin >> n;
    map<ll, ll> ans;
    for(ll i = 1;i <= sqrt(n);i++)
    {
        for(ll j = 1;j <= sqrt(n);j++)
        {
            for(ll k = 1;k <= sqrt(n);k++)
            {
                ans[i*i + j*j + k*k + i*j + j*k + i*k]++;
            }
        }
    }
    //output
    for(ll i = 0;i < n;i++)
    {
        cout << ans[i + 1] << endl;
    }
}

Measured memory_bytes: 5864
n=int(input())
s=[]
t=[]
for i in range(n):
  s.append(input())
m=int(input())
for i in range(m):
  t.append(input())

m=0
for i in range(n):
  x=s.count(s[i])-t.count(s[i])
  m=max(m,x)

print(m)

Measured memory_bytes: 9152
import java.io.*;
import java.util.*;
class Main
{
	public static void main(String[] args) throws IOException
    {
      	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer(br.readLine());
      	int h1 = Integer.parseInt(st.nextToken());
        int m1 = Integer.parseInt(st.nextToken());
      	int h2 = Integer.parseInt(st.nextToken());
        int m2 = Integer.parseInt(st.nextToken());
      	int k = Integer.parseInt(st.nextToken());
      	System.out.println(h2*60+m2-h1*60-m1-k);
    }
}

Measured memory_bytes: 32636
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  n <- unsafeSignedDecimal <$> T.getLine :: IO Int
  (a1 : as) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  bs <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    abs = zip as bs
    k = fst . foldl step (0, a1) $ abs
    step (q, r) (a, b) = if r + a <= b then (q + r + a, 0) else if r <= b then (q + b, r + a - b) else (q + b, a)
  print k

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 11772
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
//#define bint int1024_t
#define ld long double
#define vect vector<ll>
#define unmap unordered_map
#define pb push_back
#define F first
#define pll pair<ll,ll>
#define S second
#define pi 3.1415926536
#define mod int(1e9+7)
//ios_base::sync_with_stdio(false);cin.tie(NULL);
#define testcases ll t; cin>>t; while(t--)

using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

ll v[12][13];
ll n,m,x;

ll give(ll mask)
{
    ll dp[m]={0},ans=0;
    for(ll i=0;i<n;i++)
    {
        if(mask&(1<<i))
        {
            ans+=v[i][0];
            for(int j=1;j<=m;j++) dp[j-1]+=v[i][j];
        }
    }

    for(int i=0;i<m;i++) if(dp[i]<x) return LONG_MAX;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m>>x;
    for(int i=0;i<n;i++) for(int j=0;j<=m;j++) cin>>v[i][j];

    ll ans=LONG_MAX;

    for(ll i=1;i<(1<<n);i++)
    {
        ans=min(ans,give(i));
    }
    if(ans==LONG_MAX) cout<<-1;
    else cout<<ans;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define mod 1000000007
#define pb push_back
#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define reps(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) for(int i=0;i<int(b);i++)
#define first ff
#define second ss
#define size sz
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
typedef vector<int> vi;
const int INF = 1e9 + 5;
int main()
{
    csl;
    int n;
    cin >> n;
    int a[n];
    rep(i,n)
    {
        cin >> a[i];
    }

    vector<int> dp(n,INF);
    dp[0] = 0;
    rep(i,n)
    {
        for(int j:{i+1,i+2})
            {
                if(j<n)
                {
                    dp[j] = min(dp[j],dp[i] + abs(a[i]-a[j]));
                }
            }
    }

    cout << dp[n-1] << endl;
}



Measured memory_bytes: 4036
#include <stdio.h> 
 
 
 int main(){ 
     int x, y; 
     while(1){ 
         scanf("%d %d", &x, &y); 
         if(x==0 && y==0)break; 
         if(x<y){ 
             printf("%d %d\n", x, y); 
         }else{ 
             printf("%d %d\n", y, x); 
         } 
     } 
     return 0; 
 } 



Measured memory_bytes: 2044
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, now, ans = 0, be, h;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) {
    scanf("%lld", &h);
    if(i && be >= h) now++, ans = ans < now ? now : ans;
    else now = 0;
    be = h;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int N;
inline bool infected(int S, int x, int y){
  return S >> (y * N + x) & 1;
}
int next(int S, int bx, int by){
  int NS = 0;
  for(int y = 0; y < N; y++){
    for(int x = 0; x < N; x++){
      if(bx == x && by == y) continue;
      int cnt = 0;
      for(int r = 0; r < 8; r++){
        if(valid(x + dx[r], y + dy[r], N, N) && infected(S, x + dx[r], y + dy[r]))cnt++;
        if(bx == x + dx[r] && by == y + dy[r]) cnt++;
        if(cnt >= 4) break;
      }
      if(infected(S, x, y) && (cnt == 2 || cnt == 3)) NS |= 1 << (y * N + x);
      if(!infected(S, x, y) && cnt == 3) NS |= 1 << (y * N + x);
    }
  }
  return NS;
}
void output(int bx, int by, int s, int t){
  printf("time = %d:\n", t);
  REP(y, 5){
    REP(x, 5){
      if(x == bx && y == by){
        assert(!infected(s, x, y));
        putchar('@');
      }else if(infected(s, x, y)){
        putchar('#');
      }else{
        putchar('.');
      }
    }
    putchar('\n');
  }
  putchar('\n');
}

int main(){
  while(cin >> N && N){
    vector<string> grid(N);
    REP(i, N) cin >> grid[i];
    int ss = 0, sx = 0, sy = 0;
    REP(y, N) REP(x, N) {
      if(grid[y][x] == '@'){
        sx = x, sy = y;
      }
      if(grid[y][x] == '#'){
        ss |= 1 << (y * N + x);
      }
    }
    queue<int> qs, qx, qy;
    qx.push(sx); qy.push(sy); qs.push(ss);
    map<int, int> dist[5][5];
    int ans = -1;
    while(!qx.empty()){
      int x = qx.front(), y = qy.front(), s = qs.front();
      //output(x, y, s, dist[y][x][s]);
      qx.pop(); qy.pop(); qs.pop();
      if(s == 0){
        ans = dist[y][x][s];
        break;
      }
      REP(r, 8){
        int nx = x + dx[r];
        int ny = y + dy[r];
        if(valid(nx, ny, N, N) && !infected(s, nx, ny)){
          int ns = next(s, nx, ny);
          if(!dist[ny][nx].count(ns)){
            dist[ny][nx][ns] = dist[y][x][s] + 1;
            qx.push(nx); qy.push(ny); qs.push(ns);
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
std::string S;

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

  std::cin >> N >> S;

  int cnt = 0;

  for(int i=0;i+3<=N;++i){
      if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
          cnt += 1;
      }
  }

  std::cout << cnt << std::endl;
}


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


int N, M ;
int P [100000], Y [100000];
vector < int > yd [100001];
int main ()
{
    cin >> N >> M;
    for (int i =0; i < M ; i ++)
        cin >> P[i] >> Y[i], yd [ P [ i ]]. push_back ( Y [ i ]);
    for (int i =0; i < N ; i ++)
        sort ( yd [ i +1]. begin (), yd [ i +1]. end ());
    for (int i =0; i < M ; i ++)
        printf ("%012lld\n", ll ( P [ i ])*1000000+ int ( lower_bound ( yd [ P [ i ]].
                begin (), yd [ P [ i ]]. end (), Y [ i ]) - yd [ P [ i ]]. begin ())+1);
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
int dfs(int,int,int);
char table[255][256];
int dx[4]={0,1,1,-1},
	dy[4]={1,0,1,1};
int mx=-1,n,xx,yy;
int main(void)
{
	int i,j,k;

	cin>>n;
	while(n) {
		for(i=0;i<n;i++) cin>>table[i];
		mx=0;
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
				if(table[i][j]=='1') {
					for(k=0;k<4;k++) {
						mx=max(mx,dfs(i,j,k)+1);
					}
				}
			}
		}
		cout<<mx<<endl;
		cin>>n;
	}
	return 0;
}
int dfs(int y,int x,int suu)
{
	int i,j,k;
	xx=x+dx[suu];
	yy=y+dy[suu];
	if(table[yy][xx]=='1'&&yy>=0&&yy<n&&xx>=0&&xx<n) {
		return (dfs(yy,xx,suu)+1);
	}
	return 0;
}
	
	

Measured memory_bytes: 3128
from itertools import groupby

N, M = map(int, input().split())

classes = []

for m in range(M):
  P, Y = map(int, input().split())
  classes.append( (P, Y) ) 

classes_rank = {}
for key, cls in groupby(sorted(classes, key=lambda x:x[0]), lambda x:x[0]):
  for index, c in enumerate(sorted(list(cls), key=lambda x:x[1])):
    classes_rank[c] = index + 1

for cls in classes:
  P, Y = cls
  rank = classes_rank[ cls ]
  print('{P:06d}{rank:06d}'.format(P=P, rank=rank))

Measured memory_bytes: 30812
import sys
input=sys.stdin.readline
 
n,w=map(int,input().split())
dp=[0]*(w+1)
 
def ans(n,w):
  for _ in range(n):
    c,p=map(int,input().split())
    for j in range(w,c-1,-1):
      tmp=dp[j-c]+p
      if dp[j]<tmp:
        dp[j]=tmp
  return max(dp)
print(ans(n,w))

Measured memory_bytes: 9716
#include "bits/stdc++.h"
using namespace std;

int cnt[3];
char buf[100002];
int main() {
	scanf("%s", buf);
	string s = buf;
	for (int i = 0; i < s.size(); i++) {
		cnt[s[i] - 'a']++;
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (i != j) {
				for (int k = 0; k < 3; k++) {
					if (i != k&&j != k) {
						int cnt2[] = { cnt[0],cnt[1],cnt[2] };
						int ar[] = { i,j,k };
						int flag = 0;
						while (cnt2[ar[flag]]) {
							cnt2[ar[flag]]--;
							flag++;
							flag %= 3;
						}
						if (cnt2[0] == 0 && cnt2[1] == 0 && cnt2[2] == 0) {
							puts("YES");
							return 0;
						}
					}
				}
			}
		}
	}
	puts("NO");
	return 0;
}

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

const int N = 150;

int n, m, a[N];
vector<int> odd, even, ans;

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++)
		scanf("%d", a + i);
	if(m == 1) {
		if(n > 1) printf("%d\n2\n1 %d\n", a[1], a[1] - 1);
		else printf("1\n1\n1\n"); 
		return 0;
	} else {
		int cnt_odd = 0;
		for(int i = 1; i <= m; i++) {
			cnt_odd += a[i] & 1;
			if(a[i] & 1) odd.push_back(a[i]);
			else even.push_back(a[i]);
		}
		if(cnt_odd > 2) return 0 * printf("Impossible\n");
		if(!cnt_odd) {
			for(int i = 1; i <= m; i++)
				printf("%d ", a[i]);
			if(a[1] - 1) printf("\n%d\n%d ", m, a[1] - 1);
			else printf("\n%d\n", m - 1);
			for(int i = 2; i < m; i++)
				printf("%d ", a[i]);
			printf("%d\n", a[m] + 1);
			return 0;
		} else if(cnt_odd == 1) {
			printf("%d ", odd[0]);
			for(auto u : even) printf("%d ", u);
			if(odd[0] - 1) printf("\n%d\n%d ", m, odd[0] - 1);
			else printf("\n%d\n", m - 1);
			for(int i = 0; i < (int) even.size() - 1; ++i)
				printf("%d ", even[i]);
			printf("%d\n", (even[even.size() - 1]) + 1);
		} else {
			printf("%d ", odd[0]);
			for(auto u : even) printf("%d ", u);
			printf("%d", odd[1]);
			if(odd[0] - 1) printf("\n%d\n%d ", m, odd[0] - 1);
			else printf("\n%d\n", m - 1);
			for(auto u : even) printf("%d ", u);
			printf("%d\n", odd[1] + 1);
		}
	}
	return 0;
}

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

int		main(void)
{
	ll n;
	cin >> n;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 && i % 5)
			ans += i;
	}
	cout << ans << endl;
	return (0);
}


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

int main(void) {
    int K;
    string S;
    cin >> K >> S;

    if (S.size() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
from bisect import bisect_left,bisect_right

N = int(input())
A = list(map(int,input().split()))

diff_AB = [(i+1-A[i]) for i in range(N)]
diff_AB.sort()

ans = 0
for i in range(N):
    ans += (bisect_right(diff_AB,A[i]+i+1)- bisect_left(diff_AB,A[i]+i+1))

print(ans)


Measured memory_bytes: 32380
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {
    
    int n; cin >> n;
    string s; cin >> s;
    int x = 0;
    int memo[n];
    rep(i,n) {
        if (s[i] == 'I') ++x;
        else --x;
        memo[i] = x;
    }
    int ans = 0;
    rep(i,n) ans = max(ans, memo[i]);
    out(ans);
    
    return 0;
}






Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aoj.ALDS.Chapter6B
{
    class Program
    {
        /// <summary>
        /// partition??§??????????????????????????????
        /// ??????????????????????´?????????????????????\??????
        /// ??????????????????????´???????????????????????????§?????????????????????array??????????????????
        /// (array???????????´?£???????????????????)???
        /// </summary>
        /// <param name="array"></param>
        /// <param name="first">??°??????????????????????´??????????</param>
        /// <param name="last">??°??????????????????????´???????(??????)???</param>
        /// <param name="partition">partition??¨??????????????????????´??????????</param>
        /// <returns>partition??????????±??????????????´??????????</returns>
        public static int Partition<T>(List<T> array, int first, int last, int partition = -1)
        where T : IComparable<T>
        {
            if (first < 0 || last >= array.Count)
                throw new System.ArgumentException("");

            if (partition == -1)
                // ?????????????????§???????°????????´?????????????????????£?????§???????????????
                partition = last;

            // ???????????£?????§???????±???¨?????????(last?????????????§????????????????)???
            T x = array[partition];
            Swap(array, partition, last);

            int i = first;
            for (int j = first; j < last; j++)
            {
                if (array[j].CompareTo(x) <= 0)
                {
                    Swap(array, i, j);
                    // ?????°i???Swap???????????´??°???????????????????????????????????¨????¢?????????????????????????????????????
                    i++;
                }
            }

            // ????°?????????????????????????x?????????????????£?????§??????????±??????????Swap???
            Swap(array, i, last);

            return i;
        }

        private static void Swap<T>(List<T> array, int i, int j)
        {
            T tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }

        public static void Solve()
        {
            int n = int.Parse(Console.ReadLine());
            var list = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse).ToList();


            // foreach
            int pIndex = Partition(list, 0, n - 1);
            for (int i = 0; i < n; i++)
            {
                if (i == pIndex)
                {
                    Console.Write("[{0}]", list[i]);
                }
                else
                {
                    Console.Write("{0}", list[i]);
                }

                if (i < n - 1)
                    Console.Write(" ");
            }
            Console.WriteLine("");
        }
        public static void Main()
        {
            // Console.SetIn(new System.IO.StreamReader("Aoj/AlgorithmsAndDataStructures/Input/06_Sort_B_01.txt"));
            Solve();
        }
    }
}

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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

const int N = 1e5 + 5;

bool is_palin(string& t, int l, int r) {
    debug(
        for (int i = l; i < r; i++)
            cout << t[i];
        cout << endl;
    )
    int j = r-1;
    for (int i = l; i < r; i++, j--) {
        if (t[i] != t[j])
            return false;
    }

    return true;
}


int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    string t; cin >> t;
    int n = t.size();

    if (is_palin(t, 0, n) && is_palin(t, 0, n/2) && is_palin(t, (n+3)/2 - 1, n)) {
        cout << "Yes" << endl;
    } else cout << "No" << endl;

    return 0;
%>

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(){
    int x;
    cin >> x;
    string ans ="NO";
    if(x==7||x==5||x==3){
        ans = "YES";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
#include <initializer_list>
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


const unsigned int BIT_FLAG_0 = (1<<0);
const unsigned int BIT_FLAG_1 = (1<<1);
const unsigned int BIT_FLAG_2 = (1<<2);
const unsigned int BIT_FLAG_3 = (1<<3);
const unsigned int BIT_FLAG_4 = (1<<4);
const unsigned int BIT_FLAG_5 = (1<<5);
const unsigned int BIT_FLAG_6 = (1<<6);
const unsigned int BIT_FLAG_7 = (1<<7);


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;


int main(void){
  // 
  string S;
  cin>>S;

  int N=S.length();
  
  int cnt=0;
  stack<char> Ss;
  stack<char> Ll;
  // while (Ss.empty()) {
  //   Ss.push(S.)
  // }

  
  FOR(i,0,N){
    Ss.push(S[i]);
  }

  // 
  Ll.push(Ss.top());
  Ss.pop();
  char temp;
  // 
  while(Ss.size()){           // まずSsが空でないか判定．空でなければ繰り返す．
    if (Ll.size()) {              // Llの中身があるか判定．あれば次の処理を繰り返す．
      temp=Ll.top();              // Llのtopを取り出す．
      if(temp==Ss.top() ){        // SsとLlのtopを比較．(0,0),(1,1)とかならそのまま．違ければ消す
        Ll.push(Ss.top());
        Ss.pop();
        // cerr<<Ss.size()<<" ";
      }else{                    // SsとLlのtopが違うとき．消す．
        Ll.pop(); Ss.pop();
        cnt+=2;
        // cerr<<Ss.size()<<" ";
      }
    }else{                        // Llが空っぽのとき
      Ll.push(Ss.top());
      Ss.pop();
      // cerr<<Ss.size()<<" ";
    }
  }
  cout << cnt << "\n";
  return 0;
}


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


using namespace std;

int main() {
    int n;
    cin >> n;
    long a[n], plus=0;
    for (auto &ai:a) {
        cin >> ai;
        if (ai > 0) plus++;
    }
    sort(a, a+n);
    long left = a[n-1], right = a[0], outl[n], outr[n];
    int j = 0;
    if (plus < n-1) {
        for (int i=1; i<n-1 && a[i] <= 0; i++) {
            outl[j] = left;
            outr[j] = a[i];
            left -= a[i];
            j++;
        }
    }
    //cerr << j << '\n';
    if (plus > 0) {
        for (int i=n-2; i>0 && a[i] > 0; i--) {
            outl[j] = right;
            outr[j] = a[i];
            right -= a[i];
            j++;
        }
    }
    outl[j] = left;
    outr[j] = right;
    //cerr << j << '\n';
    cout << left - right << '\n';
    for (int i=0; i<n-1; i++) {
        cout << outl[i] << ' ' << outr[i] << '\n';
    }
    return 0;
}


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

int main()
{
	int a, b, c = 0;
	cin >> a >> b >> c;
	int ans = 0;
	
	while (b >= a)
	{
		ans++;
		if (ans == c)
		{
			break;
		}
		b -= a;
	}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';
#line 2 "b2.cpp"

bool f(string s) {
  ll n = s.size();
  rep(i, n) {
    if (s[i] != s[n-1-i]) {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;

  ll n = s.size();

  if (f(s) and f(s.substr(0, (n-1)/2)) and f(s.substr((n+3)/2-1))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int d[15][15];

int s[105][105];

int main() {
  int a, b;
  cin >> a >> b;
  for (int ai = 1; ai <= a; ai++) {
    for (int bi = 1; bi <= b; bi++) {
      cin >> d[ai][bi];
    }
  }
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      int ss = 0;
      for (int ai = 1; ai <= a; ai++) {
        for (int bi = 1; bi <= b; bi++) {
          int sss = d[ai][bi] - ai * i - bi * j;
          if (sss > ss) ss = sss;
        }
      }
      s[i][j] = ss;
    }
  }
  bool feasible = true;
  for (int ai = 1; ai <= a; ai++) {
    for (int bi = 1; bi <= b; bi++) {
      int dd = 999999999;
      for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
          int ddd = ai * i + bi * j + s[i][j];
          if (ddd < dd) dd = ddd;
        }
      }
      if (dd != d[ai][bi]) feasible = false;
    }
  }
  if (feasible) {
    cout << "Possible" << endl;
    cout << "202 10401" << endl;
    for (int i = 0; i < 100; i++) {
      cout << i + 1 << " " << i + 2 << " X" << endl;
    }
    for (int i = 0; i < 100; i++) {
      cout << i + 102 << " " << i + 103 << " Y" << endl;
    }
    for (int i = 0; i <= 100; i++) {
      for (int j = 0; j <= 100; j++) {
        cout << i + 1 << " " << 202 - j << " " << s[i][j] << endl;
      }
    }
    cout << "1 202" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 892