akhauriyash/Code-Regression huggingface dataset:
import bisect as bi

N,K,Q = map(int,input().split())
A = [int(input()) for i in range(Q)]
B = [K]*N
p = 0
for i in range(N+1):
    A.append(i+1)
C = sorted(A)
for i in range(N):
    B[i] += bi.bisect_left(C,i+2) - p - 1
    p = bi.bisect_left(C,i+2)
for i in range(N):
    if(B[i] > Q):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 22556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }



void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}

int n;
vector<vector<int> > g;
ll ans;

int dfs(int now, int prev) {
    int sum = 1;
    ll tmpans = 1; // すべて白
    for (int nxt : g[now]) {
        if (nxt == prev) continue;
        int tmp = dfs(nxt, now);
        sum += tmp;
        add(tmpans, (modpow(2, tmp) - 1 + mod) % mod); // debuged % > +, -
    }
    add(tmpans, (modpow(2, n - sum) - 1 + mod) % mod);
    tmpans = (modpow(2, n - 1) - tmpans + mod) % mod; // 余事象だから
    
    if (sz(g[now]) != 1) add(ans, tmpans); // 葉だったら部分木 1 つ
    return sum;
}

void solve() {
    // n = 200000;
    cin >> n;
    g.resize(n);
    rep(i, n - 1) {
        int a, b;
        // a = i; b = i + 1;
        cin >> a >> b;
        a--; b--;
        g[a].eb(b);
        g[b].eb(a);
    }
    
    /*
     各頂点が何回白として含まれるか
     2 つ以上の部分木で 1 つ以上黒の頂点がある
     余事象 : すべて白 or 1 つの部分木だけ黒を含む
     すべて白 : 1 通り
     1 つの... : 2^{部分木のサイズ} - 1
     - 1 : 全部白は避ける, 他の部分木の頂点はすべて白
     */
    
    dfs(0, -1);
    (ans *= modpow(modpow(2, n), mod - 2) % mod) %= mod; // 期待値
    cout << ans << endl;
}



Measured memory_bytes: 22272
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> a(n);

    rep(i,n){
        cin >> a[i];
        a[i]--;
    }

    map<ll,ll> mp;

    if(k <= 300000){
        ll id = 0;
        ll cur = 0;

        rep(i,k){
            cur = a[cur];
        }

        cout << cur + 1 << endl;
        return 0;
    }

    else{
        ll now = 0;
        rep(i,300000){
            mp[now]++;
            now = a[now];
        }
        ll only = 0;
        ll roop = 0;

        for(auto e: mp){
            if(e.second == 1) only++;
            else roop++;
        }

        ll amari = (k - only) % roop;

        now = 0;
        rep(i,only + amari){
            now = a[now];
        }

        cout << now + 1 << endl;
        return 0;

    }
}

Measured memory_bytes: 14644
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

void solve(int a, int b) {
  int c = b - a;
  int h = (c + 1) * c / 2;
  printf("%d\n", h - b);
}

int main() {
  int a, b;
  cin >> a >> b;
  solve(a, b);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

string s[100];

int main()
{
	int H, W;

	cin >> H >> W;
	rep(i, H) cin >> s[i];

	rep(i, H) {
		cout << s[i] << endl;
		cout << s[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	string c[2];
	cin >> c[0] >> c[1];
	reverse(c[1].begin(), c[1].end());
	if (c[0] == c[1]) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    System.out.println(a+b==c || (b+c==a || c+a==b) ? "Yes" : "No");
  }
}


Measured memory_bytes: 35608
//
//  main.cpp
//  uecontest2
//
//  Created on 2020/04/29.
//  Copyright © 2020 エロやん. All rights reserved.
//

#include <iostream>
#include <string>
using namespace std;
int main(){
    int N,K;
    string str;
    cin>>N>>K;
    cin>>str;
    if(str[K-1]=='A')
        str[K-1]='a';
    if(str[K-1]=='B')
        str[K-1]='b';
    if(str[K-1]=='C')
        str[K-1]='c';
    cout<<str<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 1024;

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	if (a>=10 or b>=10 or a == 0 or b == 0){
		printf("-1");
		return 0;
	}
	else printf("%d", a*b);
	
	return 0;
}

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

typedef unsigned long long ull;
int MAX=100005;
ull ans=0;
ull l,r;
int n;
int c[100005];
int v[100005];
ull mem[100005];


ull calc(int p){
	if( p>=n )
		return 0;
	if(v[p])
		return mem[p];
	if( p==(n-1) )
		ans=calc(p+1)+abs(c[p]-c[p+1]);
	else{
		l=abs(c[p]-c[p+1])+calc(p+1);
		r=abs(c[p]-c[p+2])+calc(p+2);
		ans=min(l,r);
	}
	mem[p]=ans;
	v[p]=1;
	return ans;
}


int main() {
	cin>>n;
	for(int i=1;i<n+1;i++)
		cin>>c[i];
	v[n]=1;
	mem[n]=0;
	cout<<calc(1);
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> A >> B >> C >> D >> E >> F;
    ll MA = F / (100 * A);
    double noudo = -1.0;
    pair<int, int> ans;
    REP(i, MA + 1) {
        ll water = 100 * A * i;
        while (water <= F) {
            if (water != 0) {
                ll f = F - water;
                ll MC = f / C;
                REP(j, MC + 1) {
                    ll lim = min(f, water * E / 100) - j * C;
                    if (lim < 0)
                        break;
                    ll k = lim / D;
                    ll sugar = C * j + D * k;
                    double tmp = (double)sugar / (water + sugar);
                    dump(tmp, water, sugar, lim);
                    if (tmp > noudo) {
                        noudo = tmp;
                        ans = {water + sugar, sugar};
                    }
                }
            }
            water += 100 * B;
        }
    }
    cout << ans.first << " " << ans.second << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
typedef unsigned int ui;
//using ui = unsigned int;

int main(void)
{
	string line;
	ui max_n, max_w;
	cin >> max_n >> max_w;
	ui v, w;

	vector<ui> table(max_w+1, 0);

	for(int i = 1; i <= max_n; ++i){
		cin >> v >> w;
		for(int j = max_w-w; j >= 1; --j){
			if(table[j] != 0 && table[w+j] < table[j] + v)
				table[w+j] = table[j] + v;
		}
		if(w <= max_w && table[w] < v)
			table[w] = v;
	}
	cout << *(max_element(begin(table), end(table))) << endl;

}

Measured memory_bytes: 1224
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
b = [[0]*2 for i in range(0,m)]
for i in range(0,m):
    b[i][1],b[i][0] = list(map(int,input().split()))

a.sort()
b.sort(reverse = True)

now = 0
end = False

for i in range(0,m):
    if now >= n or end == True:
        break
    for j in range(0,b[i][1]):
        if now >= n:
            break
        if a[now] < b[i][0]:
            a[now] = b[i][0]
            now += 1
        else:
            end = True
            break

print(sum(a))

Measured memory_bytes: 24108
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type grid struct {
	x, y int
}

func MP(bfe, aft grid) int {
	ans := 0
	ans += int(math.Abs(float64(bfe.x - aft.x)))
	ans += int(math.Abs(float64(bfe.y - aft.y)))
	return ans
}

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

	H, W, D := scanInt(), scanInt(), scanInt()
	G := make([]grid, H*W+1)
	for i := 1; i <= H; i++ {
		for j := 1; j <= W; j++ {
			a := scanInt()
			G[a].x, G[a].y = i, j
		}
	}

	RS := make([]int, H*W+1)
	for i := D + 1; i <= H*W; i++ {
		RS[i] = RS[i-D] + MP(G[i-D], G[i])
	}

	Q := scanInt()
	for i := 0; i < Q; i++ {
		L, R := scanInt(), scanInt()
		fmt.Println(RS[R] - RS[L])
	}
}


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



int main ()
{
    int a,b,c,m;  cin >> a >> b >> c;
    if(a>b) {
        m=a;
        a=b;
        b=m;
    }

    if(a>c) {
        m=a;
        a=c;
        c=m;
    }

    if(b>c) {
        m=b;
        b=c;
        c=m;
    }

    cout << a << " " << b << " " << c << endl;
    
    
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define rep(i,f,n) for(int i=(f); (i) < (n); i++)
#define repe(i,f,n) for(int i=(f); (i) <= (n); i++)
#define PI 3.14159265359
#define MOD (ll)1000000007
using namespace std;
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;}


typedef long long ll;
ll INF = 1e+18;

int main() {
  int N; cin >> N;
  vector<ll> arr(N);
  rep(i, 0, N){
    cin >> arr[i];
    if(arr[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;

  rep(i, 0, N){
    ll tmp = ans * arr[i];
    if(1000000000000000000 / ans < arr[i]){
      cout << -1 << endl;
      return 0;
    }
    ans = tmp;
  }

  cout << ans << endl;

}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pi acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define	inf (int)1e5
#define mod 1000000007
#define mem(x,val) memset(x,val,sizeof x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

using namespace __gnu_pbds;
using namespace std;

inline string str_inp(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string line_inp(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;


const int S=45;
const int N=405;
int n,ma,mb;
int a[S+5],b[S+5],c[S+5];
int dp[N+5][N+5];

int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
	while(~sf("%d %d %d",&n,&ma,&mb))
	{
		for(int i=0;i<n;i++)sf("%d %d %d",&a[i],&b[i],&c[i]);

		for(int i=0;i<=N;i++)for(int j=0;j<=N;j++)dp[i][j]=inf;
		dp[0][0]=0;
		for(int i=0;i<n;i++)
		{
			for(int ta=N;ta>=0;ta--)
			{
				for(int tb=N;tb>=0;tb--)
				{
					if(ta-a[i]>=0 && tb-b[i]>=0)dp[ta][tb]=min(dp[ta][tb],c[i]+dp[ta-a[i]][tb-b[i]]);
				}
			}
		}

		int ans=inf;
		for(int ta=1;ta<=N;ta++)
		{
			for(int tb=1;tb<=N;tb++)
			{
				if(ta*mb==tb*ma && dp[ta][tb]<ans)
				{
					ans=dp[ta][tb];
				}
			}
		}
		if(ans==inf)puts("-1");
		else pf("%d\n",ans);
	}
    return 0;
}
 


Measured memory_bytes: 896
fun main(args: Array<String>) {
    val mod = 1000000007L
    
    val N = readInputLine().toInt()
    
    val S = Array(2) { readInputLine().toCharArray() }
    
    var (ans, index) = if (S[0][0] == S[1][0]) Pair(3L, 1) else Pair(6L, 2)
    
    while (index < N) {
        if (S[0][index] == S[1][index]) {
            // index列のドミノは縦
            if (S[0][index - 1] == S[1][index - 1]) {
                // index - 1列のドミノも縦
                // 置き方は前の列の色以外のいずれか
                ans *= 2L
            }
            // index - 1列のドミノが横の場合は置き方1通りのみ
            index++
        } else {
            // index列のドミノは横
            if (S[0][index - 1] == S[1][index - 1]) {
                // index - 1列のドミノは縦
                // 置き方は前の列の色以外2色を上下いずれかに置く
                ans *= 2L
            } else {
                // index - 1列のドミノは横
                // 置き方は前の列と逆、前の列と逆かつ片方未使用色に置き換え * 2の3通り
                ans *= 3L
            }
            index += 2
        }
        ans %= mod
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 33660
package main

import (
	"fmt"
)

func main() {
	var p,q,r int
	fmt.Scan(&p,&q,&r)

	if p+q <= q+r && p+q <= r+p {
		fmt.Println(p+q)
	} else if q+r <= r+p && q+r <= p+q {
		fmt.Println(q+r)
	} else {
		fmt.Println(r+p)
	}
}


Measured memory_bytes: 512
/*input
4
10 30 40 20
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

const int N = 1e5+1;
int h[N];
int dp[N];
int n;

void solve(){
	 cin >> n;
	 RE(i,n)cin >> h[i];
	 dp[0] = h[0] = dp[1] = 0;
	 dp[2] = abs(h[2]-h[1]);
     for(int i = 3;i <=n;i++){
     	 dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
     }
     cout << dp[n];
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n, k;
	cin >> n >> k;
	if (k > (n-1)*(n-2)/2)
	{
		cout << -1 << endl;
		return;
	}
	int m = 0;
	vector<int> g[n];
	for (int i = 0; i < n-1; i++)
	{
		g[i].push_back(n - 1);
		m++;
	}
	int b = 0, e = 1;
	for (int i = (n - 1) * (n - 2) / 2; i > k; i--)
	{
		g[b].push_back(e);
		m++;
		e++;
		if (e == n-1)
		{
			b++;
			e = b + 1;
		}
	}
	cout << m << endl;
	for (int i = 0; i < n; i++)
	{
		for (int v : g[i])
		{
			cout << i + 1 << ' ' << v + 1 << '\n';
		}
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
#define PB push_back
const int MOD=1e9+7;
const int N=1e3+10;
vector<int> graph[N];
int type[N];
bool q[N];
ll ans[N];
ll dfs(int now,int from){
    if(ans[now]>0)return ans[now];
    if(type[now]==0){
        ans[now]++;
        for(int i:graph[now])if(i!=from){
            ans[now]*=dfs(i,now);
            ans[now]%=MOD;
        }
        if(q[now])ans[now]++;
    }
    else if(type[now]==1){
        for(int i:graph[now])if(i!=from){
            ans[now]+=dfs(i,now);
            ans[now]%=MOD;
        }
        if(q[now])ans[now]++;
    }
    else{
        int top;top=1<<(graph[now].size()-1);
        ll temp;
        vector<int> n;
        for(int i:graph[now])if(i!=from)n.PB(i);
        top=1<<(n.size());
        for(int i=1;i<top;i++){
            temp=1;
            for(int j=0;j<n.size();j++)if(i&(1<<j)){
                temp*=dfs(n[j],now);
                temp%=MOD;
            }
            ans[now]+=temp;
            ans[now]%=MOD;
        }
        if(q[now])ans[now]++;
    }
    return ans[now];
}
int main(){
    int n,l,r;
    char c[10];
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        ans[i]=0;
        c[0]=c[1]=' ';
        scanf("%s",c);
        q[i]=c[1]=='?';
        if(c[0]=='A')type[i]=1;
        else if(c[0]=='R')type[i]=2;
        else type[i]=0;
    }
    for(int i=1;i<n;i++){
        scanf("%d%d",&l,&r);
        graph[l].PB(r);
        graph[r].PB(l);
    }
    printf("%lld\n",dfs(1,0));
}


Measured memory_bytes: 3420
// hackerearth incom
        #include <bits/stdc++.h>

        using namespace std;

        typedef long long ll;
        const ll N = 5e5+5;
        const ll MOD = 1000000007;
        #define all(x) x.begin(),x.end()
        #define pii pair<ll,ll>
        #define pis pair<ll,string>
        #define F first
        #define S second
        #define LCM(a,b) ((a*b)/__gcd(a,b))
        #define inf 1e15
        #define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
        #define PI 3.14159265
        #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
        const double EPS = 1E-9;
        typedef vector<vector<double>> matrix;
        typedef vector<int> vi;


int id[N];
int sz[N];

multiset<int> sett;
vector< vector< pii > > adj(N);
vector< pii > nodes;
bool visited[N];


void initialize(int n){
    sett.clear();
    adj.clear();
    nodes.clear();
    memset(visited, false, sizeof visited);

    for(int i = 1;i <= n; ++i){
         id[i]=i;
         sz[i]=1;
         sett.insert(1);
     }
}
int findset(int x){
    while(id[x] != x){
        id[x] = id[id[x]];
        x = id[x];
    }
    return x;
}

void combine(int x, int y){
    int p = findset(x);
    int q = findset(y);
    if(p == q) return;
    if(sz[q] > sz[p]) swap(p,q);

        sett.erase( sett.find(sz[p])); sett.erase( sett.find(sz[q]));
        id[q]=p; sz[p]+=sz[q];

        sz[q]=-1;
        sett.insert(sz[p]);
}


int main(){

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

    initialize(n);
    int a, b;
    for(int i = 1; i <= m; i++) {
        cin >> a >> b;
        combine(a, b);
    }

    // cout << sett.size() << "\n";
    // for(auto &ele: sett) cout << ele << " "; cout << "\n";

    cout << *sett.rbegin() << "\n";
    return 0;
}


Measured memory_bytes: 26420
fn main() {
  let (n, z, w): (usize, isize, isize) = get::tuple3();
  let mut xs: Vec<isize> = get::list();

  if xs.len() == 1 {
    println!("{}", (xs[0] - w).abs());
    return
  }

  xs.insert(0, z);

  let s1 = (xs[n] - w).abs();
  let s2 = (xs[n-1] - xs[n]).abs();
  let ans = std::cmp::max(s1, s2);

  println!("{}", ans);
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().chars().collect()
  }
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	long long a = 2;
	long long b = 1;
	long long ret = 0;
	if (n == 1) {
		cout << b << endl;
		return 0;
	}
	for (int i = 2; i <= n; i++) {
		ret = a + b;
		a = b;
		b = ret;
	}
	cout << ret << endl;
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i, j) for (long long i = j; i > 0; i--)
using namespace std;

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

	int flag = 0;
	while (1) {
		for (int i = 2; i * i <= x; i++) {
			if (x % i == 0) {
				x++;
				flag = 1;
				break;
			}
		}
		if (flag == 1) {
			flag = 0;
			continue;
		}
		break;
	}

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int N;
  ci(N);
  ve<ll> L(N + 1);
  L.at(0) = 2;
  L.at(1) = 1;
  repi(i, 2, N + 1){
    L.at(i) = L.at(i - 1) + L.at(i - 2);
  }
  co(L.at(N));
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d%*c%d",&a,&b);
  if(b==0) scanf("%d",&b);
 if(a>=2020){printf("TBD");}
    else if(a==2019 && b>=5){  printf("TBD");}
    else{printf("Heisei");
}  return 0;
}


Measured memory_bytes: 128
//import java.awt.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    InputStream inputStream;
    if (args.length > 0 && args[0].equals("devTesting")) {
      try {
        inputStream = new FileInputStream(args[1]);
      } catch(FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    } else {
      inputStream = System.in;
    }
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskC solver = new TaskC();
    solver.solve(1, in, out);
    out.close();
  }
  
  static class TaskC {
    String s;
    
    void solve(int testNumber, InputReader in, PrintWriter out) {
      s = in.next();
      int a = -1, b = -1;
      for (int i = 1; a == -1 && i < s.length(); ++i) {
        if (s.charAt(i - 1) == s.charAt(i)) {
          a = i;
          b = i + 1; 
        }
      }
      for (int i = 2; a == -1 && i < s.length(); ++i) {
        if (s.charAt(i - 2) == s.charAt(i)) {
          a = i - 1;
          b = i + 1;
        }
      }
      out.println(a + " " + b);
    }
  }
    
      
  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream));
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }
    
    public String nextLine() {
      try {
        return reader.readLine();
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }
    
    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public boolean hasInput() {
      try {
        if (tokenizer != null && tokenizer.hasMoreTokens()) {
          return true;
        }
        reader.mark(1);
        int ch = reader.read();
        if (ch != -1) {
          reader.reset();
          return true;
        }
        return false;
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }
    
  }
}


Measured memory_bytes: 10836
T=[int(input())for i in range(5)]
A=list(map(lambda x:x%10,T))
S=list(map(lambda y:y//10,T))
count=0
B=[]
for j in range(5):
    if A[j]!=0:
        count+=1
        B.append(A[j])
if len(B)==0:
    print(10*(sum(S)+count))
else:
    print(10*(sum(S)+count-1)+min(B)) 

Measured memory_bytes: 3064
//正答していない問題について、ペナルティーは発生しない！！！！！！！！
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, m;
int p; string s;
bool used[100000];
int wa[100000];

signed main() {
	int i;
	
	cin >> n >> m;
	rep(i, m) {
		cin >> p >> s;
		p--;
		if (s == "AC") {
			used[p] = true;
		}
		else {
			if (!used[p]) wa[p]++;
		}
	}
	
	int ac = 0;
	rep(i, n) if (used[i]) ac++;
	
	int sumWa = 0;
	rep(i, n) {
		if (used[i]) sumWa += wa[i];
	}
	
	cout << ac << " " << sumWa << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;


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

	priority_queue<pii> q;
	int N, R, L, S[1000010], T[1000010], d, t, x;
	cin >> N >> R >> L;
	q.push(pii(0, -1));
	eREP(i, N) {
		S[i] = 0;
		T[i] = 0;
	}
	int pret = 0, pred = 1;
	REP(i, R) {
		cin >> d >> t >> x;
		S[d] += x;
		q.push(pii(S[d], -d));
		while (1) {
			pii p = q.top();
			if (p.first == S[-p.second]) {
				T[pred] += t - pret;
				pred = -p.second;
				pret = t;
				break;
			}
			q.pop();
		}
	}
	T[pred] += L - pret;
	int ans = -1, tmp;
	eREP(i, N) {
		//cout << T[i] << " ";
		if (ans < T[i]) {
			tmp = i;
			ans = T[i];
		}
	}
	cout << tmp << endl;
	return 0;
}




Measured memory_bytes: 20840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    if(X > Y){
        swap(X,Y);
        swap(A,B);
    }
    ll answer = 0;
    if(A+B <= 2*C){
        answer = X*A+Y*B;
        cout << answer << "\n";
    }else{
        answer += 2*C*X;
        Y -= X;
        if(B <= 2*C){
            answer += Y*B;
        }else{
            answer += 2*C*Y;
        }
        cout << answer << "\n";
    }
}

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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int a,b;
int ans;
int main() {
    cin >> a;
    ans = (a-2)*180;
    cout << ans << endl;
}

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

const int N = 55;

int n, m, s;
int c[N], d[N];
vector<tuple<int, int, int>> edges[N];

long long dist[N][N*N];

int solve() {
  scanf("%d %d %d", &n, &m, &s);
  s = min(s, 2500);
  for (int i = 0; i < m; ++i) {
    int u, v, a, b;
    scanf("%d %d %d %d", &u, &v, &a, &b);
    --u, --v;

    edges[u].emplace_back(v, a, b);
    edges[v].emplace_back(u, a, b);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &c[i], &d[i]);
  }

  memset(dist, -1, sizeof dist);

  priority_queue<tuple<long long, int, int>> pq;
  pq.push(make_tuple(0, 0, s));

  while (pq.size()) {
    long long dd;
    int u, s;
    tie(dd, u, s) = pq.top();
    pq.pop();

    if (dist[u][s] != -1) continue;
    dist[u][s] = -dd;

    {
      int ns = min(2500, s + c[u]);
      if (dist[u][ns] == -1) pq.push(make_tuple(dd - d[u], u, ns));
    }
    for (tuple<int, int, int> edge: edges[u]) {
      int v, a, b;
      tie(v, a, b) = edge;

      if (s - a < 0) continue;
      if (dist[v][s] != -1) continue;

      pq.push(make_tuple(dd - b, v, s-a));
    }
  }

  for (int i = 1; i < n; ++i) {
    long long mini = 1e18;
    for (int j = 0; j <= 2500; ++j) {
      if (dist[i][j] != -1) mini = min(mini, dist[i][j]);
    }

    printf("%lld\n", mini);
  }
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    // printf("Case #%d: ", tc+1);
    solve();
  }
  return 0;
}


Measured memory_bytes: 8724
n = int(input())
s = input()
ans = s.count("R")*s.count("G")*s.count("B")
for i in range(n):
    for j in range(i+1, n):
        k = j-i+j
        if k >= n:
            break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1

print(ans)

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

int main() {
  int n;
  cin >> n;
  
  ll ans = 0;
  
  rep(i, n){
    rep(x, sqrt(i)){
      rep(y, x){
        rep(z, y){
          if((x+y+z)*(x+y+z) - (x*y+y*z+z*x) == i){
            if(x == y && y == z){
              ans++;
            }
            else if(x == y || y == z || z == x){
              ans += 3;
            }
            else{
              ans += 6;
            }
          }
        }
      }
    }
    cout << ans << endl;
    ans = 0;
  }
  
}


Measured memory_bytes: 3548
S = input()
left = int(S[:2])
right = int(S[2:])

ans = "NA"
if left == 0:
  if 0 < right < 13:
    ans = "YYMM"
elif right == 0:
  if 0 < left < 13:
    ans = "MMYY"
elif 0 < left < 13:
  if 0 < right < 13:
    ans = "AMBIGUOUS"
  else:
    ans = "MMYY"
elif 0 < right < 13:
  if left > 12:
    ans = "YYMM"
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tp, T)
	{
		//cout << "Case #" << i << ": ";
		int n; cin >> n;
		vi A(n), B(n);
		FOR(i, n){
			cin >> A[i] >> B[i];
		}		
		sort(all(A)); sort(all(B));
		int min_med, max_med;
		if(n % 2){
			min_med = A[n/2];
			max_med = B[n/2];
		}
		else{
			min_med = A[n/2] + A[n/2-1];
			max_med = B[n/2] + B[n/2-1];
		}
		//cout << min_med << " " << max_med << '\n';
		/*Every number from min_med to max_med is possible as median*/
		cout << max_med-min_med+1;
		cout<<'\n';
	}
	return 0;
}

Measured memory_bytes: 6320
from itertools import combinations
N = int(input())
k = 2
while (k*(k-1))//2<N:
    k += 1
if (k*(k-1))//2!=N:
    print("No")
else:
    print("Yes")
    S = {i:[] for i in range(1,k+1)}
    cnt = 1
    for x in combinations(range(1,k+1),2):
        S[x[0]].append(cnt)
        S[x[1]].append(cnt)
        cnt += 1
    print(k)
    for i in range(1,k+1):
        print(len(S[i]),*S[i])

Measured memory_bytes: 46940
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] X1 = new int[N];
		int[] X2 = new int[N];
		int[] Y1 = new int[N];
		int[] Y2 = new int[N];
		int[] D1 = new int[N];
		int[] D2 = new int[N];
		TreeSet<Integer> xset = new TreeSet<Integer>();
		TreeSet<Integer> yset = new TreeSet<Integer>();
		TreeSet<Integer> dset = new TreeSet<Integer>();
		for (int i = 0; i < N; ++i) {
			X1[i] = sc.nextInt();
			Y1[i] = sc.nextInt();
			D1[i] = sc.nextInt();
			X2[i] = sc.nextInt();
			Y2[i] = sc.nextInt();
			D2[i] = sc.nextInt();
			xset.add(X1[i]);
			xset.add(X2[i]);
			yset.add(Y1[i]);
			yset.add(Y2[i]);
			dset.add(D1[i]);
			dset.add(D2[i]);
		}
		ArrayList<Integer> xs = new ArrayList<Integer>();
		ArrayList<Integer> ys = new ArrayList<Integer>();
		ArrayList<Integer> ds = new ArrayList<Integer>();
		for (int v : xset) {
			xs.add(v);
		}
		for (int v : yset) {
			ys.add(v);
		}
		for (int v : dset) {
			ds.add(v);
		}
		HashMap<Integer, Integer> xmap = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> ymap = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> dmap = new HashMap<Integer, Integer>();
		for (int i = 0; i < xs.size(); ++i) {
			xmap.put(xs.get(i), i);
		}
		for (int i = 0; i < ys.size(); ++i) {
			ymap.put(ys.get(i), i);
		}
		for (int i = 0; i < ds.size(); ++i) {
			dmap.put(ds.get(i), i);
		}
		int[][][] count = new int[xs.size()][ys.size()][ds.size()];
		for (int i = 0; i < N; ++i) {
			int minx = xmap.get(X1[i]);
			int maxx = xmap.get(X2[i]);
			int miny = ymap.get(Y1[i]);
			int maxy = ymap.get(Y2[i]);
			int mind = dmap.get(D1[i]);
			int maxd = dmap.get(D2[i]);
			for (int j = minx; j < maxx; ++j) {
				for (int k = miny; k < maxy; ++k) {
					for (int l = mind; l < maxd; ++l) {
						count[j][k][l]++;
					}
				}
			}
		}
		long ans = 0;
		for (int i = 0; i < xs.size() - 1; ++i) {
			long x = xs.get(i + 1) - xs.get(i);
			for (int j = 0; j < ys.size() - 1; ++j) {
				long y = ys.get(j + 1) - ys.get(j);
				for (int k = 0; k < ds.size() - 1; ++k) {
					if (count[i][j][k] >= K) {
						long d = ds.get(k + 1) - ds.get(k);
						ans += x * y * d;
					}
				}
			}
		}
		System.out.println(ans);
	}

}

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

int main(void){
	stack<int> st;
	int c;
	while(cin >> c){
		if(c == 0){
			cout << st.top() << endl;
			st.pop();
		}
		else{
			st.push(c);
		}
	}
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,x,y,b;
  cin>>n>>k>>x>>y;
  int a=min(n,k);
  if(n>k)b=n-k;
  else b=0;
  cout<<x*a+y*b<<endl;
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e5+6;
void solve(){
	ll n,a,b; 
	cin>>n>>a>>b; 
	ll d = (b-a);
	if(d%2==0){
		cout<<d/2<<endl;
		return ;
	}
	cout<<(b-a)/2+min(a,n-b+1)<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}
/// n = 12
/// 5 8
/// 6 9
/// 7 10
/// 8 11
/// 9 12
/// 10 12
/// 11 11
/// ans = 7;

/// 3 6
/// 2 5
/// 1 4
/// 1 3
/// 2 2
/// ans = 5

///4+(7-4)/2 = 5
///12-7+1+(7-4)/2 =  7



Measured memory_bytes: 3604
N = int(input())
H = list(map(int, input().split()))
 
if N == 1:
    print(0)
    quit()

start = 0
moves = []
for i in range(N-1):
    moves.append(i - start)
    if H[i] < H[i+1]:
        start = i + 1
if H[N-2] >= H[N-1]:
    moves.append(i - start + 1)
print(max(moves))

Measured memory_bytes: 14224
/*
  #問題：
  


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

  #要求：
  

  #解法：
  
*/

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

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

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


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


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

using Bint = mp::cpp_int;



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

  int a[n][30];

  int flag_m[n][m];
  FOR(i,0,n){
    FOR(j,0,m){
      flag_m[i][j]=0;
    }
  }


  
  FOR(i,0,n){
    cin>>k;
    FOR(j,0,k) {
      int temp; cin>>temp;
      flag_m[i][temp-1]=1;
    }
  }

  int s_flag=1; int cnt=0;
  FOR(i,0,m){
    s_flag=1;
    FOR(j,0,n){
      if (flag_m[j][i]!=1) {  s_flag=0;  }
    }
    if (s_flag==1) {cnt++; cerr<<"cnt: "<<cnt<<endl;}
  }

  FOR(i,0,n){
    FOR(j,0,m){
      cerr<<flag_m[i][j]<<" ";
    }
    cerr<<endl;
  }

  
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n;
	deque<int> que;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (i % 2 == 0) {
			que.push_front(a);
		}
		else {
			que.push_back(a);
		}
	}
	if (n % 2 == 1) {
		for (int i = 0; i < n; i++) {
			cout << que.front();
			if (i != n - 1) {
				cout << " ";
			}
			que.pop_front();
		}
		cout << endl;
	}
	else {
		for (int i = 0; i < n; i++) {
			cout << que.back();
			if (i != n - 1) {
				cout << " ";
			}
			que.pop_back();
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2944
import java.io.*;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        ArrayList<int[]> x = new ArrayList<>(n);
        for (int i = 0; i < n; ++i) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            x.add(new int[]{a, b});
        }
        x.sort(Comparator.comparingInt(o -> o[1]));
        boolean valid = true;
        long cur = 0;
        for (int i = 0; i < n; ++i) {
            cur += x.get(i)[0];
            if (cur > x.get(i)[1]) {
                valid = false;
                break;
            }
        }
        writer.println(valid ? "Yes" : "No");

        writer.close();
    }

    private static long compute(long a, long b, long c) {
        return b / c - (a / c + (a % c == 0 ? 0 : 1)) + 1;
    }

    private static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 65096
<?php
fscanf(STDIN, "%d %d", $n, $m);
while ($m--) {
	fscanf(STDIN, "%d %d", $a, $b);
	if ($a == 1) {
		if (isset($x[$b])) exit('POSSIBLE');
		$x[$b] = 1;
	} elseif ($b == $n) {
		if (isset($x[$a])) exit('POSSIBLE');
		$x[$a] = 1;
	}
}
echo 'IMPOSSIBLE';

Measured memory_bytes: 17400