akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll n,m,l;

int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n>>m>>l;
	
	ll adj[n][n];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			adj[i][j] = (i==j)?0:1e13;
	
	
	for(int i=0;i<m;i++)
	{
		ll a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		adj[a][b]=adj[b][a]=c;
	}
	
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
			}
		}
	}
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			adj[i][j] = adj[i][j]<=l?1:1e13;
			if(i==j)
				adj[i][j]=0;
		}
	}
	
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
			}
		}
	}
	
	int q;
	cin>>q;
	
	while(q--)
	{
		int s,t;
		cin>>s>>t;
		s--,t--;
		ll ans = adj[s][t];
		
		if(ans>=1e13)
			cout<<-1<<"\n";
		else
			cout<<(ans-1)<<"\n";
	}
	
}

Measured memory_bytes: 1280
#include<cstdio>
int main(void){
	int n;
	int a;
	scanf("%d", &n);
	for (int i = 1; i<=n+1; i++){
		if (2 * n<i*(i + 1)){
			a = n - (i*(i - 1) / 2);
			for (int j = 1; j<i; j++){
				if (j>i - a - 1)printf("%d\n", j + 1);
				else printf("%d\n", j);
			}
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
   
    int cnt = 0;
    FOR(i,1,N+1) {
        if (i % 2 == 0) continue;

        int num = 0;
        FOR(j,1,i+1) {
            if (i%j == 0) num++;
        }
        if (num == 8) cnt++;
    }

    int ans = cnt;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())

a = list(map(int,input().split()))

c_sum_left = [0]
total = 0
for i in range(N):
    c_sum_left += [c_sum_left[i] + a[i]]
    total += abs(a[i])

c_sum_right = [0]
for i in range(N):
    c_sum_right += [c_sum_right[i] + a[N-i-1]]


ans = total
for i in range(1, N):
    # print (c_sum_left[i], c_sum_right[N-i])
    ans = min(ans, abs(c_sum_left[i] - c_sum_right[N-i]))
print (ans)


Measured memory_bytes: 28532
use v5.18;
use warnings;
use List::Util qw ( sum );
sub read_line { chomp(my $str = <STDIN>); $str }
sub splited_read_line { split / /, read_line }

my $n = read_line;
my @nums = splited_read_line;
my @abss = do {
  my $i = 1;
  map { $_ - $i++ } @nums;
};

# 中央値
my @sorted = sort { $a <=> $b} @abss;
my $median = $sorted[int($n / 2)];

my $i = 1;
say sum map { abs($_ - ($median + $i++)) } @nums;


Measured memory_bytes: 46872
import collections
import itertools

n = int(input())
l = [input() for _ in [0] * n]

counter = collections.Counter(l)

a = counter.most_common()[0][-1]
b = itertools.takewhile(
    lambda kv: kv[-1] == a, counter.most_common()
)

c = sorted(list(k for k, v in b))
print(*c,sep='\n')




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

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define REPR(i, n) for(ll i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)

#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())

#define ll long long
#define ALL(a)  (a).begin(),(a).end()

#define pb(a) push_back(a)

int n,m;




int main(){
  int ans=0;
  cin >> n >> m;
  ans=(n*3+m)/2;
  cout<<(ans)<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int n,ans=0;
void dfs(ll val,int flag){
    if(val > n) return;
    if(flag == 7) ans++;
    dfs(10*val+3,flag|1);
    dfs(10*val+5,flag|(1<<1));
    dfs(10*val+7,flag|(1<<2));
    return;
}


int main(){
    scanf("%d", &n);
    dfs(0,0);
    printf("%d\n", ans);
}

Measured memory_bytes: 1688
<?php

function input() {
    return trim(fgets(STDIN));
}
function input_array() {
    return explode(' ', input());
}

$M = 1046527;

// $H = array_fill(0, $M, '');
$H = [];

function getChar($ch) {
    switch ($ch) {
        case 'A':
            return 1;
        case 'C':
            return 2;
        case 'G':
            return 3;
        case 'T':
            return 4;
        default:
            return 0;
    }
}

function getKey($str) {
    $sum = 0;
    $p = 1;
    for ($i = 0, $count = strlen($str); $i < $count; $i++) {
        $sum += $p * getChar($str[$i]);
        $p *= 5;
    }
    return $sum;
}

function h1($key) {
    global $M;
    return $key % $M;
}
function h2($key) {
    global $M;
    return 1 + ($key % ($M - 1));
}

function find($str) {
    global $M, $H;
    $key = getKey($str);
    for ($i = 0;; $i++) {
        $h = (h1($key) + $i * h2($key)) % $M;
        if (isset($H[$h]) && $H[$h] === $str) return 1;
        else if (!isset($H[$h])) return 0;
    }
    return 0;
}

function insert($str) {
    global $M, $H;
    $key = getKey($str);
    for ($i = 0;; $i++) {
        $h = (h1($key) + $i * h2($key)) % $M;
        if (isset($H[$h]) && $H[$h] === $str) return 1;
        else if (!isset($H[$h])) {
            $H[$h] = $str;
            return 0;
        }
    }
    return 0;
}

$n = input();
for ($i = 0; $i < $n; $i++) {
    $command = input_array();
    switch ($command[0]) {
        case 'insert':
            insert($command[1]);
            break;
        case 'find':
            if (find($command[1])) {
                echo "yes\n";
            } else {
                echo "no\n";
            }
            break;
        default:
            break;
    }
}


Measured memory_bytes: 59348
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, w = ns()
    a = [na() for _ in range(n)]

    dp = [-1 for _ in range(w + 1)]
    dp[0] = 0

    for wi, vi in a:
        for i in range(w - 1, -1, -1):
            if i + wi <= w and dp[i] > -1:
                dp[i + wi] = max(dp[i + wi], dp[i] + vi)

    print(max(dp))


if __name__ == '__main__':
    main()


Measured memory_bytes: 83876
# -*- coding: utf-8 -*-
n,m,x = list(map(int,input().split()))
c = [list(map(int,input().split())) for i in range(n)]
inf=float("inf")
ret = inf
#デカルト積。ネストしたforループと等価
from itertools import product
for flg_list in list(product([0,1],repeat=n)):
    rikaido_list = [0] * m
    cost = 0
    flg = True
    for i,v in enumerate(flg_list):
        if v == 1:
            cost += c[i][0]
            rikaido_list = [i+j for i,j in zip(rikaido_list,c[i][1::])]
    for i in rikaido_list:
        if i < x:
            flg = False
            break
    if flg:
        ret = min(ret,cost)

from math import isinf
if isinf(ret):
    print(-1)
else:
    print(ret)

Measured memory_bytes: 9648
#include <iostream>
#include <vector>

using namespace std;
using vi = vector<int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

const bool LOSE = false, WIN = true;
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  IN(N); IN(K);

  vi A(N);
  REP(i, N)
    cin >> A[i];
  // dp[i] = 先手が残りi個のときにどちらが勝つか(dp[0]のときの勝者かどうか)
  vector<bool> dp(K+1, LOSE);
  REP(i, K+1) {
    bool win = false;
    REP(j, N) {
      if (i - A[j] >= 0 && dp[i-A[j]] == LOSE) {
        // 相手に負ける手番を渡すことができる
        win = true;
      }
    }
    dp[i] = win;
  }
  OUT((dp[K] ? "First" : "Second"));
  // OUT(dp[K]);


  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES  // M_PI等のフラグ

#include <iostream>
#include <bitset>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <list>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;


void solve(){
    string s;
    cin >> s;

    for (int bit=0; bit<(1<<3); bit++) {
        string ans = s.substr(0,1);
        int result = s.at(0) - '0';

        for (int i=0; i<3; i++) {
            if (bit>>i&1) {
                // iビット目が1なら+演算する
                result += s.at(i+1)-'0';
                ans += "+";
            }
            else {
                // iビット目が0なら-演算する
                result -= s.at(i+1)-'0';
                ans += "-";
            }
            ans.push_back(s.at(i+1));
        }

        if (result == 7) {
            cout << ans << "=7" << endl;
            return;
        }
    }
}

int main(int argc, char const *argv[]){
    solve();
    return 0;
}

Measured memory_bytes: 3556
#include <stdio.h>

int main(){
    int h, w;
    int i, j;
    while(1){
        scanf("%d %d ", &h, &w);
        if(h==0&&w==0)break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2044
n=int(input())

import heapq
a=[]
a_heap=[]
for i in range(n):
    tmp=int(input())
    a.append(tmp)
    heapq.heappush(a_heap,(-1)*tmp)

for i in range(n):
    max_1=heapq.heappop(a_heap)
    if max_1==(-1)*a[i]:
        max_2=heapq.heappop(a_heap)
        print((-1)*max_2)
        heapq.heappush(a_heap,max_2)
    else:print((-1)*max_1)
    heapq.heappush(a_heap,max_1)

Measured memory_bytes: 102908
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

vvint g;
map<int,int> memo;

int dfs(int v) {
    if (memo.count(v)) return memo[v];
    int res = 0;
    for (int n_v : g[v]) chmax(res,dfs(n_v)+1);
    return memo[v] = res;
}

int main() {
    int n, m; cin >> n >> m;
    g.resize(n);
    rep(i,m) {
        int x, y; cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
    }
    int ans = 0;
    rep(i,n) ans = max(ans,dfs(i));
    cout << ans << endl;
}

Measured memory_bytes: 13824
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
	int q;
	while(cin>>q&&q!=-1){
		double x=q/2.0;
		while(fabs(x*x*x-q)>=0.00001*q)x-=(x*x*x-q)/(3*x*x);
		printf("%.6f\n", x);
	} 
	return 0;
}

Measured memory_bytes: 1192
#include <stdio.h>

void insertionSort(int *A, int N)
{
	int i, j, k, v;

	for (i = 0; i < N; i++) {
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		for (k = 0; k < N; k++) {
			printf(k != 0 ? " %d" : "%d", A[k]);
		}
		puts("");
	}
}


int main(void)
{
	int N, A[1000], i;

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	insertionSort(A, N);

	return 0;
}



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

int main() {
    long long N;
    cin >> N;
    long long ans = 0;
    map<int,int> mp;
    for (long long i = 0;i<N;i++) {
        long long a;
        cin >> a;
        if (mp[a] == 1) {
            mp[a] = 0;
            ans--;
        } 
        else {
            mp[a] = 1;
            ans++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n; cin >> n;
  vector<int> p(n), q(n);
  for (int i = 0; i < n; ++i) cin >> p[i];
  for (int i = 0; i < n; ++i) cin >> q[i];
  vector<int> cmp(n);
  iota(cmp.begin(), cmp.end(), 1);
  int P,Q;
  int i = 1;
  do {
    if (cmp == p) {
      P = i;
    }
    if (cmp == q) {
      Q = i;
    }
    i++;
  } while (next_permutation(cmp.begin(), cmp.end()));
  cout << abs(P-Q) << nl;
  return 0;
}



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

int bit[100001], n;
int sum(int i) {
	int s = 0;
	while (i > 0) {
		s += bit[i];
		i -= i&-i;
	}
	return s;
}
void add(int i, int x) {
	while (i <= n) {
		bit[i] += x;
		i += i&-i;
	}
}
int main() {
	int q; scanf("%d%d", &n, &q);
	rep(i, q) {
		int com, x, y; scanf("%d%d%d", &com, &x, &y);
		if (com) printf("%d\n", sum(y) - sum(x - 1));
		else add(x, y);
	}
}

Measured memory_bytes: 3588
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x1: i64,
        y1: i64,
        x2: i64,
        y2: i64,
    }
    let vx12 = x2 - x1;
    let vy12 = y2 - y1;
    let vx23 = -vy12;
    let vy23 = vx12;
    let vx34 = -vy23;
    let vy34 = vx23;
    let x3 = x2 + vx23;
    let y3 = y2 + vy23;
    let x4 = x3 + vx34;
    let y4 = y3 + vy34;
    println!("{} {} {} {}", x3, y3, x4, y4);
}


Measured memory_bytes: 4352
n,k=map(int, input().split())
h=[int(input()) for i in range(n)]
h_sorted=sorted(h)
ans=h_sorted[k-1]-h_sorted[0]
for i in range(n-k+1):
    dh=h_sorted[k+i-1]-h_sorted[i]
    if ans>dh:
        ans=dh
print(ans)

Measured memory_bytes: 8280
#include <bits/stdc++.h>
using namespace std;
const long long MOD=1e9+7;
int main(){
  	long long N,K,a=0,b=0;
  	cin>>N>>K;
  	vector<long long> A(N);
  	unordered_map<long long,long long> mp;
  	for(long long i=0;i<N;i++){
      	cin>>A.at(i);
    }
  	for(long long i=0;i<N;i++){
      	mp[A.at(i)]++;
      	for(long long j=A.at(i)+1;j<=2000;j++){
          	if(mp[j]>0){
              	a+=mp[j];
            }
        }
    }
  	for(long long i=0;i<N;i++){
      	for(long long j=A.at(i)+1;j<=2000;j++){
          	if(mp[j]>0){
              	b+=mp[j];
            }
        }
    }
    long long ans;
    if(K%2==0){
      	ans=a*K%MOD+(K/2)*(K-1)%MOD*b%MOD;
      	ans%=MOD;
    }
  	else{
      	ans=a*K%MOD+(K*((K-1)/2)%MOD)*b%MOD;
      	ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n;cin>>n;
    string s;
    vector<pair<char,ll>> v(5);
    vector<char> c={'M','A','R','C','H'};
    REP(i,5){
        v[i].first=c[i];
    }
    REP(i,n){
        cin>>s;
        char ini=s[0];
        REP(j,5){
            if(v[j].first==ini){
                v[j].second++;
                break;
            }
        }
    }
    ll sum=0;
    REP(i,3){
        ll a=v[i].second;
        FOR(j,i+1,4){
            ll b=v[j].second;
            FOR(k,j+1,5){
                ll c=v[k].second;
                sum+=a*b*c;
            }
        }
    }
    cout<<sum;
    return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) { os << p.first << " " << p.second; return os; }

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
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 (a > b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int a, b, c; cin >> a >> b >> c;
	if (a > b)swap(a, b);
	Yes(a <= c and c <= b);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

// BEGIN CUT HERE
int scc(const VV<>& g, V<>& comp) {
  int n = g.size();
  VV<> rg(n);
  for (int v = 0; v < n; v++) for (int w : g[v]) {
    rg[w].push_back(v);
  }
  V<> vs;
  V<bool> vis(n);
  comp.resize(n);
  auto dfs = [&](const auto& dfs, int v) -> void {
    vis[v] = true;
    for (int w : g[v]) if (!vis[w]) {
      dfs(dfs, w);
    }
    vs.push_back(v);
  };
  auto rdfs = [&](const auto& rdfs, int v, int k) -> void {
    vis[v] = true;
    comp[v] = k;
    for (int w : rg[v]) if (!vis[w]) {
      rdfs(rdfs, w, k);
    }
  };
  for (int v = 0; v < n; v++) if (!vis[v]) {
    dfs(dfs, v);
  }
  vis.assign(n, false);
  int k = 0;
  reverse(begin(vs), end(vs));
  for (int v : vs) if (!vis[v]) {
    rdfs(rdfs, v, k++);
  }
  return k;
}
// END CUT HERE

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  VV<> g(n);
  while (m--) {
    int s, t; cin >> s >> t;
    g[s].push_back(t);
  }
  V<> comp;
  scc(g, comp);
  int q; cin >> q;
  while (q--) {
    int u, v; cin >> u >> v;
    cout << (comp[u] == comp[v]) << '\n';
  }
}


Measured memory_bytes: 4476
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] ans = new long[m];
        long inc = (long)n*(n-1)/2;
        ans[m-1] = inc;
        Bridge[] bridges = new Bridge[m];
        for(int i=0;i<m;i++){
            bridges[i] = new Bridge(sc.nextInt()-1,sc.nextInt()-1);
        }
        UnionFind uf = new UnionFind(n);
        for(int i=m-1;i>0;){
            Bridge br = bridges[i];
            inc -= uf.inc(br);
            uf.unite(br);
            ans[--i] = inc;
        }
        for(int i=0;i<m;i++){
            System.out.println(ans[i]);
        }
    }
}

class Bridge{
    private int a;
    private int b;
    Bridge(int a, int b){
        this.a = a;
        this.b = b;
    }
    int getA(){return a;}
    int getB(){return b;}
}

class UnionFind{
    private int[] pares;
    private int[] ranks;
    private long[] sizes;
    UnionFind(int n){
        this.pares = new int[n];
        this.ranks = new int[n];
        this.sizes = new long[n];
        for(int i=0;i<n;i++){
            this.pares[i] = i;
            this.ranks[i] = 0;
            this.sizes[i] = 1L;
        }
    }

    void unite(Bridge bridge){
        int a = bridge.getA();
        int b = bridge.getB();
        int ar = root(pares[a]);
        int br = root(pares[b]);
        if(ranks[ar]>ranks[br]){
            pares[br] = ar;
            sizes[ar] += sizes[br];
        }else if(ranks[br]>ranks[ar]){
            pares[ar] = br;
            sizes[br] += sizes[ar];
        }else if(ar != br){
            pares[br] = ar;
            sizes[ar] += sizes[br];
            ranks[ar] ++;
        }
    }

    long inc(Bridge bridge){
        int a = bridge.getA();
        int b = bridge.getB();
        int ar = root(a);
        int br = root(b);
        if(ar!=br){
            return sizes[ar]*sizes[br];
        }else{
            return 0;
        }
    }

    private int root(int a){
        if(pares[a]==a){
            return a;
        }else{
            pares[a]=root(pares[a]);
            return pares[a];
        }
    }
}

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

int main(){

    int n,l;
    cin>>n;
    int maxi=0,sum=0;
    for(int i=0;i<n;i++){
        cin>>l;
        sum+=l;
        maxi=max(maxi,l);
    }

    cout<<(maxi<sum-maxi?"Yes":"No")<<endl;


    return 0;
}

Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

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

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}




int main(){

    ios_base::sync_with_stdio(0);

    string str;
    cin>>str;

    int start_len = (int)str.length()%2;
    int end_len = (str[0] == str[(int)str.length()-1] ? 1 : 0);

    if(start_len != end_len){
    	//odd number of moves
    	cout<<"First";
    }
    else{
    	cout<<"Second";
    }

    return 0;
}









Measured memory_bytes: 512
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# 1 2 3
# a, b, c = LI()


def I(): return int(sys.stdin.buffer.readline())
# a = I()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# abc def
# a, b = LS()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# a = S()


def IR(n): return [I() for i in range(n)]
# 2
# 1
# 2
# [1, 2]


def LIR(n): return [LI() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def SR(n): return [S() for i in range(n)]
# 2
# abc
# def
# [abc, def]


def LSR(n): return [LS() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def SRL(n): return [list(S()) for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


k = I()
print("ACL"*k)


Measured memory_bytes: 67896
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) std::cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) std::cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) std::cout << x << endl;
#define println(x) std::cout << x << endl;
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
const ll INF = 1e18;
using namespace std;
// using namespace atcoder;

ll mpow(ll x, ll n, ll mod){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

vector<ll> fact;

void calcFact(ll n, ll mod) {
    fact.assign(n+1, 1);
    repi(i, n+1) {
        fact[i] = fact[i-1] * i % mod;
    }
}

// with calcFact()
ll combination(ll n, ll a, ll mod) {
    if (n < a) {
        return 0;
    }

    ll X = fact[n];
    ll Y = fact[a];
    ll Z = fact[n-a];
    ll iY = mpow(Y, mod - 2, mod);
    ll iZ = mpow(Z, mod - 2, mod);

    ll res = X * iY % mod;
    res = res * iZ % mod;

    return res;
}


void Main()
{
    ll n, M, K;
    cin >> n >> M >> K;

    ll mod = 998244353;
    calcFact(n, mod);

    vector<ll> powM(n+1);
    powM[0] = 1;
    rep(i, n) powM[i+1] = powM[i] * (M-1) % mod;

    ll res = 0;
    rep(i, K+1) {
        ll v = combination(n-1, i, mod) * powM[n-i-1] % mod;
        v = v * M % mod;
        res += v;
        res %= mod;
    }
    put(res);
}
signed main(){ Main();return 0;}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int sum = 0;
  if(K > A){
    sum += A;
    K -= A;
  } else{
    sum = K;
    K = 0;
  }
  if(K > 0){
    if(K > B){
      K -= B;
    } else{
      K = 0;
    }
  }
  if(K > 0){
    sum -= K;
  }
  cout << sum <<endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <typeinfo>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;


long long dp[100001][3];


int main() {
    // inputs
    int N;
    cin >> N;

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

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for (int i = 1; i < N; i++) {
        dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][1], dp[i-1][0]);
    }

    cout << max(max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]) << endl;

    return 0;
}



Measured memory_bytes: 3712
#include <stdio.h>

int has7(int v);

int main(void) {
    int v, flg;
  
      scanf("%d", &v);
  
      flg = has7(v);
  
      if(flg) {
        printf("Yes\n");
    }else{
        printf("No\n");
    }
  
    return 0;
}

int has7(int v) {
      int i;
    for(i=0; i<3; i++) {
      if(v%10==7) {
          return 1;
      }
      v = v/10;
    }
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
bool keta(int n, set<int> d){
  while(n){
    if(d.count(n%10)) return false;
    else n /=10;
  }
  return true;
}
int main(){
  int n,k; cin >> n >> k;
  set<int>d;
  for(int i = 0; i < k; i++){
    int a; cin >> a;
    d.insert(a);
  }
  for(int i = n; ; i++){
    if(keta(i, d)){
      cout << i;
      return 0;
    }
  }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")

using namespace std;

const int N = 2777;
int n, m;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    n *= 500;
    if (n >= m){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int N;
    cin >> N;
    queue<int> A;
    int Amax, Amin;
    priority_queue<int, vector<int>, greater<int>> ans;
    set<int> num;
    rep(i, N) {
        int a;
        cin >> a;
        if (i == 0) {
            Amax = a;
            Amin = a;
        }
        else {
            Amax = max(a, Amax);
            Amin = min(a, Amin);
        }
        A.push(a);
        num.insert(a);
    }
    rep2(n, Amin, Amax+1) {
        ll res = 0;
        rep(i, N) {
            int a = A.front();
            A.pop();
            res += (n-a)*(n-a);
            A.push(a);
        }
        ans.push(res);
    }
    cout << ans.top() << endl;
}

Measured memory_bytes: 256
def solve():
    pipes = [[0 for _ in range(6)]]
    pipes.extend([list(map(int, '0{0}0'.format(input()))) for _ in range(9)])
    pipes.extend([[0 for _ in range(6)]])
    last_dirction = 2
    x, y = 1, 1
    while True:
        next_direction = (last_dirction - 1) % 4
        while True:
            if next_direction == 0:
                nx, ny = x, 2*y - 2
                if pipes[ny][nx] == 1:
                    print('U', end='')
                    x, y = x, y - 1
                    break
            elif next_direction == 1:
                nx, ny = x, 2*y - 1
                if pipes[ny][nx] == 1:
                    print('R', end='')
                    x, y = x + 1, y
                    break
            elif next_direction == 2:
                nx, ny = x, 2*y
                if pipes[ny][nx] == 1:
                    print('D', end='')
                    x, y = x, y + 1
                    break
            else:
                nx, ny = x - 1, 2*y - 1
                if pipes[ny][nx] == 1:
                    print('L', end='')
                    x, y = x - 1, y
                    break
            next_direction = (next_direction + 1) % 4
        last_dirction = next_direction
        if x == 1 and y == 1:
            print()
            break

if __name__ == "__main__":
    solve()



Measured memory_bytes: 5616
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;cin>>n>>m;
	string s;

	cout << (n+m-1)/m<< endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int x,n,i,j,s,c,k=0,min=1000;
        scanf("%d%d",&x,&n);
        int p[n];
        for(i=0;i<n;i++)
                scanf("%d",&p[i]);

        c=100;
        for(i=0;i<=101;i++){
                k=0;
                for(j=0;j<n;j++)
                        if(p[j]==i) k=1;
                if(k!=1){
                        if(x>i) s=x-i;
                        else s=i-x;
                        if(min>s) { min=s; c=i;}
                        else if(min==s && c>i) c=i;
                }
        }
        printf("%d\n",c);
        return 0;
}


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

#define ubuntu ios_base::sync_with_stdio, cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define mp make_pair
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()

const long long MXN = 3e6 + 1;
const long long MNN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef long double ldub;
typedef unsigned long long ullong;

using namespace std;

llong a , b , x;

int main(){
    ubuntu;
    ///freopen("in.in", "r", stdin);
    ///freopen("out.out", "w", stdout);
    cin >> x >> a >> b;
    x -= a;
    while (x >= b){
        x -= b;
    }cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
	int n[1000],i=0,cnt=0,j;
	while(1){
		cin>>n[i];
		if(n[i]==0) break;
		n[i]=1000-n[i];
		if(n[i]>=500){n[i]-=500; cnt+=1;}
		for(j=0;j<4;j++){if(n[i]>=100){n[i]-=100; cnt+=1;}}
		if(n[i]>=50){n[i]-=50; cnt+=1;}
		for(j=0;j<4;j++){if(n[i]>=10){n[i]-=10; cnt+=1;}}
		if(n[i]>=5){n[i]-=5; cnt+=1;}
		for(j=0;j<4;j++){if(n[i]>=1){n[i]-=1; cnt+=1;}}
		i+=1;
		cout<<cnt<<endl;
		cnt=0;
	}
	return 0;
}


Measured memory_bytes: 3052
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#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
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int x;
    cin>>x;
    if(x==1) cout<<0<<endl;
    else cout<<1<<endl;
}/*
./problem.exe
*/

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

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

  while(1)
  {
      c = c - b;
      if(c<=0)
      {
          cout<<"Yes";
          break;
      }
      a = a - d;
      if(a<=0)
      {
          cout<<"No";
          break;
      }

  }
  return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>

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

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    ll sum = 0;
    ll m = 0;
    rep(i,n){
        m = max(m,a[i]);
        sum += max(0ll,m-a[i]);
    }
    cout << sum << endl;
}

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

int a[50000], b[50000], to[50000];

int main() {
//#ifdef whyqx
//    freopen("work.in", "r", stdin);
//    freopen("work.out", "w", stdout);
//#endif
    int n, K;
    cin >> n >> K;
    if (K > (n - 1) * (n - 2) / 2) {
        cout << -1;
        return 0;
    }
    int cnt = 0;
    for (int i = 2; i <= n; ++i)
        a[++cnt] = 1, b[cnt] = i;
    int now = 2; to[now] = now;
    for (int i = K + 1; i <= (n - 1) * (n - 2) / 2; ++i) {
        if (to[now] >= n) ++now, to[now] = now;
        ++to[now];
        a[++cnt] = now, b[cnt] = to[now];
    }
    cout << cnt << endl;
    for (int i = 1; i <= cnt; ++i)
        printf("%d %d\n", a[i], b[i]);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = input()
B = input()
C = input()

x = 0
for i in range(N):
    if A[i] != B[i] and B[i] != C[i] and C[i] != A[i]:
        x += 2
    elif A[i] == B[i] and B[i] != C[i] and C[i] != A[i]:
        x += 1
    elif A[i] != B[i] and B[i] == C[i] and C[i] != A[i]:
        x += 1
    elif A[i] != B[i] and B[i] != C[i] and C[i] == A[i]:
        x += 1

print(x)


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <memory.h>
#include <functional>
#include <string.h>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int,int> pi; 
typedef double db;

const int mod=1e9+7;
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
#define MP make_pair
#define FF first
#define SS second
#define LB lower_bound
#define UB upper_bound
#define PB push_back
#define lc ((p<<1)+1)
#define rc ((p<<1)+2)
#define rep(i,n) for(int i=1;i<=n;i++)
#define rep0(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n;i;i--)
#define rrep0(i,n) for(int i=n-1;i>=0;i--)
#define forw(v) (v).begin(),(v).end()

/*
 * high precision: printf("%.12lf",(db)ans);
 *
 * clear output buffer: fflush(stdout);
 *
 * sync off: ios::sync_with_stdio(false);
 *
 */

const int Maxn=705;

int n,m;
bool edge[Maxn][Maxn];
int color[Maxn];
bool used[Maxn];
bool cnt[Maxn];

pi dfs(int now)
{
	used[now]=true;
	pi ret=pi(1,0);
	for(int i=1;i<=n;i++)
	{
		if(edge[now][i])
		{
			if(color[i]==-1)
			{
				color[i]=(color[now]^1);
				pi nex=dfs(i);
				if(nex==pi(-1,-1)) return pi(-1,-1);
				ret.FF+=nex.SS;
				ret.SS+=nex.FF;
			}
			else if(color[i]==color[now])
			{
				return pi(-1,-1);
			}
		}
	}
	return ret;
}

int main()
{
	scanf("%d%d",&n,&m);
	memset(edge,true,sizeof edge);
	memset(color,-1,sizeof color);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u][v]=edge[v][u]=false;
	}
	for(int i=1;i<=n;i++)
	{
		edge[i][i]=false;
	}
	cnt[0]=true;
	for(int i=1;i<=n;i++)
	{
		if(color[i]==-1)
		{
			color[i]=0;
			pi p=dfs(i);
			if(p==pi(-1,-1))
			{
				printf("-1\n");
				return 0;
			}
			for(int i=n;i>=0;i--)
			{
				if(cnt[i])
				{
					cnt[i]=false;
					cnt[i+p.FF]=true;
					cnt[i+p.SS]=true;
				}
			}
		}
	}
	int ans=Maxn*Maxn;
	for(int i=1;i<=n;i++)
	{
		if(cnt[i])
		{
			ans=min(ans,(i*(i-1)+(n-i)*(n-i-1))/2);
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
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;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

ll A, B, K;

int main(){
    cin >> A >> B >> K;
    if(K>=A){
        K-=A;
        A=0;
        if(K>=B)
        {
            B=0;
        }
        else
        {
            B=B-K;
        }
    }
    else {
        A=A-K;
    }
    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
 
 
def dfs(field):
    q = deque([(0, 0, 0)])
    visited = [[False] * w for _ in range(h)]
    while q:
        i, j, d = q.popleft()
        if i == h - 1 and j == w - 1:
            return d
        if visited[i][j]:
            continue
        visited[i][j] = True
        if i > 0 and field[i - 1][j] == '.':
            q.append((i - 1, j, d + 1))
        if i < h - 1 and field[i + 1][j] == '.':
            q.append((i + 1, j, d + 1))
        if j > 0 and field[i][j - 1] == '.':
            q.append((i, j - 1, d + 1))
        if j < w - 1 and field[i][j + 1] == '.':
            q.append((i, j + 1, d + 1))
    else:
        return -1
 
 
h, w = map(int, input().split())
field = [input() for _ in range(h)]
dot_cnt = sum(r.count('.') for r in field)
d = dfs(field)
if d == -1:
    print(-1)
else:
    print(dot_cnt - (d+1))

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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=b&&a<=c){
       if(b<=c) cout<<a<<" "<<b<<" "<<c<<endl;
       else cout<<a<<" "<<c<<" "<<b<<endl;
    }
    else if(b<=c&&b<=a){
       if(a<=c) cout<<b<<" "<<a<<" "<<c<<endl;
       else cout<<b<<" "<<c<<" "<<a<<endl;
    }
    else{
       if(a>=b) cout<<c<<" "<<b<<" "<<a<<endl;
       else cout<<c<<" "<<a<<" "<<b<<endl;
         }

    return 0;
}


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

typedef long long ll;

#define PB push_back
#define MP make_pair

ll findGCD(ll a, ll b) {
    if (a == 0) return b;
    return findGCD(b % a, a);
}

ll findLCM(ll a, ll b) 
{ 
    return (a * b) / findGCD(a, b);
} 

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll dc = (b / c) - (a / c);
    ll dd = (b / d) - (a / d);
    if (a % c == 0) ++dc;
    if (a % d == 0) ++dd;
    ll dboth = (b / findLCM(c, d)) - (a / findLCM(c, d));
    if (a % findLCM(c, d) == 0) ++dboth;
    ll ans = b - a + 1 - dc - dd + dboth;
    cout << ans << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
n = int(input())
maxv = n*(n-1)//2
to = [[] for _ in range(maxv)]
vid = [[-1]*n for _ in range(n)]
def toId(i,j):
    if i > j: i,j = j,i
    return vid[i][j]
    
visited = [False]*maxv
calculated = [False]*maxv
dp = [0]*maxv
def dfs(v):
    if visited[v]:
        if not calculated[v]: return -1
        return dp[v]
    visited[v] = True
    dp[v] = 1
    for u in to[v]:
        res = dfs(u)
        if res == -1: return -1
        dp[v] = max(dp[v], res+1)
    calculated[v] = True
    return dp[v]

a = [[int(i)-1 for i in input().split()] for _ in range(n)]
v = 0
for i in range(n):
    for j in range(i+1,n):
        vid[i][j] = v
        v += 1
for i in range(n):
    for j in range(n-1): a[i][j] = toId(i,a[i][j])
    for j in range(n-2): to[a[i][j+1]].append(a[i][j])
ans = 0
for i in range(maxv):
    res = dfs(i)
    if res == -1:
        print(-1)
        exit()
    ans = max(ans, res)
print(ans)

Measured memory_bytes: 222028
#include <stdio.h>

int main(void){
  int a, b, i, ans;
  scanf("%d", &a);
  scanf("%d", &b);
  //aでもbでもない数
  for(i=1; i<3+1; i++){
    if(i!=a && i!=b){
      ans = i;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>

#define ll long long
#define db double
#define ull unsigned long long
#define uint unsigned int
#define FIO ""
#define dbug(...) fprintf(stderr, __VA_ARGS__)

template <typename Y> inline bool updmin(Y &a, Y b){if (a > b) {a = b; return 1;} return 0;}
template <typename Y> inline bool updmax(Y &a, Y b){if (a < b) {a = b; return 1;} return 0;}
template <typename Y> inline Y abs(Y a){if (a < 0) a = -a; return a;}
template <typename Y> inline Y sqr(Y a){return a * a;}

typedef std::pair<int, int> par;
#define fx first
#define fy second
#define mpar std::make_pair
#define pb push_back

int read() {
  int w = 1, q = 0, ch = ' ';
  for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') w = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) q = q * 10 + ch - 48;
  return q * w;
}

inline void FileIO(){freopen(FIO".in", "r", stdin); freopen(FIO".out", "w", stdout);}

#include <cstring>
const int N = 100010, mod = 1000000007;
char s[N];
int g[N], f[N], n, sum[N];

int main() {
  scanf("%s", s + 1);
  n = (int)strlen(s + 1);
  g[n + 1] = n + 1;
  sum[n + 1] = 0;
  for (int i = n; i; i--) {
    g[i] = s[i] == s[i + 1] ? i + 1 : g[i + 1];
    sum[i] = (sum[i + 1] + s[i] - 'a' + 1) % 3;
  }
  if (g[1] == n + 1) {
    puts("1");
    return 0;
  }
  f[0] = 1;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (i && sum[i + 1] == 0) {
      ans = (ans + f[i]) % mod;
    }
    f[i + 1] = (f[i + 1] + f[i]) % mod;
    f[g[i + 1]] = (f[g[i + 1]] + f[i]) % mod;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1408