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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int a[3][3], appear[3][3];
    rep(i, 3) rep(j, 3) appear[i][j] = 0;
    rep(i, 3) rep(j, 3) cin >> a[i][j];
    int n;
    cin >> n;
    rep(k, n) {
        int b;
        cin >> b;
        rep(i, 3) rep(j, 3) {
            if (a[i][j] == b) appear[i][j] = 1;
        }
    }
    bool ans = false;
    rep(i, 3) {
        int apps = 0;
        rep(j, 3) if (appear[i][j]) apps++;
        if (apps == 3) ans = true;
    }
    rep(j, 3) {
        int apps = 0;
        rep(i, 3) if (appear[i][j]) apps++;
        if (apps == 3) ans = true;
    }
    {
        int apps = 0;
        rep(j, 3) if (appear[j][j]) apps++;
        if (apps == 3) ans = true;
    }
    {
        int apps = 0;
        rep(j, 3) if (appear[j][2-j]) apps++;
        if (apps == 3) ans = true;
    }
    puts(ans ? "Yes" : "No");
    return 0;
}


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;

int n;
int mx[maxn], par[maxn], c[maxn];
map<int, int> f[maxn];
vector<int> nei[maxn];

/*
u > mx[u]
	c[u] = c[par[u]] + N[u][mx[par[u]]]
u < mx[u]
	c[u] = c[par[u]] - (N[u][mx[par[u]]] - N[u][mx[u]])
		 = c[par[u]] + (N[u][mx[u]] - N[u][mx[par[u]]])
*/

inline void dfs(int u, int p, int m){
	par[u] = p;
	mx[u] = m;
	m = max(m, u);
	FOR(i, 0, nei[u].size()){
		int v = nei[u][i];
		if(v != p)
			dfs(v, u, m);
	}
	return;
}

inline int calc1(int u, int val){
	if(f[u].find(val) != f[u].end())
		return f[u][val];
	int ret = 0;
	FOR(i, 0, nei[u].size()){
		int v = nei[u][i];
		if(v == par[u] || v > val)
			continue;
		ret += calc1(v, val) + 1;
	}
//	printf("u = %d val = %d ret = %d\n", u, val, ret);
	return (f[u][val] = ret);
}

inline void calc2(int u, int p){
	if(u){
		//printf("u = %d mx = %d mxpar = %d f = %d %d\n", u, mx[u], mx[par[u]], f[u][mx[u]], f[u][mx[par[u]]]);
		if(u > mx[par[u]])
			c[u] = c[par[u]] + f[u][mx[u]] + 1;
		else
			c[u] = c[par[u]] + f[u][mx[u]] - f[u][mx[par[u]]];
	}
	FOR(i, 0, nei[u].size()){
		int v = nei[u][i];
		if(v == p)
			continue;
		calc2(v, u);
	}
	return;
}

int main(){
	scanf("%d", &n);
	FOR(i, 1, n){
		int u, v;
		scanf("%d%d", &u, &v);
		--u; --v;
		nei[u].PB(v);
		nei[v].PB(u);
	}
	dfs(0, -1, -1);
	FOR(u, 1, n){
		calc1(u, mx[u]);
		calc1(u, mx[par[u]]);
	}
//	c[0] = 1;
	calc2(0, -1);
	FOR(u, 1, n)
		printf("%d ", c[u]);
	puts("");
	return 0;
}

Measured memory_bytes: 43904
#include<bits/stdc++.h>
using namespace std; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define length size()
#define int long long
template<typename T> string join(vector<T> &vec ,const string &sp){
    int si = vec.length;
    if(si==0){
        return "";
    }else{
        stringstream ss;
        rep(i,si-1){
            ss << vec[i] << sp;
        }
        ss << vec[si - 1];
        return ss.str();
    }
}
signed main(void){
    int a,b,c,d;
    int x,y;
    cin >> a >> b >> c >> d;
    cout << max(a*c,max(b*d,max(a*d,b*c))) << endl;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e4 + 15;
int n, m, t;
const int a[11] = {0, 2,5,5,4,5,6,3,7,6};
unordered_map<int, int> mp;
int dp[N];
int res[N][10];
int main() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> t;
        int l = a[t];
        if (!mp.count(l) || t > mp[l])
            mp[l] = t;
    }
    memset(dp, 255, sizeof dp);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        if (dp[i] == -1) continue;
        for (auto [l, num] : mp) {
            if (dp[i] + 1 > dp[i + l]) {
                dp[i + l] = dp[i] + 1;
                // copy
                for (int k = 1; k < 10; ++k) {
                    res[i + l][k] = res[i][k];
                }
                res[i + l][num]++;
            } else if (dp[i] + 1 == dp[i + l]) {
                bool ok = true;
                for (int k = 9; k > 0; --k) {
                    if (res[i + l][k] > res[i][k]) {
                        ok = false;
                        break;
                    } else if (res[i + l][k] < res[i][k]){
                        break;
                    }
                }
                if (!ok) continue;
                for (int k = 1; k < 10; ++k) {
                    res[i + l][k] = res[i][k];
                }
                res[i + l][num]++;
            }
        }
    }
    vector<ii> p;
    for (int i = 1; i < 10; ++i) {
        if (res[n][i]) {
            p.push_back({i, res[n][i]});
        }
    }
    sort(p.begin(), p.end(), greater<ii>());
    for (auto [i, j] : p) {
        for (int k = 0; k < j; ++k) {
            cout << i;
        }
    }
    cout << endl;
    return 0;
}


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

string str, ans;

int main() {
  cin >> str;
  ans = "Yes";
  for (size_t i = 0; i < str.length() / 2; i++) {
    if (str.at(i) != str.at(str.length() - i - 1)) {
      ans = "No";
    }
  }
  for (size_t i = 0; i < (str.length() - 1) / 4; i++) {
    if (str.at(i) != str.at(((str.length() - 1) / 2) - i - 1)) {
      ans = "No";
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 1000000007
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll par[300000], depth[300000];

void init(ll n) {
  REP(i, n) {
    par[i] = i;
    depth[i] = 0;
  }
  return;
}

ll find(ll x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void merge(ll x, ll y) {
  x = find(x);
  y = find(y);
  if (x == y) {
    return;
  }
  if (depth[x] > depth[y]) {
    par[y] = x;
  } else {
    par[x] = y;
    if (depth[x] == depth[y]) {
      depth[y]++;
    }
  }
}

bool same(ll x, ll y) {
  if (find(x) != find(y)) {
    return false;
  }
  return true;
}
//親を知りたいときは必ずfind()を使う！

int main() {
  init(224514);
  ll n;
  cin >> n;
  if (n == 1)
    return !printf("%lld\n", 0);
  map<ll, ll> m, ans;
  vector<ll> aa, bb;
  REP(i, n) {
    ll h;
    cin >> h;
    m[h - 1] = i;
    aa.pb(h);
    bb.pb(h);
  }
  sort(aa.begin(), aa.end());
  if (aa == bb)
    return !printf("%lld\n", 0);
  REP(i, n - 1) {
    if (m[i + 1] > m[i]) {
      merge(i, i + 1);
    }
  }

  REP(i, n - 1) { ans[find(i)]++; }
  ll maxa = 0;
  for (auto &a : ans) {
    maxa = max(maxa, a.second);
  }

  cout << n - maxa << endl;
}


Measured memory_bytes: 32224
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<map>
#include<set>
using namespace std;

typedef long long ll;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=10*x+ch-'0';ch=getchar();}
	return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}

const int N=300100;

int w,h,n;

struct point
{
	int x,y;
	
	friend bool operator<(const point &a,const point &b)
	{return a.x<b.x;}
	
}p[N];

struct segment_tree{int w,tag;}tr[N<<2];

inline void pushup(int k)
{tr[k].w=max(tr[k<<1].w,tr[k<<1|1].w);}

inline void pushdown(int k)
{
	if(tr[k].tag)
	{
		int tmp(tr[k].tag);
		tr[k<<1].w+=tmp,tr[k<<1].tag+=tmp,
		tr[k<<1|1].w+=tmp,tr[k<<1|1].tag+=tmp,
		tr[k].tag=0;
	}
}

inline void modify(int k,int l,int r,int x,int y,int val)
{
	if(l>=x && r<=y)
	{tr[k].w+=val,tr[k].tag+=val;return ;}
	int mid=(l+r)>>1;pushdown(k);
	if(x<=mid) modify(k<<1,l,mid,x,y,val);
	if(y>mid) modify(k<<1|1,mid+1,r,x,y,val);
	pushup(k);
}

int query(int k,int l,int r,int x)
{
	if(l==r) return tr[k].w;
	int mid=(l+r)>>1;pushdown(k);
	return x<=mid ? query(k<<1,l,mid,x) : query(k<<1|1,mid+1,r,x);
}

int Y[N];

int st[2][N],top[2];

int ans(0);

void solve()
{
	register int i;
	sort(p+2,p+1+n);
	
	top[0]=top[1]=0,
	st[0][0]=st[1][0]=1;
	modify(1,1,n,1,n,h<<1);
	for(i=2;i<=n;++i)
	{
		modify(1,1,n,1,i-1,(p[i].x-p[i-1].x)<<1);
		ans=max(ans,tr[1].w);
		if(p[i].y>=(h>>1))
		{
			modify(1,1,n,st[0][top[0]],i-1,(p[i].y-h)<<1);
			while(top[0] && p[st[0][top[0]]].y>=p[i].y)
				modify(1,1,n,st[0][top[0]-1],st[0][top[0]]-1,(p[i].y-p[st[0][top[0]]].y)<<1),
				top[0]--;
			st[0][++top[0]]=i;
		}
		else
		{
			modify(1,1,n,st[1][top[1]],i-1,-p[i].y<<1);
			while(top[1] && p[st[1][top[1]]].y<=p[i].y)
				modify(1,1,n,st[1][top[1]-1],st[1][top[1]]-1,(p[st[1][top[1]]].y-p[i].y)<<1),
				top[1]--;
			st[1][++top[1]]=i;
		}
	}
	memset(tr,0,sizeof(tr));
}

int main()
{
	w=read(),h=read(),n=read()+1;
	register int i;
	for(i=2;i<=n;++i)
		p[i].x=read(),p[i].y=read();
	p[++n]=(point){w,h};
	
	solve();
	swap(w,h);
	for(i=1;i<=n;++i)
		swap(p[i].x,p[i].y);
	solve();
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'
 
 
signed main() {
	vi a = {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};
	int k;
	cin >> k;
	cout << a[k - 1] << endl;
	return 0;

}

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

using namespace std;

int main(void){
    int n;
    int h[100];
    int k[100] = {0};
    int l, r;
    int ans = 0;
    int max = 0;
    int flag = 1;

    cin >> n;
    // cout << "a" << endl;
    for(int i = 0; i < n; i++){
        cin >> h[i];
        if(h[i] > 0){
            flag = 0;
        }
        if(max < h[i]){
            max = h[i];
        }
    }

    if(flag){
        cout << 0 << endl;
        return 0;
    }

    // cout << "b" << endl;

    for(;;){
        for(int i = 0; i < n; i++){
            if(h[i] > 0){
                l = i;
                for(int j = i; j < n; j++){
                    if(h[j] == 0){
                        r = j-1;
                        // cout << "c" << endl;
                        // cout << i << " " << j << endl;
                        break;
                    }
                    else if(j == n-1){
                        r = j;
                    }
                }
                // cout << "l:" << l << "r:" << r << endl;
                break;
            }
        }

        for(int i = l; i <= r; i++){
            h[i]--;
        }
        ans++;

        for(int i = 0; i < n; i++){
            if(h[i] > 0){
                break;
            }
            if(i == n-1){
                cout << ans << endl;
                return 0;
            }
        }

        /*
        for(int i = 0; i < n; i++){
            cout << h[i] << " ";
        }
        cout << endl;
        */
    }

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+1)
	b := make([]int, n)
	for i, _ := range a {
		fmt.Scan(&a[i])
	}
	for i, _ := range b {
		fmt.Scan(&b[i])
	}

	ans := 0
	for i := 0; i < n; i++ {
		if i != 0 {
			ans += min(b[i-1], a[i])
			a[i] -= min(b[i-1], a[i])
		}
		ans += min(b[i], a[i])
		if a[i] < b[i] {
			b[i] -= min(a[i], b[i])
		} else {
			b[i] = 0
		}
		if i == n-1 {
			ans += min(b[i], a[i+1])
		}
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

Measured memory_bytes: 5504
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

using namespace std;

int32_t N;
std::string S;
int64_t Bsum[2000000];
int64_t Csum[2000000];
int64_t BCsum[2000000];

int main()
{
	using std::endl;
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	cin >> N >> S;
	for (size_t i = 0; i < S.size(); i++)
	{
		if (S[i] == 'M') { Bsum[i] += 1; }
		if (S[i] == 'C') { Csum[i] += 1; }
		Bsum[i + 1] = Bsum[i];
		Csum[i + 1] = Csum[i];
	}
	for (size_t i = S.size(); i < 2000000; i++)
	{
		Bsum[i + 1] = Bsum[i];
		Csum[i + 1] = Csum[i];
	}
	for (size_t i = 1; i < S.size(); i++)
	{
		BCsum[i] = BCsum[i - 1];
		if (S[i] == 'C') { BCsum[i] += Bsum[i-1]; }
	}
	for (size_t i = S.size(); i < 2000000; i++)
	{
		BCsum[i] = BCsum[i - 1];
	}

	int Q;
	cin >> Q;
	while(Q--)
	{
		int k;
		cin >> k;

		int64_t count = 0;
		for (size_t i = 0; i < S.size(); i++)
		{
			if (S[i] == 'D') { 
				count += BCsum[i + k-1] - BCsum[i] - (Csum[i + k-1] - Csum[i])*Bsum[i];
			}
		}
		cout << count << '\n';
	}



	return 0;
}
#endif


Measured memory_bytes: 48244
N = int(input())
L = []
for _ in range(3):
    l = list(map(int,input().split()))
    L.append(sorted(l))
import bisect
ans = 0
for x in L[1]:
    n = bisect.bisect_left(L[0],x)
    m = bisect.bisect_right(L[2],x)
    m = N - m
    ans += n*m
print(ans)

Measured memory_bytes: 24864
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] arg) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String[] param = new String[10];
		do {
			for (int i = 0; i < n; i++) {
				String name = in.next();
				int point = in.nextInt() * 3;
				in.next();
				point += in.nextInt();
				param[i] = String.format("%02d%02d%s,%d", 30-point, i,
						name, point);
			}
			Arrays.sort(param, 0, n);
			for (int i = 0; i < n; i++) {
				System.out.println(param[i].substring(4));
			}
			if ((n = in.nextInt()) == 0) {
				break;
			} else {
				System.out.println();
			}
		} while (true);
	}
}

Measured memory_bytes: 20800
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const line0vars = line0.split(" ");

	const n = parseInt(line0vars[0], 10);
	const d = parseInt(line0vars[1], 10);

	var result = 0;
	for (var i = 1; i <= n; i++) {
		const line1 = inputLines[i];
		const line1vars = line1.split(" ");
		const x = parseInt(line1vars[0], 10);
		const y = parseInt(line1vars[1], 10);
		if (Math.sqrt(x * x + y * y) <= d) {
			result += 1;
		}
	}
	console.log(result);

	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

	//出力
	// console.log('%d %s',a+b+c,s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)


Measured memory_bytes: 62768
import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.Queue;

 
public class Main{
	
	public static void main(String args[])throws Exception{
		FastScanner sc = new FastScanner();
		
		int x =sc.nextInt();
		System.out.println(x*x*x);
		
		
	}
}









class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}





Measured memory_bytes: 24056
#include <bits/stdc++.h>
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N;
    string s;
    scan(N, s);

    rep(i, s.size()) {
        s[i] = (s[i] + N);
        if ('Z' < s[i])
            s[i] -= 26;
    }
    print(s);

    return 0;
}

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

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <complex>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FIXED cout << fixed << setprecision(12);
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)])

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

signed main() {
    FAST; FIXED; RANDOM;
    ll a, p;
    cin >> a >> p;
    p += 3 * a;
    cout << p / 2;
    return 0;
}   

Measured memory_bytes: 256
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
///////////////////////////////////////////////////////////

const int mod = 1000000007;
struct mint {
  long long x; // typedef long long ll;
  mint(long long x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) { if((x+=a.x)>=mod)x-=mod;return *this;}
  mint& operator-=(const mint a) { if((x+=mod-a.x)>=mod)x-=mod; return *this;}
  mint& operator*=(const mint a) { (x *=a.x)%=mod; return *this;}
  mint operator+(const mint a) const { mint res(*this);return res+=a;}
  mint operator-(const mint a) const { mint res(*this);return res-=a;}
  mint operator*(const mint a) const { mint res(*this);return res*=a;}
  mint pow(ll t) const {
    if (!t) return 1;mint a = pow(t>>1);a*=a;
    if (t&1) a *= *this;return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return (*this) *= a.inv();}
  mint operator/(const mint a){mint res(*this);return res/= a;}
  friend ostream& operator<<(ostream& os, const mint& m){os<<m.x;return os;}
};
mint mod_pow(long long p,long long q){mint res = p;return res.pow(q);}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    int n;cin >> n;
    vl a(n);rep(i,n)cin >> a[i];
    vector<mint> c(100010);
    rep(i,100010){
        mint b = (mint)i;
        if(i == 0)c[i] = (mint)1;
        else if(i == 1)c[i] = (mint)1;
        else c[i] = c[i-1] + b.inv();
    }
    mint ans = 0;
    for(int i = 0;i < n;i++){
        ans += (c[i+1] + c[n-i] - (mint)1)*(mint)a[i];
    }
    for(int i = 1;i <= n;i++)ans *= (mint)i;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  lli n; vector<lli> a;
  cin >> n;
  init_n(a, n);
  lli l = 0, r = 0;
  for (lli i=0; i<n; ++i) {
    cin >> a[i];
    r += a[i];
  }
  lli ans = 1e18;
  for (lli i=0; i<n-1; ++i) {
    r -= a[i];
    l += a[i];
    ans = min(ans, abs(r-l));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

void solve() {
    int k; 
    sc(k);
    bool a[k] = {0};

    int x = 7 % k;
    int ans = 1;
    while (x) {
        if (a[x]) {
            cout << -1;
            return;
        }
        a[x] = 1;
        ans++;
        x = (10 * x + 7) % k;
    }
    cout << ans;
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

int n;
int dp[4][4][4][4][100];

void adds(int& i, int j) {
    if((i += j) >= mod) i -= mod;
    return ;
}

bool rd(int i, int j, int k, int d) {
    if(j == 1 && k == 2 && d == 3) return true;
    swap(i, j);
    if(j == 1 && k == 2 && d == 3) return true;
    swap(i, j);
    swap(j, k);
    if(j == 1 && k == 2 && d == 3) return true;
    swap(j, k);
    swap(k, d);
    if(j == 1 && k == 2 && d == 3) return true;
    if(i == 1 && j == 2 && k == 3) return true;
    swap(k, d);
    return false;
}

int f(int i, int j, int k, int d, int r) {
    if(rd(i, j, k, d)) return 0;
    if(r == n) return 1;
    if(dp[i][j][k][d][r] != -1) return dp[i][j][k][d][r];
    int mx = 0;
    for(int l = 0; l < 4; ++l)
        adds(mx, f(j, k, d, l, r + 1));
    
    return dp[i][j][k][d][r] = mx;
}

int main() {
    cin >> n;
  memset(dp, -1, sizeof dp);
    cout << f(0, 0, 0, 0, 0);
    return 0;
}

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


int main()
{
    int n;cin>>n;
    vector<int> a(n);
    int i;
    for(i=0;i<n;i++)cin>>a.at(i);
    vector<int> count(n,0);
    if(n%2==0)
    {
        for(i=1;i<n;i+=2)
        {
            count.at(i)=2;
        }
    }
    else
    {
        for(i=0;i<n;i+=2)
        {
            if(i==0)count.at(i)=1;
            else count.at(i)=2;
        }
    }
    for(i=0;i<n;i++)count.at(a.at(i))--;
    long long ans=1;
    for(i=0;i<n;i++)if(count.at(i)!=0)ans=0;
    if(ans==1)
    {
        for(i=0;i<n/2;i++)ans=(ans*2)%MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = k;
    ans *= pow(k - 1, n - 1);
    cout << ans << '\n';
}


Measured memory_bytes: 256
import std;

alias P = Tuple!(double, "x", double, "y");

double radians(double deg) {
    return PI * deg / 180.0;
}

P rotate(P p, double degree) {
    auto rad = radians(degree);
    auto x = p.x * cos(rad) - p.y * sin(rad);
    auto y = p.x * sin(rad) + p.y * cos(rad);
    return P(x, y);
}

double calc(double a, double b, double h, double m) {
    // 短針:
    //     1 周するのに 12 * 60 分
    //     現在の角度 = (60 * h + m) / (12 * 60) * 360
    // 長針:
    //     1 周するのに 60 分
    //     現在の角度 = m / 60 * 360

    auto s = rotate(P(0, a), (60 * h + m) / (12 * 60) * 360);
    auto t = rotate(P(0, b), m / 60 * 360);
    return hypot(s.x - t.x, s.y - t.y);
}

void main() {
    int a, b, h, m; scan(a, b, h, m);
    writefln("%.20f", calc(a, b, h, m));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;


Measured memory_bytes: 3940
n,k= list(map(int,input().split()))
l = [0 for i in range(n+1)]
 
for i in range(k):
    d = int(input())
    m = list(map(int,input().split()))
    for j in range(d):
        l[m[j]] = 1
 
 
print(l[1:].count(0))

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


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

    vector<int> aa(N+1, a[1]), bb(N+1, b[1]), cc(N+1, c[1]);
    for (int i = 2; i <= N; i++) {
        aa[i] = max(bb[i-1], cc[i-1]) + a[i];
        bb[i] = max(aa[i-1], cc[i-1]) + b[i];
        cc[i] = max(bb[i-1], aa[i-1]) + c[i];
    }

    cout << max({aa[N], bb[N], cc[N]}) << endl;
}

Measured memory_bytes: 5620
def main():
    X, Y, A, B, C = list(map(int, input().split()))
    P = sorted(list(map(int, input().split())), reverse=True) + [10**9 + 1]
    Q = sorted(list(map(int, input().split())), reverse=True) + [10**9 + 1]
    R = sorted(list(map(int, input().split())), reverse=True)
    t = sum(P[:X]) + sum(Q[:Y])
    x, y = X - 1, Y - 1
    p, q = P[x], Q[y]
    for r in R:
        if p < q:
            if r > p:
                t += r - p
                x -= 1
                p = P[x]
        else:
            if r > q:
                t += r - q
                y -= 1
                q = Q[y]

    return t

print(main())


Measured memory_bytes: 107364
//OPTIMIZATONS
#pragma GCC optimize("02")
//CODE
#include<bits/stdc++.h>
#define int long long
#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a,b,n;
	cin>>a>>b>>n;
	int x;
	if(n>=b) x = b-1;
	else x = n;
	cout<<((a*x)/b - a*(x/b))<<endl;
}
	

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define all(vec) vec.begin(),vec.end()
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e8;
typedef pair<int,int> P;

int main(){
  int N;cin>>N;
  if(N%2==1){
    print(0)
    return 0;
  }
  vector<int> D(N);
  REP(i,0,N)cin>>D[i];
  sort(all(D));
  int left,right;
  left=D[N/2-1];
  right=D[N/2];
  print(right-left)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define hell (int)(1e9+7)
#define int long int

using namespace std;

vector <int> adj[100005];
vector <bool> vis(100005,false);

unordered_map <int,int> mp[100005];

vector <pair <int,int> > edge;

int k;

void bfs(int s){
    queue < pair <int,int> > q;
    q.push({s,-1});
    vis[s]=true;
    while(!q.empty()){
        auto p=q.front();
        s=p.first;
        q.pop();
        k=max(k,(int)adj[s].size());
        int pc=p.second;
        int st=1;
        for(int x:adj[s]){
            while(st==pc)
                st++;
            if(!vis[x]){
                q.push({x,st});
                vis[x]=true;
                mp[min(s,x)][max(s,x)]=st++;
            }
        }
    }
}

void solve(){
    int n;
    cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
        edge.push_back({min(u,v),max(u,v)});
    }
    bfs(1);
    cout<<k<<"\n";
    for(auto &x:edge)
        cout<<mp[x.first][x.second]<<"\n";
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


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


using namespace std;

int main(){

	int n,m;
	cin >> n >> m;

	vector<int> a;
	int box;

	int sum = 0;
	int pre_1 = 1;
	int pre_2 = 1;

	int cnt = 0;

	int i;
	if(m != 0){
		for(i = 0; i < m; i++){

			cin >> box;
			a.push_back(box);
		//cout << a[i] << endl;
		}
	}
	else{
		a.push_back(-1);
	}

	for(i = 0; i <= n; i++){
//cout << "i = " << i << endl;
		if(i == 0 || i == 1){
			//階段1が穴だった時
			if( a[cnt] == i ){

				sum = 1;
				pre_1 = 0;

				if(cnt < m) cnt++;
			}
			else{

			sum = 1;
			pre_1 = 1;
			}
		}
		else{
			if(a[cnt] == i){
				if(pre_1 == 0){

					sum = 0;
					break;
				}

				//sum = 0;
				pre_2 = pre_1;
				pre_1 = 0;
				
				if(cnt < m) cnt++;
				//cout << "i = " << i << endl;
			}
			else{
			sum = (pre_1 + pre_2) % 1000000007;
			pre_2 = pre_1;
			pre_1 = sum;
			}
		}

	//cout << "sum = " << sum << endl;
	}
	cout << sum << endl;
}

Measured memory_bytes: 892
n = int(input())
a = list(map(int,input().split()))
if sorted(a)[0] == 0:
  sum = 0
else:
  sum = 1
if sum == 1:
  for i in a:
    sum *= i
    if sum > 1000000000000000000:
      sum = -1
      break
print(sum)

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

int main() {
    ll n, d, ans = 0;
    cin >> n >> d;
    vector<pair<ll, ll>> xy(n);
    for(int i; i < n; i++) {
        cin >> xy[i].first >> xy[i].second;
        double p = sqrt(xy[i].first * xy[i].first + xy[i].second * xy[i].second);
        if(p <= d) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6484
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
    string S; cin >> S;
    long long ans = 0;
    int answer = 0;
    rep(i, S.size()) {
        if (S.at(i) == 'W') {
            ans += i - answer;
            answer++;
        }
    }
    cout << ans << endl;
}

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

int main() {
  int64_t A, B;
  cin >> A >> B;
  if((A - B) % 2 == 0) {
    cout << (A + B) / 2 << endl;
  }
  else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>

using namespace std;

struct Side{
  int h,w,ul,ur,dl,dr; // h:上端からの距離 w:縦棒aとa+1をむずぶ
  // ul:左上にたどった時の縦棒 ur:右上にたどった時の縦棒 dl:左下へたどった時の縦棒 dr:右下へたどった時の縦棒
  Side(int h=0, int w=0, int ul=-1, int ur=-1, int dl=-1, int dr=-1):h(h),w(w),ul(ul),ur(ur),dl(dl),dr(dr){}
  bool operator<(const Side &a)const{ return h < a.h; }
};

const int INF = 1<<30;

int N,M,H,K;
Side ss[100005];
int s[1024], l[1024];
map<int, int>m;

int main(){
  while(scanf("%d%d%d%d", &N,&M,&H,&K) && N||M||H||K){
    m.clear();
    for(int i=0;i<N;i++) scanf("%d", &s[i]);
    for(int i=0;i<M;i++){
      int a,b;
      scanf("%d%d", &a,&b); a--;
      ss[i] = Side(b,a);
    }
    for(int i=0;i<N;i++) l[i] = i;
    sort(ss, ss+M);
    for(int i=0;i<M;i++){
      Side &sd = ss[i];
      sd.ul = l[sd.w]; sd.ur = l[sd.w+1];
      swap(l[sd.w], l[sd.w+1]);
      sd.dl = l[sd.w]; sd.dr = l[sd.w+1];
    }
    for(int i=0;i<N;i++) m[l[i]] = i;
    for(int i=0;i<M;i++){
      Side &sd = ss[i];
      sd.dl = m[sd.dl]; sd.dr = m[sd.dr];
      //      printf("%d %d %d %d %d %d\n", sd.h, sd.w, sd.ul, sd.ur, sd.dl, sd.dr);
    }
    //    for(int i=0;i<N;i++) printf("%d ", l[i]); puts("");
    int sum = 0;
    for(int i=0;i<K;i++) sum += s[m[i]];
    int res = sum;
    //    printf("%d\n", res);
    for(int i=0;i<M;i++){
      Side sd = ss[i];
      int diff = 0;
      int l=0, r=0;
      if(0 <= sd.ul && sd.ul < K) l = 1;
      if(0 <= sd.ur && sd.ur < K) r = 1;
      if(!l && r) diff = s[sd.dr] - s[sd.dl];
      else if(l && !r) diff = s[sd.dl] - s[sd.dr];
      //      printf("%d %d %d\n", l, r, diff);
      //      printf("%d\n", sum + diff);
      res = min(res, sum + diff);
    }
    printf("%d\n", res);
  }
  return 0;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

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

  if(n%2==0)cout<<n<<endl;
  else cout<<n*2<<endl;

return 0;}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n, m;
    //n = odd
    //m = even
    scanf("%d %d", &n, &m);
    int even = n * (n - 1) / 2;
    int odd = m * (m - 1) / 2;
    int total = odd + even;
    printf("%d\n", total);
    return 0;
}

Measured memory_bytes: 1720
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            int A;int B;
            Multi(out A, out B);
            var ans = Math.Max(A + B, Math.Max(A - B, A * B));

            Console.WriteLine(ans);
        }


        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=55,MAX_M=11;

int n,ok;
int m[MAX_N];
vector<vector<int>> x(MAX_N,vector<int>(MAX_M))
                    ,y(MAX_N,vector<int>(MAX_M));

void translate(int p){
    for (int i=1;i<m[p];++i)
        x[p][i]-=x[p][0],y[p][i]-=y[p][0];
    x[p][0]=y[p][0]=0;
}

void rotate(int p){
    if (x[p][1]>0) return;
    else if (x[p][1]<0){
        for (int i=0;i<m[p];++i)
            x[p][i]*=-1,y[p][i]*=-1;
    } else if (y[p][1]>0){
        for (int i=0;i<m[p];++i){
            swap(x[p][i],y[p][i]);
            y[p][i]*=-1;
        }
    } else {
        for (int i=0;i<m[p];++i){
            swap(x[p][i],y[p][i]);
            x[p][i]*=-1;
        }
    }
}

void solve(){
    translate(0); rotate(0);
    for (int i=1;i<=n;++i){
        if (m[i]!=m[0]) continue;
        translate(i); rotate(i);
        ok=0;
        for (int j=0;j<m[0];++j){
            if (x[i][j]!=x[0][j]||y[i][j]!=y[0][j]) break;
            if (j==m[0]-1){cout << i << '\n'; ok=1;}
        }
        if (ok) continue;
        reverse(x[i].begin(),x[i].begin()+m[i]);
        reverse(y[i].begin(),y[i].begin()+m[i]);
        translate(i); rotate(i);
        for (int j=0;j<m[0];++j){
            if (x[i][j]!=x[0][j]||y[i][j]!=y[0][j]) break;
            if (j==m[0]-1){cout << i << '\n';}
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n,n){
        for (int i=0;i<=n;++i){
            cin >> m[i];
            for (int j=0;j<m[i];++j)
                cin >> x[i][j] >> y[i][j];
        }
        solve();
        cout << "+++++" << '\n';
    }
}


Measured memory_bytes: 3204
use proconio::input;

fn main() {
    input! {
        s: String,
    }
    let s = s
        .chars()
        .collect::<Vec<_>>()
        .iter()
        .map(|x| x.to_digit(10).unwrap() as i64)
        .collect::<Vec<_>>();
    let mut mi = i64::max_value();
    for i in 0..s.len() - 2 {
        let n = s[i] * 100 + s[i + 1] * 10 + s[i + 2];
        if (n - 753).abs() < mi {
            mi = (n - 753).abs();
        }
    }
    println!("{}", mi);
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[15];
int n;
void dfs(int now,int p)
{
    if(now>n)
    {
        for(int i=1;i<=n;i++)
        {
            printf("%c",a[i]+'a');
        }
        printf("\n");
        return;
    }
    for(int i=0;i<26;i++)
    {
        if(i==p+2)break;
        a[now]=i;
        dfs(now+1,max(i,p));
    }
}
int main()
{
    scanf("%d",&n);
    dfs(2,0);
}


Measured memory_bytes: 1536