akhauriyash/Code-Regression huggingface dataset:
/*
 *  author : Atul Anand   
 *  created on : Sat Mar 28 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        long K = in.nextLong();
        int N = in.nextInt();
        long A[] = new long[N];
        read(A, N);

        long sum = 0;
        long max = 0;
        for(int i = 1; i < N; i++){
            sum += A[i] - A[i-1];
            max = Math.max(max, A[i] - A[i-1]);
        }
        sum += K  - (A[N-1] - A[0]);
        max = Math.max(max, K - (A[N-1] - A[0]));

        println(sum - max);

        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 48024
// Code by H~$~C
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n, x, d;
ll ans;
set<pair<ll, ll>> st;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> n >> x >> d;
  if (d == 0) {
    cout << (x == 0 ? 1 : n + 1) << endl;
    return 0;
  }
  if (d < 0) x = -x, d = -d;
  int g = __gcd(abs(x), abs(d));
  x /= g, d /= g;
  
  ans = 0;
  register int r, i;
  for (r = 0; r < d; ++r) {
    st.clear();
    for (i = r; i <= n; i += d) {
      ll left = 1LL * i / d * x + 1LL * (i - 1) * i / 2;
      ll right = 1LL * i / d * x + 1LL * (n - i + n - 1) * i / 2 + 1;
      st.insert({left, right});
    }
    ll mxr = -1e18;
    for (auto &pr: st) {
      ll left = pr.first, right = pr.second;
      ans += max(0LL, right - max(mxr, left));
      mxr = max(mxr, right);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12800
#!/usr/bin/python3.7
# -*- coding: utf-8 -*-

#ABC157B

a = []
for i in range(3):
	a.append(list(map(int, input().split())))

n = int(input())
b = []
for i in range (n):
	b.append(int(input()))

ans = False
for i in range(3):
	c = 0
	for j in range(3):
		if a[i][j] in b:
			a[i][j] = 0
			c += 1
	if c == 3:
		ans = True
		break

if ans :
	print('Yes')
elif a[0][0] + a[1][0] + a[2][0] == 0:
	print('Yes')
elif a[0][1] + a[1][1] + a[2][1] == 0:
	print('Yes')
elif a[0][2] + a[1][2] + a[2][2] == 0:
	print('Yes')
elif a[0][0] + a[1][1] + a[2][2] == 0:
	print('Yes')
elif a[0][2] + a[1][1] + a[2][0] == 0:
	print('Yes')
else:
	print('No')










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

#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

signed main() {
    int N;
    bool flag = true;

    cin >> N;
    int t = 0, x = 0, y = 0;
    Rep(i, N) {
        int tt, xx, yy;
        cin >> tt >> xx >> yy;
        int k = abs(xx - x) + abs(yy - y);

        if ( tt - t < k || ((tt - t) - k) % 2 != 0 ) flag = false;
        t = tt; x = xx; y = yy;
    }

    if ( flag ) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MAX = 999999;
const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}
template<typename T> T my_lcm(T a, T b){
    return a * b / my_gcd(a, b);    
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;

    string rep_a = "", rep_b = "";
    rep(i, a) rep_b += to_string(b);
    rep(i, b) rep_a += to_string(a);

    if (rep_a < rep_b) cout << rep_a << endl;
    else cout << rep_b << endl;

    return 0;
}

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

int main(){
	int n,a[100005],b[100005];
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[a[i]]=i;
	}
	for(int i=1;i<n;i++){
		printf("%d ",b[i]);
	}
	printf("%d",b[n]);
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define IC ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll ;
#define pb push_back

using namespace std;
//-------------------------------
const int N = 2e5 + 10 ;
int n , maxa ;
int arr[N] ;
ll ans ;
//------------------
int main()
{
    cin >> n ;
    for(int i = 0 ; i < n ; i++)
        cin >> arr[i] ;
    for(int i = 0 ; i < n ; i++)
    {
        maxa = max(maxa , arr[i]) ;
        ans += maxa - arr[i] ;
    }
    cout << ans ;
}


Measured memory_bytes: 4412
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var score = 0;
var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  const d = next();//365
  const n = 26;
  const c = nexts(n);
  const s = nextm(d,n);
  var a = xArray(0,n);
  for(var i = 0; i < d; i++){
    var t = next();
    for(var j = 0; j < n; j++){
      a[j] -= c[j];
    }
    a[t-1] = 0;
    score += s[i][t-1];
    for(var j = 0; j < n; j++)score += a[j];
    console.log(score);
  }
}

Measured memory_bytes: 34032
//default
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

signed main(){
  int n,ans=0;
  cin >> n;
  for(int i=1;i<=n;i++){
    if(i%2==0) continue;
    if(getDivisor(i).size()==8) ans++;
  }
  answer
  return 0;
}


Measured memory_bytes: 256
// B

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  ll N,A[200000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>A[i];
  ll cnt(0);
  ll sum(0);
  for (int i(0);i<N;i++) sum+=A[i];
  if (sum%2==1){
    cnt++;
    ll tmpmin1(0),tmpmin2(0);
    ll tmp(0);
    bool flag=false;
    A[N]= 1;
    for(int i(0);i<N;i++) {
      tmp+=A[i];
      if (tmp == (sum+1)/2){
        //cout << cnt << endl;
        return 0;
      }else if (tmp > (sum+1)/2 && flag == false){
        cnt += 2*min(tmp - (sum+1)/2,(sum+1)/2 - (tmp - A[i]));
        flag = true;
        tmpmin1 = cnt;
      }
    }
    tmp = 0;
    cnt = 1;
    A[N-1]-=1;
    //cout << sum << "f" << endl;
    for(int i(0);i<N;i++) {
      tmp+=A[i];
      if (tmp == (sum-1)/2){
        //cout << cnt << endl;
        return 0;
      }else if (tmp > (sum-1)/2){
      //  cout << tmp << i << "FD" <<endl;
        cnt += 2*min(tmp - (sum-1)/2,(sum-1)/2 - (tmp - A[i]));
        //cout << cnt << endl;
        tmpmin2 = cnt;
        cout << min(tmpmin1,tmpmin2) << endl;
        return 0;
      }
    }
    cout << tmpmin1 << tmpmin2 << endl;
    return 0;
  }else{
    ll tmp(0);
    //cout << sum /2 << endl;
    for(int i(0);i<N;i++) {
      tmp+=A[i];
      if (tmp == sum/2){
        cout << cnt << endl;
        return 0;
      }else if (tmp > sum/2){
        cnt += 2*min(tmp - sum/2,sum/2 - (tmp - A[i]));
        cout << cnt << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	long long H;
	cin >> H;
	long long W;
	cin >> W;
	long long M;
	cin >> M;

	map<long long, long long> colsMap;
	map<long long, long long> rowsMap;
	vector<long long> colsVec (W, 0);
	vector<long long> rowsVec (H, 0);
	map<string, bool> bombs;
	for (long long i = 0; i < M; ++i)
	{
		long long h;
		cin >> h;
		
		if (rowsMap.find(h - 1) != rowsMap.end())
		{
			rowsMap[h - 1]++;
		}
		else
		{
			rowsMap[h - 1] = 1;
		}
		rowsVec[h - 1]++;

		long long w;
		cin >> w;
		if (colsMap.find(w - 1) != colsMap.end())
		{
			colsMap[w - 1]++;
		}
		else
		{
			colsMap[w - 1] = 1;
		}
		colsVec[w - 1]++;

		string s = to_string(w-1);
		s.append(",");
		s.append(to_string(h-1));
		bombs[s] = true;
	}

	sort(rowsVec.begin(), rowsVec.end(), std::greater<long long>());

	vector<long long> maxRowIds;
	for (long long i = 0; i < H; ++i)
	{
		if (rowsMap[i] == rowsVec[0])
		{
			maxRowIds.emplace_back(i);
		}
	}

	sort(colsVec.begin(), colsVec.end(), std::greater<long long>());

	vector<long long> maxColIds;
	for (long long i = 0; i < W; ++i)
	{
		if (colsMap[i] == colsVec[0])
		{
			maxColIds.emplace_back(i);
		}
	}

	bool noBombFound = false;
	for (long long i = 0; i < maxRowIds.size(); ++i)
	{
		for (long long j = 0; j < maxColIds.size(); ++j)
		{
			string s = to_string(maxColIds[j]);
			s.append(",");
			s.append(to_string(maxRowIds[i]));
			if (bombs.find(s) == bombs.end())
			{
				noBombFound = true;
				break;
			}
		}

		if (noBombFound)
		{
			break;
		}
	}
	
	if (noBombFound)
	{
		cout << rowsVec[0] + colsVec[0] << endl;
	}
	else
	{
		cout << rowsVec[0] + colsVec[0] - 1 << endl;
	}
}

Measured memory_bytes: 77340
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
c = [0] + list(map(int,read().split()))

mod = 10**9 + 7
m = 2*10**5

before = [-1] * (m+1)
dp = [0] * (n+1)
dp[0] = 1

for i,ci in enumerate(c[1:],1):
    if(c[i-1]==ci):
        dp[i] = dp[i-1]
        continue

    if(before[ci] == -1):
        dp[i] = dp[i-1]
        before[ci] = i
        continue

    dp[i] = (dp[i-1] + dp[before[ci]])%mod
    before[ci] = i

print(dp[-1])

Measured memory_bytes: 64648
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int M(int x) { return x >= mod ? x - mod : x; }
long long x, y;
long long f[102];
int res, sum, lim = 87;

bool dfs(long long a, long long b, int d) {
    if (a * f[d - 1] + b * (d > 1 ? f[d - 2] : 0) > x ||
        a * f[d] + b * f[d - 1] > y)
        return 0;
    if (d == 1) {
        if (x >= a + b) sum = M(sum + (x - b) / a % mod);
        return sum = M(sum + (y - b) / a % mod), 1;
    }

    for (int i = 1 + (!b);; ++i)
        if (!dfs(b + a * i, a, d - 1)) return i > 1;
}

int main() {
    int T;
    scanf("%d", &T), f[0] = 1, f[1] = 1;
    for (int i = 2; i <= lim; ++i) f[i] = f[i - 1] + f[i - 2];
    while (T--) {
        scanf("%lld%lld", &x, &y);
        if (x > y) swap(x, y);
        if (x == 1) {
            printf("1 %d\n", y % mod);
            continue;
        }
        for (int i = 1; i <= lim; ++i) {
            if (x < f[i - 1] || y < f[i]) {
                res = i - 2;
                break;
            }
        }
        sum = 0, dfs(1, 0, res), printf("%d %d\n", res, sum);
    }
    return 0;
}

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

using namespace std;

int my_abs(int x) {
    return x < 0 ? -x : x;
}

int main() {

    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin >> h[i];

    unsigned long long dp[100010];
    dp[0] = 0;
    dp[1] = my_abs(h[1]-h[0]);

    for(int i=2; i<n; i++) {
        if(my_abs(h[i-1]-h[i]) + dp[i-1] < my_abs(h[i-2]-h[i]) + dp[i-2]) {
            dp[i] = my_abs(h[i-1]-h[i]) + dp[i-1];
        }
        else {
            dp[i] = my_abs(h[i-2]-h[i]) + dp[i-2];
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1408
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

use std::collections::VecDeque;

fn main() {
    scan!(h, w; usize);
    let mut maze = vec![vec![false; w]; h];
    for i in 0..h {
        scan!(line; String);
        for (j, c) in line.chars().enumerate() {
            if c == '.' { maze[i][j] = true; }
        }
    }

    let mut max_depth = 0;
    for i in 0..h {
        for j in 0..w {
            if !maze[i][j] { continue; }

            let mut que = VecDeque::new();
            let mut visited: Vec<Vec<bool>> = vec![vec![false; w]; h];
            que.push_front((0, (i, j)));
            let mut md = 0;

            while let Some(t) = que.pop_back() {
                let d = t.0;
                if md < d { md = d; }
                let p = t.1;
                if visited[p.0][p.1] { continue; }
                visited[p.0][p.1] = true;

                let four = vec![
                              (-1,  0),
                    ( 0, -1),           ( 0,  1),
                              ( 1,  0),
                ];

                for (dx, dy) in four {
                    let (a, b) = (p.0 as i64 + dx, p.1 as i64 + dy);
                    if a < 0 || h as i64 <= a || b < 0 || w as i64 <= b {
                        continue;
                    }
                    let (a, b) = (a as usize, b as usize);
                    if maze[a][b] && !visited[a][b] {
                        que.push_front((d+1, (a, b)));
                    }
                }
            }
            if max_depth < md {
                max_depth = md;
            }
        }
    }

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


Measured memory_bytes: 4352
n=int(input())
al=[]
l=[]
for i in range(n):
  a=int(input())
  al.append(a)
  templ=[list(map(int,input().split())) for i in range(a)]
  l.append(templ)
ans=0
for i in range(2**n):
  b=bin(i)
  chkdic={}
  n_honest=0#正直者の人数をカウント
  flag=False#矛盾が生じるかどうか
  for j in range(n):
    if ((i >> j) & 1):#もし正直者なら
      n_honest+=1
      #saying_l=l[j]
      #a=al[j]
      chkdic[j+1]=1
    else:
      chkdic[j+1]=0
  #chkdicをもとに判定
  for j in range(n):
    if ((i >> j) & 1):
      saying_l=l[j]
      a=al[j]
      for k in range(a):
        saying=saying_l[k]
        if chkdic[saying[0]]!=saying[1]:
          flag=True
          break
    if flag:
      break  
  if not flag:
    ans=max(ans,n_honest)
print(ans)
      



Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

void solve(int N, int M, vector<int> const &A) {
  double sum = accumulate(begin(A), end(A), 0);
  auto const thd = sum / (4 * M);
  int k = 0;
  REP(i, N) {
    if (thd <= A[i]) { ++k; }
  }
  cout << (k >= M ? "Yes":"No") << endl;
}

int main() {
  // cout << fixed << setprecision(10);

  int N, M;
  cin >> N >> M;
  vector<int> A;
  REP(i, N) {
    int Ai;
    cin >> Ai;
    A.push_back(Ai);
  }
  sort(begin(A), end(A), std::greater<int>());
  solve (N, M, A);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

char t[200005];
string s;
LL res;
int i, co;

int main() {
scanf("%s", t);
s = t;
res = 0;
co = 0;
for (i=0;i<s.size();i++) if (s[i] == 'B') co++; else res+=co;
cout << res << endl;
return 0;
}



Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
ch=0

b=[0 for _ in range(8)]
for r in a:
  t=r//400
  if t>=8:
    ch+=1
  else:
    b[t]+=1
    
c=8-b.count(0)
print(str(max(1,c))+' '+str(c+ch))

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

int main() {
   int N, M;
   cin >> N >> M;
   vector<int> a(N), b(N), c(M), d(M);

   for(int i=0; i<N; i++) {
      cin >> a[i] >> b[i];
   }
   for(int j=0; j<M; j++) {
      cin >> c[j] >> d[j];
   }


   for(int i=0; i<N; i++) {
      int min_d = abs(a[i]-c[0])+ abs(b[i]-d[0]);
      int ans = 1;
      for(int j=0; j<M; j++) {
         if(min_d > abs(a[i]-c[j])+ abs(b[i]-d[j])) {
            min_d = abs(a[i]-c[j])+ abs(b[i]-d[j]);
            ans = j + 1;
         }
      }
      cout << ans << endl;
   }
}

Measured memory_bytes: 3552
#include <iostream>

using namespace std;

int main()
{
int x;
cin >> x;
for(int i=1;i<=x;i++)
{if(i%3==0)
{cout << " " << i;}
else if(i%10==3)
{cout << " " << i;}
else if(i%100>=30 && i%100<40)
{cout << " " << i;}
else if(i%1000>=300 && i%1000<400)
{cout << " " << i;}
else if(i%10000>=3000 && i%10000<4000)
{cout << " " << i;}
}
cout << endl;
}




Measured memory_bytes: 3104
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

a,b,x = lr()
if a<=x<=a+b:
    print('YES')
else:
    print('NO')

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

vector<int> x, y;
int ax[52], ay[52];

bool ok(int yy1, int yy2, int xx1, int xx2, int u){
	if(ax[u] < x[xx1] || x[xx2] < ax[u])return 0;
	if(ay[u] < y[yy1] || y[yy2] < ay[u])return 0;
	return 1;
}

signed main(){
	int n, k;
	scanf("%lld%lld", &n, &k);
	for(int i = 0;i < n;i++){
		scanf("%lld%lld", &ax[i], &ay[i]);
		x.push_back(ax[i]);
		y.push_back(ay[i]);
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	
	int ans = (x[n-1]-x[0])*(y[n-1]-y[0]);
	for(int yy1 = 0;yy1 < n;yy1++){
		for(int yy2 = yy1+1;yy2 < n;yy2++){
			for(int xx1 = 0;xx1 < n;xx1++){
				for(int xx2 = xx1+1;xx2 < n;xx2++){
					int dis = (x[xx2]-x[xx1])*(y[yy2]-y[yy1]);
					int cnt = 0;
					for(int i = 0;i < n;i++){
						if(ok(yy1, yy2, xx1, xx2, i))cnt++;
					}
					if(cnt >= k)ans = min(ans, dis);
				}
			}
		}
	}
	
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();
    int m = ni();

    int[][] key = new int[m][2];
    for (int i = 0; i < m; i++) {
      key[i][0] = ni();

      int b = ni();
      for (int j = 0; j < b; j++) {
        key[i][1] |= 1 << (ni() - 1);
      }
    }

    int[] dp = new int[1 << n];
    Arrays.fill(dp, Integer.MAX_VALUE / 2);
    dp[0] = 0;

    for (int i = 0; i < (1 << n); i++) {
      for (int j = 0; j < m; j++) {
        dp[i | key[j][1]] = Math.min(dp[i | key[j][1]], dp[i] + key[j][0]);
      }
    }

    if (dp[(1 << n) - 1] >= Integer.MAX_VALUE / 2) {
      System.out.println(-1);
    } else {
      System.out.println(dp[(1 << n) - 1]);
    }

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

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

  private static long nl() {
    return Long.parseLong(next());
  }

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

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 25120
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N, M;
  cin >> N >> M;

  int a = 0, b = 1;
  rep(i, M) {
    cout << a + 1 << " " << b + 1 << "\n";

    if (N % 2 == 0 && i + 1 == N / 4) {
      b++;
    }
    a = (a + N - 1) % N;
    b = (b + 1) % N;
  }

  return 0;
}

Measured memory_bytes: 3632
#![allow(dead_code, unused_imports, non_snake_case)]

use std::io::*;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::str::FromStr;

const MOD: i32 = 1_000_000_007;

fn main() {
    let x: u32 = input();
    let mut now = 0;
    let mut ans = 0;
    for i in 0..(1e9 as u32) {
        now += i;
        if now >= x {
            ans = i;
            break;
        }
    }
    println!("{}", ans);
}

trait Read {
    fn read(s: &str) -> Self;
}

fn input<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

macro_rules! read_impl {
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl Read for String {
    fn read(s: &str) -> Self {
        s.to_string()
    }
}

impl Read for Vec<char> {
    fn read(s: &str) -> Self {
        s.chars().collect()
    }
}

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}

impl<A: Read, B: Read, C: Read, D: Read> Read for (A, B, C, D) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]), D::read(tokens[3]))
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 2000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl

//ifstream in("Text.txt");cin.rdbuf(in.rdbuf());



int main() {
    int N;
    cin >> N;
    set<int>st;
    rep(i, N) {
        int A;
        cin >> A;
        if (st.find(A) != st.end()) {
            st.erase(A);
        }
        else {
            st.insert(A);
        }
    }
    cout << st.size() << endl;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */


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

    vector< vector<int> > G(n+1);
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> check(n+1);
    for(int i=0; i<=n; i++){
        check[i] = 0;
    }
    queue<int> q;
    q.push(1);
    while(!q.empty()){
        int now = q.front();
        q.pop();
        for(int nv : G[now]){
            if(check[nv] == 0){
                check[nv] = now;
                q.push(nv);
            }
        }
    }
    cout << "Yes" << endl;
    for(int i=2; i<=n; i++){
        cout << check[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10124
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int main(){
    int N, D, X;
    cin >> N >> D >> X;
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        X += (D + A - 1) / A;
    }
    cout << X << endl;
}


Measured memory_bytes: 256
from math import sqrt,pi,cos,sin

a,b,h,m = map(int, input().split())

ta = h*2*pi/12 + m*2*pi/(12*60)
tb = m*2*pi/60

xa = a*cos(ta)
ya = a*sin(ta)
xb = b*cos(tb)
yb = b*sin(tb)

print(sqrt((xa-xb)**2 + (ya-yb)**2))

Measured memory_bytes: 9476
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// 22:00ぐらい？
// アイデアは22:08

// constexpr inline ll mod = 1'000'000'007;
constexpr int max_n = 200'000 + 5;

int n,q;
vector<vector<int>> edges(max_n);
vector<int> p(max_n), x(max_n);
vector<int> cnts(max_n);

void dfs(int u = 0, int parent = -1) {
    for (int v : edges[u]) {
        if (v == parent) {
            continue;
        }
        cnts[v] += cnts[u];
        dfs(v, u);
    }
}

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(10); // 浮動小数の表示の精度

    cin>>n>>q;
    edges.resize(n);
    p.resize(q);
    x.resize(q);
    cnts.resize(n);
    rep(i, n - 1)
    {
        int a,b; cin>>a>>b;
        a--;b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    rep(j,q){
        cin>>p[j]>>x[j];
        p[j]--;
    }

    // q回足す
    rep(j, q) {
        cnts[p[j]] += x[j];
    }

    // 集計
    dfs();

    rep(i,n){
        cout<<cnts[i]<<endl;
    }

    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  map<int, int> mp;
  rep(i,n) {
    mp[a[i]-1]++;
    mp[a[i]]++;
    mp[a[i]+1]++;
  }
  int ans = 0;
  for(auto it = mp.begin(); it != mp.end(); it++) {
    ans = max(ans, it->se);
  }
  cout << ans << endl;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  string s[3];
  FOR(i,0,2) cin >> s[i];
  if (s[0][SZ(s[0])-1] == s[1][0] && s[1][SZ(s[1])-1] == s[2][0]) cout << "YES";
  else cout << "NO";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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; }

const long long INF = 1000000000000000;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n, m,k,l; string s;
char maze[60][60];
int dis[101][101];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main() {
	cin >> h >> w;
	vector<string> str(h);
	rep(i, h) {
		cin >> str[i];
	}
	rep(i, h) {
		cout << str[i] << endl;
		cout << str[i] << endl;
	}
}


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



int main()
{
    ios_base::sync_with_stdio(false);
    /*cin.tie(NULL);
    cout.tie(NULL);*/

    long long int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

    cin>>n;

    if(n%1000==0)
        cout<<"0\n";
    else
    {
        cout<<1000-(n%1000)<<"\n";
    }
    return 0;


}


Measured memory_bytes: 3620
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
N = lines.shift()
S = lines.shift()
if (S.length % 2 == 0 && S.slice(0, S.length / 2) == S.slice(S.length / 2)) {
    console.log('Yes')
} else {
    console.log('No')
}


Measured memory_bytes: 21064
#include <iostream>
#include <vector>
using namespace std;
#define MAX 100001
#define infty (1<<31)-1

vector <int> A(MAX);

void update(int i,int x){
   A[i]=x;
}

int find(int s,int t){
    int ans=infty;
    for(int i=s;i<t+1;i++){
        if(ans>A[i])ans=A[i];
    }
    
    return ans;
}

int main(){
    int n,q;
    int com,x,y;
    cin>>n>>q;
    
    for(int i=0;i<n;i++){
        A[i]=infty;
    }
    for(int i=0;i<q;i++){
        cin>>com>>x>>y;
        if(com==0) update(x,y);
        else if(com==1)cout<<find(x,y)<<endl;
    }
    
    return 0;
    
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

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

    int l = n / 2;

    if (n % 2 == 0) {
        int s = 0;
        for (int i = 0; i < m; i++) {
            if ((l + 1 + i) - (l - i) >= l) s = 1;
            cout << l - i - s << ' ' << l + 1 + i << '\n';
        }
    } else {
        for (int i = 0; i < m; i++) {
            cout << l - i << ' ' << l + 1 + i << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int n;
int solve(int k){
	int m=0;
	while(k>0){
		m+=(k%10);
		k/=10;
	}
	return m;
}

int main(){
	cin>>n;
	int ans=INF;
	for(int i=1;i<n;i++){
		ans=min(ans,solve(i)+solve(n-i));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int x, a;
    cin >> x >> a;

    if(x < a){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }

    return 0;
}


Measured memory_bytes: 888
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let N: i64 = read();
    let X: i64 = read();
    let mut siz: Vec<i64> = vec![1];
    let mut n_p: Vec<i64> = vec![1];
    for i in 1..55 {
        let tmp = siz[i-1]*2+3;
        siz.push(tmp);
        let tmp = n_p[i-1]*2+1;
        n_p.push(tmp);
    }
    let mut depth = N as usize;
    let mut x = X-1;
    let mut ans: i64 = 0;
    loop{
        match x {
            _ if x <= 0 => {if depth==0 {ans += 1;} break;},
            _ if x < siz[depth]/2 => x -= 1,
            _ if x <= siz[depth]/2 => {ans += n_p[depth-1] + 1; break;},
            _ if x < siz[depth]-1 => {ans += n_p[depth-1] + 1; x -= siz[depth-1]+2},
            _ if x < siz[depth] => {ans += n_p[depth]; break;}
            _ => panic!()
        }
        depth -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define endl "\n"
template <typename T>
void printvec(vector<T> &v, int n, int start = 0)
{
    //cout << "\nprinting vector\n";
    for (int i = start; i < n; i++)
    {
        cout << v[i] << " ";
    }
    cout << "done printing";
    cout << endl;
}
const int mod = 1e9 + 7;
int h, w, sh, sw, dh, dw;

inline bool valid(int row, int col)
{
    return row >= 0 && col >= 0 && row < h && col < w;
}

void solve()
{
    int cnt = 0;
    cin >> h >> w >> sh >> sw >> dh >> dw;
    sh--, sw--, dh--, dw--;
    vector<string> grid(h);
    for (string &x : grid)
        cin >> x;
    vvi dist(h, vi(w, 1e7));
    deque<pii> q;
    q.push_front({sh, sw});
    // vvb vis(h, vb(w));
    dist[sh][sw] = 0;
    // vis[sh][sw] = 1;
    int d;
    int r, c;
    while (!q.empty())
    {
        pii x = q.front();
        r = x.first;
        c = x.second;
        // cout<<r<<" "<<c<<endl;
        q.pop_front();
        if (r == dh && c == dw)
            break;
        for (int dx = -2; dx <= 2; dx++)
        {
            for (int dy = -2; dy <= 2; dy++)
            {
                // cout<<r-dx<<" "<<c+dy<<endl;
                if (!valid(r + dx, c + dy) || grid[r + dx][c + dy] == '#' || (dx == 0 && dy == 0))
                    continue;
                d = 0;
                if (!((abs(dx) == 1 && dy == 0) || (dx == 0 && abs(dy) == 1)))
                    d = 1;
                if (dist[r + dx][c + dy] > dist[r][c] + d)
                {
                    dist[r + dx][c + dy] = dist[r][c] +d;
                    if (d == 0)
                        q.push_front({r + dx, c + dy});
                    else
                        q.push_back({r + dx, c + dy});
                }
            }
        }
    }
    if (r != dh && c != dw)
        dist[dh][dw] = -1;
    cout << dist[dh][dw] << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 8740