akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<int,int>;

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

    i64 ans = 1e18;
    for(i64 i = 1; i*i <= N; i++){
        if(N % i == 0){
            ans = min(ans, (N/i - 1) + (i-1));
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
n = int(input())
flst = []
for _ in range(n):
  flst.append([int(i) for i in input().split()])
plst = []
for _ in range(n):
  plst.append([int(i) for i in input().split()])
m = - 1 << 30
for i in range(1, 1 << 10):
  r = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if (i >> k & 1) & flst[j][k]:
        c += 1
    r += plst[j][c]
  m = max(m, r)
print(m)


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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll n, m;
  cin >> n >> m;
  
  vector<ll> l(m);
  vector<ll> r(m);
  for (ll i = 0; i < m; ++i) {
    cin >> l[i] >> r[i];
  }
  sort(l.begin(), l.end(), greater<ll>());
  sort(r.begin(), r.end());

  cout << max(r[0]-l[0]+1, ll(0)) << endl;

  return 0;
}

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

# AtCoder Grand Contest
# Problem A


if __name__ == '__main__':
    from itertools import accumulate
    from collections import Counter

    n = int(input())
    a = [0] + list(map(int, input().split()))

    # See:
    # https://www.youtube.com/watch?v=8BHBFMrZ8VM
    # https://beta.atcoder.jp/contests/agc023/submissions/2431021
    s = list(accumulate(a))

    print(sum([si * (si - 1) // 2 for si in Counter(s).values()]))


Measured memory_bytes: 41620
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}


ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n,a,b;cin>>n>>a>>b;
  cout << ((mpow(2, n) - 1 + MOD)%MOD - (nCr(n, a) + nCr(n, b))%MOD + MOD) %MOD<<endl;
  return 0;
}

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

int main() {
    int n, a;
    cin >> n;
    set<int> st;
    rep(i, n) {
        cin >> a;
        st.insert(a);
    }
    if(st.size() == n) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 9600
#include<cstdio>
#include<vector>
#include<utility>
#include<functional>
#include<algorithm>
using namespace std;

int main(){
	unsigned N, M;
	scanf("%u %u", &N, &M);
	if(M == 1){ // n=1 の素因数分解は n^1
		printf("1\n");
		return 0;
	}
	vector<pair<unsigned, unsigned> > res;
	unsigned _M = M;
	for(unsigned i = 2; i*i <= M; ++i){
		unsigned count = 0;
		while(_M % i == 0){
			count++; // 素数i^{res[i]}
			_M /= i;
		}
		if(count) res.push_back(make_pair(i,count));
	}
	if(_M != 1) res.push_back(make_pair(_M, 1));
	vector<unsigned> divisor;
	divisor.push_back(1);
	for (unsigned i = 0; i < res.size(); ++i){
		vector<unsigned> to_add_divisor;
		unsigned multiple = 1;
		for (unsigned j = 0; j < res[i].second; ++j){
			multiple *= res[i].first;
			for (unsigned k = 0; k < divisor.size(); ++k){
				to_add_divisor.push_back(divisor[k]*multiple);
			}
		}
		for(unsigned j : to_add_divisor){
			divisor.push_back(j);
		}
	}
	sort(divisor.begin(), divisor.end(), greater<unsigned>());
	for(unsigned gcd : divisor){
		if(M/gcd >= N){
			printf("%u\n", gcd);
			return 0;
		}
	}
	return 0;
}

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

#define INF 1000000000

using namespace std;

typedef long long int lli;
typedef pair<int, int> P;

struct edge{
	int to, cost;
};

int V, E;
vector<edge> e[10000];
int mincost[10000];
bool used[10000];


int main(void){
	cin >> V >> E;

	for(int i = 0;i < V;i++){
		mincost[i] = INF;
		used[i] = false;
	}

	for(int i = 0;i < E;i++){
		int a, b, c;
		cin >> a >> b >> c;
		edge d;
		d.to = b;
		d.cost = c;
		e[a].push_back(d);
		d.to = a;
		e[b].push_back(d);
	}


	mincost[0] = 0;
	long long int res = 0;

	while(true){
		int v = -1;
		for(int u = 0;u < V;u++){
			if(!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
		}

		if(v == -1) break;
		used[v] = true;
		res += mincost[v];

		for(int u = 0;u < e[v].size();u++){
			mincost[e[v][u].to] = min(mincost[e[v][u].to], e[v][u].cost);
		}
	}
	cout << res << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    vec.at(i) = a;
  }
  int j = 1;
  int s = 0;
  while (j != 2) {
    j = vec.at(j-1);
    s++;
    if (j == 2) {
      cout << s << endl;
      break;
    }
    if (s == N) {
      cout << -1 << endl;
      break;
    }
  }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='A'&&s[1]=='B'||s[0]=='B'&&s[1]=='A')
        cout<<"Yes";
    else if(s[1]=='A'&&s[2]=='B'||s[1]=='B'&&s[2]=='A')
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
def custom_round(number, ndigits=0):
    if type(number) == int:
        return number
    d_point = len(str(number).split('.')[1])
    if ndigits >= d_point:
        return number
    c = (10 ** d_point) * 2
    return round((number * c + 1) / c, ndigits)

N=int(input())
A=list(map(int,input().split()))
ave=custom_round(sum(A)/N,0)
total=0
for i in range(N):
    total+=(A[i]-ave)**2
print(int(total))

Measured memory_bytes: 3064
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[0])

cnt = 0
cost = 0
for a, b in AB:
    if M >= cnt:
        cnt += b
        cost += a*b
        if cnt == M:
            print(cost)
            break
        elif cnt > M:
            cost += (M-cnt)*a
            print(cost)
            break

Measured memory_bytes: 28724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
bool dp[110][110];
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
vector<string> tugi = {
    "6314",
    "2#2#",
    "1364",
    "5#5#"
};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h)
    {
        cin >> s[i];
    }
    dp[0][0] = true;
    queue<P> que;
    que.push(P(0, 0));
    while (!que.empty())
    {
        P p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++)
        {
            if (p.first + dx[i] < 0 || p.first + dx[i] >= w)
            {
                continue;
            }
            if (p.second + dy[i] < 0 || p.second + dy[i] >= h)
            {
                continue;
            }
            if (s[p.second + dy[i]][p.first + dx[i]] == '#')
            {
                continue;
            }
            if (dp[p.second + dy[i]][p.first + dx[i]])
            {
                continue;
            }
            int val = s[p.second + dy[i]][p.first + dx[i]] - '0';
            int now = s[p.second][p.first] - '0';
            char c = tugi[(p.second + dy[i])%4][(p.first + dx[i])%4];
            if (val != c-'0')
            {
                continue;
            }
            dp[p.second + dy[i]][p.first + dx[i]] = true;
            que.push(P(p.first + dx[i], p.second + dy[i]));
        }
    }
    if (dp[h - 1][w - 1])
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
const int inf = 1000000000;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338; // double PI = 4*atan(1);

	 

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	//ifstream cin (".in");
	//ofstream cout (".out");
	//int t;
	//cin >> t;
	//while(t--){
	int n;
	cin >> n;
	std::vector<int> p(n);
	for(int i=0; i<n; i++)cin >> p[i];
	int ans =inf;
	for(int i=1; i<100; i++){
		int sum = 0;
		for(int j=0; j<n; j++){
			sum+=(p[j]-i)*(p[j]-i);
		}
		ans = min(ans,sum);
	}	
    cout << ans << endl;
    return 0;
 }


Measured memory_bytes: 3572
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 LN         PIC X(21).
01 S          PIC X(10).
01 T          PIC X(10).
01 U          PIC X(10).
01 A          PIC 9(2).
01 B          PIC 9(2).
01 ZS         PIC Z(2)9.
01 DUMMY      PIC X(1).
01 ans        PIC X(2).
01 z          PIC X(5).

PROCEDURE DIVISION.
  ACCEPT LN.
  UNSTRING LN DELIMITED BY SPACE INTO S T.
  ACCEPT LN.
  UNSTRING LN DELIMITED BY SPACE INTO A B.
  ACCEPT U.
  IF S = U
      ADD -1 TO A
  ELSE
      ADD -1 TO B
  END-IF.
  MOVE A TO ZS.
  PERFORM UNANS.
  STRING ans(1:FUNCTION STORED-CHAR-LENGTH(ans)) INTO z.
  MOVE B TO ZS.
  PERFORM UNANS.
  STRING  z(1:FUNCTION STORED-CHAR-LENGTH(z))
          SPACE
          ans(1:FUNCTION STORED-CHAR-LENGTH(ans))
  INTO z.
  DISPLAY z(1:FUNCTION STORED-CHAR-LENGTH(z)).
  STOP RUN.

UNANS SECTION.
  UNSTRING
  ZS DELIMITED BY ALL SPACE
  INTO DUMMY ans.


Measured memory_bytes: 384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc = new FastScanner();
	static PrintWriter out = new PrintWriter(System.out);
	static int n, x, m, max = -114514;
	static int[] l, r, s, array, ans;

	static void solve() {
		n = sc.nextInt();
		x = sc.nextInt();
		m = sc.nextInt();
		l = new int[m];
		r = new int[m];
		s = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt() - 1;
			r[i] = sc.nextInt() - 1;
			s[i] = sc.nextInt();
		}
		array = new int[n];
		po(0, array);
		if (max == -114514) {
			out.println(-1);
		} else {
			out.print(ans[0]);
			for (int i = 1; i < n; i++) {
				out.print(" ");
				out.print(ans[i]);
			}
		}
		out.flush();
	}

	public static void main(String[] args) {
		solve();
	}

	static void po(int index, int[] array) {
		if (index == n) {
			for (int i = 0; i < m; i++) {
				int lion = 0;
				for (int j = l[i]; j <= r[i]; j++) {
					lion += array[j];
				}
				if (lion != s[i]) {
					return;
				}
			}
			int sum = 0;
			for (int i = 0; i < n; i++) {
				sum += array[i];
			}
			if (sum > max) {
				max = sum;
				ans = array.clone();
			}
			return;
		}
		for (int i = 0; i <= x; i++) {
			array[index] = i;
			po(index + 1, array);
		}
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private static boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

}

Measured memory_bytes: 26448
#include <bits/stdc++.h>
#include <cstdlib> 
using namespace std;
 
int main(){
  string s;
  cin >> s;
  int l=s.size();
  int c=0;
  
  for (int i=0;i<l;i++){
    if (s.at(i)=='o')c=c+1;
  }
  if (c+(15-l)>=8)cout << "YES";
  else cout << "NO";
}


Measured memory_bytes: 256
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inp_list(): return list(map(int, sys.stdin.readline().split()))


def lcm(x, y): return (x * y) // gcd(x, y)


N = inp()
S = input()

"""
    Conditions:
        1. S[i] \ne S[j] and S[j] \ne S[k] and S[k] \ne S[i]
        2. j - i \ne k - j
"""

r = S.count('R')
g = S.count('G')
b = S.count('B')
# 条件1を満たす組は rgb 個。それから「条件1を満たしてかつ条件 2 を満たさない」組を引く。条件を満たさないもののほうが多い。


cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        k = j + (j - i) # => k - j == j - i
        if k > N - 1: break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            cnt += 1

print(r * g * b - cnt)


Measured memory_bytes: 11040
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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 n;
int main(){
    cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    REP(i,n){
        cin >> x[i] >> u[i];
    }
    double res = 0;
    REP(i,n){
        if(u[i]=="JPY"){
            res+=x[i];
        }else{
            res+=x[i]*380000;
        }
    }
    cout << setprecision(15) << res << endl;

}


Measured memory_bytes: 256
<?php
while (true)
{
    $in = explode(" ", trim(fgets(STDIN)));
    $h = $in[0];
    $w = $in[1];
    if($h == 0 && $w == 0)
    {
        break;
    }
    for($i = 0; $i < $h; $i++)
    {
        if($i == 0 || $i == ($h - 1))
        {
            for($j = 0; $j < $w; $j++)
            {
                echo "#";
            }
        }
        else
        {
            for($j = 0; $j < $w; $j++)
            {
                if($j == 0 || $j == ($w - 1))
                {
                    echo "#";
                }
                else
                {
                    echo ".";
                }
            }
        }
        echo "\n";
    }
    echo "\n";
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

const int MOD = 1000000007;
const int INF = 1999999999;

template<typename T>
T MIN(V<T> v){return *min_element(ALL(v));}

template<typename T>
T MAX(V<T> v){return *max_element(ALL(v));}

//Bipartite method : x^n
LL BMPow(int x,int n,int m=0){
    LL ans=1;LL p=x;
    if(m==0){ while(n>0){if(n&1==1){ans*=p;} p*=p; n>>=1;}}
    else{ while(n>0){if(n&1==1){ans=(ans*p)%m;} p=(p*p)%m ;n>>=1;}}
    return ans;
}

//x^-1=x^(m-2) mod m
LL modInv(LL x,int m){return BMPow(x,m-2,m);}

//x! or x! mod m
LL factorial(int x,int m=0){
    LL a=1;
    if(m==0){REPD2(i,x,1){a*=i;}}else{REPD2(i,x,1){a=(a*i)%m;}}
    return a;
}

int main(){
    int n,a,b;
    cin>>n>>a>>b;

    LL all = BMPow(2,n,MOD) - 1;

    LL nCa = 1;
    REPD2(i,n,n-a+1) nCa = (nCa * i) % MOD;
    nCa = (nCa * modInv(factorial(a,MOD),MOD))%MOD;

    LL nCb = 1;
    REPD2(i,n,n-b+1) nCb = (nCb * i) % MOD;
    nCb = (nCb * modInv(factorial(b,MOD),MOD))%MOD;

    LL ans = all;
    ans = (ans-nCa<0) ? ((ans-nCa) % MOD + MOD) : ((ans-nCa) % MOD);
    ans = (ans-nCb<0) ? ((ans-nCb) % MOD + MOD) : ((ans-nCb) % MOD);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char a;
    scanf("%c",&a);
    switch(a)
    {
        case 'A':printf("T");break;
        case 'C':printf("G");break;
        case 'G':printf("C");break;
        case 'T':printf("A");break;
    }
    return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]

for i in range(N):
    nearest_diatance = 4*10**8
    ans = 0
    for j in range(M):
        x = abs(ab[i][0] - cd[j][0])
        y = abs(ab[i][1] - cd[j][1])
        if x+y < nearest_diatance:
            nearest_diatance = x+y
            ans = j+1
    else:
        print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;

signed main() {
int n;
cin>>n;
vector<int>x(n);
vector<int>y(n);
rep(i,n)cin>>y[i]>>x[i];
vector<int>a(0);
rep(i,8)a.push_back(i);
do{
  int h=0;
rep(i,n){
  if(a[y[i]]!=x[i]){h++;}
}
if(h)continue;
rep(i,8){
  for(int j=i+1;j<8;j++){
    if(j-i==abs(a[j]-a[i])){h++;}
  }
}
if(!h){
  rep(i,8){
    rep(j,8){
      if(a[i]==j)cout<<'Q';
      else cout<<'.';
      if(j==7)cout<<endl;
    }
  }
  exit(0);
}
}while(next_permutation(a.begin(),a.end()));

}



Measured memory_bytes: 3156
import sys
input = sys.stdin.buffer.readline

def main():
    N,W = map(int,input().split())
    use = [[] for _ in range(4)]
    wc,v = map(int,input().split())
    use[0].append(v)
    for _ in range(N-1):
        w,v = map(int,input().split())
        use[w-wc].append(v)

    for i in range(4):
        use[i].sort(reverse = True)
        use[i] = [0]+use[i]
        l = len(use[i])
        for x in range(l-1):
            use[i][x+1] += use[i][x]

    ans = 0
    for i in range(min(len(use[3]),W//(wc+3)+1)):
        Wa = W-(wc+3)*i
        for j in range(min(len(use[2]),Wa//(wc+2)+1)):
            Wb = Wa-(wc+2)*j
            for k in range(min(len(use[1]),Wb//(wc+1)+1)):
                Wc = Wb-(wc+1)*k
                l = min(len(use[0])-1,Wc//wc)
                point = use[0][l]+use[1][k]+use[2][j]+use[3][i]
                ans = max(point,ans)
                
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
n, m = map(int, input().split())
n, m = max(n, m), min(n, m)
div = 10 ** 9 + 7
res = 1
if n - m == 0:
  for i in range(1, n + 1):
    res *= i
    res %= div
  res = res * res * 2
  print(res % div)
elif n - m == 1:
  for i in range(1, n + 1):
    res *= i
    res %= div
  for i in range(1, m + 1):
    res *= i
    res %= div
  print(res)
else:
  print(0)

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	string str;
	cin>>str;
	int flag=1;
	fr(i,1,SZ(str)+1)
	{
		if(i%2==1)
		{
			if(str[i-1]=='L')
				flag=0;
		}
		else
		{
			if(str[i-1]=='R')
				flag=0;
		}
	}
	if(flag)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
}

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb puah_back

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(){
    int n, m; cin >> n >> m;
    string s, t; cin >> s >> t;
    vector<int> flag(1e6, 0);
    ll g = gcd(n, m);
    for(int i = 0, j = 0; i < n; i += n / g, j += m / g){
        if(s[i] != t[j]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << lcm(n, m) << endl;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define sz size
#define pb push_back
#define mper make_pair
#define PI 3.14159
#define fe first
#define se second
#define ll long long
//#define forik(i, a, b) for(ll i = a; i <= b; ++i)
//#define vl vector<ll>
//#define pll pair<ll, ll>
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define saken string
#define all(x) (x).begin(), x.end()
using namespace std;

const ll MAXN = 2e5 + 100;
string s;
pair <int, int> pref[MAXN], suff[MAXN];
ll ans = 0;
ll col[MAXN];

int main(){

mal

cin >> s;


for(int i = 0; i < s.sz(); ++i) {

    if(s[i] == 'A') {
        pref[i].se = i + 1;
        pref[i].fe = 1;
    }

    if(s[i] == 'B' && s[i + 1] == 'C') {suff[i].se = i + 2; suff[i].fe = 1;}

}

for(int i = 0; i < s.sz(); ++i) {

    if(s[i] == s[i - 1] && s[i] == 'A') {

        pref[i].fe = pref[i - 1].fe + 1;
        if(pref[i - 1].se != 0) {pref[i].se = pref[i - 1].se;}
    }

}

for(int i = s.sz() - 1; i >= 0; --i) {

    if(s[i] == 'C' && s[i - 1] == 'B') {

        suff[i - 1].fe = suff[i + 1].fe + 1;

        if(suff[i + 1].se != 0) {suff[i - 1].se = suff[i + 1].se;}

    }

}

for(int i = 0; i < s.sz(); ++i) {

    if(s[i] == 'B' && s[i + 1] == 'C') {

        ll all = pref[i - 1].fe + col[i - pref[i - 1].fe - 1];
        col[suff[i].se - 1] = all;

        ans += (all * suff[i].fe);


        i = suff[i].se - 1;

    }

}


cout << ans;

return 0;
}



Measured memory_bytes: 5268
using System;

class Program
{
  static void Main(String[] args)
  {
    var firstLine = Console.ReadLine().Split(' '); 
    int x = int.Parse(firstLine[0]) + 2;
    int y = int.Parse(firstLine[1]) + 2;
    int cnt1,cnt2,cnt3 = 0;
    String strBuff;
    char[,] mass = new char[x,y];
    bool result = true;

    Array.Clear(mass,0,mass.Length);

    for( cnt1 = 1; cnt1 < (x-1); cnt1++ )
    {
      strBuff = Console.ReadLine();
      
      for( cnt2 = 1; cnt2 < (y-1); cnt2++ )
      {
        mass[cnt1,cnt2] = strBuff[cnt2-1];
      }
    }
    
    for( cnt1 = 1; cnt1 < (x-1); cnt1++ )
    {
      for( cnt2 = 1; cnt2 < (y-1); cnt2++ )
      {
        if( ( mass[cnt1,cnt2] == '#' ) && ( mass[(cnt1-1),cnt2] != '#' ) &&
          ( mass[cnt1,cnt2-1] != '#' ) && ( mass[cnt1,cnt2+1] != '#' ) && 
          ( mass[(cnt1+1),cnt2] != '#' ) )
        {
          result = false;
          break;
        }
        else
        {
         /* 無処理 */ 
        }
      }
      
      if( result == false )
      {
        break;
      }
    }
    
    Console.WriteLine("{0}",(result?"Yes":"No"));
  }
}

Measured memory_bytes: 13140
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>

#define INF 0x7f7f7f7f
#define PI acos(-1.0)

#define L(x)    (x) << 1
#define R(x)    (x) << 1 | 1
#define lowbit(x)   (x)&(-x)
#define Mid(l, r)   (l + r) >> 1
#define Min(x, y)   (x) < (y) ? (x) : (y)
#define Max(x, y)   (x) < (y) ? (y) : (x)
#define iabs(x)     (x) < 0 ? -(x) : (x)
#define CLR(arr, val)    memset(arr, val, sizeof(arr))

using namespace std;

map<string, int> res;

int dir[4] = {1, -1, 4, -4};

void bfs() {
	queue<string> que;
	que.push("01234567");
	while (!que.empty()) {
		string u = que.front();
		que.pop();

		int pos;
		for (int i = 0; i < 8; i++) {
			if (u[i] == '0')	pos = i;
		}
		for (int i = 0; i < 4; i++) {
			if (pos + dir[i] >= 0 && pos + dir[i] < 8 &&
			        !(pos == 3 && dir[i] == 1) && !(pos == 4 && dir[i] == -1)) {
				string v = u;
				swap(v[pos], v[pos + dir[i]]);
				if (res[v] == 0) {
					res[v] = res[u] + 1;
					que.push(v);
				}
			}
		}
	}
}

int main() {
	res["01234567"] = 1;
	bfs();
	
	char ch;
	while (cin >> ch) {
		string str = "";
		str += ch;
		for (int i = 1; i < 8; i++) {
			cin >> ch;
			str += ch;
		}
		cout << res[str] - 1 << endl;		
	}
	return 0;
}

Measured memory_bytes: 3444
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>

class AGarden {
public:
	void solve(std::istream& in, std::ostream& out) {
        int a, b;
	    std::cin >> a >> b;
	    std::cout << (a-1)*(b-1) << std::endl;
	}
};


int main() {
	AGarden solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3560
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        fozubaoyou    pass System Test!
        from:https://codeforces.com/contest/472/submission/7996840
*/
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



int main(void){
    
	int n,C;
	cin>>n>>C;
	vvi d(C,vi(C));
	rep(i,C)rep(j,C)cin>>d[i][j];
	vvi c(n,vi(n));
	rep(i,n)rep(j,n){
		cin>>c[i][j];
		c[i][j]--;
	}

	vvll sum(3,vll(C,INF));
	

	for(int k=0;k<=2;k++){//sum[k]
		for(int i=0;i<C;i++){//sum[k][i]
			int tmp=0;
			for(int y=0;y<n;y++){
				for(int x=0;x<n;x++){
					if((y+x)%3==k&&c[y][x]!=i){
						tmp+=d[c[y][x]][i];
					}
				}
			}
			sum[k][i]=tmp;
		}
	}

	ll ans=INF;
	// cout<<"--------------"<<endl;
	for(int c1=0;c1<C;c1++){
		for(int c2=0;c2<C;c2++){
			if(c1==c2)continue;
			for(int c3=0;c3<C;c3++){
				if(c1==c3||c2==c3)continue;
				ll cost;
				// cout<<sum[0][c1]<<" "<<sum[0][c2]<<" "<<sum[0][c3]<<endl;
				cost = sum[0][c1]+sum[1][c2]+sum[2][c3];
				ans=min(ans,cost);
			}
		}
	}

	fin(ans);
	// cout<<"-----------"<<endl;
	// for(int i=0;i<3;i++){
	// 	for(int j=0;j<C;j++){
	// 		cout<<sum[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }

}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  10000005;
vector<ll> v;
void dfs(ll stepNum) 
{ 

  if(stepNum>=4e9)
    return;
  v.pb(stepNum);
  ll lastDigit = stepNum % 10; 

  ll stepNumA = stepNum*10 + (lastDigit-1);
  ll stepNumB = stepNum*10 + (lastDigit); 
  ll stepNumC = stepNum*10 + (lastDigit+1); 

  dfs(stepNumB); 

  if (lastDigit == 0) 
  dfs(stepNumC); 

  else if(lastDigit == 9) 
      dfs(stepNumA); 
  else{

    dfs(stepNumA);
    dfs(stepNumC); 
  } 
} 

signed main() { 

  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  ll n;
  cin>> n;
 for (ll i = 1 ; i <= 9 ; i++) 
    dfs(i); 
  sort(v.begin(), v.end());
  c(v[n-1]);
  return 0; 
} 


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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
typedef long long ll;

int main() {
    int A,B; cin >> A >> B;
    string op;
    if (A == B) {
        op = " == ";
    } else if (A > B) {
        op = " > ";
    } else {
        op = " < ";
    }
    cout << "a" << op << "b" << endl;
}


Measured memory_bytes: 3196
import sys
from heapq import heappush, heappop

def solve():
    file_input = sys.stdin
    N, R, L = map(int, file_input.readline().split())
    
    hq = []
    m = {}
    for i in range(1, N + 1):
        team = [0, i, 0]
        heappush(hq, team)
        m[i] = team
    
    time = 0
    for line in file_input:
        d, t, x = map(int, line.split())
        hq[0][2] += t - time
        time = t
        
        scored_team = m[d][:]
        scored_team[0] -= x
        heappush(hq, scored_team)
        m[d][2] = -1
        m[d] = scored_team
        
        while hq[0][2] == -1:
            heappop(hq)
    hq[0][2] += L - time
    ans_team = max(hq, key = lambda x: (x[2], -x[1]))
    print(ans_team[1])

solve()


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

namespace B_K_th_Common_Divisor
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABK = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = ABK[0];
            var B = ABK[1];
            var K = ABK[2];

            for (int i = Math.Max(A, B), cnt = 0; i >= 1; i--)
            {
                if (A % i == 0 && B % i == 0)
                {
                    cnt++;
                    if (cnt == K)
                    {
                        Console.WriteLine(i);
                        continue;
                    }
                }
            }

        }
    }
}

Measured memory_bytes: 13268
#include <stdio.h>

int main(void){
    int N;
    scanf("%d", &N);
    int p[N];
    for (int i = 0; i < N; i++){
        scanf("%d", &p[i]);
    }

    int max = 0;
    for (int i = 0; i < N; i++){ 
        if (p[i] > max){
            max = p[i];
        }
    }

    max = max / 2;
    int ans = 0;

    for (int i = 0; i < N; i++){
        ans += p[i];
    }
    ans -= max;

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(long long A, long long B, long long C){
    cout << C - min(A - B, C) << endl;
}

signed main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    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();
        int b = sc.nextInt();
        int area = a * b;
        int length = 2 * (a + b);
        System.out.println(area + " " + length);
    }
}


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

using namespace std;

typedef struct dice
{
    int a1,a2,a3,a4,a5,a6;
    int up=1;
    dice(int q,int w,int e,int r,int t,int y):a1(q),a2(w),a3(e),a4(r),a5(t),a6(y) {}
    dice() {}
} D;

int main()
{
//    freopen("in.txt","r",stdin);

    int a[10];
    for(int i=0; i<6; i++)
        cin>>a[i];

    D touzi=D(a[0],a[1],a[2],a[3],a[4],a[5]);

    int a1=touzi.a1,a2=touzi.a2,a3=touzi.a3,a4=touzi.a4,a5=touzi.a5,a6=touzi.a6;


    int n;
    cin>>n;

    while(n--)
    {
        int u,f;
        cin>>u>>f;

        if(u==touzi.a1)
        {
            if(f==touzi.a2)
                cout<<touzi.a3<<endl;
            else if(f==touzi.a3)
                cout<<touzi.a5<<endl;
            else if(f==touzi.a5)
                cout<<touzi.a4<<endl;
            else if(f==touzi.a4)
                cout<<touzi.a2<<endl;
        }
        else if(u==touzi.a2)
        {
            if(f==touzi.a6)
                cout<<touzi.a3<<endl;
            else if(f==touzi.a3)
                cout<<touzi.a1<<endl;
            else if(f==touzi.a1)
                cout<<touzi.a4<<endl;
            else if(f==touzi.a4)
                cout<<touzi.a6<<endl;
        }
        else if(u==touzi.a3)
        {
            if(f==touzi.a1)
                cout<<touzi.a2<<endl;
            else if(f==touzi.a2)
                cout<<touzi.a6<<endl;
            else if(f==touzi.a6)
                cout<<touzi.a5<<endl;
            else if(f==touzi.a5)
                cout<<touzi.a1<<endl;
        }
        else if(u==touzi.a4)
        {
            if(f==touzi.a2)
                cout<<touzi.a1<<endl;
            else if(f==touzi.a1)
                cout<<touzi.a5<<endl;
            else if(f==touzi.a5)
                cout<<touzi.a6<<endl;
            else if(f==touzi.a6)
                cout<<touzi.a2<<endl;
        }
        else if(u==touzi.a5)
        {
            if(f==touzi.a1)
                cout<<touzi.a3<<endl;
            else if(f==touzi.a3)
                cout<<touzi.a6<<endl;
            else if(f==touzi.a6)
                cout<<touzi.a4<<endl;
            else if(f=touzi.a4)
                cout<<touzi.a1<<endl;
        }
        else if(u==touzi.a6)
        {
            if(f==touzi.a3)
                cout<<touzi.a2<<endl;
            else if(f==touzi.a2)
                cout<<touzi.a4<<endl;
            else if(f==touzi.a4)
                cout<<touzi.a5<<endl;
            else if(f==touzi.a5)
                cout<<touzi.a3<<endl;
        }
    }


}



Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,c1,m1,s1,m2,s2,m3,s3,m4,s4,a[4],b[4],i,j,k;
while(cin>>n){
if(n==0)break;
cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
a[0]=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
b[0]=c1;
cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
a[1]=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
b[1]=c1;
cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
a[2]=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
b[2]=c1;
cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
a[3]=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
b[3]=c1;
for(i=0;i<4;i++)
for(j=i+1;j<4;j++){
if(a[i]>a[j]){m1=a[i];a[i]=a[j];a[j]=m1;m1=b[i];b[i]=b[j];b[j]=m1;}
}
for(i=4;i<n;i++){
cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
m1=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
if(m1<a[0]){a[1]=a[0];a[0]=m1;b[1]=b[0];b[0]=c1;}
else if(m1<a[1]){a[1]=m1;b[1]=c1;}
else if(m1>a[3]){a[2]=a[3];a[3]=m1;b[2]=b[3];b[3]=c1;}
else if(m1>a[2]){a[2]=m1;b[2]=c1;}
}
cout<<b[0]<<endl;
cout<<b[1]<<endl;
cout<<b[2]<<endl;
}
return 0;
}

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

int main(){
  long long mod=1e9+7;
  int N,M;
  cin >> N >> M;
  vector<bool>a(N+1,true);
  for(int i=0;i<M;i++){
    int x;
    cin >> x;
    a[x]=false;
  }
  vector<long long>d(N+1);
  d[0]=1;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<=min(i+2,N);j++){
      if(a[j]){
        d[j]+=d[i];
        d[j]%=mod;
      }
    }
  }
  cout << d[N] << endl;
        
}
      


Measured memory_bytes: 1024
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"	
	typedef long long LL;
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)	
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i]; 
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}
	 
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll n,k;
		cin>>n>>k;
		vll A(n);
		forn(i,n)cin>>A[i];
		ll dp[100010];
		mem(dp,mod);
		// forn(i,k)
		// {
		// 	dp[i]=A[i];
		// }
		dp[0]=0;
		forab(i,1,n-1)
		{
			for(ll j=i-1;j>=max(0LL,i-k);j--)
			{
				dp[i]=min(dp[j]+abs(A[i]-A[j]),dp[i]);
			}
		}
		cout<<dp[n-1]<<endl;
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
		//cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}

	
	

Measured memory_bytes: 4760
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

#define rep(i, n) for (long long i = 0; i < n; i++)

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
    inl(N, M);

    if (2LL * N >= M)
        out(M / 2LL);
    else
        out(N + (M - 2LL * N) / 4LL);
}


Measured memory_bytes: 3608
#include<iostream>
constexpr int N = 100005;
bool hikui[N];
int main(){
    using namespace std;
    int n,m;
    cin >> n  >> m;
    int h[N];
    for(int i=1; i<=n; i++) cin >> h[i];
    for(int i=0; i<m; i++) {
        int a,b;
        cin >> a >> b;
        if(h[a]<h[b])  hikui[a] = true;
        if(h[a]==h[b]) hikui[a] = hikui[b] = true;
        if(h[a]>h[b])  hikui[b] = true;
    }
    int ans = 0;
    for(int i=1; i<=n; i++){
        if(!hikui[i])ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4112
import java.io.*;

public class Main{
	public static void main(String[] argv) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = null;
		while((line = br.readLine()) != null){
			String[] splited = line.split(" ");
			int value = Integer.parseInt(splited[0]) + Integer.parseInt(splited[1]);
			System.out.print(Integer.toString(value).length() + "\n");
		}
		br.close();
	}
}

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

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N,M;
    cin >> N >> M;
    Graph G(N);
    REP(i,M){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    cout << "Yes" << "\n";
    vector<int> dist(N, -1);
    vector<int> mark(N, -1);
    queue<int> que;
    dist[0] = 0;
    que.push(0);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            mark[nv] = v;
            que.push(nv);
        }
    }
    REP(i,N){
        if(i == 0)continue;
        cout << mark[i]+1 << "\n";
    }
}

Measured memory_bytes: 10720
#include <iostream>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, m, n) for (int i = m; i <= n; ++i)
using namespace std;

int main() {
    int N, d[110];
    cin >> N;
    REP(i,N) cin >> d[i];

    int num[110] = {0};
    REP(i,N) {
        ++num[d[i]];
    }

    int res = 0;
    FOR(i,1,100) {
        if ( num[i] ) {
            ++res;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // string s;
    // cin>>s;
   	// int flag=1;
    // for(int i=0;i<s.size();++i){
    // 	for(int j=i+1;j<s.size();++j){
    // 		if(s[i]==s[j]){
    // 			flag=0;
    // 			break;
    // 		}
    // 	}
    // }
    // cout<<((flag)?"yes":"no");



    // string s;
    // cin>>s;
    // set<char>c;
    // for(char k:s) c.insert(k);
    // cout<<((s.size()==c.size())?"yes":"no");
    


    // string s;
    // cin>>s;
    // map<char,int>m;
    // for(int i=0;i<s.size();++i){
    // 	if(m[s[i]]>0){
    // 		cout<<"no";
    // 		return 0;
    // 	}
    // 	++m[s[i]];
    // }
    // cout<<"yes";

    // int a,b;
    // cin>>a>>b;
    // int ans=a+b;
    // (ans>=10)?cout<<"error":cout<<ans;
    

    // int n;
    // cin>>n;
    // int a,mx=0,mi=1000;
    // for(int i=0;i<n;++i){
    // 	cin>>a;
    // 	if(mx<a) mx=a;
    // 	if(mi>a) mi=a;
    // }


    int n;
    cin>>n;
    int ar[n];
    for(int i=0;i<n;++i) cin>>ar[i];
   	cout<<*max_element(ar,ar+n)-*min_element(ar,ar+n);
    return 0;
}


Measured memory_bytes: 3632