akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <queue>

int main(void){

	int n, count, next_node, num_neighbors;
	std::vector< std::vector<int> > edges;
	std::vector< std::vector<int> > neighbors;
	std::vector<bool> isUsed;
	std::vector<int> distance;
	std::priority_queue< std::pair<int, int> > distance_heap;
	
	scanf("%d", &n);
	
	edges.resize(n);
	isUsed.resize(n);
	neighbors.resize(n);
	distance.resize(n);
	
	for(int i=0;i<n;i++){
		scanf("%d %d", &next_node, &num_neighbors);
		edges[next_node].resize(num_neighbors);
		neighbors[next_node].resize(num_neighbors);
		for (int j=0;j<num_neighbors;j++){
			scanf("%d %d", &neighbors[next_node][j], &edges[next_node][j]);
		}
		isUsed[next_node]=-false;
		distance[next_node]=300000;
	}
	isUsed[0] = true;
	count=0;
	distance[0] = 0;
	for(int i=0;i<neighbors[0].size();i++){
		distance[neighbors[0][i]] = edges[0][i];
		distance_heap.push(std::make_pair(distance[neighbors[0][i]]*(-1), neighbors[0][i]));
	}
	count=1;
	while(count<n-1){
		std::pair<int, int> p = distance_heap.top();
		distance_heap.pop();
		next_node = p.second;
		if (isUsed[next_node]) continue;
		isUsed[next_node] = true;
		for(int i=0; i<neighbors[next_node].size();i++){
			int neighbor = neighbors[next_node][i];
			if ((!isUsed[neighbor]) && (distance[neighbor] > distance[next_node] + edges[next_node][i])){
				distance[neighbor] = distance[next_node] + edges[next_node][i];
				distance_heap.push(std::make_pair(distance[neighbor]*(-1), neighbor));
			}
		}
		count ++;
	}
	for(int i=0;i<n;i++){
		printf("%d %d\n", i, distance[i]);
	}
	return 0;
}

Measured memory_bytes: 6600
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n,m,ans;
    cin>>n;
    long long t[n];
    f(i,0,n){
        cin>>t[i];
    }
    cin>>m;
    long long p[m],x[m];
    f(i,0,m){
        cin>>p[i]>>x[i];
    }
    f(i,0,m){
        ans=0;
        f(j,0,n){
            if(j+1==p[i]){
                ans+=x[i];
            }
            else{
                ans+=t[j];
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3568
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, Y] = [int(input_raw[0]), int(input_raw[1])]

    is_exist = False;
    for x in range(0, 2000 + 1):
        for y in range(0, 2000 + 1):
            z = N - x - y
            if z >= 0:
                if 10000*x + 5000 *y + 1000 * z == Y:
                    is_exist = True
                    break;
        if is_exist == True:
            break;
    if is_exist== True:
        print x, y, z;
    else:
        print -1, -1, -1;

if __name__ == '__main__':
    main()


Measured memory_bytes: 2692
#![allow(dead_code)]
use std::io;

fn main() {
    solve_c();
}

fn solve_c() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    let n = n.trim().parse::<u32>().unwrap();

    let mut taro = 0;
    let mut hanako = 0;
    for _i in 0..n {
        let mut line = String::new();
        io::stdin().read_line(&mut line).unwrap();
        let line: Vec<&str> = line.trim().split_whitespace().collect();
        let a = line[0];
        let b = line[1];

        if a == b {
            taro += 1;
            hanako += 1;
        } else if a < b {
            hanako += 3;
        } else {
            taro += 3;
        }
    }

    println!("{} {}", taro, hanako);
}



Measured memory_bytes: 5024
package main

import (
	"fmt"
	"math"
)

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}
func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var n, l int
	fmt.Scan(&n, &l)
	a := make([]int, n)
	sum := 0
	for i := range a {
		a[i] = l + i
		sum += a[i]
	}
	ans := math.MaxInt32
	var b int
	for i := 0; i < n; i++ {
		t := 0
		for j := 0; j < n; j++ {
			if i != j {
				t += a[j]
			}
		}
		d := abs(sum - t)
		if ans > d {
			ans = d
			b = i
		}
	}
	fmt.Println(sum - a[b])
}


Measured memory_bytes: 512
// AOJ 0272: The Lonely Girl's Lie
// 2017.10.14 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 280000

int n;
int a[40003], b[40003];
char buf[280001], *p;
int f[100002];

int getInt()
{
	int n = 0;
	if (*p == ' ') p++;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

void getdata(int *a)
{
	int i, j, k, max;
	int *aa;

	memset(f, 0, sizeof(f));
	max = 0, k = n;
	while (k--) {
		i = getInt(), f[i]++; if (i > max) max = i;
	} 
	for (k = n, aa = a, i = max; k; i--) if (f[i]) {
		j = f[i], k -= j; while (j--) *aa++ = i;
	}
}

int main()
{
	int k, ans;
	int *aa, *bb;

	while (fgets(p = buf, 20, stdin) && *p != '0') {
		n = getInt();
		fgets(p = buf, MAX, stdin),	getdata(a);
		fgets(p = buf, MAX, stdin),	getdata(b);

		for (ans = n, aa = a, bb = b, k = 0; k < n; k += 2, aa++) {
			if (*aa++ > *bb++) { ans = k + 1; break; }
		}
		if (ans == n) puts("NA");
		else printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2668
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb1 push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//
ll dp[55][55][3000]; //i番目までのカードからj枚使って総和をkにできる総数
//
//initialization finish


// your function is here
//



//
// your function finished



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

	// your code is here
	//
	int n, a; cin >> n >> a;
	int x[55];rep(i, n) cin >> x[i];
	memset(dp, 0, sizeof dp);

	// dp初期化する
	rep(i, n) dp[i][0][0] = 1;
	//更新

	rep(i, n)FOR(j,1, i+2)rep(k,n*50+1)
	{
		if(k >= x[i])dp[i + 1][j][k] = dp[i][j][k] + dp[i][j - 1][k - x[i]];
		else dp[i + 1][j][k] = dp[i][j][k];
	}

	ll sum = 0;

	rep(i, n+1) sum += dp[n][i][a*i];

	Print(sum);
	//
	// your code finished

	return 0;
}

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

typedef long long ll;
ll x, k, d;

int main(){
    scanf("%lld%lld%lld", &x, &k, &d);
    if (k % 2 == 1){
        --k;
        x = min(abs(x + d), abs(x - d));
    }
    if (k == 0){
        printf("%lld", abs(x));
        return 0;
    }
    ll absx = abs(x);
    ll floor = absx / abs(2 * d);
    floor = min(floor, k / 2 - 1);
    ll a = abs(absx - floor * 2 * d);
    ll b = abs(absx - (floor + 1) * 2 * d);
    printf("%lld", min(a, b));
}


Measured memory_bytes: 3820
import math

n, W = map(int, input().split())
costs, weights = [], []
sum_vals = 0
for i in range(n):
    a,b =map(int, input().split())
    sum_vals+=b
    costs.append(b)
    weights.append(a)
dp = [int(10e18)+1]*(sum_vals+1)
dp[0] = 0
for item in range(0, n):
    for value_already in range(sum_vals-costs[item], -1, -1):
        dp[value_already+costs[item]] = min(dp[value_already+costs[item]], dp[value_already]+weights[item])
ans = 0
for i in range(1, sum_vals+1):
    if(dp[i]<= W):
        ans = max(ans, i)
print(ans)

Measured memory_bytes: 80860
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;


int main(void) {
	long long int x, y;
	long long int r;

	cin >> x >> y;

	r = x%y;
	while (r!=0) {
		x = y;
		y = r;
		r = x%y;
	}

	cout << y<< endl;


	return 0;
}


Measured memory_bytes: 3112
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,l,p=0,m,x=0;
    int a[100];
    scanf("%d",&n);
    for(int i=n;i>0;i--)
    {
        l=0;
        for(int j=i;j>0; )
        {
            if(j%2==1)break;
             j/=2;
            l++;

        }
        a[i]=l;
    }
    for(int i=1;i<=n;i++)
    {
       if(x<a[i])
        {
            x=a[i];
        }

    }
     for(int i=1;i<=n;i++)
    {
      if(a[i]==x)
      printf("%d",i);
    }
}


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

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

signed main() {
		int n;
		cin >> n;
		int ans = 0;
		if(n < 7) ans = 1;
		else if(n < 12) ans = 2;
		else{
				ans = n / 11;
				ans *= 2;
				if(n%11 > 6) ans+=2;
				else if(n%11 != 0) ans++;
		}
		cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
const int mod = 1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,m,t,n,b,c,d,a,l,r;
    cin >> n;
    vector<ll>v(n);
    for (ll i = 0; i < n; i++)
        cin >> v[i];
    vector<ll> cum(n);
    cum[0] = v[0];
    for (int i = 1; i < n; i++)
        cum[i] = cum[i - 1] + v[i];
    ll ans = 0;
    for (ll i = 0; i < n - 1; i++)
    {
        ll temp=(v[i] % mod)*((cum[n - 1] - cum[i])%mod);
        temp%= mod;
        ans=(ans+temp)%mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6368
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int r = scanner.nextInt();
        int g = scanner.nextInt();
        int b = scanner.nextInt();
        System.out.println((g * 10 + b) % 4 == 0 ? "YES" : "NO");
    }
}

Measured memory_bytes: 22740
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    ans = sys.maxsize
    for a in range(1, N):
        b = N - a
        ta = 0
        while a:
            ta += a % 10
            a //= 10
        while b:
            ta += b % 10
            b //= 10

        ans = min(ta, ans)

    return ans


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7744
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
N = int(input())
import math
eps = 10**(-6)
for n in range(1,N+1):
    ans = 0
    nn = int(math.sqrt(n))+1
    for x in range(1,nn):
        for y in range(1,nn):
            D = 4*n-3*x*x-3*y*y-2*x*y
            if D<=0:continue
            z = (-x-y+math.sqrt(D))
            if z<0:continue
            zr = round(z)
            if abs(z-zr)>eps or zr%2==1 or zr<1:
                continue
            z = zr//2
            if x*x+y*y+z*z+x*y+y*z+z*x==n:
                ans += 1
    print(ans)



Measured memory_bytes: 70504
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
int mod(ll a){return a%1000000007;};
typedef pair<int,int> i_i;



int c[200005];

int main(){
    int n,m;cin>>n>>m;
    for(int i=0;i<=m-1;i++){
        int a,b;cin>>a>>b;
        if(a==1)c[b]++;
        if(b==n)c[a]++;
    }
    bool flag=false;
    for(int i=2;i<=n-1;i++){
        if(c[i]>=2){flag=true;break;};
    }
    if(flag==true)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    
    return 0;
}


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

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<long long> x(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  long long ans = LONG_LONG_MAX;
  for (int i = 0; i < N - K + 1; i++) {
    ans =
        min(ans, min(abs(x[i]), abs(x[i + K - 1])) + abs(x[i] - x[i + K - 1]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
def inpl(): return [int(i) for i in input().split()]
import sys
from collections import defaultdict
H = defaultdict(lambda: 0)
N = int(input())
A = inpl()
mod = 10**9+7
if N%2:
    H[0] = -1
    for i in range(1, 1+N//2):
        H[2*i] = -2
else:
    for i in range(1, 1+N//2):
        H[2*i-1] = -2
for i in A:
    H[i] += 1
H = list(H.values())
if any(H):
    print(0)
    sys.exit()
print(2**(N//2)%mod)

Measured memory_bytes: 15068
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;

  vll as(n);
  rep(i, n) cin >> as[i];

  vvll to(n);
  rep(i, m){
    ll x, y;
    cin >> x >> y;
    to[x].push_back(y);
    to[y].push_back(x);
  }

  if(n < 2*(n-m-1)){
    cout << "Impossible" << endl;
    return 0;
  } else if(m == n - 1){
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;

  vll lst;
  vll seen(n, 0);
  rep(i, n){
    if(seen[i]) continue;
    queue<ll> que;
    que.push(i);
    seen[i] = 1;
    vll ilst;
    ll mv = INF, midx = -1;
    while(!que.empty()){
      ll u = que.front();
      que.pop();
      if(as[u] < mv){
        mv = as[u];
        midx = ilst.size();
      }
      ilst.push_back(as[u]);
      for(ll v : to[u]){
        if(seen[v]) continue;
        seen[v] = 1;
        que.push(v);
      }
    }
    ans += mv;
    rep(j, (ll)ilst.size()){
      if(j != midx) lst.push_back(ilst[j]);
    }
  }
  Sort(lst);
  rep(i, n-m-2) ans += lst[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 13180
x, y, a, b, c = map(int, input().split())
*p, = map(int, input().split())
*q, = map(int, input().split())
*r, = map(int, input().split())

p.sort(reverse=True)
q.sort(reverse=True)

pool = p[:x] + q[:y] + r
pool.sort(reverse=True)

pool = pool[:x + y]
ans = sum(pool)
print(ans)


Measured memory_bytes: 23328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int a,b; 
	scanf("%d %d", &a, &b);

	printf("%d\n",a+b/2);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        400005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}  

void solve(){
    double a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    if(a == b || v > w && abs(a-b) <= t*(v-w))cout << "YES\n";
    else cout <<  "NO\n";
}   
signed main()
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){   
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...
 

Measured memory_bytes: 3740
#include<bits/stdc++.h>                                                                                                                                                                                     
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
 
#define pb push_back
#define PII pair<int,int>
 
#define VS vector<string>
#define VI vector<int>
#define ll long long int
#define debug(x) cout << x << " :" <<#x << endl  
int main(void) {
    int a,b;cin >> a >> b;
    if(a+b < 10) cout << a+b << endl;
    else cout << "error" << endl;
}


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }

  vector<ll> imos(m);
  for(int i=0; i<n-1; i++) {
    int p = (a[i]+1)%m;
    int q = a[i+1];
    if (p <= q) {
      imos[p]++;
      imos[q]--;
    } else {
      imos[0]++;
      imos[q]--;
      imos[p]++;
    }
  }
  for(int i=0; i<m-1; i++) {
    imos[i+1] += imos[i];
  }
  vector<int> cost(m);
  for(int i=0; i<n-1; i++) {
    cost[a[i+1]] += (a[i+1]-a[i]+m)%m-1;
  }

  vector<ll> ans(m);
  for(int i=0; i<n-1; i++) {
    if (a[i] > a[i+1]) {
      ans[0] += a[i+1]+1;
    } else {
      ans[0] += a[i+1]-a[i];
    }
  }
  ll ret = ans[0];
  debug(ans[0]);
  for(int i=0; i<m-1; i++) {
    debug(ans[i], cost[i], imos[i]);
    ans[i+1] = ans[i] + cost[i] - imos[i];
    chmin(ret, ans[i+1]);
    debug(ans[i+1]);
  }
  cout << ret << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

vector<ll> enum_div(ll n) {
    vector<ll> res;
    for(ll i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            res.push_back(i);
            if(i != 1 && i * i != n) {
                res.push_back(n / i);
            }
        }
    }
    return res;
}

int main() {
    ll n;
    ll check[1000005];
    m0(check);

    cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++) {
        cin >> a[i];
        check[a[i]]++;
    }

    ll ans = 0;
    for(ll i = 0; i < n; i++) {
        bool flag = true;
        for(auto x : enum_div(a[i])) {
            if(x != a[i] && check[x] != 0)
                flag = false;
            if(check[a[i]] != 1)
                flag = false;
        }
        if(flag) {
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12748
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
typedef long long ll;
typedef double d;
typedef long double ld;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,x;
    cin>>n>>x;
    vector<ll> v(n);
    ll minv=1000000000000;
    for(ll i=0;i<n;i++)
    {
        ll y;
        cin>>y;
        v[i]=abs(y-x);
    }
    ll ans=v[0];
    for(ll i=1;i<n;i++)
    {
        ans=__gcd(v[i],ans);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n;
  cin >> n;
  priority_queue<double, vector<double>, greater<double>> v;
  REP(i, n) {
    double t;
    cin >> t;
    v.push(t);
  }
  REP(i, n - 1) {
    double tmp1 = v.top();
    v.pop();
    double tmp2 = v.top();
    v.pop();
    v.push((tmp1 + tmp2) / 2);
  }
  cout <<fixed<<setprecision(6) <<v.top() << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin>>n;
  int b[4][3][10] = {0};
  while(n--)
  {
    int l, f, r, n; cin>>l>>f>>r>>n;
    b[--l][--f][--r] += n;
  }
  for(int i = 0; i < 4; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      for (int k = 0; k < 10; k++)
        cout << " " << b[i][j][k];
      cout << "\n";
    }
    if(i!=3)cout << "####################\n";
  }
}


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

int main(){
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	for(int i=0;i<n;i++) cin>>a[i];
	ll dp[k+1];
    memset(dp,0,sizeof(dp));
    sort(a,a+n);
    for(int i=0;i<=k;i++){
    	for(int j=0;j<n;j++){
    		if(i+a[j]<=k)
    		dp[i+a[j]]=max(dp[i+a[j]],1-dp[i]);
    	}
    }

    if(dp[k]) cout<<"First"<<endl;
    else cout<<"Second"<<endl;

}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef vector<int> vi;
typedef vector<vi> vvi;

/*{
  }*/
int h, w, k;
string S[300];

int ans[301][301];
int s[301][301];

signed main(){
  cin >> h >> w >> k;
  rep(i, 0, h) cin >> S[i];

  rep(i, 0, h) rep(j, 0, w){
    if(S[i][j] == '#'){
      s[i+1][j+1] = 1;
    }
  }

  rep(i, 0, h+1) rep(j, 0, w) s[i][j+1] += s[i][j];
  rep(i, 0, w+1) rep(j, 0, h) s[j+1][i] += s[j][i];
  
  int num = 1, cnt = 0;
  rep(i, 0, h){
    int c = 0, next = 0;
    rep(j, 0, w){
      if(S[i][j] == '#') c++;
      if(c == 2){
        rep(u, i-cnt, i+1) rep(k, next, j) ans[u][k] = num;
        c--;
        num++;
        next = j;
      }
    }

    if(c == 0) cnt++;
    else{
      rep(u, i-cnt, i+1) rep(j, next, w) ans[u][j] = num;
      num++;
      cnt = 0;
    }
  }

  rep(i, 1, h){
    rep(j, 0, w) if(ans[i][j] == 0) ans[i][j] = ans[i-1][j];
  }

  rep(i, 0, h) rep(j, 0, w) cout << ans[i][j] << " \n"[j==w-1];

  return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 18;
int a[2][N];
int dp[1<<N][N];

int main(){
  fastIO;
  int n;
  cin >> n;
  for(int i = 0 ;i < n; i ++ ){
    cin >> a[i%2][i];
  }
  for(int i = 0 ; i < n; i ++ ){
    cin >> a[1-i%2][i];
  }
  for(int i = 0 ; i < (1 << n); i ++ ){
    for(int j = 0 ; j < n ; j ++ )
      dp[i][j] = (int)1e9;
  }
  for(int i = 0 ; i < n ; i ++ ){
    dp[(1<<i)][i] = i;
  }
  int p;
  int d, las;
  int ct;
  for(int i = 1; i < (1 << n) ; i ++ ){
    p = __builtin_popcount(i);
    for(int l = 0 ; l < n; l ++ ){
      if(dp[i][l] == (int)1e9) continue;
      ct = 0;
      for(int j = 0 ; j < n; j ++ ){
        if(!(i & (1 << j))){
          if(a[(p-1)%2][l] <= a[p%2][j]){
            dp[(i|(1<<j))][j] = min(dp[i|(1<<j)][j],dp[i][l]+ct);
          }
          ct++;
        }
      }
    }
  }
  int res = (int)1e9;
  for(int i = 0; i < n; i ++ )
    res = min(res, dp[(1<<n)-1][i]);
  if(res != (int)1e9)cout << res << "\n";
  else cout << -1 << "\n";
  return 0;
}


Measured memory_bytes: 18688
(defun solver ()
  (let ((n (read)) (m (read)) temp)
    (when (< m n) (setf temp n n m m temp))
    (cond ((and (= n 1) (= m 1)) (format t "1~%"))
          ((= n 1) (format t "~a~%" (- m 2)))
          (t (format t "~a~%" (* (- n 2) (- m 2)))))))

(solver)

Measured memory_bytes: 3944
S = input()
S = list(S)
S1 = S[0] + S[1]
S1 = int(S1)
S2 = S[2] + S[3]
S2 = int(S2)

if 1 <= S1 and S1 <= 12:
    if 1 <= S2 and S2 <=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
    
elif 1 <= S2 and S2 <= 12:
    print("YYMM")

else:
    print("NA")

Measured memory_bytes: 3064
import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();

        int X = nextInt();

        int D = 0;
        int count = 1;
        for(int i=0; i<N; i++){
            int L = nextInt();
            D += L;
            if(D > X){
                break;
            }
            count++;
        }
        println(count);
    }

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

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 25684
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    ll dp[n+1][3];
    rep(i,n+1)rep(j,3) dp[i][j]=-LINF;
    dp[0][0]=0;
    rep(i,n){
        if(i%2){
            chmax(dp[i+1][0],dp[i][0]);
            chmax(dp[i+1][1],dp[i][1]+a[i]);
            chmax(dp[i+1][2],dp[i][2]);

            if(i>0) chmax(dp[i+1][1],dp[i-1][0]+a[i]);
            
        }else{
            chmax(dp[i+1][0],dp[i][0]+a[i]);
            chmax(dp[i+1][1],dp[i][1]);
            chmax(dp[i+1][2],dp[i][2]+a[i]);
            
            if(i>1){
                chmax(dp[i+1][2],dp[i-2][0]+a[i]);
                chmax(dp[i+1][2],dp[i-1][1]+a[i]);
            }
        }
    }
    if(n%2){
        cout<<max({dp[n-1][0],dp[n][1],dp[n][2]})<<endl;
    }else{
        cout<<max({dp[n][0],dp[n][1]})<<endl;
    }
    return 0;
}


Measured memory_bytes: 9524
import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * @author Tran Anh Tai
 * @template for CP codes
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
    // main solver
    static class Task{
        static int MOD = 998244353;
        public void solve(InputReader in, PrintWriter out){
            int n = in.nextInt();
            int k = in.nextInt();
            int p[]=  new int[n];
            for(int i = 0; i < n; i++){
                p[i] = in.nextInt();
            }
            Arrays.sort(p);
            int r = 0;
            for (int i =0;i<k ;i++){
                r += p[i];
            }
            out.println(r);
        }
    }
    // fast input reader class;
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (line == null) {
                    return null;
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        public long nextLong(){
            return Long.parseLong(nextToken());
        }
    }
}

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

int main(void){
    int N;
    cin >> N;
    
    for(int i = 1 ; i <= 9 ; i++){
        for(int j = 1 ; j <= 9 ; j++){
            if(N == i*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"

using namespace std;

const int MAXN = 200007;
int tab[MAXN][26];

vector <int> find_points(string& x)
{
  vector <int> X;
  set <char> S;
  int n = (int)x.size();
  for(int i=0; i<n; i++)
  {
    S.insert(x[i]);
    if(S.size() == 26)
    {
      X.push_back(i);
      S.clear();
    }
  }
  return X;
}

bool exists(char letter, int a, int b)
{
  if(!a)
    return tab[b][letter-'a'];
  return tab[b][letter-'a'] != tab[a-1][letter-'a'];
}

int main()
{
  string x;
  cin >> x;
  for(int i=1; i<=(int)x.size(); i++)
    tab[i][x[i-1]-'a']++;
  for(int i=1; i<=(int)x.size(); i++)
    for(int j=0; j<26; j++)
      tab[i][j] += tab[i-1][j];
  reverse(x.begin(), x.end());
  auto rele = find_points(x);
  for(int i=0; i<(int)rele.size(); i++)
    rele[i] = (int)x.size() - rele[i];
  reverse(rele.begin(), rele.end());
  reverse(x.begin(), x.end());
  rele.push_back(x.size()+1);
  int ile = rele.size();
  int poprz = -1;
  string res = "";
  for(int i=0; i<ile; i++)
  {
    //cerr << "P" << poprz << " " << rele[i] << "\n";
    for(char e='a'; e<='z'; e++)
      if(!exists(e, poprz+1, rele[i]-1))
      {
        res += e;
        for(int j=rele[i]; j<=(int)x.size(); j++)
          if(x[j-1] == e)
          {
            poprz = j;
            break;
          }
        break;
      }
  }
  cout << res << "\n";
}


Measured memory_bytes: 20996
// Problem : B - Minor Change
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vdb vector<double>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii > 
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define bloop(i,a,b) for(int i = a;i>=b;i--)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"<<endl
#define CHECK1(a) cout<<a<<endl
#define CHECK2(a,b) cout<<a<<' '<<b<<endl;
#define br '\n'
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
using namespace std;
int mod = 1e9+7;
int inf = 1e18;
int m_inf = INT_MIN;
// int extendedgcd(int a,int b,int &x,int &y){
	// if(a == 0){
		// x = 0; y = 1;
		// return b;
	// }
	// int x1,y1;
	// int d = extendedgcd(b%a,a,x1,y1);
	// x = y1 - (b/a)*x1;y = x1;
	// return d;
// }
// int expmod(int a,int b) {
// 	if(b == 1) return a;
// 	if(b == 0) return 1;
// 	int m1 = expmod(a,b/2)%mod;
// 	if(b%2) return ((m1*m1)%mod*a%mod)%mod;
// 	return (m1*m1)%mod;
// }
// int power(int a,int b) {
// 	if(b == 1) return a;
// 	if(b == 0) return 1;
// 	int m1 = power(a,b/2);
// 	if(b%2) return m1*m1*a;
// 	return m1*m1;
// }
// int logn(int n, int r) 
// { 
//     return (n > r - 1) ? 1 + logn(n / r, r) : 0; 
// } 

// int nCr(int n,int r)
// {
	// r = min(r,n-r);
	// if(r<0)
		// return 0;
	// if(r == 0)
		// return 1;
	// int ans = 1;
	// for(int i = 1;i<=r;i++)
	// {
		// ans = ans*(n-i+1)/i;
	// }
	// return ans;
// 		
// }
// vi factmod(int n)
// {
	// vi ans(n+1);
	// ans[0] = 1;
	// loop(i,1,n+1)
	// {
		// ans[i] = (ans[i-1]*i)%mod;
	// }
	// return ans;
// }
// int nCrmod(int n,int r,vi &fact)
// {
	// int x1,y1;
	// extendedgcd(fact[r],mod,x1,y1);
	// int x2,y2;
	// extendedgcd(fact[n-r],mod,x2,y2);
	// int ans = (fact[n]*((x1+mod)%mod))%mod;
	// ans = (ans*((x2+mod)%mod))%mod;
	// return ans;
// }

// void dfs(vector<vector<int> > &adj,int root,vbool &vis)
// {
// 	vis[root] = true;
// 	for(int i = 0;i<adj[root].size();i++){
// 		int v = adj[root][i];
// 		if(!vis[v])		
// 			dfs(adj,v,vis);
// 	}
// }

int32_t main() 
{
	FastIO; PRECISION;
	int t = 1;
	// cin>>t;
	while(t--)
	{
		string s,t;
		cin>>s>>t;
		int n = s.size();
		int count = 0;
		loop(i,0,n)
		{
			if(s[i] != t[i])
				count++;
		}
		cout<<count<<'\n';
	}
}

Measured memory_bytes: 3836
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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 int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

void solve() {
	int n; cin >> n;
    vector<int> p(n * n);
    rep(i, n * n) {
        cin >> p[i];
        -- p[i];
    }
    vector<vector<int>> dist(n, vector<int>(n, inf));
    vector<vector<bool>> used(n, vector<bool>(n, 0));
    rep(i, n) {
        rep(j, n) {
            dist[i][j] = min({i , j, n - 1 - i, n - 1 - j});
        }
    }
    queue<P> que;
    int ans = 0;
    rep(i, n * n) {
        int x = p[i] / n, y = p[i] % n;
        ans += dist[x][y];
        used[x][y] = 1;
        que.push({x, y});
        while(!que.empty()) {
            P p = que.front(); que.pop();
            rep(k, 4) {
                int nx = p.fr + dx[k], ny = p.sc + dy[k];
                if(0 <= nx && nx < n && 0 <= ny && ny < n) {
                    if(used[p.fr][p.sc]) {
                        if(chmin(dist[nx][ny], dist[p.fr][p.sc])){
                            que.push({nx, ny});
                        }
                    } else {
                        if(chmin(dist[nx][ny], dist[p.fr][p.sc] + 1)){
                            que.push({nx, ny});
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 5308
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<long long int> A(n+1,0),B(n,0);
  for(int i=0;i<n+1;i++){cin >> A[i];}
  for(int i=0;i<n;i++){cin >> B[i];}
  long long int ans=0;
  for(int i=0;i<n;i++){
    if(A[i]<=B[i]){
      ans+=A[i];
      B[i]-=A[i];
      A[i]=0;
    }
    else{
      ans+=B[i];
      A[i]-=B[i];
      B[i]=0;
    }
    if(A[i+1]<=B[i]){
      ans+=A[i+1];
      B[i]-=A[i+1];
      A[i+1]=0;
    }
    else{
      ans+=B[i];
      A[i+1]-=B[i];
      B[i]=0;
    }  
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, M;
        cin >> N >> M;
        vector<vector<char>> A(N, vector<char>(N));
        vector<vector<char>> B(M, vector<char>(M));
        rep(i, 0, N) rep(j, 0, N) cin >> A[i][j];
        rep(i, 0, M) rep(j, 0, M) cin >> B[i][j];

        rep(i, 0, N-M+1) {
                rep(j, 0, N-M+1) {
                        bool flg = true;
                        rep(r, 0, M) {
                                rep(c, 0, M) {
                                        if (A[i+r][j+c] != B[r][c]) flg = false;
                                }
                        }
                        if (flg) {
                                cout << "Yes" << endl;
                                return 0;
                        }
                }
        }
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> pl;
const ll INF=100000000000000001;
const double PI=3.141592653589;


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

  ll ans=INF;
  int nn=sqrt(n);
  // cout<<nn<<endl;
  for(int i=1;i<=nn;i++){
    if(n%i==0){
      ll a=(n/i-1)+(i-1);
      ans=min(ans,a);
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
L = input().split()
L = np.array([int(l) for l in L])

l_max = np.max(L)
l_i_max = np.argmax(L)
sum = 0

for i, l in enumerate(L):
  if i == l_i_max:
    continue
  sum += l

if l_max < sum:
  print("Yes")
else:
  print("No")

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

//pdf見て回答

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

    for(int i = 1; i < b; i++){
        if(a * i % b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

// x 問解いたときの最大スコア
ll calc(const vector<pair<ll, ll>>& pc, int mid) {
  int n = pc.size();
  ll ret = 0;
  for (int bit = 0; bit < (1<<n); bit++) {  // 全問解く問題を決める
    int x = mid;
    ll score = 0;
    for (int i = 0; i < n; i++) {
      if (!((bit>>i) & 1)) continue;
      score += pc[i].first * (i+1) * 100 + pc[i].second;
      x -= pc[i].first;
    }
    if (x < 0) continue;
    for (int i = n-1; i >= 0; i--) {
      if (((bit>>i) & 1)) continue;   // 全問解いているのでパス
      if (x >= pc[i].first) {
        x -= pc[i].first;
        score += (i+1) * 100 * pc[i].first + pc[i].second;  // ここに来たときは 次の bit に進んで良いはずだけど
      } else {
        score += (i+1) * 100 * x;
        break;
      }
    }
    chmax(ret, score);
  }
  return ret;
}


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

  int d, g;
  cin >> d >> g;
  int n = 0;
  vector<pair<ll, ll>> pc;
  rep(i, d) {
    ll p, c;
    cin >> p >> c;
    n += p;
    pc.push_back({p, c});
  }

  int ub = n;
  int lb = 0;
  while (ub - lb > 1) {
    int mid = lb + (ub - lb) / 2;
    if (calc(pc, mid) >= g) ub = mid;
    else lb = mid;
  }

  cout << ub << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    ll N,M; cin >> N >> M;
    vector<ll> H(N);
    ll ans = 0;
    vector<ll> highest(N, 0);


    for (ll i = 0; i < N; ++i) {
        cin >> H[i];
    }

    for (ll j = 0; j < M; ++j) {
        ll A, B;
        cin >> A >> B;
        highest[A-1] = max(highest[A-1], H[B-1]);
        highest[B-1] = max(highest[B-1], H[A-1]);
    }

    for (int k = 0; k < N; ++k) {
        if(highest[k]<H[k])ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4844