akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

ll dp[201][201][201]; //現在の順位, 上の空き, 下の数

int main(){
  int N;
  char c[200];

  scanf("%d", &N);

  for (int i=0; i<N; i++) {
    scanf(" %c", c+i);
  }

  dp[0][0][0] = 1;

  for (int i=0; i<N; i++) {
    for (int j=0; j<=i; j++) {
      for (int k=0; k<=i; k++) {
        if (c[i] == '-') {
          dp[i+1][j][k] = (dp[i+1][j][k] + dp[i][j][k]) % mod;
        }
        if (c[i] == 'D') {
          if (j > 0)
            dp[i+1][j][k] = (dp[i+1][j][k] + dp[i][j][k] * j) % mod;
          if (j > 0 && k > 0)
            dp[i+1][j-1][k-1] = (dp[i+1][j-1][k-1] + dp[i][j][k] * j * k) % mod;
        }
        if (c[i] == 'U') {
          dp[i+1][j+1][k+1] = (dp[i+1][j+1][k+1] + dp[i][j][k]) % mod;
          if (k > 0)
            dp[i+1][j][k] = (dp[i+1][j][k] + dp[i][j][k] * k) % mod;
        }
      }
    }
  }

  printf("%lld\n", dp[N][0][0]);

  return 0;
}



Measured memory_bytes: 35396
#include <algorithm>
#include <climits>
#include <cstring>
#include <inttypes.h>
#include <iostream>
#include <iterator>
#include <map>
#include <utility>
#include <vector>

using namespace std;

const int cap = 1001;
const int mod = 1e9 + 7;
int H, W;
char c;
int dp[cap][cap];

int main() {
    scanf("%d %d", &H, &W);
    fill(&dp[0][0], &dp[0][0] + cap * (H + 1), 0);
    dp[0][1] = 1;
    for (int i = 1; i <= H; ++i)
        for (int j = 1; j <= W; ++j) {
            scanf(" %c", &c);
            if (c == '#')
                dp[i][j] = 0;
            else
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
        }
    printf("%d\n", dp[H][W]);
}


Measured memory_bytes: 4096
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
  idx = a[i] - 1
  ans += b[idx]
  if i + 1 < n:
    if a[i] + 1 == a[i + 1]:
      ans += c[a[i] - 1]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int n;
    cin >> n;
    cout << n / 3 << endl;
}


Measured memory_bytes: 256
// フェルマーの小定理
package main

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

const (
	m = 1000000007
)

func mpow(x, y int) int {
	result := 1
	for y != 0 {
		if y&1 == 1 {
			result *= x
			result %= m
		}
		x *= x
		x %= m
		y >>= 1
	}
	return result
}

var (
	fac []int
)

func mcomb(n, k int) int {
	if n == 0 && k == 0 {
		return 1
	}
	if n < k || k < 0 {
		return 0
	}
	return (fac[n] * mpow(fac[n-k], m-2) % m) * mpow(fac[k], m-2) % m
}

func main() {
	N := readInt()
	K := readInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	fac = make([]int, N+1)
	fac[0] = 1
	for i := 0; i < N; i++ {
		fac[i+1] = fac[i] * (i + 1) % m
	}

	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	result := 0
	for i := 0; i < N-K+1; i++ {
		result += A[i] * mcomb(N-(i+1), K-1)
		result %= m
	}

	sort.Ints(A)
	t := 0
	for i := 0; i < N-K+1; i++ {
		t += A[i] * mcomb(N-(i+1), K-1)
		t %= m
	}

	result -= t
	result %= m
	result += m
	result %= m
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

int main()
{
    int d,n;
    cin >> d >> n;
    
    if(d==0){
        if(n==100){
            cout << 101 << endl;
        }else{
            cout << n << endl;
        }
    }else if(d==1){
        if(n==100){
            cout << 10100 << endl;
        }else{
            cout << 100 * n << endl;
        }          
    }else if(d==2){
        if(n==100){
            cout << 1010000 << endl;
        }else{
            cout << 10000 * n << endl;
        }  
    } 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n';


signed main(){
	string s;cin>>s;
	int c = 0;
	for(auto x : s){
		c += x-'0';
		c%=9;
	}
	cout<<(c?"No":"Yes")<<endl;
	return 0;
}



Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>

using namespace std;

double f(double x, double q) {
   
    return (x * x * x - q);
}

double df(double x) {
    return (3 * x * x);
}

double newton(double x, double q) {
    
    if(abs(f(x, q)) < 0.00001 * q) {
        return x; 
  }
    return newton(x - f(x, q)/df(x),q);
}

int main(void){
    double x;
    double q;
    while(cin >> q){
        if(q == -1) break;
        x = q/2;
        cout << fixed << setprecision(6) << newton(x,q) << endl;
    }
}



Measured memory_bytes: 3184
N,x = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
for i in range(1,N):
    y = max(A[i]+A[i-1]-x,0)
    if A[i]>=y:
        A[i] -= y
    else:
        A[i] = 0
    ans += y
print(ans)        

Measured memory_bytes: 63856
x = input().split()
s = input()
n = int(x[0])
a = int(x[1])
b = int(x[2])
c = int(x[3])
d = int(x[4])
 
 
kome_flag = False # ##がないとTrue
santen_flag = False # ... があればTrue
 
a_s = s[a:c]
b_s = s[b:d]
 
 
if d < c:
  if '...' in s[b-2:d+1]:
    santen_flag = True
kome_flag = True
if '##' in a_s or '##' in b_s:
  kome_flag = False
    

if True:
	if c < d:
		if kome_flag:
			print('Yes')
		else:
			print('No')
 
	if d < c:
		if kome_flag and santen_flag:
			print('Yes')
		else:
			print('No')

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

typedef long long int ll;
typedef vector<int> vi;            
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int>     pii;
typedef vector<bool> vb;
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#ifdef LOCAL
    #include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}

void solve(){
    string n; cin>>n;
    ll sum = 0;
    for(auto &c: n) sum += c - '0';
    if(sum%9==0) cout<<"Yes"; else cout<<"No";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifdef LOCAL
        freopen(".inp.txt", "r", stdin);
        freopen(".out.txt", "w", stdout);
        freopen(".err.txt", "w", stderr);
    #endif
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 3740
#include <stdio.h>
int main(int argc, char const *argv[]) {
    int a,b,c,sum;

    scanf("%d %d %d",&a,&b,&c );

    sum = a+b+c;

    if (sum<=21) {
        printf("win\n");
    }else{
        printf("bust\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
using namespace std;
const int maxn=222222;
char ss[maxn];
int N,A,B,C,D;
bool check1(int x,int y)
{
	for(int i=x+2;i<y;++i)if(ss[i]=='#'&&ss[i-1]=='#') return false;
	return true;
}
bool check2(int x,int y)
{
	for(int i=x;i<=y;++i)if(ss[i]=='.'&&ss[i-1]=='.'&&ss[i+1]=='.') return true;
	return false;
}
int main()
{
	scanf("%d%d%d%d%d",&N,&A,&B,&C,&D);
	scanf("%s",ss+1);
	if(C<D)
	{
		if(check1(A,C)&&check1(B,D)) puts("Yes");
		else puts("No");
	}
	else
	{
		if(check1(B,D)&&check2(B,D)&&check1(A,B)&&check1(D,C)) puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  l[1] = 0;
  for(int i=1; i<n+1; ++i) cin >> l[i];

  int d = 0, cnt = 0;
    
  for(int i=0; i<n+1; ++i){
    d += l[i];
    if(d>x) break;
    cnt++;
  }

  cout << cnt;
   return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
d = {}
for x in a:
    d[x] = d.get(x, 0) + 1
l = []
ans = 0
for num, cnt in sorted(d.items(), key=lambda x: x[0], reverse=True):
    if cnt > 3:
        if len(l) == 0:
            ans = num ** 2
            print(ans)
            exit()
        else:
            l.append(num)
            ans = l[0] * l[1]
            print(ans)
            exit()
    elif cnt > 1:
        l.append(num)
        if len(l) == 2:
            ans = l[0] * l[1]
            print(ans)
            exit()
print(ans)

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

int h, w, k;
bool goal(int y, int x) {
	return (y < 0 or h <= y) or (x < 0 or w <= x);
}

int main() {
	cin >> h >> w >> k;
	char a[h][w];
	int sy, sx;
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			cin >> a[i][j];
			if(a[i][j] == 'S') {
				sy = i;
				sx = j;
				a[i][j] = '.';
			}
		}
	}
	int dp[h][w];
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			dp[i][j] = 1e9;
		}
	}
	dp[sy][sx] = 0;
	queue<tuple<int, int, int>> que; 
	que.emplace(sy, sx, 0);
	while(not que.empty()) {
		int y, x, cost;
		tie(y, x, cost) = que.front();
		que.pop();
		if(cost == k) continue;
		if(cost > dp[y][x]) continue;
		const int dy[] = {0, -1, 0, 1};
		const int dx[] = {1, 0, -1, 0};
		for(int d = 0; d < 4; ++d) {
			int ny = y + dy[d];
			int nx = x + dx[d];
			if(goal(ny, nx)) {
				cout << 1 << '\n';
				return 0;
			}
			if(a[ny][nx] == '#') continue;
			if(cost + 1 < dp[ny][nx]) {
				dp[ny][nx] = cost + 1;
				que.emplace(ny, nx, cost + 1);
			}
		}
	}
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			if(dp[i][j] != 1e9) {
				dp[i][j] = 0;
				que.emplace(i, j, dp[i][j]);
			}
		}
	}
	while(not que.empty()) {
		int y, x, cost;
		tie(y, x, cost) = que.front();
		que.pop();
		if(cost > dp[y][x]) continue;
		const int dy[] = {0, -1, 0, 1};
		const int dx[] = {1, 0, -1, 0};
		for(int d = 0; d < 4; ++d) {
			int ny = y + dy[d];
			int nx = x + dx[d];
			if(goal(ny, nx)) continue;
			if(cost + 1 < dp[ny][nx]) {
				dp[ny][nx] = cost + 1;
				que.emplace(ny, nx, cost + 1);
			}
		}
	}
	int ans = 1e9;
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			if(i == 0 or i == h - 1) {
				ans = min(ans, (dp[i][j] + k - 1) / k + 1);
			}
			if(j == 0 or j == w - 1) {
				ans = min(ans, (dp[i][j] + k - 1) / k + 1);
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
using namespace std;
int main(){
	int discount[2]={17*60+30,19*60+30};
	int D[7]={0,6,13,18,23,43,58};
	int C[7][7]={
		{0,300,500,600,700,1350,1650},
		{0,0,350,450,600,1150,1500},
		{0,0,0,250,400,1000,1350},
		{0,0,0,0,250,850,1300},
		{0,0,0,0,0,600,1150},
		{0,0,0,0,0,0,500},
	};
	int in,out;
	while(cin>>in,in){
		int h1,m1,h2,m2,fare;
		cin>>h1>>m1;
		cin>>out;
		cin>>h2>>m2;
		if(in>out){
			int tmp=in;
			in=out;
			in=tmp;
		}
		int d=D[out-1]-D[in-1];
		int min1=h1*60+m1,min2=h2*60+m2;
		if(((discount[0]<=min1&&min1<=discount[1])||(discount[0]<=min2&&min2<=discount[1]))&&d<=40) fare=(C[in-1][out-1]/2+49)/50*50;
		else fare=C[in-1][out-1];
		cout<<fare<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

unsigned long long dp[301][301];
const int cm = 1 << 12;
char cn[cm], * ci = cn, ct;

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


	fread(cn, 1, cm, stdin);
	int N = 0, M = 0;
	while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';
	while ((ct = *ci++) >= '0') M = M * 10 + ct - '0';

	int xm[301][4], xM[301][4];
	rep1(i, N) {
		xm[i][1] = N;
		xm[i][2] = N;
		xM[i][2] = -1;
		xM[i][3] = -1;
	}
	rep(i, M) {
		int l = 0, r = 0;
		while ((ct = *ci++) >= '0') l = l * 10 + ct - '0';
		while ((ct = *ci++) >= '0') r = r * 10 + ct - '0';
		int x = *ci++ - '0';
		+ci++;
		chmin(xm[r][x], l);
		chmax(xM[r][x], l);
	}

	const int mod = 1e9 + 7;
	dp[0][0] = 1;
	int mj = 0;
	int mk = 0;
	unsigned long long yabai = 1;
	rep1(i, N) {
		for (int j = i - 1; j >= mj; j--) {
			auto dpj = dp[j];
			for (int k = i - 1; k >= max(j, mk); k--) {
				dpj[i] += dpj[k];
				dp[k][i] += dpj[k];
			}
		}
		yabai *= i + 1;
		bool yaba = (yabai > 18446744073709551615 / (i + 1));
		for (int j = i; j > max(xm[i][2], mj - 1); j--) {
			for (int k = i; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		for (int j = xm[i][2]; j > max(xM[i][3], mj - 1); j--) {
			for (int k = i; k > max(max(xm[i][1], mk - 1), j - 1); k--) dp[j][k] = 0;
			if (yaba) {
				for (int k = xm[i][1]; k > max(max(xM[i][2], mk - 1), j - 1); k--) {
					dp[j][k] %= mod;
				}
			}
			for (int k = xM[i][2]; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		for (int j = xM[i][3]; j >= mj; j--) {
			for (int k = i; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		if (yaba) yabai = mod;
		if (mj <= xM[i][3]) mj = xM[i][3] + 1;
		if (mk <= xM[i][2]) mk = xM[i][2] + 1;
	}

	ll kotae = 0;
	for (int j = mj; j <= N; j++) for (int k = max(mk, j); k <= N; k++) {
		kotae += dp[j][k] % mod;
	}
	printf("%lld", kotae% mod);

	Would you please return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<math.h>

#define MN 200000

int n;
int a[MN];

int main(){
  std::cin >> n;
  for( int i = 0; i < n; i++ ){
	std::cin >> a[i];
  }
  int k = 0;
  std::cout << a[n-1];
  for( k = n-3; k >= 0; k-=2 ){
	std::cout << " " << a[k];
  }
  if( (k+4) % 2 == 1 ){
	std::cout << " " << a[0];
	k = 2;
  }else{
	k = 1;
  }
  for( ; k < n; k+=2 ){
	std::cout << " " << a[k];
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 2944
/*      Abhijith    */
#include<bits/stdc++.h>
#include<iomanip>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
using namespace std;

int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     lld n,m;
     cin>>n>>m;
     vector<lld> v(n);
     rep(i,0,n-1)
     cin>>v[i];
     sort(all(v));
     vector<vector<lld> > qn(m,vector<lld>(2));
     priority_queue<pair<lld,lld> > big;
     rep(i,0,m-1)
     {
         cin>>qn[i][1]>>qn[i][0];
         big.push(mp(qn[i][0],qn[i][1]));
     }
     lld i=0;
     while(!big.empty()&&i<=n-1)
     {
         pair<lld,lld> req=big.top();
         lld haa=req.second;
         big.pop();
         while(haa--)
         {
             if(v[i]>=req.first)
            break;
            //cout<<i<<" "<<v[i]<<" "<<req.first<<" "<<req.second<<endl;
            v[i]=req.first;
            i++;
         }
         if(v[i]>=req.first)
            break;
     }
     lld ans=0;
     rep(i,0,n-1)
     ans+=v[i];
     cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8692
#include<iostream>
#include<string>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;
int main() {
	//input
	int H, W;
	cin >> H >> W;
	string S[50];
	for (int i = 0; i < H; i++)cin >> S[i];

	//initialize
	int white = 0;
	int cost[50][50];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cost[i][j] = 3000;//big enough
			if (S[i][j] == '.')white++;
		}
	}

	//bfs
	int dy[4] = { -1,1,0,0 };
	int dx[4] = { 0,0,-1,1 };
	queue<pair<int, int>>que;
	cost[0][0] = 1;
	que.push(make_pair(0, 0));
	while (!que.empty()) {
		int y = que.front().first;
		int x = que.front().second;
		que.pop();
		for (int i = 0; i < 4; i++) {
			if (y + dy[i] < 0 || y + dy[i] >= H || x + dx[i] < 0 || x + dx[i] >= W)continue;
			if (S[y + dy[i]][x + dx[i]] == '#')continue;
			if (cost[y + dy[i]][x + dx[i]] > cost[y][x] + 1) {
				cost[y + dy[i]][x + dx[i]] = cost[y][x] + 1;
				que.push(make_pair(y + dy[i],x + dx[i]));

			}
		}
	}

	//output
	if (cost[H - 1][W - 1] == 3000)cout << -1 << endl;
	else cout << white - cost[H - 1][W - 1] << endl;

	return 0;
}


Measured memory_bytes: 3632
def solve():
    N, M, X = [int(_) for _ in input().split()]
    masu = [0] * (N + 1)
    A = [int(_) for _ in input().split()]
    for a in A:
        masu[a] = 1
    return min(sum(masu[0:X]), sum(masu[X:]))
if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>
#include <set>
#include <string>
#include <iterator>
#include <queue>
#include <cmath>
#include <cassert>

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

int main ()
{
    int N;
    cin >> N;
    vector < int > W(N);
    REP(i,N) cin >> W[i];

    int suma = 0, sumb = 0;
    suma = W[0];
    for (int i = 1; i < N; i++) sumb += W[i];

    int ans = 1e9;
    for (int i = 1; i < N; i ++) {
        ans = min(ans, abs(suma - sumb));
        suma += W[i];
        sumb -= W[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import bisect

M={}
D=[]

def insert(M,D,key,x):
    if key not in M:
        M[key]=[]
        bisect.insort_left(D,key)
    M[key].append(x)
    return M,D

def get(M,D,key):
    if key in M and M[key]!=[]:
        print('\n'.join(map(str,M[key])))

def erase(M,D,key):
    if key in M:
        M[key]=[]
    return M,D

def dump(M,D,L,R):
    s=bisect.bisect_left(D,L)
    e=bisect.bisect_right(D,R)
    if e-s>0:
        #ループを使わずにできる方法を考える
        for i in range(s,e):
            for j in M[D[i]]:
                print(D[i],j)

q=int(input())
for i in range(q):
    query=list(map(str,input().split()))
    query[0]=int(query[0])
    if query[0]==0:
        M,D=insert(M,D,query[1],int(query[2]))
    elif query[0]==1:
        get(M,D,query[1])
    elif query[0]==2:
        M,D=erase(M,D,query[1])
    else:
        dump(M,D,query[1],query[2])



Measured memory_bytes: 39216
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

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

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;
	vector<int>sum;
	if (S[0] == '0')sum.push_back(0);
	for (int i = 0; i < N;) {
		int j = i;
		while (j < S.size() && S[j] == S[i]) {
			j++;
		}
		sum.push_back(j - i);
		i = j;
	}
	if (S.back() == '0')sum.push_back(0);
	vector<int>fuck(sum.size() + 1, 0);
	for (int i = 0; i < sum.size(); ++i) {
		fuck[i + 1] = fuck[i] + sum[i];
	}
	int res = 0;
	for (int left = 0; left < fuck.size(); left+=2) {
		int right = left + K * 2 + 1;
		if (right >= fuck.size())right = (int)fuck.size() - 1;
		res = max(res, fuck[right] - fuck[left]);
	}
	cout << res << endl;
	return 0;
}




Measured memory_bytes: 1272
import collections as c
ip = lambda : map(int, input().split())

# ##############
N,M = ip()
A = list(map(int, input().split()))
cc = c.Counter(A)
for i in range(M):
    b,c = ip()
    cc[c] = cc[c] + b

ans = 0
for i in sorted(cc, reverse = True):
    ans += min(cc[i],N)*i
    N -= cc[i]
    if N<=0:
        print(ans)
        exit()

Measured memory_bytes: 32448
#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 n, ave = 0, ans = 0;
    double sum = 0;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) sum += a[i];
    if (sum < 0)
    {
        ave = (sum / n - 0.5);
    }
    else
    {
        ave = (sum / n + 0.5);
    }
    rep(i, n) ans += (a[i] - ave) * (a[i] - ave);
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> T(N);
  int total = 0;
  for (int i = 0; i < N; i++)
  {
    cin >> T.at(i);
    total += T.at(i);
  }

  int M;
  cin >> M;
  vector<pair<int, int>> D(M);
  for (int i = 0; i < M; i++)
  {
    int a;
    int b;
    cin >> a >> b;
    D.at(i) = make_pair(a, b);
  }

  for (int i = 0; i < M; i++)
  {
    int a;
    int b;
    tie(a, b) = D.at(i);
    int ans = 0;
    ans = total - T.at(a - 1) + b;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n, a, b, c, x;
ll y[100100];

int main() {
	while (cin >> n >> a >> b >> c >> x&&n + a + b + c + x) {
		rep(i, n)cin >> y[i];
		ll now = 0;
		ll ans = 0;
		bool ok = false;
		rep(i, 10001) {
			if (x == y[now]) {
				now++;
				if (now == n) {
					ok = true;
					break;
				}
			}
			ans++;
			x = (a*x + b) % c;
		}
		if (ok)cout << ans << endl;
		else cout << -1 << endl;
	}
}


Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
    int n;cin >> n;
    vector<ll> t(n),a(n);
    ll A=1,B=1;
    for(int i=0;i<n;i++) cin >> t[i] >> a[i];
    for(int i=0;i<n;i++){
        A=(A+t[i]-1)/t[i];
        B=(B+a[i]-1)/a[i];
        ll mx=max(A,B);
        A=mx*t[i];
        B=mx*a[i];
    }
    cout << A+B << endl;
    return 0;
}

Measured memory_bytes: 256
using namespace std;

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

void solve(){

}
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    bool vic = false;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        if (a[i] % 2 == 1){
            vic = true;
        }
    }
    if (vic){
        cout << "first" << endl;
    } else {
        cout << "second" << endl;
    }
    

    return 0;
}


Measured memory_bytes: 640
n,c,v,t;main(m){for(;~scanf("%d%d",&m,&n);m&&printf("%d\n",c))for(c=0;m&&m<=n;c+=v==1)for(t=v=n--;t/=v%2?v%3?v%5?~t:5:3:2;)v=t;}

Measured memory_bytes: 408
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,M = I()
if M <= N*2:
    print(M//2)
else:
    print(N+(M-N*2)//4)

Measured memory_bytes: 77400
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int n,m;
  cin >> n >> m;
  int s,c;
  int chk[n+1] = {0};
  bool flag = true;
  rep(i,m){
    cin >> s >> c;
    if(s==1){
      if(c==0 && n > 1){
        flag = false;
      }
    }
    if(chk[s] == 0) chk[s] = c;
    else{
      if(chk[s] != c) flag = false;
    }
  }
  if(!flag){
    printf("-1\n");
    return 0;
  }
  if(chk[1]==0 && n > 1) chk[1] = 1;
  for(int i = 1; i <= n; i++){
    printf("%d", chk[i]);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	cin >> N;
	vl A(N);
	vl sum(N + 1);
	sum[0] = 0;
	for (i = 0; i < N; i++) {
		cin >> A[i];
		sum[i + 1] = sum[i] + A[i];
	}
	ans = INF;
	for (i = 1; i <= N-1; i++) {
		ans = min(ans, abs(sum[i] - (sum[N] - sum[i])));
	}
	cout << ans;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s;
    long long a=0,b=0,c=0,d=1,e=1,f=0,g=0;
    vector<int> u(0);
    cin >> s;
    for (int i=0;i<s.size();i++){
        if (s.at(i)=='.') c++;
        else if (s.at(i)=='(') c++;
        else if (s.at(i)==')') break;
        else {
            if (c>=1) a++;
            if (c==2) b++;
            u.push_back(s.at(i)-'0');
        }
    }
    for (int i=0;i<u.size();i++){
        f+=d*u.at(u.size()-i-1);
        d*=10;
    }
    d=1;
    if (b>0) {for (int i=0;i<u.size()-b;i++){
        f-=d*u.at(u.size()-b-i-1);
        d*=10;
    }
    d=1;
    }
    for (int i=0;i<a;i++){
        d*=10;
    }
    int h=0;
    if (b>0){
    for (int i=0;i<a-b+1;i++){
        if (i==0) h=1;
        else h*=10;
    }
    }
    g=d-h;
    int y=__gcd(f,g);
    f=f/y;g=g/y;
    cout << f << "/" << g << endl;
    
}




Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    int INF = 1e18;
    int M = INF;
    int S = 0;
    for (int i=0; i < n; i++){
        int x, y;
        cin >> x >> y;
        S += x;
        if (x<=y) continue;
        M = min(M, y);
    }
    if (M==INF) cout << 0 << endl;
    else cout << S-M << endl;
    return 0;
}


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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	sort(v.begin(), v.end());
	int sum = 0, ans = n;
	for (int i = n - 1; i >= 0; i--)
		if (sum + v[i] < k)
			sum += v[i];
		else
			ans = i;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
 
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

def main():
  inf = float("INF")
  a,b,q = map(int, input().split())
  s = [None] * (a + 3)
  s[0:2] = [-inf,-inf]
  s[-1] = inf
  t = [None] * (b + 3)
  t[0:2] = [-inf,-inf]
  t[-1] = inf
  for i in range(a):
      s[i+2] = int(input())
  for i in range(b):
      t[i+2] = int(input())

  from bisect import bisect_right

  for _ in range(q):
    ans = inf
    x = int(input())
    sr = bisect_right(s, x)
    tr = bisect_right(t, x)    
    for si in (sr, sr-1):
      for ti in (tr, tr-1):
        ans = min(ans, abs(x-s[si]) + abs(s[si]-t[ti]), abs(x-t[ti]) + abs(s[si]-t[ti]))
    print(ans)
  
if __name__ == "__main__":
  main()


Measured memory_bytes: 62940
#include <iostream>
#include<cmath>
#include <algorithm>
using namespace std;

bool palindromas(string s)
{
 string t(s.rbegin(), s.rend());
 return s == t;

}

int main()
{
   string s;
   cin >> s;
   int n = s.size();
   if(palindromas(s) && palindromas(s.substr(0, (n-1)/2)) && palindromas(s.substr(((n+1)/2)))){
       cout << "Yes";
   }
    else cout << "No";
}


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

#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

int bitCount(long bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
  int size;
  cin >> size;
  int v;
  int x = 0;

  for(int i = 0; i < size; i++) {
    cin >> v;
    x = x | v;
  }

  cout << bitCount((x & -x) - 1);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main(){
  int n;
  cin >> n;
  map<P,int> mp;
  for(int i=1; i<=n; ++i){
    int a, b;
    a = i%10;
    b = i;
    while(b>=10) b /= 10;
    mp[make_pair(a,b)]++;
  }
  ll ans=0;
  for(auto pi: mp){
    int a, b;
    a = pi.first.first;
    b = pi.first.second;
    ans += (ll)pi.second * (ll)mp[make_pair(b,a)];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

bool N[999999];

int FindPrime(int n) {
  int ans = 0;
  for(int i = 1; i <= sqrt(n); i++) {
    if(N[i - 1]) {
      for(int j = 2; j <= n / i; j++) {
        N[i * j - 1] = false;
      }
    }
  }

  for(int i = 0; i < n; i++) {
    if(N[i]) {
      ans++;
    }
  }

  return ans;
}

int main() {
  int n;
  while(cin >> n) {
    for(int i = 1; i < n; i++) {
      N[i] = true;
    }

    int ans = FindPrime(n);

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  int n, p[30];
  cin >> n;
  rep(i, n) cin >> p[i];

  int ans = 0;
  for (int i = 1; i <= n-2; i++) {
    if (((p[i] > p[i-1]) && (p[i] < p[i+1])) || ((p[i] < p[i-1]) && (p[i] > p[i+1]))) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt();
		if(A == B && B == C && A % 2 == 0) System.out.println(-1);
		else {
			int cnt = 0;
			while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
				int half_A = A / 2, half_B = B / 2, half_C = C / 2;
				A = half_B + half_C;
				B = half_A + half_C;
				C = half_A + half_B;
				cnt++;
			}
			System.out.println(cnt);
		}
	}
}


Measured memory_bytes: 22996
#include <cstdio>  
#include <iostream>
#include <vector>  
#include <cstring>  
#include <algorithm>  
using namespace std;  
const int maxn = 100 + 10;  
const int INF = 100000000;  
  
int M, N;  
int X1[maxn], Y1[maxn];  
int X2[maxn], Z2[maxn];  
  
//计算按x值对多边形切片得到的宽度  
double width(int* X, int* Y, int n, double x)  
{  
	double lb = INF, ub = -INF;  
	for (int i = 0; i < n; i++){  
		double x1 = X[i], y1 = Y[i], x2 = X[(i + 1) % n], y2 = Y[(i + 1) % n];  
		//检查与第i条边是否相交  
		if ((x1 - x) * (x2 - x) <= 0 && x1 != x2){  
			//计算交点的坐标  
			double y = y1 + (y2 - y1) * (x - x1) / (x2 - x1);  
			lb = min(lb, y);  
			ub = max(ub, y);  
		}  
	} 
	return max(0.0, ub - lb);  
}  
  
void solve()  
{  
	//枚举区间的端点  
	int min1 = *min_element(X1, X1 + M);  
	int max1 = *max_element(X1, X1 + M);  
	int min2 = *min_element(X2, X2 + N);  
	int max2 = *max_element(X2, X2 + N);  
	vector<int> xs;  
	for (int i = 0; i < M; i++)  
		xs.push_back(X1[i]);  
	for (int i = 0; i < N; i++)  
		xs.push_back(X2[i]);  
	sort(xs.begin(), xs.end());  
  
	double res = 0;  
	for (int i = 0; i + 1 < xs.size(); i++){  
		double a = xs[i], b = xs[i + 1], c = (a + b) / 2;  
		if (min1 <= c && c <= max1 && min2 <= c && c <= max2){  
			//利用Simpson公式求积分  
			double fa = width(X1, Y1, M, a) * width(X2, Z2, N, a);  
			double fb = width(X1, Y1, M, b) * width(X2, Z2, N, b);  
			double fc = width(X1, Y1, M, c) * width(X2, Z2, N, c);  
			res += (b - a) / 6 * (fa + 4 * fc + fb);  
		}  
	}  
	printf("%.10f\n", res);  
}  
  
int main()  
{  
	while (scanf("%d%d", &M, &N), M || N){  
		for (int i = 0; i < M; i++){  
			scanf("%d%d", &X1[i], &Y1[i]);  
		}  
		for (int i = 0; i < N; i++){  
			scanf("%d%d", &X2[i], &Z2[i]);  
		}  
		solve();  
	}  
	return 0;  
}  


Measured memory_bytes: 3276
//	-*- mode: C++ -*-
//	Circle
//		Write a program which calculates the area and circumference of a circle for given radius r.
//
//	Input
//		A real number r is given.
//
//	Output
//		Print the area and circumference of the circle in a line. Put a single space between them. The output should not contain an absolute error greater than 10-5.
//
//	Constraints
//		0 < r < 10000
//	Sample Input 1
//		2
//	Sample Output 1
//		12.566371 12.566371

#define	_USE_MATH_DEFINES
#include <iostream>
#include <cmath>

int	main(int	argc,
		 char*	argv[])
{
	double	r	{0.0};

	std::cin >> r;

	std::cout << std::fixed << M_PI * r * r << ' ' << 2 * M_PI * r << '\n';
}



Measured memory_bytes: 3240
#include <stdio.h>

int main(){
  int i,n,f[50];

  f[0] = 1;
  f[1] = 1;

  scanf("%d",&n);

  for(i=2;i<=n;i++){
    f[i]=f[i-1]+f[i-2];
  }

  printf("%d\n",f[n]);

  return 0;
}



Measured memory_bytes: 2068
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int a,b,c;
	bool flg=false;
	cin>>a>>b>>c;
	if(a+b>=c){
		flg=true;
	}
	cout<<((flg)?"Yes":"No")<<endl;
	return 0;
}
		

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

typedef long long ll;
typedef pair<ll, ll> pii;
const int N = 2e5+10, mod = 1e9+7;

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

    set<pii> s;
    ll mxa = -1ll * mod * mod;
    ll mna = LLONG_MAX;
    ll mxb = -1ll * mod * mod;
    ll mnb = LLONG_MAX;
    ll mxc = 0;
    ll mnc = LLONG_MAX;

    for (int i = 0; i < n; ++i) {
        ll x, y; cin >> x >> y;
        if (s.count({x, y}) == 0) {
            s.insert({x, y});
            mxa = max(mxa, x + y);
            mna = min(mna, x + y);
            mxb = max(mxb, x - y);
            mnb = min(mnb, x - y);
            // mxc = max(mxc, y - x);
            // mnc = min(mnc, y - x);
        }
    }

    cout << max(mxa - mna, mxb - mnb) << endl;
}

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


Measured memory_bytes: 16112
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
const ll mod = 1e9+7;
const ll mod1 = 998244353;
#define rep(i,a,b) for(ll i=a;i<b;i++)

void swap(ll &a , ll &b){
    ll t = a;
    a = b;
    b = t;
}

ll min(ll a, ll b){
    if(a<b)return a;
    return b;
}

ll max(ll a, ll b){
    if(a>b)return a;
    return b;
}

 ll pow(ll a, ll b) {
    a %= mod;
    ll ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return ans;
 }

 int n;
 int visited[102] = {0};
int x[102], y[102];

void dfs(int i)
{
    visited[i] = 1;
    for(int j=0; j<n; j++)
    {
        if(x[j] == x[i] || y[j]==y[i] )
        {
            if(visited[j] == 0)
            {
                dfs(j);
            }
        }
    }
}

int main(){

   ios_base :: sync_with_stdio(0);
   cin.tie(0);

   ll a,b,n;
   cin>>a>>b>>n;

   ll mini = b<=n? b-1 : n;
   ll mini2 = b-1;

   ll ans = ((a*mini) / b) - (a* (mini/b));
   cout<<ans<<endl;

   //brute
   /*ll maxi = 0;
   ll in = -1;
   rep(i,0,n+1)
   {
       ll an = ((a*i) / b) - (a* (i/b));
       if(an>=maxi)
       {
           maxi = an;
           in = i;
       }
   }
   cout<<"brute: "<<maxi<<" for "<<in<<endl;*/
    return 0;

}


Measured memory_bytes: 3648
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Data.Ord 

main :: IO ()
main = readLn >>= main'
    where
        main' n = replicateM 2 (readf n) >>= print . solve 
        readf n = fmap edit <$> replicateM n breads
        edit [x, y] = (x, y)

solve :: [[(Int, Int)]] -> Int 
solve [xs, ys] = calc 0 xs $ sortBy (comparing fst) ys

calc :: Int -> [(Int, Int)] -> [(Int, Int)] -> Int
calc acc xs ((ya, yb) : ys) = check bs $ sortBy (flip (comparing snd)) as
    where
        (as, bs) = partition (\(a, _) -> a < ya) xs

        check cs (d@(_, b) : ds)
            | b < yb = calc (acc + 1) (ds ++ cs) ys
            | otherwise = check (d : cs) ds
        check _ _ = calc acc xs ys

calc acc _ _ = acc


breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)

Measured memory_bytes: 1020
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j,k;
		Scanner sc = new Scanner(System.in);
		int n = parseInt(sc.next());
		int[] p = new int[n];
		int[] q = new int[n];
		for(i=0;i<n;i++) {
			p[i] = parseInt(sc.next());
			q[i] = p[i];
		}
		sc.close();
		Arrays.sort(q);
		boolean f = true;
		int cnt = 0;
		for(i=0;i<n;i++) {
			if(p[i]!=q[i]) {
				cnt++;
				if(cnt >= 3) {
					f = false;
					break;
				}
			}
		}
		if(f)out.println("YES");
		else out.println("NO");
	}
}

Measured memory_bytes: 23636
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N1 200005
#define ll long long
#define inf 0x3f3f3f3f
#define mod 998244353
using namespace std;

int n,m;
int stk[N1],tp,use[N1];

struct Edge{
int to[N1],nxt[N1],head[N1],cte;
void ae(int u,int v)
{
	cte++; to[cte]=v; nxt[cte]=head[u]; head[u]=cte;
}
}e;

int main()
{
//	freopen("c.txt","r",stdin);
	scanf("%d%d",&n,&m);
	int x,y,u,v,num=0;
	for(int i=1;i<=m;i++) 
	{
		scanf("%d%d",&x,&y);
		e.ae(x,y); e.ae(y,x);
	}
	for(int i=1;i<=n;i++)
	{
		if(use[i]) continue;
		use[i]=1, stk[++tp]=i; num++;
		while(tp)
		{
			u=stk[tp]; tp--;
			for(int j=e.head[u];j;j=e.nxt[j])
			{
				v=e.to[j];
				if(use[v]) continue;
				stk[++tp]=v; use[v]=1;
			}
		}
	}
	printf("%d\n",num-1);
	return 0;
}



Measured memory_bytes: 5668
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int p[100],q[100];
signed main(){
    int n,cnt=0;
    cin>>n;
    rep(i,n){
        cin>>p[i];
        q[i]=p[i];
    }
    sort(q,q+n);
    rep(i,n){
        if(p[i]!=q[i])cnt++;
    }
    if(cnt==0||cnt==2)puts("YES");
    else puts("NO");
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=b*c;
    ans=max(ans,a*c);
    ans=max(ans,a*d);
    ans=max(ans,b*d);
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n), y(n);
    rep(i, 0, n){
        cin >> x[i];
    }
    rep(i, 0, m){
        cin >> y[i];
    }
    for(int i = -100; i <= 100; i++){
        bool f = true;
        if(X < i && i <= Y){
            rep(j, 0, n){
                if(x[j] >= i) f = false;
            }
            rep(j, 0, m){
                if(y[j] < i) f = false;
            }
            if(f){
                cout << "No War" << endl;
                return 0;
            }
        }
    }
    cout << "War" << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M,T;
int A[111111],B[111111],C[111111];

int uku[111111];
vpint lis[111111];
void beet(set<int>&s,int x,int t){
	for(auto y:s){
		int tmp=t-max(uku[x],uku[y]);
		lis[x].pb({y,tmp});
		lis[y].pb({x,tmp});
	}
}

int latte[111111];

signed main(){
	scanf("%lld%lld%lld",&N,&M,&T);
	rep(i,M){
		scanf("%lld%lld%lld",&A[i],&B[i],&C[i]);
		B[i]--;
	}

	set<int>s;
	rep(i,M){
		if(C[i]==1){
			uku[B[i]]=A[i];
			s.insert(B[i]);
		}
		else{
			s.erase(B[i]);
			beet(s,B[i],A[i]);
		}
	}
	while(s.size()){
		int x=*s.begin();
		s.erase(x);
		beet(s,x,T);
	}

	rep(i,N){
		for(auto p:lis[i]){
			latte[p.fi]+=p.se;
		}
		pint ans;
		if(i==0)ans.se=-1;
		for(auto p:lis[i]){
			chmax(ans,pint(latte[p.fi],-p.fi));
			latte[p.fi]=0;
		}
		printf("%lld\n",-ans.se+1);
	}
	return 0;
}


Measured memory_bytes: 176868
#include <iostream>
#include <vector>
#include <set>
using namespace std;

#include <iostream>
#include <vector>
#include <set>
using namespace std;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};


void solve(long long N, long long M, std::vector<long long> X, std::vector<long long> Y, std::vector<long long> Z){
    UnionFind uf(N);

    for (int i=0; i<M; i++) {
        uf.merge(X[i], Y[i]);
    }
    set<int> se;
    for (int i=0; i<N; i++) {
        // cout << uf.root(i) << endl;
        se.insert(uf.root(i));
    }
    cout << (int)se.size() << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> X(M);
    std::vector<long long> Y(M);
    std::vector<long long> Z(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&Y[i]);
        scanf("%lld",&Z[i]);
        X[i]--;
        Y[i]--;
    }
    // cout << X[0] << Y[0] << endl;
    solve(N, M, std::move(X), std::move(Y), std::move(Z));
    return 0;
}


Measured memory_bytes: 7680