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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int n;
	cin >> n;
	Int ans = 0;
	RC(i, n + 1){
		if(i % 3 && i % 5){
			ans += i;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e18;
const ll mod = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	ll ans = 111;
	while(n > ans){
		ans += 111;
	}
	dump(ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);


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

  ll n, m;
  cin >> n >> m;
  if (n > m) swap(n, m);
  ll ans = 0;
  if (n == 1 && m == 1) {
    ans = 1;
  } else if (n == 1) {
    ans = m - 2;
  } else if (n == 2) {
    ans = 0;
  } else {
    ans = (n * m) - (2 * n + 2 * m - 4);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
const int INF = 1 << 29;

struct Edge {
  int to, cap, rev;
  Edge(int t, int c, int r) : to(t), cap(c), rev(r) {}
};

struct Flow {
  vector< vector< Edge > > G;
  const int MAXC = 1 << 29;
  int n;
  vector<int> used;
  Flow(int n_) : G(n_), n(n_), used(n_, false) {}

  void add_edge(int from, int to, int cap) {
    G[from].push_back(Edge(to, cap, G[to].size()));
    G[to  ].push_back(Edge(from, 0, G[from].size() - 1));
  }

  int dfs(int v, int t, int f) {
    if(v == t) return f;
    used[v] = true;
    for(int i=0; i<G[v].size(); i++) {
      Edge &e = G[v][i];
      if(!used[e.to] and e.cap > 0) {
	int d = dfs(e.to, t, min(f, e.cap));
	if(d > 0) {
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }

  int max_flow(int s, int t) {
    int flow = 0;
    while(1) {
      fill(used.begin(), used.end(), false);
      int f = dfs(s, t, INF);
      if(f == 0) return flow;
      flow += f;
    }
  }
};

int main() {
  int N; cin >> N;
  vector<int> a(N), b(N);
  for(int i=0; i<N; i++) {
    cin >> a[i] >> b[i];
  }

  const int D = 32;
  Flow fl(N + D + 2);
  int source = N + D, sink = source + 1;
  for(int i=0; i<N; i++) fl.add_edge(source, i, 1);
  for(int i=0; i<D; i++) fl.add_edge(N+i, sink, 1);
  for(int i=0; i<N; i++) {
    for(int j=a[i]; j<=b[i]; j++) {
      fl.add_edge(i, N+j, 1);
    }
  }
  int one = fl.max_flow(source, sink);
  int two = 31 - one;
  cout << one * 100 + two * 50 << endl;
  return 0;
}



Measured memory_bytes: 3160
N,Y = map(int, input().split())
# print([10*x+5*y+(N-x-y) for y in range(N+1) for x in range(N+1)].count(Y/1000))
res = '-1 -1 -1'
for x in range(N+1):
    for y in range(N+1-x):
        z = N-x-y
        if (10000*x+5000*y+1000*z==Y):
            res = str(x)+' '+str(y)+' '+str(z)
            break
print(res)

Measured memory_bytes: 3060
a = [[int(i) for i in input().split()] for _ in range(3)]
c=[[False]*3 for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                c[i][j] = True
ok = False
for i in range(3):
    d = True
    for j in range(3):
        if c[i][j] == False:
            d = False
    if d:
        ok = True

for i in range(3):
    d = True
    for j in range(3):
        if c[j][i] == False:
            d = False
    if d:
        ok = True
d = True
for j in range(3):
    if c[j][j] == False:
        d = False
if d:
    ok = True

d = True
for j in range(3):
    if c[j][2-j] == False:
        d = False
if d:
    ok = True
print("Yes"if ok else"No")

Measured memory_bytes: 38384
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dw[300100];
ll de[300100];

int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	clr(dw,0);
	clr(de,0);
	rep(i,0,s.sz){
		if(s[i]=='E'){
			de[i+1]=1;
		}
		else{
			dw[i+1]=1;
		}
	}
	rep(i,1,s.sz+1){
		de[i]+=de[i-1];
		dw[i]+=dw[i-1];
	}
	ll mn = 1000000000;
	rep(i,0,s.sz){
		mn = min(mn,dw[i]+de[s.sz]-de[i+1]);
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 5380
N = int(input())
S = input()

cnt = 0
s = ''
for i in range(N):
    if S[i] == '(':
        cnt += 1
    else:
        cnt -= 1
        if cnt < 0:
            s += '('
            cnt = 0
s += S
if cnt:
    s += ')' * cnt

print(s)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    string a,b;
    cin >> a >> b;
    string c = a+b;
    int d = stoi(c);
    int num = sqrt(d);
    if(pow(num,2)==d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	long long zb = 0;
	int n,w;
	cin >> n >> w;
	vector<int> predmeti(n);
	vector<int> tezine(n);
	for (int i = 0; i < n; i++)
	{
		cin >> tezine[i] >> predmeti[i];
		zb += predmeti[i];
	}
	vector<long long> dp(zb + 1, 1e13);
	dp[0] = 0;
	for (int i = 0; i < n; i++)
		for (int j = zb; j >= predmeti[i]; j--)
			dp[j] = min(dp[j - predmeti[i]] + tezine[i], dp[j]);
	for (int j = zb; j >= 0; j--)
		if (dp[j] <= w)
		{
			cout << j;
			break;
		}
}

Measured memory_bytes: 1024
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x: u32,
    }
    if x < 1200 {
        println!("ABC");
    } else {
        println!("ARC");
    }
} 


Measured memory_bytes: 4352
S = input()
count = 0
start = 0
end = 1
hold_value = ""
while end <= len(S):
    if hold_value == S[start:end]:
        end += 1
    else:
        hold_value = S[start:end]
        #print(hold_value)
        start = end
        end += 1
        count += 1
print(count)

Measured memory_bytes: 3500
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include<algorithm>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;

int main()
{
    ll H,W,res;

    cin >> H >> W;

    vector <string> strMap(H);

    ll L[2100][2100];
    ll R[2100][2100];
    ll U[2100][2100];
    ll D[2100][2100];

    REP(i,H)
    {
        cin >> strMap[i];
    }
    ll cur;
    //各点が何ます上下に行けるかをみる

    //左　左は端が0
    REP(i,H)
    {
        cur = 0;
        REP(j,W)
        {
            if(strMap[i][j] == '#')cur = 0;
            else cur++;
            L[i][j] = cur;
        }
    }
    //右
    REP(i,H)
    {
        cur = 0;
        for(ll j = W - 1; j >= 0; j--)
        {
            if(strMap[i][j] == '#')cur = 0;
            else cur++;
            R[i][j] = cur;
        }
    }
    //上 Wが先
    REP(i,W)
    {
        cur = 0;
        for(ll j = 0; j < H; j++)
        {
            if(strMap[j][i] == '#')cur = 0;
            else cur++;
            U[j][i] = cur;
        }
    }
    //上 Wが先
    REP(i,W)
    {
        cur = 0;
        for(ll j = H - 1; j >=0; j--)
        {
            if(strMap[j][i] == '#')cur = 0;
            else cur++;
            D[j][i] = cur;
        }
    }

    //合計
    res = 0;
    REP(i,H) {
        REP(j,W) {
            if (strMap[i][j] == '#') continue;
            res = max(res, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
            //自分の位置を4つで全部足してるので -3 
        }
    }

    cout << res << endl;

}



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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    unordered_map<int64_t, int64_t> mp, mm;
    for (auto i : irange(0L, n)) {
        int64_t a;
        cin >> a;

        ++mp[a + i];
        ++mm[a - i];
    }

    int64_t ans = 0;
    for (const auto& [t, m] : mp) {
        ans += m * mm[-t];
    }

    cout << ans << endl;
}

Measured memory_bytes: 26344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int N;
  cin >> N;
  int X = 111;
  rep(i, 10) {
    if(N <= X) {
      break;
    }
    X += 111;
  }
  cout << X << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
int n,last,nb,cou[5],cnt;
bool vis[100005];
int main()
{
	scanf("%d",&n);
	for(int N=1;N<=n;N<<=1){if(N==n) return 0*puts("No");vis[N]=1;}
	puts("Yes");
	puts("1 2");
	puts("2 3");
	printf("3 %d\n",1+n);
	printf("%d %d\n",n+1,n+2);
	printf("%d %d\n",n+2,n+3);
	if(n%4==3) {
		for(int i=4;i<=n;i+=4)
		{
			printf("%d %d\n",i-1+n,i);
			for(int j=i;j<i+3;j++) printf("%d %d\n",j,j+1);
			printf("%d %d\n",i+3,i+n);
			for(int j=i+n;j<i+n+3;j++) printf("%d %d\n",j,j+1);
		}
		return 0;
	}
	for(int i=4;i+3<=n;i+=4)
	{
		for(int j=i;j<i+3;j++) printf("%d %d\n",j,j+1);
		printf("%d %d\n",i+3,i+n);
		for(int j=i+n;j<i+n+3;j++) printf("%d %d\n",j,j+1);
	}
	for(int i=n;i%4!=3;i--) cou[++cnt]=i;
	if(vis[cou[cnt]]&&cnt==3) {
		int U=cou[cnt];
		printf("%d %d\n%d %d\n",U+1,U+2,U+1+n,U+2+n);
		printf("%d %d\n%d %d\n",U+2,3,U+1+n,3);
		printf("%d %d\n%d %d\n",U,1+n,U+n,U+2);
		for(int i=4;i+3<=n;i+=4)
			printf("%d %d\n",i-1+n,i);
		return 0;
	}
	for(int i=cnt;i>=2;i--) printf("%d %d\n%d %d\n",cou[i],cou[i-1],cou[i]+n,cou[i-1]+n);
	last=cou[cnt]+n;
	for(int i=1;i<=4-cnt;i++) nb^=cou[1]+i;
	if(nb%4)
	{
		printf("%d %d\n",last,nb%4);
		last=nb%4;
	}
	else printf("%d 1\n",last);
	for(int i=4;i+3<=n;i+=4)
	{
		printf("%d %d\n",last,i);
		if(vis[i]&&((nb/i)&1)) last=i;
	}
	printf("%d %d\n",last,cou[1]);
	return 0;
}

Measured memory_bytes: 2816
from itertools import permutations

n,m=map(int,input().split())
ans=0
s=[list(map(int,input().split())) for i in range(m)]

t=list(permutations(list(range(1,n+1))))
for i in range(len(t)):
    flag=True
    if t[i][0]!=1: continue
    for j in range(n-1):
        a=sorted([t[i][j],t[i][j+1]])
        if a not in s: flag=False
    if flag: ans+=1
print(ans)

Measured memory_bytes: 8052
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

#pythonだとTLE/pypyだとAC
'''
r,g,b,n = iim()
ans = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        num = n-i*r-j*g
        if num%b == 0 and num//b >= 0:
#            print(i,j,num//b)
            ans += 1
print(ans)
'''

#上を受けてpythonでも通るように改良
*num,n = iim()
a,b,c = map(int,sorted(num))
ans = 0
for i in range(n//c+1):
    if a!= 1:
        for j in range(n//b+1):
            num = n-i*c-j*b
            if num%a == 0 and num//a >= 0:
                ans += 1
    else:
        ret = n - i*c
        ans += ret//b+1
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N),vec(N);
    rep(i,0,N)cin >> V[i];
    sort(V.begin(), V.end());
    ll sum = 0;
    //偶数
    rep(i,0,N){
        if(i < N/2){
            vec[i * 2 + 1] = V[i];
        }else{
            vec[(i - N / 2) * 2] = V[i];
        }
    }
    if(N % 2){
        if(N >= 3)swap(vec[N-1], vec[2]);
    }
    //rep(i,0,N)cout << vec[i] << " \n"[i == N-1];
    rep(i,0,N-1){
        sum += std::abs(vec[i+1] - vec[i]);
    }
    if(N % 2 == 0){
        cout << sum << endl;
        return 0;
    }
    //cout << sum << endl;

    ll maxi = sum;
    sum = 0;
    
    rep(i,0,N){
        if(i < N/2+1){
            vec[i * 2] = V[i];
        }else{
            vec[(i - N / 2) * 2 - 1] = V[i];
        }
    }
        if(N >= 4)swap(vec[0], vec[N-3]);   

    //rep(i, 0, N) cout << vec[i] << " \n"[i == N - 1];
    rep(i, 0, N - 1)
    {
        sum += std::abs(vec[i + 1] - vec[i]);
    }
    maxi = max(maxi, sum);
    cout << maxi << endl;
    /*
    do{
        sum = 0;
        rep(i, 0, N - 1)
        {
            sum += std::abs(V[i + 1] - V[i]);
        }
        maxi = max(maxi, sum);
    } while (next_permutation(V.begin(), V.end()));
    cout << maxi << endl;
    */
}  

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  string s;
  cin>>s;
  ll one=0, zero=0;
  rep(i,s.size()){
    if(s[i]=='0')zero++;
    else one++;
  }
  //cout<<one<<zero<<endl;
  cout<<2*min(one,zero)<<endl;
}

Measured memory_bytes: 512
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n,k=map(int,input().split())
k-=1
x=list(map(int,input().split()))

ans=10**9

for i in range(n-k):
    # light up [i,i+k]
    if x[i]<0 and x[i+k]<0:
        ans=min(ans,-x[i])
    elif x[i]>0 and x[i+k]>0:
        ans=min(ans,x[i+k])
    else:
        t=abs(x[i])+abs(x[i+k])+min(abs(x[i]),abs(x[i+k]))
        ans=min(ans,t)
print(ans)


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int K;
  int a[32] = {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
  cin >> K;
  cout << a[K-1] << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)

def main():
    N,K = map(int,input().split())
    sushi = [tuple(map(int,input().split())) for _ in range(N)]

    sushi.sort(key = lambda x:x[1],reverse = True)
    ans = 0
    dic = {}
    change = []
    for a,b in sushi[:K]:
        if a in dic:
            dic[a].append(b)
            change.append((a,b))
        else:
            dic[a] = [b]
        ans += b

    various = len(dic)
    ans += various ** 2
    ret = ans
    used_type = set(dic.keys())
    suggestion = [p for p in sushi[K:] if p[0] not in used_type]
    for a,b in suggestion:
        if len(change) == 0:
            break
        if a in used_type:
            continue
        dic[change[-1][0]].pop()
        ret -= change[-1][1]
        ret += b + 2*various + 1
        dic[a] = b
        change.pop()
        various += 1
        used_type.add(a)
        ans = max(ans,ret)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 30896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair

int main() {
	double a,b,x;
	cin >> a >> b >> x;
	double pi = 3.141592653589793238;
	cout << fixed << setprecision(10);
	if((a*a*b)/2.0>=x) cout << atan2(a*b*b,x*2)*180/pi << endl;
	else cout << atan2(2*(a*a*b-x),a*a*a)*180/pi << endl;
}


Measured memory_bytes: 4100
#include<bits/stdc++.h>
using namespace std;
int mcxi_to_dec(string mcxi){

  int num=0;
  int n=1;
  bool check;
  
  for(int i=0 ; i < mcxi.size() ; i++){
    check=false;
    if(mcxi[i] >= '2' && mcxi[i] <= '9'){
      n=mcxi[i]-48;
      check=true;
    }
    
    if(mcxi[i] == 'm'){
      num+=n*1000;
    }else if(mcxi[i] == 'c'){
      num+=n*100;
    }else if(mcxi[i] == 'x'){
      num+=n*10;
    }else if(mcxi[i] == 'i'){
      num+=n;
    }
    
    if(!check){
      n=1;
    }
  }
 
  return num;
}
void output(int sum){
  
  int n[4];
  
  n[0]=sum/1000;
  sum%=1000;
  n[1]=sum/100;
  sum%=100;
  n[2]=sum/10;
  n[3]=sum%10;
  
  for(int i=0 ; i < 4 ; i++){
    if(n[i] == 0)continue;
    if(n[i] != 1)cout <<n[i];
    switch(i){
    case 0:
      cout <<"m";
      break;
    case 1:
      cout <<"c";
      break;
    case 2:
      cout <<"x";
      break;
    case 3:
      cout <<"i";
      break;
    }
  }
  
  cout <<endl;
  
}
int main(){

  int n,sum;
  string mcxi1,mcxi2;

  cin >>n;
  
  for(int i=0 ; i < n ; i++){
    cin >>mcxi1>>mcxi2;
    sum=mcxi_to_dec(mcxi1)+mcxi_to_dec(mcxi2);
    output(sum);
  }

}

Measured memory_bytes: 1212
package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

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

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

	n := nextInt()
	k := nextInt()

	if k == 1 {
		fmt.Println(0)
		return
	}

	var left = n - k

	fmt.Println(left)
}


Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
int main(void){
	long int i,a,n,n1,n2,n3=0;
	scanf("%ld",&a);
	scanf("%ld",&n);
	n1=n;
	n2=n;
	n3=n;
	for(i=1;i<a;i++){
		scanf("%ld",&n);
		if(n1>n){
		n1=n;
		}
		if(n2<n){
		n2=n;
		}
		n3+=n;
	}
	printf("%ld %ld %ld\n",n1,n2,n3);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

vector<long long> Dijkstra(long long start,vector<vector<pair<long long,long long>>> adj){
  long long V = adj.size();
  vector<long long> dmin(V,-1);
  priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>> pque;
  pque.push(make_pair(0,start));
  pair<long long,long long> p;
  while(pque.size()){
    p = pque.top();
    pque.pop();
    if(dmin[p.second] == -1){
      dmin[p.second] = p.first;
      for(auto x:adj[p.second]){
        if(dmin[x.first] == -1)pque.push(make_pair(dmin[p.second]+x.second,x.first));
      }
    }
  }
  return dmin;
}

signed main(){
  int n,m,s,t;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  vector<vector<pair<ll,ll>>> sunuke(n),yen(n);
  int u,v,a,b;
  FOR(i,0,m){
    cin >> u >> v >> a >> b;
    u--;
    v--;
    yen[u].pb(make_pair(v,a));
    yen[v].pb(make_pair(u,a));
    sunuke[u].pb(make_pair(v,b));
    sunuke[v].pb(make_pair(u,b));
  }
  vector<long long> dminy = Dijkstra(s,yen),dmins = Dijkstra(t,sunuke);
  long long MAX = 0;
  long long ans[n];
  REP(i,0,n){
    MAX = max(MAX,(ll)1e15-dminy[i]-dmins[i]);
    ans[i] = MAX;
  }
  FOR(i,0,n){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 27448
let id x = x
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern

let (h, w) = Scanf.scanf "%d %d\n" @@ fun h w -> (h, w)
let a = Array.init h (fun _ -> Array.of_list (split_string (Scanf.scanf "%s\n" id)))

let da = Array.init h @@ fun x -> Array.init w @@ fun y -> if a.(x).(y) = "#" then 0 else max_int

let que = Queue.create ()

let add x y d = 
  List.iter (fun (x, y) ->
    if 0 <= x && x < h && 0 <= y && y < w && da.(x).(y) > d then Queue.add (x, y, d) que
  ) [(x + 1, y); (x - 1, y); (x, y + 1); (x, y - 1)]

let () =
  for x = 0 to (h - 1) do
    for y = 0 to (w - 1) do
      if da.(x).(y) = 0 then 
        add x y 1          
    done
  done;
  while not (Queue.is_empty que) do
    let (x, y, d) = Queue.pop que in
    if da.(x).(y) > d then begin
      da.(x).(y) <- d;
      add x y (d + 1)
    end
  done;
  print_int @@ Array.fold_left max 0 @@ Array.map (Array.fold_left max 0) da

Measured memory_bytes: 162072
#include <iostream>
#include <vector>

using namespace std;

long A[100000];
long sum[100001];
long sum_abs[100001];
vector<int> negs;

int main(){
    int N;
    cin >> N;
    //cout << negs.size() << endl;
    long ans;
    sum[0] = 0;
    sum_abs[0] = 0;
    cin >> A[0];
    sum[1] = A[0];
    sum_abs[1] = A[0];
    for(int i = 1; i < N; i++){
        char op;
        cin >> op;
        cin >> A[i];
        if(op == '-') {
            A[i] *= -1;
            negs.push_back(i);
        }
        sum[i+1] = sum[i]+A[i];
        sum_abs[i+1] = sum_abs[i]+abs(A[i]);
    }
    ans = sum[N];
    for(int i = 0; i+1 < negs.size(); i++){
        int l = negs[i];
        int r = negs[i+1];
        long tmp = sum_abs[N]-sum_abs[r] + sum[l+1] - (sum_abs[r]-sum_abs[l+1]);
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3064
import java.util.*;


public class Main{ 

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int nodeNum = scan.nextInt();
		AdjacencyMatrices am = new AdjacencyMatrices(nodeNum);

		am.readMatrix(scan);
		Iterator<Edge> iter = am.getIter();

		UnionFind unionFind  = new UnionFind(nodeNum);
		int sumDist = 0;
		int id=0;
		while(iter.hasNext()){
			Edge e = iter.next();

			if(!unionFind.same(e.x, e.y)){
				sumDist += e.dist;
				unionFind.union(e.x, e.y);
			}
		}
		System.out.println(""+sumDist);
	}

}

class Edge implements Comparable<Edge>{
	int x;
	int y;
	int dist;
	int id;
	public Edge(int x, int y, int d,int id){
		this.x = x;
		this.y = y;
		this.dist = d;
		this.id = id;
	}
	@Override
 	public int compareTo(Edge other) {
		return this.dist - other.dist;
	}
	@Override
	public String toString(){
		return "x: " + x + " y : " + y + " dist : " + dist;
	}
}
class AdjacencyMatrices{
	int pointNum;
	ArrayList<Edge> edgeList = new ArrayList<Edge>();
	public AdjacencyMatrices(int n){
		pointNum = n;
	}
	public void readMatrix(Scanner scan){
		int id = 0;
		for(int i=0; i<pointNum; i++)
			for(int j=0; j< pointNum; j++){
				int dist = scan.nextInt();
				if(j > i && dist>=0)
					edgeList.add(new Edge(i, j, dist, id++));
		}
	}

	public Iterator<Edge> getIter(){
		Collections.sort(edgeList);
		return edgeList.iterator();
	}

}
class UnionFind{
    int[] index;
    public UnionFind(int n){
        index = new int[n];
        for(int i=0; i<n; i++)
            index[i] = i;
    }
    int find(int x){
        if(index[x]==x)
            return x;
        else
            return find(index[x]);
    }
    boolean same(int x, int y){
        return find(x) == find(y);
    }
    void union(int x, int y){
        int rootx = find(x);
        int rooty = find(y);
        if(rootx == rooty)
            return;
        else
            index[rooty] = rootx;
    }
    void printIndex(){
        for(int i=0; i<index.length; i++)
            System.out.print(" " + index[i]);
        System.out.println("");
    }

}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = input1[0];
            var K = input1[1];

            IEnumerable<int> A = new List<int>();

            for (int i = 0; i < K; i++)
            {
                Console.ReadLine();
                A = A.Concat(Console.ReadLine().Split().Select(int.Parse));
            }

            Console.WriteLine(N - A.Distinct().Count());
        }
    }
}


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

class CantWaitHoliday
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();

        string[] dayList = new string[7]
        {
            "SAT","FRI","THU","WED","TUE","MON","SUN"
        };

        for(var i = 0; i < dayList.Length; i++)
        {
            if(input == dayList[i])
            {
                Console.WriteLine(i + 1);
            }
        }
    }
}

Measured memory_bytes: 11092
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    ArrayList[] list1 = new ArrayList[n];
    ArrayList[] list2 = new ArrayList[n];
    for(int i = 0; i < n; i++) {
      ArrayList<Integer> l1 = new ArrayList<Integer>();
      ArrayList<Integer> l2 = new ArrayList<Integer>();
      int a = sc.nextInt();
      for(int j = 0; j < a; j++) {
        int x = sc.nextInt();
        int y = sc.nextInt();
        l1.add(x - 1);
        l2.add(y);
      }
      list1[i] = l1;
      list2[i] = l2;
    }
    int ans = 0;
    for(int i = 1; i < (int)Math.pow(2, n); i++) {
      int[] p = new int[n];
      int sum = 0;
      for(int j = 0; j < n; j++) {
        if((i & (1 << j)) != 0) {
          p[j] = 1;
          sum++;
        }
      }
      int t = 0;
      for(int j = 0; j < n; j++) {
        if(p[j] == 1) {
          ArrayList<Integer> l1 = list1[j];
          ArrayList<Integer> l2 = list2[j];
          for(int k = 0; k < l1.size(); k++) {
            if(p[l1.get(k)] != l2.get(k)) t++;
          }
        }
      }
      if(t == 0) ans = Math.max(ans, sum); 
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 24992
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t N,K;
  cin>>N>>K;
  if(K%2!=0){
  int64_t ans=N/K;
    ans=powl(ans,3);
    cout<<ans<<endl;
  }else{
  int64_t a=N/K;
    a=powl(a,3);
    int64_t b=(N+K/2)/K;
    b=powl(b,3);
    int64_t ans=a+b;
    cout<<ans<<endl;
  }
  
   return 0;
}

Measured memory_bytes: 512
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;

int main()
{
	sync;
	ll arr[5];
	input(arr,(ll)5);
	ll k;
	cin>>k;
	int flag=1;
	for(ll i=0;i<5;i++)
	for(ll j=0;j<5;j++)
	if(abs(arr[i]-arr[j])>k)
	flag=0;
	if(flag)
	cout<<"Yay!";
	else
	cout<<":(";
}


Measured memory_bytes: 256
d = dict()
d['a'] = 1
d['b'] = 2
d['c'] = 3
d['d'] = 4
d['e'] = 5
d['f'] = 6
d['g'] = 7
d['h'] = 8
d['i'] = 9
d['j'] = 10
d['k'] = 11
d['l'] = 12
d['m'] = 13
d['n'] = 14
d['o'] = 15
d['p'] = 16
d['q'] = 17
d['r'] = 18
d['s'] = 19
d['t'] = 20
d['u'] = 21
d['v'] = 22
d['w'] = 23
d['x'] = 24
d['y'] = 25
d['z'] = 26

e = dict()
e[1] = 'a'
e[2] = 'b'
e[3] = 'c'
e[4] = 'd'
e[5] = 'e'
e[6] = 'f'
e[7] = 'g'
e[8] = 'h'
e[9] = 'i'
e[10] = 'j'
e[11] = 'k'
e[12] = 'l'
e[13] = 'm'
e[14] = 'n'
e[15] = 'o'
e[16] = 'p'
e[17] = 'q'
e[18] = 'r'
e[19] = 's'
e[20] = 't'
e[21] = 'u'
e[22] = 'v'
e[23] = 'w'
e[24] = 'x'
e[25] = 'y'
e[26] = 'z'

s = input()
t = input()
lists = []
listt = []
for i in range(len(s)):
	lists.append(d[s[i]])
for i in range(len(t)):
	listt.append(d[t[i]])
lists.sort()
listt.sort()
listt.reverse()
check = True
for i in range(len(s)):
	if i < len(listt):
		if lists[i] < listt[i]:
			check = True
			break
		elif lists[i] > listt[i]:
			check = False
			break
		else:
			if i != len(t)-1:
				check = True
			else:
				check = False
if check:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3192
#include<iostream>
using namespace std;
int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;
  for (int i = 0;i < dx;++ i) cout << 'R';
  for (int i = 0;i < dy;++ i) cout << 'U';
  for (int i = 0;i < dx;++ i) cout << 'L';
  for (int i = 0;i <= dy;++ i) cout << 'D';
  for (int i = 0;i <= dx;++ i) cout << 'R';
  for (int i = 0;i <= dy;++ i) cout << 'U';
  cout << "LU";
  for (int i = 0;i <= dx;++ i) cout << 'L';
  for (int i = 0;i <= dy;++ i) cout << 'D';
  cout << 'R';
}

Measured memory_bytes: 256
#include <stdio.h>
 
double j(double,double,double,double,double,double,double,double);
 
main(){
  double x1, x2, x3, y1, y2, y3, xp, yp;
  double xc, yc;
  int ans;
 
  while(1){
    ans=0;
    if(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp)==EOF) break;
    xc=(x1+x2+x3)/3;
    yc=(y1+y2+y3)/3;
    if(j(x1,y1,x2,y2,xp,yp,xc,yc)<0.0){
      ans=1;
    }
    if(j(x1,y1,x3,y3,xp,yp,xc,yc)<0.0){
      ans=1;
    }
    if(j(x2,y2,x3,y3,xp,yp,xc,yc)<0.0){
      ans=1;
    }
    if(ans==1) printf("NO\n");
    else if(ans==0) printf("YES\n");
  }
  return 0;
}
 
double j(double p1x,double p1y,double p2x,double p2y,double p3x,double p3y,double p4x,double p4y){
  double a;
  a=((p1x-p2x)*(p3y-p1y)+(p1y-p2y)*(p1x-p3x))*
    ((p1x-p2x)*(p4y-p1y)+(p1y-p2y)*(p1x-p4x));
 
  return a;
}

Measured memory_bytes: 612
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
 ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
    ll ans  = n * (mi+ma) /2;
    return ans;
}
ll kw(ll k,ll n){
    
    ll ans  =0;
    ll mi,ma;
    mi= wa(k,0,k-1);
    
    ma = wa(k,n-k+1,n);
    
    return (ma-mi +1)%modd;
}

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

    ll ans = 0;

    for(int i = 1;i<n;i++){
        ans += i;
    }
    cout << ans <<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N, K;
    string S;
    cin >> N >> K >> S;
    int l = 0, r = 1;
    int iter = 0;
    while (l < N && K > 0) {
        while (r < N && S[l] == S[r]) ++r;
        if (iter % 2) {
            FOR(i, l, r) S[i] = S[0];
            --K;
        }
        ++iter;
        l = r++;
    }
    int res = 0;
    REP(i, N - 1) res += (S[i] == S[i + 1]);
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define US unordered_set
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<vector<ll>> Graph;
struct Node {ll v,d,p,l,r;};
typedef vector<Node> Tree;

int main(){
  ll N; cin>>N;
  vi p(N); REP(i,N) cin>>p[i];
  ll cnt=0;
  REP(i,N-1) if(p[i]==i+1) {swap(p[i],p[i+1]);cnt++;}

  if(p[N-1]==N) {
    cnt++;
  }

  cout<<cnt<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int n;
  cin>>n;
  int ac=0;
  int wa=0;
  int tle=0;
  int re=0;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    if(s=="AC") ac++;
    else if(s=="WA") wa++;
    else if(s=="TLE") tle++;
    else re++;
  }
  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;
}

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

const int K = 18, N = 1<<K, X = 9;

typedef pair<int, int> PII;
int v[N], w[N], cnt[N];
vector<PII> small[N];

vector<PII> combine(vector<PII> x) {
    vector<PII> ans;
    ans.push_back({0, 0});

    for (PII pr: x) {
        vector<PII> ex;
        for (int i=0; i<ans.size(); i++) {
            PII nw = {ans[i].first+pr.first, ans[i].second+pr.second};
            ex.push_back(nw);
        }
        vector<PII> merged(ans.size()+ex.size());
        merge(ans.begin(), ans.end(), ex.begin(), ex.end(), merged.begin());
        ans = merged;
    }
    return ans;
}

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

    int n;
    cin>>n;

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


    int q;
    cin>>q;

    while (q--) {
        int u, L;
        cin>>u>>L;

        vector<pair<int, int>> ll, rr;
        while (u) {
            PII pr = {w[u], v[u]};
            if (ll.size() == X)  rr.push_back(pr);
            else                 ll.push_back(pr);
            u = u/2;
        }

        ll = combine(ll);
        rr = combine(rr);

        for (int i=1; i<ll.size(); i++) ll[i].second = max(ll[i].second, ll[i-1].second);
        for (int i=1; i<rr.size(); i++) rr[i].second = max(rr[i].second, rr[i-1].second);


        int ans = 0;
        for (int i=0; i<ll.size(); i++) {
            if (ll[i].first > L)    break;
            int rem = L-ll[i].first;
            while (rr.size() && rr.back().first>rem)    rr.pop_back();
            assert(rr.size());

            ans = max(ans, ll[i].second+rr.back().second);
        }
        cout<<ans<<"\n";
    }
}


Measured memory_bytes: 11884
#include<iostream>
#include<math.h>
using namespace std;

int main() {
    int N, D; cin >> N >> D;
    int X[N][D];
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            double dis = 0;
            for (int k = 0; k < D; k++) {
                dis += pow(X[i][k] - X[j][k], 2);
            }
            if (sqrt(dis) == int(sqrt(dis))) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

int main(){
    int h, w, a, b;
    scanf("%d%d%d%d", &h, &w, &a, &b);

    int x, y;
    bool flag = false;
    rep(i, h+1){
        rep(j, w+1){
            if(a*i+(w-a)*(h-i) == b*j+(h-b)*(w-j)){
                flag = true;
                x = i;
                y = j;
                break;
            }
        }
        if(flag) break;
    }

    if(!flag){
        printf("No\n");
        return 0;
    }

    int s[h][w];
    rep(i, h)rep(j, w) s[i][j] = 0;
    int l = 0; int r = a;
    int cnt[w], lim[w];
    rep(j, w) cnt[j] = 0;
    rep(j, y) lim[j] = b;
    For(j, y, w) lim[j] = h-b;
    rep(i, x){
        while(l < w && cnt[l] == lim[l]){
            ++l;
            ++r;
        }
        if(l == w) break;
        For(j, l, min(r, w)){
            s[i][j] = 1;
            ++cnt[j];
        }
    }
    l = 0; r = w-a;
    For(i, x, h){
        while(l < w && cnt[l] == lim[l]){
            ++l;
            ++r;
        }
        if(l == w) break;
        For(j, l, min(r, w)){
            s[i][j] = 1;
            ++cnt[j];
        }
    }

    rep(i, h){
        rep(j, w) printf("%d", s[i][j]);
        printf("\n");
    }
}

Measured memory_bytes: 5248
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE OverloadedStrings #-}

import           Control.Applicative
import           Control.Monad
import           Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

import           Prelude               hiding (getChar)

import           Data.Array.IO
import           Data.Array.MArray

-- 螺旋本の移植

-- n以上の素数
_M :: Int
_M = 1046527

getChar :: Char -> Int
getChar 'A' = 1
getChar 'C' = 2
getChar 'G' = 3
getChar 'T' = 4
getChar _   = 0

-- 逆順にしたものを5進数とみなして10進数に変換
-- 例：ACG -> 321 -> 86
getKey :: ByteString -> Int
getKey bs = go 0 1 bs
  where
    go !s !p cs =
        case B.uncons cs of
            Nothing      -> s
            Just (x, xs) -> go (s + p * getChar x) (p * 5) xs

h1 :: Int -> Int
h1 key = key `mod` _M

h2 :: Int -> Int
h2 key = 1 + key `mod` (_M - 1)

find :: ByteString -> IOArray Int ByteString -> IO Bool
find bs ary = go 0
  where
    key = getKey bs
    v1 = h1 key
    v2 = h2 key

    go :: Int -> IO Bool
    go !i = do
        let h = (v1 + i * v2) `mod` _M
        v <- readArray ary h
        case () of
            _ | v == bs   -> return True
              | B.null v  -> return False
              | otherwise -> go (i + 1)

insert :: ByteString -> IOArray Int ByteString -> IO (IOArray Int ByteString)
insert bs ary = go 0
  where
    key = getKey bs
    v1 = h1 key
    v2 = h2 key

    go :: Int -> IO (IOArray Int ByteString)
    go !i = do
        let h = (v1 + i * v2) `mod` _M
        v <- readArray ary h
        case () of
            _ | v == bs   -> return ary
              | B.null v  -> writeArray ary h bs >> return ary
              | otherwise -> go (i + 1)

solve :: IOArray Int ByteString -> [(ByteString, ByteString)] -> IO ()
solve ary commands = go ary commands
  where
    go _ [] = return ()
    go !a ((c, b):cs)
        | B.head c == 'i' = insert b a >> go a cs
        | B.head c == 'f' = do
            exists <- find b a
            if exists
                then putStrLn "yes" >> go a cs
                else putStrLn "no" >> go a cs

main :: IO ()
main = do
    B.getLine
    xs <- fmap ((\[a,b] -> (a,b)) . B.words) . B.lines <$> B.getContents
    ary <- newArray (0, _M) "" :: IO (IOArray Int ByteString)
    solve ary xs



Measured memory_bytes: 45568
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;
//ここから

void solve(){
  ll n;
  cin>>n;
  ll mul=1;
  rep(i,n)mul*=(ll)i+1,mul%=mod;
  cout<<mul;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
n = input()

n_list = n.split()

x = int(n_list[0])
k = int(n_list[1])
d = int(n_list[2])

def count(x, k, d):
	
	# 絶対値しか気にしないのでサッサと正の話に持っていく
	x = abs(x)
	
	# まずベスポジエリア(abs(d)の範囲)までいけるかを確認
	if x / d > k:
		# いけない
		return x - d * k
	
	# いける
	
	# ベスポジエリアまで何回掛かるか？
	cnt = int(x / d)
	
	c = k - cnt # 残りの移動回数
#	print('残り{}回'.format(c))
	
	x = x - d * cnt
#	print('xは{}'.format(x))
	
	# 残りの移動回数が偶数なら現時点がベストになる
	if c % 2 == 0:
		return x
	
	# 奇数の場合（つまりまだ後1回移動できるとき）
	return min(abs(x + d), abs(x - d))
	

print('{}'.format(count(x,k,d)))
	


Measured memory_bytes: 9184
n = int(input())
arr = list(map(int, input().split()))
last = arr[0]
cnt = 0
ans = 0
for i in range(1, n):
    if arr[i] <= last:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0
    last = arr[i]
ans = max(ans, cnt)
print(ans)


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int a,b; cin>>a>>b;
  int ans = a + b/2;
  cout<<ans;
  

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
#define N 1000+20
#define ll long long
stack<char> st;
int main()
{
	string s;
	cin >> s;
	int len = s.length();
	for (int i = 0; i < len; i++)
	{
		if (!st.empty()&&st.top() == 'S' && s[i] == 'T')
		{
			st.pop();
			continue;
		}
		st.push(s[i]);
	}
	cout << st.size() << endl;
}

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

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

	string N;
	cin >> N;
	int ans = 0;

	for (int i = 0; i < N.size(); i++) {
		if (N.at(i)=='2') ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B;
    cin >> A >> B;
    int sam = 0;
    if(A>B){
        sam = A + (A - 1);
    }else if(A<B){
        sam = B + (B - 1);
    }else{
        sam = A + B;
    }
    cout << sam << endl;
}

Measured memory_bytes: 256