akhauriyash/Code-Regression huggingface dataset:
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve() {
		long X = nl();
		long tot = X / 500 * 1000L;
		X -= X / 500 * 500;
		tot += X / 5 * 5L;
		out.println(tot);
	}
			
	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 24660
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int K = sc.nextInt();
		int X = sc.nextInt();
		if(K*500>=X) {
		    System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, a[100009], b[100009];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int tmp = min(a[i], b[i]);
		ans += tmp;
		b[i] -= tmp;
		tmp = min(a[i + 1], b[i]);
		ans += tmp;
		a[i + 1] -= tmp;
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    fix20;
    double r;
    cin >> r;
    double p = 6.28318530717958623200;
    cout << r * p << endl;
}

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

typedef long long LL;

const int N=100000,INF=(1<<30)-1;

int n,a[N+9],b[N+9];

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i){
	scanf("%d",&a[i]);
    ++a[i];
  }
  for (int i=1;i<=n;++i){
	scanf("%d",&b[i]);
	++b[i];
  }
}

int id[N*2+9],st,td,cn;
struct side{
  int y,next,f;
}e[N*20+9];
int lin[N*2+9],cs;

void Ins(int x,int y,int f){e[++cs].y=y;e[cs].f=f;e[cs].next=lin[x];lin[x]=cs;}
void Ins_flow(int x,int y,int f){Ins(x,y,f);Ins(y,x,0);}

int vis[N*2+9],ans;

void Get_graph(){
  cs=1;
  for (int i=1;i<=n;++i){
	if (!vis[i]){
	  ++cn;
	  for (int j=i;!vis[j];vis[j]=1,j=a[j]) id[j]=cn;
	}
    if (!vis[i+n]){
	  ++cn;
	  for (int j=i;!vis[j+n];vis[j+n]=1,j=b[j]) id[j+n]=cn;
	}
  }
  st=++cn;td=++cn;
  ans=n;
  for (int i=1;i<=n;++i){
	if (i==a[i]&&i==b[i]) {--ans;continue;}
	Ins_flow(id[i],id[i+n],1);
	if (a[i]==b[i]) Ins_flow(id[i+n],id[i],1);
	if (i==a[i]) Ins_flow(st,id[i+n],1);
	if (i==b[i]) Ins_flow(id[i],td,1);
  }
}

void work(){
  Get_graph();
}

int dis[N*2+9];
queue<int>q;

bool Bfs_dis(int st,int td){
  for (int i=1;i<=cn;++i) dis[i]=0;
  dis[st]=1;q.push(st);
  for (;!q.empty();){
	int t=q.front();q.pop();
	for (int i=lin[t];i;i=e[i].next)
	  if (e[i].f&&!dis[e[i].y]) dis[e[i].y]=dis[t]+1,q.push(e[i].y);
  }
  return dis[td];
}

int cur[N*2+9];

int Dfs_flow(int k,int td,int f){
  if (k==td||!f) return f;
  int res=0;
  for (int &i=cur[k];i;i=e[i].next)
	if (e[i].f&&dis[k]+1==dis[e[i].y]){
	  int t=Dfs_flow(e[i].y,td,min(f,e[i].f));
	  if (!t) dis[e[i].y]=0;
	  f-=t;res+=t;
	  e[i].f-=t;e[i^1].f+=t;
	  if (!f) return res;
	}
  return res;
}

int Max_flow(int st,int td){
  int res=0;
  for (;Bfs_dis(st,td);res+=Dfs_flow(st,td,INF))
    for (int i=1;i<=cn;++i) cur[i]=lin[i];
  return res;
}

void outo(){
  printf("%d\n",ans-Max_flow(st,td));
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 15220
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
inline ll pow2(const int n) { return 1ll << n; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;
// 1. 問題よくよめえええええええええええええええええええええええええ
// 2. intオーバーフロー << * + あたり
// 3. 落ち着け

int N, T;
vi c, t;

int main() {
    cin >> N >> T;
    c.resize(N); t.resize(N);
    rep(i, N) cin >> c[i] >> t[i];

    int ans = INF;
    rep(i, N) {
        if (t[i] <= T){
            chmin(ans, c[i]);
        }
    }
    if (ans == INF) write("TLE");
    else write(ans);
}

Measured memory_bytes: 256
from heapq import heappush, heappop
from typing import List, Tuple
import sys


if __name__ == "__main__":
    num_vertices = int(input())
    adj_list: List[List[Tuple[int, int]]] = [[] for _ in range(num_vertices)]

    for _ in range(num_vertices):
        vertex, adj_num, *adjs = map(lambda x: int(x), input().split())
        for i in range(adj_num):
            # (cost, adj)
            adj_list[vertex].append((adjs[2 * i + 1], adjs[2 * i]))

    distances: List[int] = [sys.maxsize] * num_vertices
    distances[0] = 0
    que: List[Tuple[int, int]] = []
    heappush(que, (0, 0))

    while [] != que:
        base_distance, parent = heappop(que)
        for cost, adj in adj_list[parent]:
            distance = base_distance + cost
            if distance < distances[adj]:
                distances[adj] = distance
                heappush(que, (distance, adj))

    for vertex, distance in enumerate(distances):
        print(f"{vertex} {distance}")



Measured memory_bytes: 7676
#include <stdio.h>

int main()
{
	int a[100];
	int i,n;
	
	scanf("%d",&n);
	for(i = 0; i < n; i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=n-1; i>0; i--)
	{
		printf("%d ",a[i]);
	}
	printf("%d\n",a[0]);

	return 0;
}

Measured memory_bytes: 596
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

ll expo(ll a, ll b){
    ll ex = 1;
    rep(i, b){
        ex *= a;
    }
    return ex;
}

ll fact(ll a){
    ll fc = 1;
    REP(i, 1, a+1){
        fc *= i;
    }
    return fc;
}

int main() {
    ll n;
    cin >> n;
    if(n<1000) {
        cout << "ABC" << endl;
    }
    else {
        cout << "ABD" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb emplace_back
#define rt(v) return cout<<v,0
#define sz(v) (int)(v.size())
#define all(a) a.begin(),a.end()
#define endl '\n'
#define space " "
typedef long long ll;
typedef unsigned long long ull;
const int N = 10 + 1e5;
const int mod = 1e9 + 7;
/*

███╗   ███╗███████╗███╗   ███╗███████╗    ██╗      ██████╗ ██████╗ ██████╗
████╗ ████║██╔════╝████╗ ████║██╔════╝    ██║     ██╔═══██╗██╔══██╗██╔══██╗
██╔████╔██║█████╗  ██╔████╔██║█████╗      ██║     ██║   ██║██████╔╝██║  ██║
██║╚██╔╝██║██╔══╝  ██║╚██╔╝██║██╔══╝      ██║     ██║   ██║██╔══██╗██║  ██║
██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║███████╗    ███████╗╚██████╔╝██║  ██║██████╔╝
╚═╝     ╚═╝╚══════╝╚═╝     ╚═╝╚══════╝    ╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝

*/

using namespace std;
void Ferrari() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main() {
	Ferrari();
	string s; cin >> s;
	string y = s;
	reverse(all(s));
	if (s != y) rt("No");
	string a = y.substr(0, sz(s) / 2);
	string b = y.substr((sz(s) + 3) / 2 - 1);
	string a1 = a;
	reverse(all(a1));
	string b2 = b;
	reverse(all(b2));
	if (a1 == a && b2 == b) cout << "Yes";
	else cout << "No";
	return 0;
}
//1 2 3 4 5 -


//5 4 3 2 1
/* stuff you should look for
	* keepin sharp mind.
	* int overflow, array bounds.
	* special cases (n=1?), set tle , make sure you understand the problem correctly.
	* don`t stuck in a problem.
	* test the idea on samples.
	*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(A<=C && C<=B) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val n: Int = sc.nextInt()
    val w = IntArray(n)
    for(i in 0 until n) {
        w[i] = sc.nextInt()
    }
    
    val sum = w.sum()
    var psum = 0
    var nsum = 0
    var prev = 0
    for(i in 0 until n) {
        psum += w[i]
        nsum = sum - psum
        if(psum > nsum){
            val curr = psum - nsum
            println(if(prev > curr) curr else prev)
            break
        }
        prev = nsum - psum
    }
}


Measured memory_bytes: 36036
fun main(args: Array<String>){
    val K = readLine()!!.toInt()
    val list: List<Int> = readLine()!!.split(" ").map { it.toInt() }


    for (i in list[0]..list[1]){
        if (i % K == 0) {
            println("OK")
            return
        }
    }
    println("NG")
}

Measured memory_bytes: 36360
#include<stdio.h>

int main(void){
    int A,B,C;
    scanf("%d %d %d",&A, &B, &C);
    if(!(A==B && B==C) && ((A==B) || (B==C) || (C==A))){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
while 1:
    nums = int(input())
    if nums != 0:
        d = {}
        stars = list(map(int,input().split()))
        for x in stars:
            if x not in d:
                d[x] = 1
            else:
                d[x] += 1

        key = list(d.keys())
        val = list(d.values())
        m = int(max(val))
        if m > nums/2:
            res = key[val.index(m)]
            print(res)
        else:
            print("NO COLOR")
    else:break

Measured memory_bytes: 126732
a, b, m = map(int,raw_input().split())
dr = map(int,raw_input().split())
wa = map(int,raw_input().split())
xyc = [map(int,raw_input().split()) for i in range(m)]
low = 200001

for i in range(m):
    f = xyc[i][0] - 1
    d = xyc[i][1] - 1
    if low >= dr[f]+wa[d]-xyc[i][2]:
        low = dr[f]+wa[d]-xyc[i][2]

dr.sort()
wa.sort()

if low >= (dr[0] + wa[0]):
    print (dr[0] + wa[0])
else:
    print low

Measured memory_bytes: 30260
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define RB rbegin()
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define MD 1000000007
#define PPF pop_front()
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;u.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>u;
map<LL,LL>ww,cc;
LL ar[50000001];
LL br[50000001];
LL cr[500][500];
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    while(tt--)
    {
        UOSMOY;
        cin>>n;
        for(i=0; i<n; i++)
        {
            cin>>ar[i];
        }
        sort(ar,ar+n);
        k=0;
        for(i=n-1,l=n-1; i>0; i--,l--)
        {
            if(i==n-1)
            {
                k+=ar[n-1];
            }
            else
            {
                k+=ar[l];
                if(i!=1)
                {
                    k+=ar[l];
                }
                i--;
            }
        }
        cout<<k<<endl;
    }
    return 0;
    //IN
    //AL
}


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

const int maxn = 1000005;
int n, a, prime[maxn];
set <int> st, st2, tmp;

int main() {
    cin >> n;
    for (int i = 2; i < maxn; i++){
        if (!prime[i]){
            for (int j = i; j < maxn; j += i){
                prime[j] = i;
            }
        }
    }
    cin >> a;
    while (prime[a]){
        st.insert(prime[a]);
        int x = prime[a];
        while (a % x == 0) a /= x;
    }
    st2 = st;
    bool pairwise = true;
    for (int i = 1; i < n; i++){
        cin >> a;
        tmp.clear();
        for (auto j:st2){
            if (a % j == 0) tmp.insert(j);
        }
        st2 = tmp;
        if (pairwise){
            while (prime[a]){
                if (st.count(prime[a])) pairwise = false;
                st.insert(prime[a]);
                int x = prime[a];
                while (a % x == 0) a /= x;
            }
        }
    }
    if (pairwise) cout << "pairwise coprime\n";
    else if (!st2.size()) cout << "setwise coprime\n";
    else cout << "not coprime\n";
}


Measured memory_bytes: 11176
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,Q,d[N],a[N],b[N];
int Get(int x,int y)
{
	return min(x,abs(x-y));
}
int main()
{
	scanf("%d%d",&n,&d[0]);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		d[i]=Get(d[i-1],a[i]);
	}
	b[n+1]=0;
	for (int i=n;i>=1;i--)
	{
		if (b[i+1]<a[i]/2) b[i]=b[i+1];
		else b[i]=b[i+1]+a[i];
	}
	scanf("%d",&Q);
	for (int i=1;i<=Q;i++)
	{
		int x;
		scanf("%d",&x);
		puts(d[x-1]<=b[x+1]?"NO":"YES");
	}
}

Measured memory_bytes: 7808
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    int n, k, cnt;
    ArrayList<Integer>[] es;
    int[] parent;

    void run() {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt(); k = sc.nextInt();
        es = new ArrayList[n];
        parent = new int[n];
        for (int i = 0; i < n; i++) es[i] = new ArrayList<>();
        cnt = sc.nextInt() != 1 ? 1 : 0;

        for (int i = 1; i < n; i++) {
            int next = sc.nextInt() - 1;
            es[next].add(i);
            parent[i] = next;
        }
        dfs(0);
        System.out.println(cnt);
    }

    int dfs(int p) {
        int max = 0;
        for (int next: es[p]) {
            max = Math.max(max, dfs(next));
        }
        max++;
        if (p == 0) return 0;
        debug(p, max);
        if (max == k && parent[p] != 0) {
            cnt++;
            return 0;
        } else {
            return max;
        }
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 115816
#include "bits/stdc++.h"
using namespace std;

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

Measured memory_bytes: 768
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))

if N >= M :
    print(0)
    exit()

sub = []
for i in range(1,M):
    sub.append(X[i]-X[i-1])
sub = sorted(sub)

if N == 1:
    print(sum(sub))
else:
    ans = sum(sub[:-(N-1)])
    print(ans)





Measured memory_bytes: 13960
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
 
  int n;
  cin >> n;
  
  vector<vector<bool>> edges(n + 1, vector<bool>(n + 1));
  int num = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      edges[i][j] = true;
      ++num;
    }
  }
  
  if (n % 2 == 1) {
    for (int i = 1; i < n - i; ++i) {
      edges[i][n - i] = false;
      --num;
    }
  } else {
    for (int i = 1; i < n - i + 1; ++i) {
      edges[i][n - i + 1] = false;
      --num;
    }
  }
  
  cout << num << '\n';
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      if (edges[i][j]) {
        cout << i << ' ' << j << '\n';
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
//---------- begin union_find ----------
#[allow(dead_code)]
mod union_find {
    pub struct UF {
        p: Vec<i32>,
    }
    impl UF {
        pub fn new(n: usize) -> UF {
            UF {p: vec![-1; n] }
        }
        pub fn init(&mut self) {
            for p in self.p.iter_mut() {
                *p = -1;
            }
        }
        pub fn root(&mut self, mut x: usize) -> usize {
            let mut stack = vec![];
            while self.p[x] >= 0 {
                stack.push(x);
                x = self.p[x] as usize;
            }
            while let Some(v) = stack.pop() {
                self.p[v] = x as i32;
            }
            x
        }
        pub fn same(&mut self, x: usize, y: usize) -> bool {
            self.root(x) == self.root(y)
        }
        pub fn unite(&mut self, mut x: usize, mut y: usize) -> Option<(usize, usize)> {
            x = self.root(x);
            y = self.root(y);
            if x == y {
                return None;
            }
            if self.p[x] > self.p[y] {
                let s = x;
                x = y;
                y = s;
            }
            self.p[x] += self.p[y];
            self.p[y] = x as i32;
            Some((x, y))
        }
        pub fn get_size(&mut self, x: usize) -> usize {
            let r = self.root(x);
            (-self.p[r]) as usize
        }
    }
}
//---------- end union_find ----------

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let d: u64 = it.next().unwrap().parse().unwrap();
    let a: Vec<u64> = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect();
    let mut e = vec![];
    let mut stack = vec![(0, n)];
    while let Some((l, r)) = stack.pop() {
        if l + 1 == r {
            continue;
        }
        let m = (l + r) / 2;
        stack.push((l, m));
        stack.push((m, r));
        let mut local = (a[l], l);
        for i in (l + 1)..m {
            local.0 += d;
            if local.0 > a[i] {
                local = (a[i], i);
            }
        }
        for i in m..r {
            local.0 += d;
            e.push((local.1, i, local.0 + a[i]));
        }
        let mut local = (a[r - 1], r - 1);
        for i in (m..(r - 1)).rev() {
            local.0 += d;
            if local.0 > a[i] {
                local = (a[i], i);
            }
        }
        for i in (l..m).rev() {
            local.0 += d;
            e.push((i, local.1, local.0 + a[i]));
        }
    }
    e.sort_by_key(|e| e.2);
    let mut u = union_find::UF::new(n);
    let mut ans = 0;
    for (a, b, c) in e {
        if u.unite(a, b).is_some() {
            ans += c;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 134512
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min
#include <iomanip> // std::setprecision

int main() {
  long int L;
  std::cin >> L;
  double Ld = static_cast<double>(L);
  double ans = pow(Ld/3.0, 3.0);
  std::cout << std::setprecision(std::numeric_limits<long double>::digits10 + 1)
            << ans 
            << std::endl;
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main(){
	unsigned long long int a = 1;
  	unsigned long long int num;
  	unsigned long long int *p;
  	cin >> num;
  	p = new unsigned long long int[num];
  	for(int i = 0;i < num;i++){
      	unsigned long long int buf;
      	cin >> buf;
      	p[i] = buf;
      	if(buf == 0){
        	cout << 0;
          return 0;
        }
    }
  for(int i = 0;i < num;i++){
    unsigned long long int buf = a;
    	if(p[i] > 1000000000000000000){
        	cout << -1;
          return 0;
        }a*= p[i];
    if(a > 1000000000000000000 || a < buf){
    	cout << -1;
      return 0;
    }
  }
  	cout << a;
	return 0;
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
}

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

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
#define vll vector<ll>

#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

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

  ll k, a, b;
  cin >> k >> a >> b;

  FOR(i, a, b + 1) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }

  cout << "NG" << endl;

  return 0;
}

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

int main(void)
{
  int n;
  scanf("%d", &n);
  int i, a[n], b[n];
  memset(b, 0, sizeof(b));
  for (i = 2; i <= n; i++)
  {
    scanf("%d", &a[i]);
    b[a[i] - 1]++;
  }
  
  for (i = 0; i < n; i++)
    printf("%d\n", b[i]);
  
  return 0;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

vi Z_Algorithm(string s){
	int S=s.size();
	vi A(S);
	A[0]=S;
	int i=1,j=0;
	while(i<S){
		while(i+j<S&&s[j]==s[i+j]) j++;
		A[i]=j;
		if(!j){
			i++;continue;
		}
		int k=1;
		while(i+k<S&&k+A[k]<j) A[i+k]=A[k],k++;
		i+=k;j-=k;
	}
	return A;
}

string s,t;
vi a;

int main(){
	cin>>s>>t;
	int n=s.size(),m=t.size();
	string s_=t;
	for(int i=0;i<m/n+5;i++) s_+=s;
	vi z=Z_Algorithm(s_);
	a=vi(n);
	for(int i=0;i<n;i++) if(z[m+i]>=m) a[i]++;
	int res=0;
	vi b(n);
	for(int i=0;i<n;i++) if(a[i]&&!b[i]){
		int id=i;
		bool B=0;
		do{
			int nx=(id-m%n+n)%n;
			if(a[nx]) id=nx;
			else break;
			B=1;
		}while(i!=id);
		if(i==id&&B){
			cout<<-1<<endl;
			return 0;
		}
		int cnt=0;
		while(a[id]){
			b[id]=1;
			(id+=m)%=n;
			cnt++;
		}
		res=max(res,cnt);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 22836
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            List<int> lstInp = new List<int>();
            sS = System.Console.ReadLine().Trim().Split(' ');
            for (int i = 0; i < sS.Length; i++)
            {
                lstInp.Add(int.Parse(sS[i]));
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iCnt = lstInp.Count;
            lstInp = lstInp.Distinct().ToList();
            string sOut = "NO";
            if (lstInp.Count == iCnt) { sOut = "YES"; }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 43080
//
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);

int gcd(int a,int b){
  if(a<b) swap(a,b);
  while(a%b){
    int r = a%b;
    a=b;
    b=r;
  }
 return b;
}

int main() {
    int N; cin >> N;
    vi a(N);rep(i,N) cin>>a[i];
    int ans=a[0];
    rep(i,N-1) ans=gcd(ans,a[i+1]);
  
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pi           acos(-1)


ll t;
vector<ll>v[100005];



int main()
{
    ll a,b,c,d,e,g,i,j;
    cin>>a>>b;
    a=a*(a-1);
    a/=2;
    b=b*(b-1);
    b/=2;
    cout<<a+b<<endl;
    return 0;
}


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

using namespace std;

int main()
{
    string s;
    cin>>s;
    int ans=0;
    map<char,int>mp;
    for(int i=0;i<s.size();i++)
    {
        mp[s[i]]++;
        if(mp[s[i]] == 2)ans++;
    }
    if(ans == 2)cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int s;
  scanf("%d",&s);
  int s1=s/10;
  int s2=s/100;
  int s3=s/1000;
  if((s%10)==(s1%10)||(s1%10)==(s2%10)||(s2%10)==(s3%10)){
      printf("Bad");
  }else{
    printf("Good");
  }
  return 0;
}

Measured memory_bytes: 128
/*
        Choo Lo jo mujhe tum kabhi, kho na jaoon main raat din
    Nazaron mein tum ho basey
        Keh do jo tum ek baar, Mere ho bas tum mere
    Nazaron mein tum ho basey
*/
 
#include<bits/stdc++.h>
#include<cstdio>
 
#define deb(x) cout << #x << " -> " << x << el
#define db double
#define ll long long int
#define ull unsigned long long int
#define umap unordered_map
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define sclu(x) scanf("%llu", &x)
#define scd(x) scanf("%lf", &x)
#define pass cout<<"pass\n"
#define vi vector<int>
#define pb push_back
#define vec vector
#define el "\n"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define umap unordered_map
#define f(i,x,y) for(int i=x;i<y;++i)
#define ff(i,x,y) for(int i=x;i<=y;++i)
#define mem(x) memset(x, 0, sizeof(x))
#define mems(x,y) memset(x, y, sizeof(x))
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ppi pair<int, pii>
#define mat vector<vector<ll> > 
#define mod 1000000007
#define MAX 100005
 
using namespace std;

const int INF = 1e9 + 5;

void solve() {
	int n, W;
	sc(n); sc(W);

	vec<ll> dp(n * 1000 + 1, INF);
	dp[0] = 0;

	ll sum_value = 0LL;
	// dp[val] = minimum weight to reach the value val
	for(int item = 0; item < n; ++item) {
		int weight, value;
		cin >> weight >> value;

		sum_value += value;

		for(int v = n * 1000; v >= value; --v) {
			dp[v] = min(dp[v], dp[v - value] + weight);
		}
	}
	
	for(int i = sum_value; i > 0; --i) {
		if(dp[i] <= W) {
			cout << i << el;
			break;
		}
	}
}



int main() {
    int ccc = 1;
    // sc(ccc);
    while(ccc--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    int w,h,n;
    cin >> w >> h >> n;
    vector<vector<int>> s(h,vector<int> (w,0));
    int x,y,a;
    for(int i = 0;i < n;i++) {
        cin >> x >> y >> a;
        if(a == 1) {
            for(int j = 0;j < h;j++) {
                for(int k = 0;k < x;k++) {
                    s.at(j).at(k) = 1;
                }
            }
        }else if(a == 2) {
            for(int j = 0;j < h;j++) {
                for(int k = x;k < w;k++) {
                    s.at(j).at(k) = 1;
                }
            }
        }else if(a == 3) {
            for(int j = h - y;j < h;j++) {
                for(int k = 0;k < w;k++) {
                    s.at(j).at(k) = 1;
                }
            }
        }else {
            for(int j = 0;j < h - y;j++) {
                for(int k = 0;k < w;k++) {
                    s.at(j).at(k) = 1;
                }
            }
        }
    }
    int sum = 0;
    for(int i = 0;i < h;i++) {
        for(int j = 0;j < w;j++) {
            sum += s.at(i).at(j);
        }
    }
    cout << w * h - sum << endl;
}


Measured memory_bytes: 256
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Measured memory_bytes: 7736
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007

int main() {
    string s;
    cin >> s;
    if (s[0]==s[2]) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    var a = Math.min(input[0],input[1])*input[2]+(input[0]-input[1]>0?input[0]-input[1]:0)*input[3];
    console.log(a)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));

Measured memory_bytes: 7372
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7

# 組合せ nCr (MOD) 逆元を使う方法
def perm(n,k):
    if k > n or k < 0: return 0
    return fact[n] * fact_inv[n-k] % MOD

def cmb(n, k):
    if k < 0 or k > n: return 0 
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD

def cumprod(arr, MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv

U = 10 ** 5 + 100 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
N, K = lr()
A = np.array(lr())
A.sort()
if K == 1:
    print(0); exit()
coef = np.zeros(N, np.int64)
coef[K-1:] = [cmb(n, K-1) for n in range(K-1, N)]
answer = (A * coef % MOD).sum() % MOD
coef = np.zeros(N, np.int64)
coef[:-K+1] = [cmb(n, K-1) for n in range(N-1, K-2, -1)]
answer -= (A * coef % MOD).sum() % MOD
print(answer%MOD)
# 53

Measured memory_bytes: 26476
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD ((1<<31)-1)
#define f(i,n) for(int i=0;i<int(n);i++)
#define N (1000000)
#define M (1000000000)
int a[N];
int sl[N];
int sr[N];
int l[N];
int r[N];
int nx;

//初期化
void init(void){
	f(i, N){
		a[i] = MOD;
		sl[i] = -1;
		sr[i] = -1;
	}
	l[0] = 0;
	r[0] = M;
	nx = 1;
	return;
}


//変更(k=0-(M-1))
void change(int k, int x){
	stack<int>st;
	int p = 0;
	int y;
	while (l[p] + 1 < r[p]){
		st.push(p);
		y = (l[p] + r[p]) / 2;
		if (k < y){
			if (sl[p] == -1){
				l[nx] = l[p];
				r[nx] = y;
				sl[p] = nx;
				p = nx;
				nx++;
			}
			else{
				p = sl[p];
			}
		}
		else{
			if (sr[p] == -1){
				l[nx] = y;
				r[nx] = r[p];
				sr[p] = nx;
				p = nx;
				nx++;

			}
			else{
				p = sr[p];
			}
		}
	}
	a[p] = x;
	while (!st.empty()){
		p = st.top();
		if (sr[p] == -1)a[p] = a[sl[p]];
		else if (sl[p] == -1)a[p] = a[sr[p]];
		else a[p] = min(a[sl[p]], a[sr[p]]);
		st.pop();
	}
	return;
}
//探索(0<=l<r<=n)範囲は(l<=x<r)初期は(l,r,0)
int min_search(int ll, int rr, int k){
	int vl, vr;
	if (rr <= l[k] || r[k] <= ll)return MOD;
	else if (ll <= l[k] && r[k] <= rr) return a[k];
	else{
		if (sl[k] != -1)vl = min_search(ll, rr, sl[k]);
		else vl = MOD;
		if (sr[k] != -1)vr = min_search(ll, rr, sr[k]);
		else vr = MOD;
		return min(vl, vr);
	}
}


int main(void){
	int q;
	int c, k, x, y;
	init();
	scanf("%d %d",&c, &q);
	f(qq, q){
		scanf("%d", &c);
		if (c == 0){
			scanf("%d %d", &k, &x);
			change(k, x);
		}
		else if (c == 1){
			scanf("%d %d", &x, &y);
			k = min_search(x, y + 1, 0);
			printf("%d\n", k);
		}
	}

	return 0;
}


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

int main(){
  int num, a, b, tmp;
  cin >> num;
  tmp = num / 1000;
  a = num / 10;
  b = num - (tmp * 1000);
  if (!(a % 111) || !(b % 111)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
 }

Measured memory_bytes: 3604
import math
N = int(input())

ans = []
d = 40

t = 0
while d >= 0:
    bottom = t+(-2)**d+(-2)*(1-4**(d//2))//(-3)
    top = t+(-2)**d+(1-4**math.ceil(d/2))//(-3)
    if bottom <= N <= top:
        ans.append('1')
        t += (-2)**d
    else:
        ans.append('0')
    d -= 1

print(int(''.join(ans)))


Measured memory_bytes: 38384
#include<iostream>
#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 <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
struct UnionFind{
  vector<int>d;
  UnionFind(int n=0):d(n,-1){}
  int find(int x){
    if(d[x]<0)return x;
    return d[x]=find(d[x]);
  }
  bool unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y)return false;
    if(d[x]>d[y])swap(x,y);
    d[x]+=d[y];
    d[y]=x;
    return false;
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  int size(int x){return -d[find(x)];}
};
int main(){ 
  int a,b;cin>>a>>b;
  if(a>b)cout<<"safe";
  else cout<<"unsafe";
}


Measured memory_bytes: 3648
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var values = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var t = values[0];
            var a = values[1];
            var count = values[2];
            var i = 0;

            while (i < count)
            {
                if (t % 2 == 1)
                {
                    t--;
                }

                a += t / 2;
                t /= 2;

                i++;

                if (i >= count)
                {
                    break;
                }
                
                if (a % 2 == 1)
                {
                    a--;
                }

                t += a / 2;
                a /= 2;

                i++;
            }
            
            Console.WriteLine(t + " " + a);

        }
    }
}


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

set<pair<int, int>> bomb;

int main(){
  ll H,W,M;cin>>H>>W>>M;
  map<int, int> row,col;
  ll maxr=0,maxc=0;
  rep(i,M){
    ll h,w;cin>>h>>w;h--,w--;
    row[h]++;col[w]++;
    if(row[h]>maxr) maxr=row[h];
    if(col[w]>maxc) maxc=col[w];
    bomb.insert({h,w});
  }
  vll vr{},vc{};
  for(auto r : row){
    if(r.second==maxr) vr.push_back(r.first);
  }
  for(auto c : col){
    if(c.second==maxc) vc.push_back(c.first);
  }
  ll ans = maxr + maxc;
  for(auto r : vr) {
    for(auto c : vc){
      if(bomb.find({r,c})!=bomb.end()) continue;
      cout << ans << endl;
      return 0;
    }
  }
  --ans;
  cout << ans << endl;
}

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

using namespace std;

#define int long long
#define INF 1e9
#define LINF 1e18

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, M;
int x[1000], y[1000], z[1000];

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

    cin >> N >> M;
    for(int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i] >> z[i];
    }
    int res = 0;
    for(int i = 0; i < (1 << 3); ++i) {
        vector<int> sum(N, 0);
        for(int j = 0; j < N; ++j) {
            int X = x[j] * (i & 1 ? -1 : 1);
            int Y = y[j] * (i & 2 ? -1 : 1);
            int Z = z[j] * (i & 4 ? -1 : 1);
            sum[j] = X + Y + Z;
        }
        sort(sum.begin(), sum.end(), greater<int>());
        int total = 0;
        for(int j = 0; j < M; ++j) total += sum[j];
        chmax(res, total);
    }
    cout << res << endl;
    return 0;
}

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

int main(){
  int H, N;
  cin >> H >> N;
  long long A[N];
  rep(i, N) cin >> A[i];
  long long sums = 0;
  rep(i, N) sums += A[i];
  if (sums >= H) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 4356
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
typedef long long LL;

LL a[maxn];
int pos[maxn];

int main(void)
{
    LL n;
    scanf("%lld",&n);
    memset(pos,-1,sizeof pos);
    LL x,m;
    scanf("%lld%lld",&x,&m);
    a[1]=x;
    pos[x]=1;
    int l,r;
    for(int i=2;i<maxn;i++){
        a[i] = 1ll*a[i-1]*a[i-1]%m;
        if(pos[a[i]]!=-1){
            l=pos[a[i]];
            r=i;
            break;
        }
        pos[a[i]]=i;
    }
    for(int i=2;i<=r;i++) a[i]+=a[i-1];
    if(n<=r) printf("%lld\n",a[n]);
    else{
        LL times = (n-(l-1))/(r-l);
        int mmm = (n-(l-1))%(r-l);
        // printf("%d %d %lld %d\n",l,r,times,mmm);
        LL ans = times*(a[r]-a[l])+a[l-1+mmm];
        printf("%lld\n",ans);
    }
}



Measured memory_bytes: 4992
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#define ll long long
#define M 1001000
using namespace std;
int read() {
	int nm = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
	return nm * f;
}
int n;
int note[M];
int main() {
//	freopen("hat.in", "r", stdin), freopen("hat.out", "w", stdout);
//	int T = read();
//	while(T--) {
	n = read();
	int notea = -1, noteb = -1, numa = 0, numb = 0;
	bool flag = true;

	for(int i = 1; i <= n; i++) {
		int op = read();
		if(notea == op) numa++;
		else if(noteb == op) numb++;
		else if(notea == -1) notea = op, numa = 1;
		else if(noteb == -1) noteb = op, numb = 1;
		else flag = false;
	}
	if(flag == false) cout << "No\n";
	else {
		flag = false;
		if(noteb == -1) {
			if(notea == n - 1 || notea == 1 || notea * 2 <= n)
				cout << "Yes\n";
			else cout << "No\n";
			return 0;
		}
		if(notea > noteb) swap(notea, noteb), swap(numa, numb);
		if(noteb == notea + 1) {
			if(numb != 1) {
				if(numa <= notea) {
					int op = notea + 1 - numa;
					if(numb >= op * 2) {
						flag = true;
					}
				}
			}
		}
		puts(!flag ? "No" : "Yes");
	}
//	}
	return 0;
}
/*

9
3
1 2 2
3
1 1 2
5
4 3 4 3 4
3
1 2 2
3
1 1 2
5
4 3 4 3 4
3
1 2 2
3
1 1 2
5
4 3 4 3 4


*/

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    ll n;cin>>n;
    bool ok=1;
    lol(i,n){
	ll a;cin>>a;
	if(a%2==1)ok=0;
    }
    cout<<(ok?"second":"first")<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<memory.h>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
char A[10][10];
int main() {
	int i, j, k; ll N, M;
	cin >> N >> M; int ans = 0;
	if (N == 1 && M == 1) printf("1");
	else if (N == 1) {
		cout << M - 2;
	}
	else if (M == 1) {
		cout << N - 2;
	}
	else {
		cout << N*M - N * 2 - M * 2 + 4;
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n;cin>>n;
  ll ans = 0;
  rep(i,n){
    ll a;cin>>a;
    ans = gcd(ans,a);
  }
  print(ans);
  return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int y=sc.nextInt();
		System.out.println(gcd(x,y));
	}
	public static int gcd(int x,int y){
		if(x<y){
			swap(x,y);
		}
		int r;
		while(y>0){
			r=x%y;
			x=y;
			y=r;
		}
		return x;
	}
	public static void swap(int x,int y){
		int tmp=x;
		x=y;
		y=tmp;
	}
}


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

int main()
{
    string s;
    cin >> s;
    int a = 0;
    int b=0;
    for (size_t i = 0; i < s.length(); i++)
    {
        if((s[i]=='0'&&i%2==0) ||(s[i]=='1'&&i%2==1)){
            a++;
        }
        else{
            b++;
        }
    }
    cout << min(s.length() - a, s.length() - b) << endl;

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
using namespace std;
int v[100000];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",v+i);
	std::sort(v,v+a);
	long long ret=1;
	int mod=1000000007;
	int at=0;
	for(int i=0;i<a;i++){
		while(at<a&&v[i]+b>=v[at])at++;
	//	printf("%d\n",at);
		ret=ret*(at-i)%mod;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 1432