akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Arrays;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        ArrayList<String> strs = new ArrayList<>();
        
        int[][] lines = new int[H][W];
        int[][] rows = new int[H][W];
        
        for(int i=0;i<H;i++) strs.add(sc.next());

        int startLine;
        int line;
        for (int i=0; i<H; i++){
            startLine=0;
            line=0;
            for (int j=0; j<W; j++){
                if (strs.get(i).charAt(j)=='.'){
                    line++;
                }else {
                    if(line!=0) {
                        for(int k=startLine;k<j;k++){
                            lines[i][k] = line;
                        }
                        line = 0;
                    }
                    startLine=j+1;
                }

                if(j==W-1){
                    if(line!=0) {
                        for(int k=startLine;k<W;k++){
                            lines[i][k] = line;
                        }
                        line = 0;
                    }
                    startLine=j+1;
                }
            }
        }

        for (int i=0; i<W; i++){
            startLine=0;
            line=0;
            for (int j=0; j<H; j++){
                if (strs.get(j).charAt(i)=='.'){
                    line++;
                }else {
                    if(line!=0) {
                        for(int k=startLine;k<j;k++){
                            rows[k][i] = line;
                        }
                        line = 0;
                    }
                    startLine=j+1;
                }

                if(j==H-1){
                    if(line!=0) {
                        for(int k=startLine;k<H;k++){
                            rows[k][i] = line;
                        }
                        line = 0;
                    }
                    startLine=j+1;
                }
            }
        }

        int max=0;
        for (int i=0; i<H; i++) {
            for (int j = 0; j < W; j++) {
                max= max(max,lines[i][j]+rows[i][j]-1);
            }
        }

        System.out.println(max);

    }
}


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

using namespace std;

#define run_forrest_run ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define vi vector <int>
#define pii pair <int, int>
#define sz(a) (int)a.size()
#define F first
#define S second
#define si set <int>
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int gcd(int a,int b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);} 

const int inf = 1e9;	
const int mod = inf + 7;

const int N = 1e5+500;
vector <int> g[N];
vector <bool> visited(N);
vector <int> color(N);	

vector <pair <ll,ll> >v;

int main()
{                   
	run_forrest_run;
	int n;
	cin >> n;
	ll sum = 0;
	for (int i = 0; i < n; i++)
	{
		int a,b;
		cin >> a >> b;
		v.pb(mp(b,a));
	}
	sort(all(v));
	for (int i = 0; i < n; i++)
	{
		if (v[i].F < sum+v[i].S)
		{
			cout << "No";
			return 0;
		}
		else
			sum+=v[i].S;
	}
		cout << "Yes";


}

Measured memory_bytes: 9200
#include <stdio.h>

int main(void) {
	int a,b,i;
	char op;
	for(i=1; ;i++){
	scanf("%d %c %d",&a,&op,&b);
	if(op=='?')break;
	
	if( op == '+'){
		printf("%d\n",a+b);
	} else if ( op== '-'){
		printf("%d\n",a-b);
	}else if ( op=='*'){
		printf("%d\n",a*b);
	}else if(op=='/'){
		printf("%d\n",a/b);
	}
		
	}
	return 0;
}

Measured memory_bytes: 600
n=int(input())
t=[input().split() for i in range(n)]
x=input()
s=[g[1] for g in t]
o=[l[0] for l in t]
ans=0
for i in range(n):
    if x==o[i]:
        for j in range(i+1,n):
            ans+=int(s[j])
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k,q;cin>>n>>k>>q;
    int cnt[n+1];
    fill(cnt,cnt+n+1,0);
    rep(i,0,q){
        int a;cin>>a;
        cnt[a]++;
    }
    rep(i,1,n+1){
        if(cnt[i]>q-k){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 1024
s = input()
n = len(s)
l = [1]*n

for i in range(n - 1):
    if s[i] == s[i + 1] == "R":
        l[i + 2] += l[i]
        l[i] = 0
    if s[-i - 1] == s[-i - 2] == "L":
        l[-i - 3] += l[-i - 1]
        l[-i - 1] = 0

print(*l)

Measured memory_bytes: 6400
from itertools import accumulate

N=int(input())
A=[int(x) for x in input().split()]
ans=abs(sum(A)-A[0]*2)

S=list(accumulate(A))

for i in range(1,N-1):
  ans=min(ans,abs(S[N-1]-S[i]*2))

print(ans)


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

 int main(){
 int A, B, C;
 cin >> A >> B >> C;
 if(A <= C && B >= C) yes;
 else no;
 
 }

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



int main(){
    int a, b;
    cin >> a >> b;
    cout << a*b-a-b+1<< endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#define ll long long
#define il inline
#define rgi register int

using namespace std;

il int read()
{
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int main()
{
	int a = read(), b = read();
	printf("%d", max(a + b, max(a - b, a * b)));
	return 0;
}


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

int mod = 1000000007;

int main()
{
    int N, M, X, Y, tmp;
    cin >> N >> M >> X >> Y;
    int Xmax = X, Ymin = Y;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        Xmax = max(Xmax, tmp);
    }
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        Ymin = min(Ymin, tmp);
    }
    cout << (Xmax < Ymin ? "No War" : "War");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
#include<utility>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

int N;
int A[15];
int x[15][15],y[15][15];

void dfs(ll M,int bits,int &count){
    if(M>N) return;
    if(bits==0b111) count++;
    dfs(M*10+7,bits|0b100,count);
    dfs(M*10+5,bits|0b010,count);
    dfs(M*10+3,bits|0b001,count);
}

int main(){
    cin>>N;
    ll M=0;
    int bits=0b000;
    int count=0;
    dfs(M,bits,count);
    cout<<count<<endl;
}

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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> cookie (3);
    cin >> cookie[0] >> cookie[1] >> cookie[2];
    vector<vector<int>> memory (0,vector<int>(3));
    if(cookie[0] % 2 == 1 || cookie[1] % 2 == 1 || cookie[2] % 2 == 1){
        cout << 0 << endl;
        ED
    }
    for(int i = 1;true;i++){
        memory.push_back(cookie);
        vector<int> dummy (3);
        dummy[0] =cookie[1]/2 + cookie[2]/2;
        dummy[1] =cookie[0]/2 + cookie[2]/2;
        dummy[2] =cookie[0]/2 + cookie[1]/2;
        cookie = dummy;
        if(cookie[0] % 2 == 1 || cookie[1] % 2 == 1 || cookie[2] % 2 == 1){
            cout << i << endl;
            ED
        }
        for(int i = 0;i < memory.size();i++){
            if(cookie == memory[i]){
                cout << "-1" << endl;
                ED
            }
        }
    }
}


Measured memory_bytes: 256
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)


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

g = gcd(N, M)
n = N // g
m = M // g

lcm_ = lcm(N, M)

x = 0
while x * n < N and x * m < M:
    if s[x * n] != t[x * m]:
        print(-1)
        exit()
    x += 1
print(lcm_)

"""
0-indexedで考える。
s : x[0], x[k*L/N], x[k*L/N*2], ...
t : x[0], x[k*L/M], x[k*L/M*2], ...
同じindexを指しているとき、同じ文字である必要がある。

len(x)はlcm(N,M)の倍数。

N = gn
M = gm
L = gnm = NM/g

s : x[0], x[k*M/g], x[k*M/g*2], ... x[k*M/g*a], ...
t : x[0], x[k*N/g], x[k*N/g*2], ... x[k*N/g*b], ...

k*M/g*a==k*N/g*b

kにかかわらず
if ma==nb:
    # m,nは互いに素なので、a=xn, b=xm
    if s[a] != t[b]:
        return False
"""


Measured memory_bytes: 3316
fun main(arg: Array<String>) {
    val (N, K) = listOfInt()
    val XY = Array(N) { listOfLong().toTypedArray() }
    var ans = Long.MAX_VALUE
    for (xi in 0 until N) for (xj in xi + 1 until N)
        for (yi in 0 until N) for (yj in yi + 1 until N) {
            var count = 0
            val (x0, x1) = listOf(XY[xi][0], XY[xj][0]).sorted()
            val (y0, y1) = listOf(XY[yi][1], XY[yj][1]).sorted()
            for (n in 0 until N)
                if (XY[n][0] in x0 .. x1 && XY[n][1] in y0 .. y1) count += 1
            if (count >= K) ans = Math.min(ans, (x1 - x0) * (y1 - y0))
        }
    println(ans)
}
//50^4=6250000

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { Integer.parseInt(it) + d }
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map { it.toDouble() }


Measured memory_bytes: 109868
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	int n;
	cin >> n;
	vector<int>a(n+1), b(n );
	for (int i = 0; i < n+1; i++)cin >> a[i];
	for (int i = 0; i < n; i++)cin >> b[i];
	long long int r = 0, ans = 0;

	for (int i = 0; i < n; i++) {
		int t = min(a[i], (int)r);
		ans += t;
		a[i] -= t;
		int y = min(a[i], b[i]);
		ans += y;
		r = b[i] - y;
	}
	ans += min(a[n], (int)r);
	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 1024
# include <iostream>
# include <cstring>
# include <cstdio>
using namespace std;
const int N = 1e5 + 12;
const int M = 2e5 + 12;
char str[N];
int cur,cnt,last,nex[M][26],fa[M],dis[M],ch[M][26],l[M];
void build(int c,int id){
	last = cur;cur = ++cnt;
	int u = last;dis[cur] = id;
	while(u &&!nex[u][c])nex[u][c] = cur,u = fa[u];
	if(!u)fa[cur] = 1;
	else {
		int v = nex[u][c];
		if(dis[v] == dis[u] + 1)fa[cur] = v;
		else {
		    int nv = ++cnt;dis[nv] = dis[u] + 1;
		    memcpy(nex[nv],nex[v],sizeof nex[v]);
		    fa[nv] = fa[v];fa[v] = fa[cur] = nv;
		    while(u && nex[u][c] == v)nex[u][c] = nv,u = fa[u];
		}
	}
}
int len,n,Q,x,now,size;
int bac[N],y[M],ans[N],f[M];
int main(){
	scanf("%s",str);
	len = strlen(str);
	cnt = cur = 1;
	for(int i = 0;i < len;i++)build(str[i] - 'a',i + 1);
	for(int i = 1;i <= cnt;i++)bac[dis[i]]++;
	for(int i = 1;i <= len;i++)bac[i] += bac[i - 1];
	for(int i = cnt;i >= 1;i--)y[bac[dis[i]]--] = i;
	for(int i = 1;i <= cnt;i++)f[i] = 1;
	for(int i = 1;i <= cnt;i++){
		for(int j = 0;j < 26;j++){
			if(nex[i][j])ch[i][++l[i]] = j;
		}
	}
	for(int i = cnt;i >= 1;i--){
		for(int j = 1;j <= l[y[i]];j++){
			f[y[i]] += f[nex[y[i]][ch[y[i]][j]]];
		}
	}
    	scanf("%d",&x);
    	len = 0;now = 1;size = 0;
    	while(x){
    		for(int i = 1;i <= l[now];i++){
    			if(f[nex[now][ch[now][i]]] < x)x -= f[nex[now][ch[now][i]]];
    			else {
    				x--;
    				str[size++] = 'a' + ch[now][i];
    				now = nex[now][ch[now][i]];
    				break;
				}
			}
		}
		str[size] = '\0';
		puts(str);
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}


main() {
    int N; cin >> N;
    int A[N]; rep(i,N) cin >> A[i];
    int L[N],R[N];
    rep(i,N){
        if(i==0)L[i]=A[0];
        else L[i]=gcd(L[i-1],A[i]);
    }
    for(int i=N-1;i>=0;i--){
        if(i==N-1)R[i]=A[N-1];
        else R[i]=gcd(R[i+1],A[i]);
    }
    int ans=0;
    rep(i,N){
        int pos;
        if(i==0) pos=R[1];
        else if(i==N-1) pos=L[N-2];
        else pos = gcd(L[i-1],R[i+1]);
        ans=max(ans,pos);
    }
    cout << ans << endl;
     
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
    int a,b,c;
    char op;
    while(cin >> a >> op >> b && op!='?'){
        switch(op){
            case '+': c=a+b; break;
            case '-': c=a-b; break;
            case '*': c=a*b; break;
            case '/': c=a/b; break;
        }
        cout << c << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        var c = Console.ReadLine();
        var vow = new List<string> { "a", "e", "i", "o", "u" };
        if (vow.Any(x => x == c))
        {
            Console.WriteLine("vowel");
        }
        else
        {
            Console.WriteLine("consonant");
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <stack>

using namespace std;
typedef long long ll;

#define _SI(arr) (sizeof(arr)/sizeof(arr[0])

int main() {
	ll N;
	cin >> N;

	printf("ABC%d\n", N);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define sfi(a) scanf("%d",&a)
#define m_p make_pair
#define inf 1e9
#define ff first
#define ss second
#define pi(x) pair<x,x>
#define mem(x) memset(x,-1,sizeof(x))
#define TEST_CASE(t) for(int z=1 ; z<=t ; z++)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define FAST  ios_base::sync_with_stdio(0);cout.tie(0)

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int maxn = 100010;
const ll M = 1e9+7;


int main()
{
    string str,str_r;
    cin >> str;
    bool flag = true;
    str_r = str;
    reverse(str.begin(),str.end());
    if(str!=str_r) flag = false;
    int a,b,c,d;
    a = 0;
    b = (((str.size()) - 1) / 2) - 1 ;
    c = ((str.size()+3)/2) - 1;
    d = str.size()-1;

    string str1="", str2="";
    for(int i=a;i<=b;i++) str1 += str[i];
    for(int i=c;i<=d;i++) str2 += str[i];
    string str1_r,str2_r;
    str1_r = str1;
    reverse(str1.begin(),str1.end());
    str2_r = str2;
    reverse(str2.begin(),str2.end());
    if(str1!=str1_r) flag = false;
    if(str2!=str2_r) flag = false;

    if(flag) puts("Yes");
    else puts("No");
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

ll a, b, c;

int main() {
	cin >> a >> b >> c;

	if (a >= c) {
		cout << c + b << endl;
	}
	else if(a + b >= c){
		cout << c + b << endl;
	}
	else {
		cout << a + 2 * b + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False]*(k+1)
for i in range(1,k+1):
    ok=False
    for j in range(n):
        if i-a[j]>=0:
            if not dp[i-a[j]]:
                ok=True
    if ok:
        dp[i]=True
if dp[k]:
    print("First")
else:
    print("Second")

Measured memory_bytes: 74372
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include <iomanip> 
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int k, x;
    while (cin >> k >> x)
    {
        if (500 * k >= x) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
#define mod 1000000007
bool isPerfectSquare(int x) 
{   
    long double xx=(long double)x;
  long double sr = sqrt(xx); 
  
  // If square root is an integer 
  return ((sr - floor(sr)) == 0); 
} 
int main() 
{  
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    

   long long int n,d,min1=pow(10,18);
   cin>>n>>d;
   if(d-n>=2019)
   cout<<0;
   else
   {
       for(long long int i=n;i<d;i++)
       {
           for(long long int j=i+1;j<=d;j++)
           {
            min1=min((i*j)%2019,min1);  
          //  cout<<i<<"  "<<j<<" "<<min1<<'\n';
            
           }
       }
       cout<<min1;
   }


    return 0;
}

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

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 50;
const double EPS = 1e-9;


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

int a[MX];
int b[MX];
int c[MX];
int d[MX];

int n, m, q;
vi cur;

int mx = 0;

void gen(int ind, int prev) {
	if (ind == n) {
		int cursc = 0;
		fi(0, q) {
			if (cur[b[i] - 1] - cur[a[i] - 1] == c[i])
				cursc += d[i];
		}
		maxe(mx, cursc);
	} else {
		fi(prev, m + 1) {
			cur.push_back(i);
			gen(ind + 1, i);
			cur.pop_back();
		}
	}
}

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

    cin >> n >> m >> q;
    fi(0, q) {
    	cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    gen(0, 1);
    cout << mx << '\n';
}

Measured memory_bytes: 3608
class UnionFind:
    def __init__(self, n):
        self.par = list(range(n))
        self.rank = [0] * n
        self.size = [1] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            x, y = y, x
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        self.size[x] += self.size[y]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]
      
from collections import Counter


def abc049_d():
    n, k, l = map(int, input().split())

    road = UnionFind(n)
    for i in range(k):
        p, q = map(int, input().split())
        road.unite(p - 1, q - 1)

    rail = UnionFind(n)
    for i in range(l):
        r, s = map(int, input().split())
        rail.unite(r - 1, s - 1)

    set1 = []
    for i in range(n):
        set1.append((road.find(i), rail.find(i)))
    c = Counter(set1)
    ans = []
    for i in range(n):
        ans.append(c[(road.find(i), rail.find(i))])
    print(*ans)


if __name__ == '__main__':
    abc049_d()


Measured memory_bytes: 121376
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;


void insertionSort(int A[], int n, int g){
  for (int i=0; i<n; i++){
    int v = A[i];
    int j = i - g;
    while(j>=0&&A[j] > v){
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[], int n){
  for (int h=1; ; ){
    if (h > n)break;
    G.push_back(h);
    h = 3*h+1;
  }

  for (int i = G.size()-1; i>=0; i--){
    insertionSort(A, n, G[i]);
  }
}


int main() {
  cin >> n;
  for (int i=0; i < n; i++) cin >> A[i];
  cnt = 0;

  shellSort(A, n);

  cout << G.size() << endl;
  for (int i=G.size()-1; i>=0; i--){
    cout << G[i];
    if (i) cout << " ";
  }

  cout << endl;
  cout << cnt << endl;

  for (int i=0; i<n; i++) cout << A[i] << endl;
}

Measured memory_bytes: 7048
#n=int(input())
n,m,x=map(int,input().split())
#a=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(n)]

def tas(l1,l2):
    l3=[]
    for i in range(m+1):
        l3.append(l1[i]+l2[i])
    return l3


ll=[[0 for i in range(m+1)]]
for i in range(n):
    for j in range(len(ll)):
        ll.append(tas(ll[j],l[i]))

lm=[]
for i in ll:
    lll=[]
    for j in range(1,len(i)):
        if i[j]>=x:
            lll.append(True)
        else:
            lll.append(False)
    if all(lll)==True:
        lm.append(i[0])

if len(lm)>0:
    print(min(lm))
else:
    print(-1)


Measured memory_bytes: 69580
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

string s, ans_str;
int n, ans_num;
bool f[8];
map<int, int> m;

typedef string::const_iterator State;
int number(State&);
int factor(State&);
int term(State&);
int expression(State&);

// ??°??????????????????????????????????????°????????????
int number(State &begin) {
    int ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}

// ??¬??§?????°???????????????????????????????????????????????????
int factor(State &begin) {
    if (*begin == '(') {
        begin++; // '('????£???°??????
        int ret = expression(begin);
        begin++; // ')'????£???°??????
    } else {
        return number(begin);
    }
    return INF;
}

// ?????????????????????????????????????????????????????????????????????
int term(State &begin) {
    int ret = factor(begin);

    for (;;) {
        if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        } else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        } else {
            break;
        }
    }

    return ret;
}

// ?????????????????????????????????????????????????????????????????????
int expression(State &begin) {
    int ret = term(begin);

    for (;;) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);
        } else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        } else {
            break;
        }
    }

    return ret;
}

void solve(string p, int i){
    if(i == s.size()){
        State it = p.begin();
        int temp = expression(it);
        if(abs(n - ans_num) >= abs(n - temp) && n >= temp){
            ans_str = p;
            ans_num = temp;
            m[temp]++;
        }
        return;
    }

    p+=s[i];
    solve(p, i + 1);
    if(i + 1 != s.size() && f[i] == 0 && f[i + 1] == 0){
        p+='+';
        solve(p, i + 1);
    }
}

void check(){
    string temp;
    int m = static_cast<int>(log10(n));

    rep(i,s.size() - m){
        string temp = s.substr(i,m);
        State it = s.begin();
        if(number(it) == n){
            range(j,i,i + m){
                f[j] = 1;
            }
        }
    }
}


int main(){
    while(cin >> n >> s, n||s[0] != '0'){
        m.clear();
        ans_num = -1;
        rep(i,8) f[i] = 0;

        solve("", 0);

        State it = s.begin();
        if(ans_num == -1){
            cout << "error" << endl;
        }else if(m[ans_num] > 1){
            cout << "rejected" << endl;
        }else{
            cout << ans_num << ' ';
            rep(i,ans_str.size()){
                if(ans_str[i] == '+') cout << ' ';
                else cout << ans_str[i];
            }
            cout << endl;
        }
    }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int v[3] = {10000, 5000, 1000};

// Problem Specific Parameter:

int main() {
  ll n, y; cin >> n >> y;
  for(ll i = 0; i <= n; ++i) {
    for(ll j = 0; j <= n; ++j) {
      ll k = n - i - j;
      if(k >= 0) {
        ll price = 10000 * i + 5000 * j + k*1000;
        if(price == y) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;


int main(){


	int A, B, K; std::cin >> A >> B >> K;

	std::set<int> s;

	for(int i = 0; i < K; i++){
		if(A + i <= B)s.insert(A + i);
		if(B - i >= A)s.insert(B - i);
	}

	for(const auto &v : s){
		std::cout << v << std::endl;
	}


	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

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

cnt = 0
now = 1
for i in range(N):
    if A[i] == now:
        now += 1
    else:
        cnt += 1
if N == cnt:
    print(-1)
else:
    print(cnt)


Measured memory_bytes: 24744
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll K,A,B;
    cin >>K>>A>>B;
    REP(i,B-A+1){
        if((i+A)%K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;    
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int main()
{

  SCIN(S);
  REP(i, S.size()) {
    if (S[i] == S[i + 1]) {
      printf("%d %d\n", i + 1, i + 2);
      return 0;
    }
    if (S[i + 1] == S[i + 2] || S[i] == S[i + 2]) {
      // debug(i + 3);
      if (i + 3 > S.size()) break;
      printf("%d %d\n", i + 1, i + 3);
      return 0;
    }
  }
  printf("-1 -1\n");

  return 0;
}



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

namespace ConsoleApp14
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Calc();
        }
    }

    public class Solver
    {
        public class Ans
        {
            public long No;
            public bool bSuccess;
        }



        public void Calc()
        {


            var NM = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
            var N = NM[0];
            var M = NM[1];

            var anss = new Ans[M];
            for (var i = 0; i < M; i++)
            {
                var pp = Console.ReadLine().Split().ToArray();
                anss[i] = new Ans { No = int.Parse(pp[0]), bSuccess = pp[1] == "AC" };
            }

            var dic = anss.GroupBy(x => x.No);

            var a = 0;
            var p = 0;
            foreach (var d in dic)
            {
                var pl = 0;
                var al = 0;
                foreach (var ans in d)
                {
                    if (ans.bSuccess)
                    {
                        al++;
                        a++;
                        break;
                    }
                    else
                    {
                        pl++;
                    }
                }
                if (al == 1)
                {
                    p += pl;
                }
            }


            Console.WriteLine($"{a} {p}");

        }
    }
}

Measured memory_bytes: 31252
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int[] array = Arrays.stream(a).filter(i -> i % 2 == 0).mapToInt(i -> i).toArray();
        int result = 0;
        for (int num : array) {
            while (num % 2 == 0) {
                num /= 2;
                result++;
            }
        }

        // 出力
        System.out.println(result);
    }
}


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

int main() {
    int n,k,s;
    cin >> n >> k >> s;
    int inf;
    if(s==1000000000) inf = s-1;
    else inf = 1000000000;
    for(int i = 0; i < n; i++) {
        if(i<k) cout << s << ' ';
        else if(i<n-1) cout << inf << ' ';
        else cout << inf <<endl;
    }

    return 0;
}

Measured memory_bytes: 3584
/* -----KAUN_MEET--------*/

#include <bits/stdc++.h>
using namespace std;
#define int long long int
int mod = 1000000007;
// int maxi=100;
int maxi=1e18+5;
#define P get<0>
#define D get<1>
#define T get<2>
#define C get<3>
#define PB push_back
#define MP make_pair
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define F first
#define S second
#define gcd __gcd
#define fastio               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

void __print(int x)
{
    cerr << x;
}
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename Th, typename V>
void __print(const pair<Th, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename Th>
void __print(const Th &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename Th, typename... V>
void _print(Th t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif
int n;
int w;
vector <pair<int,int>> p;
int ans[105][100000+10];
int answer(int i,int val){
    if(val<=0){
        ans[i][val]=0;
        return 0;
    }

    int j,k,l;

    if(i>=n) return maxi;
    if(ans[i][val]!=-1) return ans[i][val];

int costi=p[i].F;
int valui=p[i].S;

    if(i==0){
        
        if(valui==val){
            ans[i][val]=costi;
        }
        else{
            ans[i][val]=maxi;
        }

        return ans[i][val];
    }
    int ans1=answer(i-1,val);
    int ans2;
    if(val<valui){
        ans2=maxi;
    }
    else{
        ans2=answer(i-1,val-valui)+costi;

    }
    ans[i][val]=min(ans1,ans2);
    return ans[i][val];



}
void binary_rock()
{
    cin>>n;
    cin>>w;
    int i,j,k,l;
    int sum=0;
    for(i=0;i<n;i++){
        cin>>j>>k;
        p.PB({j,k});
        sum+=k;
    }
    sort(p.begin(),p.end());
    for(i=0;i<n;i++){
        for(j=0;j<=sum;j++)
        ans[i][j]=-1;
    }
int yy=0;
    for(i=0;i<=sum;i++){
        if(answer(n-1,i)<=w){
            yy=i;
        }
    }
    cout<<yy<<endl;

// for(i=0;i<n;i++){
//     for(j=0;j<=sum;j++)
//     {
//         cout<<ans[i][j]<<" ";
//     }
//     cout<<endl;
// }
}

signed main()
{
    fastio
        clock_t t1 = clock();

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

    clock_t t2 = clock();
    // cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl;
    // cout << CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 80256
//
// Created on 2020/04/19.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int ans;
    int n ;
    int m;
    cin>>n>>m;
    int sum = 0;
    for (int i = 0; i < m; ++i) {
        int a;
        cin>>a;
        sum += a;
    }

    ans = max(n - sum,-1);
    cout<<ans<<endl;
    return 0;
}


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

int main(){
	int n;
	ll h[110000];
	cin >> n;
	int cnt = 0;
	int ans = 0;
	rep(i, n){
		cin >> h[i];
	}
	rep(i, n - 1){
		if(h[i] >= h[i + 1]) cnt++;
		else{
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

const int MAX_N = 1 << 19;
const int MAX_LG = 20;

pair<int, int> dp [MAX_N][MAX_LG];
int ans [MAX_N];
int arr [MAX_N];

pair<int, int> merge (pair<int, int> p, pair<int, int> q) {
  if (p.first < q.first) {
    swap(p, q);
  }
  return make_pair(p.first, max(p.second, q.first));
}

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

  for (int i = 0; i < 1 << length; i++) {
    cin >> arr[i];
  }

  for (int i = 0; i < 1 << length; i++) {
    dp[i][0] = make_pair(arr[i], -1);
  }

  for (int k = 1; k <= length; k++) {
    for (int i = 0; i < 1 << length; i++) {
      if (i & (1 << (k - 1))) {
        dp[i][k] = merge(dp[i][k - 1], dp[i - (1 << (k - 1))][k - 1]);
      } else {
        dp[i][k] = dp[i][k - 1];
      }
    }
  }

  for (int i = 1; i < 1 << length; i++) {
    ans[i] = max(ans[i - 1], dp[i][length].first + dp[i][length].second);
    cout << ans[i] << '\n';
  }
}


Measured memory_bytes: 49152
a = list(input().split())
stc = []

for i in range(len(a)):
    if a[i]=="+":
        stc.append(stc.pop() + stc.pop())
    elif a[i]=="-":
        stc.append(-(stc.pop() - stc.pop()))
    elif a[i]=="*":
        stc.append(stc.pop() * stc.pop())
    else:
        stc.append(int(a[i]))
        
print(stc[-1])


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

const int M = 64;

int main() {
    int N; cin >> N;
    vector<vector<int64_t>> A(M, vector<int64_t>(M));

    rep(i, N) {
        long double a; cin >> a;
        int64_t n = (int64_t)(a * 1e9 + 0.5);
        int two = 0, five = 0;
        while(n % 2 == 0) n /= 2, two++;
        while(n % 5 == 0) n /= 5, five++;
        A[two][five]++;
    }

    vector<pair<int, int>> pairs;
    rep(i, M) rep(j, M) pairs.emplace_back(i, j);

    int64_t ans = 0;
    rep(i, pairs.size()) for(int j = i; j < pairs.size(); ++j) {
        auto[t, f] = pairs[i];
        auto[_t, _f] = pairs[j];
        if(t + _t < 18 || f + _f < 18) continue;
        if(i == j) ans += A[t][f] * (A[t][f] - 1) / 2;
        else ans += A[t][f] * A[_t][_f];
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#include <stdlib.h>
#include <cmath>
using namespace std;
typedef long long ll;
ll mod=1000000007;
ll BIG=1e9;

int mp[160][160];
int sum[160][160];

int main(){
    int N,K; cin>>N>>K;
    vector<ll> x,y;
    vector<pair<ll,ll>> d;
    for(int i=0;i<N;i++){
        ll a,b; cin>>a>>b;
        d.push_back(make_pair(a,b));
        x.push_back(a-1);
        x.push_back(a);
        x.push_back(a+1);
        y.push_back(b-1);
        y.push_back(b);
        y.push_back(b+1);
    }

    
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    sort(d.begin(),d.end());

    x.erase(unique(x.begin(), x.end()), x.end());
    y.erase(unique(y.begin(), y.end()), y.end());

    for(int i=0;i<N;i++){
        ll X=d.at(i).first, Y=d.at(i).second;
        mp[find(x.begin(),x.end(),X)-x.begin()][find(y.begin(),y.end(),Y)-y.begin()]++;
    }

    for(int i=0;i<x.size();i++){
        for(int j=0;j<y.size();j++) sum[i+1][j+1]=sum[i+1][j]+sum[i][j+1]-sum[i][j]+mp[i][j];
    }

    int X=x.size(), Y=y.size();
    ll ans=(x.at(X-1)-x.at(0))*(y.at(Y-1)-y.at(0));

    for(int i=0;i<X;i++){
        for(int j=i;j<X;j++){
            for(int p=0;p<Y;p++){
                for(int q=p;q<Y;q++){
                    while(sum[j+1][q+1]-sum[i][q+1]-sum[j+1][p]+sum[i][p]<K){
                        q++;
                        if(q==Y) break;
                        if((x.at(j)-x.at(i))*(y.at(q)-y.at(p))>=ans) break;
                    }

                    if(q==Y) break;
                    ans=min(ans,(x.at(j)-x.at(i))*(y.at(q)-y.at(p)));
                }
            }
        }
    }
    
    cout<<ans<<endl;
    



}

Measured memory_bytes: 512
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX_N 3000
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  int64_t Ans = 0;
  rep(i, N) {
    int a;
    cin >> a;
    Ans += a - 1;
  }
  cout << Ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairInt;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[]) {
  int N, K;

  scanf("%d%d", &N, &K);

  set<int> not_replyed;
  set<int> not_replying;
  map<int, int> replying;

  FOR1(i, 1, N + 1) { not_replyed.insert(i); }

  FOR1(i, 1, N + 1) {
    int a;
    scanf("%d", &a);
    if (a != 0) {
      replying.insert(make_pair(i, a));
      not_replyed.erase(a);
    } else {
      not_replying.insert(i);
    }
  }

  set<int> displayed(not_replyed);
  set<int> temp(not_replyed);
  FOR(i, K - 1) {
    set<int> temp2;
    for (auto x : temp) {
      auto it = replying.find(x);
      if (it != replying.end() &&
          displayed.find(it->second) == displayed.end()) {
        temp2.insert(it->second);
        displayed.insert(it->second);
      }
    }
    temp = move(temp2);
  }
  displayed.insert(not_replying.begin(), not_replying.end());

  printf("%lu\n", displayed.size());

  return 0;
}

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

int main(void)
{
    int a[7] = {1, 3, 5, 7, 8, 10, 12};
    int b[4] = {4, 6, 9, 11};

    int x, y;
    int judge_a = 0;
    int judge_b = 0;
    cin >> x >> y;
    for( int i = 0; i < 7; i++){
        if( a[i] == x){
            judge_a = 1;
        }
        if( a[i] == y){
            judge_b = 1;
        }
    }
    for( int i = 0; i < 4; i++){
        if( b[i] == x){
            judge_a = 2;
        }
        if( b[i] == y){
            judge_b = 2;
        }
    }
    if( judge_a == judge_b) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <stdio.h>

int c[22], a[22][22];

int main(void)
{
	int n, m, x, i, j, l, ans = 0x7fffffff;

	scanf("%d %d %d", &n, &m, &x);
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &c[i]);
		for (j = 1; j <= m; j++)
			scanf("%d", &a[i][j]);
	}

	int k[22];
	for (i = 0; i < (1 << n); i++)
	{
		int tmp = i;
		for (j = 1; j <= n; j++)
		{
			k[j] = tmp & 1;
			tmp >>= 1;
		}

		int t[22] = { 0 }, sum = 0;
		for (j = 1; j <= n; j++)
			if (k[j])
			{
				for (l = 1; l <= m; l++)
					t[l] += a[j][l];
				sum += c[j];
			}

		int cnt = 0;
		for (j = 1; j <= m; j++)
			if (t[j] >= x)
				++cnt;

		if (cnt == m)
		{
			if (ans > sum)
				ans = sum;
		}
	}

	if (ans == 0x7fffffff)
		puts("-1");
	else
		printf("%d", ans);
	return 0;
}

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

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

    int result = 0;
    for(int x = 0; x <= k; ++x){
        for(int y = 0; y <= k && x+y <= s; ++y){
            if(s-x-y <= k){++result;}
        }
    }
    
    cout << result << endl; return 0;
}

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

int main(){
    int n; cin >> n;
    int ans = 0;
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n-1; i++){
        if(a[i] == i){
            ans++;
            int x = a[i]; a[i] = a[i+1]; a[i+1] = x;
        }
    }
    if(a[n] == n){
        ans++;
        int x = a[n]; a[n] = a[n-1]; a[n-1] = x;
    }
    cout << ans << endl;
}

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

using namespace std;
int main(){
    int n,p,i,flag=0;
    cin >> n;
    for(i=0; i<n; i++){
      cin >> p;
      if(p!=i+1) flag++;
    }
    if(flag<=2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3532
#include <stdio.h>
#include <string.h>

#define N 1000

int calc_lcs(char *,char *);

int main(){
  int n,i;
  char x[N+1],y[N+1];
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%s",x);
    scanf("%s",y);
    printf("%d\n",calc_lcs(x,y));
  }
  return 0;
}

int calc_lcs(char *x,char *y){
  int m,n,i,j,c[N+1][N+1]={0};
  m=strlen(x);
  n=strlen(y);
  for(i=1; i<=m; i++){
    for(j=1; j<=n; j++){
      if(x[i-1]==y[j-1]){
	c[i][j]=c[i-1][j-1]+1;
      }else if(c[i-1][j]>=c[i][j-1]){
	c[i][j]=c[i-1][j];
      }else{
	c[i][j]=c[i][j-1];
      }
    }
  }
  return c[m][n];
}



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

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int H[200010];
    rep(i, N) cin >> H[i];
    sort(H, H + N, greater<int>());
    int ans = 0;
    rep(i, N) {
        if(K > 0) {
            K--;
            continue;
        }
        ans += H[i];
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1792