akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

int n, m, q;
int ans = 0;
int a[50], b[50], c[50], d[50];

void dfs(int num[], int t){
    if(t == n){
        // rep(i, n) cout << num[i] << " ";
        // cout << endl;
        int sm = 0;
        for (int i = 0; i < q; i++){
            if(num[b[i]] - num[a[i]] == c[i]){
                sm += d[i];
            }
        }
        ans = max(ans, sm);
        return;
    }

    int num1[n];
    rep(i, n) num1[i] = num[i];
    for (int i = num[t-1]; i <= m; i++){
        num1[t] = i;
        dfs(num1, t + 1);
    }
    
}


int main(){
    
    cin >> n >> m >> q;
    rep(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    
    int num[n];
    rep(i, n) num[i] = 1;
    for (int i = 1; i <= m; i++){
        num[0] = i;
        dfs(num, 1);
    }
    
    
    cout << ans << endl;
}


Measured memory_bytes: 3632
k,x = map(int,input().split())
c = [str(x)]
for y in range(k):
  if k == 1:
    break
  elif y == 0:
    continue
  else:
    if x+y < 1000000:
      c.append(str(x+y))
    if x-y > -1000000:
      c.insert(0,str(x-y))
print(' '.join(c))


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

ll N;

void dfs(string s, char c) {
    if(s.size() == N) {
        cout << s << endl;
    } else {
        for(char i = 'a';i <= c;i++) dfs(s + i, (c == i ? min((char)(i + 1), 'z') : c));
    }
}

int main(void) {
    cin >> N;
    dfs("", 'a');
    return 0;
}


Measured memory_bytes: 1536
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
S = gets.chomp

def check_double(str1, str2)
  (str1.split('').to_set & str2.split('').to_set).length
end

test = (S.length-1).times.map do |i|
  str1 = S[0..i]
  str2 = S[i+1..]
  check_double(str1, str2)
end
puts test.max


Measured memory_bytes: 14540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
  return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
  template <class C>
  static char test(typename C::const_iterator*);
  template <class C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o, const C& c) {
  o << '[';
  for (auto it = c.begin(); it != c.end();)
      o << *it << (++it != c.end() ? ", " : "");
  return o << ']';
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
  return o << '(' << p.fi << ", " << p.se << ')';
}

void solve() {
  ll a, b, v, w, t;
  cin >> a >> v >> b >> w >> t;
  cout << (abs(b - a) <= t * max(0ll, v - w) ? "YES" : "NO") << endl;
}

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

  int tt = 1;
  FOR (t, 1, tt + 1) {
      // cout << "Case #" << t << ": ";
      solve();
  }

  return 0;
}


Measured memory_bytes: 3652
import sys
ab=input().rstrip().split(" ")
a=int(ab[0])
b=int(ab[1])
if a>=b:
    l=a
    s=b
elif a<b:
    l=b
    s=a
for i in range(1,s+1):
    u=i*l
    if u%s==0:
        ans=u
        print(ans)
        sys.exit()

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

const int maxn = 100000;

int main() {
    int n;
    cin>>n;
    int a[maxn];
    int b[maxn];
    int c[maxn];
    int dpa[maxn], dpb[maxn], dpc[maxn];
    for (int i=0; i<n; i++) {
        cin>> a[i] >> b[i] >> c[i];
    }
    dpa[0]=a[0];
    dpb[0]=b[0];
    dpc[0]=c[0];
    for (int i=1; i<n; ++i){
        dpa[i]=max(dpb[i-1]+a[i], dpc[i-1]+a[i]);
        dpb[i]=max(dpa[i-1]+b[i], dpc[i-1]+b[i]);
        dpc[i]=max(dpa[i-1]+c[i], dpb[i-1]+c[i]);
    }
    cout<< max(max(dpa[n-1], dpb[n-1]), dpc[n-1])<<'\n'; 

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int main() {
    ll a, b, c, s, i;
    scanf("%lld%lld%lld", &a, &b, &c);
    if(a==b && a==c && a%2==0) {
        printf("-1\n");
        return 0;
    }
    s=a+b+c;
    for(i=0; ; i++) {
        if(a%2 || b%2 || c%2) break;
        a=(s-a)/2;
        b=(s-b)/2;
        c=(s-c)/2;
    }
    printf("%lld\n", i);
    return 0;
}

Measured memory_bytes: 256
import math
a,b,C=map(float,input().split())
C_rad=math.pi*C/180
print("{0:.8f}".format(math.sin(C_rad)*a*b/2))
print("{0:.8f}".format(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(C_rad))))
print("{0:.8f}".format(b*math.sin(C_rad)))


Measured memory_bytes: 5700
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010];
int mx1,num1,mx2;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>mx1){
				mx2=mx1;
				mx1=a[i];
		}
		else mx2=max(mx2,a[i]);
	}
	for(int i=0;i<n;i++){
		if(a[i]==mx1){
			cout<<mx2<<endl;
		}
		else cout<<mx1<<endl;
	}
    return 0; 
}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    ll ans = 0;
    if(n > m) swap(n, m);
    if((ll)n*m==1) ans = 1;
    else if (n == 1) ans = m-2;
    else ans = (ll)(n-2)*(m-2);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int top[5]={0,0,0,0,0};
	int yama;

	cin >> top[0];
	for(int i=0; i<9; i++){
		cin >> yama;
		
		for(int j=0; j<3; j++){
			if(yama >top[j]){
				top[j+2] = top[j+1];
				top[j+1] = top[j];
				top[j] =yama;
				break;
			}
		}
	}
	for(int i=0; i<3; i++)
		cout << top[i] << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7, mod = 998244353;
#define debug(x) cerr << #x << " " << x << "\n";
long long tab1[N], tab2[N], tab3[N], tab4[N];
long long odej;

long long pot(long long a, long long b) {
	long long re = 1;
	while(b) {
		if(b % 2 == 1) re *= a;
		a *= a;
		b /= 2;
		a %= mod;
		re %= mod;
	}
	return re;
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie();
	int n;
	cin >> n;

	for(int i = 0; i < n; i++) {
		int a;
		cin >> a;
		odej += a;
		odej %= mod;
		tab1[a] += a;
		tab1[a] %= mod;
	}

	for(int i = 1; i <= 1e6; i++) {
		for(int j = i; j <= 1e6; j+= i) {
			tab2[i] += tab1[j];
			tab2[i] %= mod;
		}
	}

	for(int i = 1; i <= 1e6; i++) {
		tab3[i] = tab2[i] * tab2[i];
		tab3[i] %= mod;
	}

	for(int i = 1e6; i > 0; i--) {
		tab4[i] = tab3[i];
		for(int j = 2 * i; j <= 1e6; j+= i) {
			tab4[i] -= tab4[j];
			if(tab4[i] < 0) tab4[i] += mod;
		}

		// cout << tab4[i] << endl;
	}

	long long ans = 0;

	for(int i = 1; i <= 1e6; i++) {
		ans += pot(i, mod - 2) * tab4[i];
		ans %= mod;
	}

	// debug(ans);
	// debug(odej);

	ans -= odej;
	if(ans < 0) ans += mod;
	ans = (ans * pot(2, mod - 2)) % mod;
	cout << ans << endl;
}

Measured memory_bytes: 31488
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll solve(ll h){
	if(h==1) return 1;
	return 2*solve(h/2)+1;
}
int main()
{
	ll h;
	cin>>h;
	cout<<solve(h)<<endl;	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int n; cin >> n;
	mk(arr, n, int);

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

	//sort(arr, arr + n);

	int ans = 0;
	mii cnt;

	for (int i = 0; i < n; ++i)
	{
		ans += cnt[i - arr[i]];
		cnt[arr[i] + i]++;
	}

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 27880
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main() {
		long int N;
		cin >> N;
		vector<long long int> a(N);
		for(int i = 0; i < N; ++i){
				cin >> a[i];
		}
		long int count = 0;
		long int max_count = 0;
		for(int i = 0; i < N; ++i){
				if(a[i] >= a[i + 1] && i != N - 1){
						count += 1;
				} else {
						if(max_count <= count){
								max_count = count;
						}
						count = 0;
				}
		}
		cout << max_count << endl;
}

					


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
int main()
{    
    set<string> t;
    string s,be;
    int N;
    cin >> N;
    bool is = true;
    for(int i = 0;i < N; ++i)
    {
        cin >> s;
        auto l = t.insert(s);
        if(!l.second)
            is = false;
        if(i == 0)
        {
            be = s;
            continue;
        }
        if(be[be.size() - 1] != s[0])
            is = false;
        be = s;
    }
    cout << (is ? "Yes\n" : "No\n");
}   



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
using namespace std;
int main() {
	int s, w; cin >> s >> w;
	if (s <= w) {
		cout << "unsafe" << endl;
		return 0;
	}
	cout << "safe" << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int a,b,c,sum;cin>>a>>b>>c;
    sum=a+b+c;
    cout<<sum-(max(a,max(b,c)))<<endl;
}


Measured memory_bytes: 256
num_list = [0 for l in range(6)] #人数をカウントするためのリスト作成

#身長に合わせてリストの数をカウンタ変数にしカウントする
for _ in range(int(input())):
    num = float(input())
    if num < 165:num_list[0] += 1
    elif num < 170:num_list[1] += 1
    elif num < 175:num_list[2] += 1
    elif num < 180:num_list[3] += 1
    elif num < 185:num_list[4] += 1
    else:num_list[5] += 1
    
#出力
for j in range(1,7):
    print(str(j) + ":",end="")
    for k in range(num_list[j - 1]):
        print("*",end="")
    print()


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

int main()
{
  while(1){
    int n, r;
    cin >> n >> r;
    if(n == 0 && r == 0){
      break;
    }else{
      stack <int> x, y, z;
      while(!x.empty())
	x.pop();
      for(int i = 1; i <= n; i++)
	x.push(i);
      for(int i = 0; i < r; i++){
	int p, c;
	cin >> p >> c;
	for(int j = 1; j < p; j++){
	  y.push(x.top());
	  x.pop();
	}
	for(int j = 0; j < c; j++){
	  z.push(x.top());
	  x.pop();
	}
	while(!y.empty()){
	  x.push(y.top());
	  y.pop();
	}
	while(!z.empty()){
	  x.push(z.top());
	  z.pop();
	}
      }
      cout << x.top() << endl;
    }
  }
}

Measured memory_bytes: 1200
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		char[] str = sc.next().toCharArray();

		long total = 0;
		
		int[][] colors = new int[3][n];
		
		for(int i = n - 2; i >= 0; i--) {
			if(str[i + 1] == 'R') {
				colors[0][i]++;
			}
			if(str[i + 1] == 'G') {
				colors[1][i]++;
			}
			if(str[i + 1] == 'B') {
				colors[2][i]++;
			}
			
			for(int j = 0; j < 3; j++) {
				colors[j][i] += colors[j][i + 1];
			}
		}
		
		//debug
//		for(int i = 0; i < 3; i++) {
//			for(int j = 0; j < n; j++) {
//				System.out.print(colors[i][j]+" ");
//			}
//			System.out.println();
//		}
		
		boolean[] appear = new boolean[3];
		for(int i = 0; i < n - 2; i++) {
			for(int j = i + 1; j < n - 1; j++) {
				if(str[i] == str[j]) {
					continue;
				}
				
//				System.out.println("i = "+i+" j = "+j);
				if(str[i] == 'R' || str[j] == 'R') {
					appear[0] = true;
				}
				if(str[i] == 'G' || str[j] == 'G') {
					appear[1] = true;
				}
				if(str[i] == 'B' || str[j] == 'B') {
					appear[2] = true;
				}
				
				for(int k = 0; k < 3; k++) {
					if(!appear[k]) {
						total += colors[k][j];
						
						int dist = j - i;
						
						if(j + dist < n && str[i] != str[j + dist] && str[j] != str[j + dist]) {
							total--;
						}
					}
				}
				Arrays.fill(appear, false);
//				System.out.println("total "+total);
			}
			
			
		}
		
		System.out.println(total);
	}

}


Measured memory_bytes: 28032
def gcd (a, b):
    while b != 0:
        a, b = b, a%b
    return a
 
def lcm(a, b,mod):
    return a*b//gcd(a,b)
 
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
b = 1
for i in range(N):
    a = A[i]
    b = lcm(a,b,mod)
ans = 0
for a in A:
    ans += b//a
print(ans%mod)

Measured memory_bytes: 74604
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
	string s;
	cin >> a >> b;
	cin.ignore(1, '\n');
	getline(cin, s);
	int k = 0;
	bool ok = true;
	for(char c : s){
		if(c >= '0' && c <= '9'){
			if(k == 0) a--;
			if(k == 1) b--;
		}else if(c == '-'){
			k++;
			if(k > 1) break;
		}else{
			ok = false;
			break;
		}
	}
	if(ok && a == 0 && b == 0 && k == 1) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
//
//  B80-HarshadNumber.cpp
//  programing
//
//  Created by 毛利源 on 2019/01/29.
//

#include<iostream>
using namespace std;

int main(){
  // bool isHarshad = false;
  int n;
  cin >> n;
  int N = n;
  int sum = 0;
  while (n!=0) {
    sum += n%10;
    n = n/10;
  }

  if (N % sum ==0){
    cout << "Yes" << '\n';
  }else{
    cout << "No" << '\n';
  }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>

using namespace std;
#define N 4
#define N2 16

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle {
  int f[N2], space, MD;
  int cost;

  bool operator < ( const Puzzle &p ) const {
    for ( int i = 0; i < N2; i++ ) {
      if ( f[i] == p.f[i] ) continue;
      return f[i] < p.f[i];
    }
    return false;
  }
};

struct State {
  Puzzle puzzle;
  int estimated;
  bool operator < (const State &s) const {
    return estimated > s.estimated;
  }
};

int getAllMD(Puzzle pz) {
  int sum = 0;
  for ( int i = 0; i < N2; i++ ) {
    if ( pz.f[i] == N2 ) continue;
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}

int astar(Puzzle s) {
  priority_queue<State> PQ;
  s.MD = getAllMD(s);
  s.cost = 0;
  map<Puzzle, bool> V;
  Puzzle u, v;
  State initial;
  initial.puzzle = s;
  initial.estimated = getAllMD(s);
  PQ.push(initial);

  while ( !PQ.empty() ) {
    State st = PQ.top(); PQ.pop();
    u = st.puzzle;

    if ( u.MD == 0 ) return u.cost;
    V[u] = true;

    int sx = u.space / N;
    int sy = u.space % N;

    for ( int r = 0; r < 4; r++ ) {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
      v = u;

      v.MD -= MDT[tx * N + ty][v.f[tx * N + ty] - 1];
      v.MD += MDT[sx * N + sy][v.f[tx * N + ty] - 1];

      swap(v.f[sx * N + sy], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if ( !V[v] ) {
        v.cost++;
        State news;
        news.puzzle = v;
        news.estimated = v.cost + v.MD;
        PQ.push(news);
      }
    }
  }
  return -1;
}

int main() {
  for ( int i = 0; i < N2; i++ )
    for ( int j = 0; j < N2; j++ )
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

  Puzzle in;

  for ( int i = 0; i < N2; i++ ) {
    cin >> in.f[i];
    if ( in.f[i] == 0 ) {
      in.f[i] = N2;
      in.space = i;
    }
  }
  cout << astar(in) << endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) ( ((x)&1)==0?0:1 )
#define SIGN(x) ( ((x) > 0) - ((x) < 0)  )
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

inline ll sq(int x){
    return (ll) x*x;
}

int main() {
    READ(0);
    int n;cin>>n;
    vi x(n);
    FOR(i,n) cin>>x[i];
    sort(x.begin(),x.end());
    ll ret=INFL;
    for(int i=x[0];i<=x[n-1];++i){
        ll este=0;
        for(int j=0;j<n;++j){
            este += sq(x[j]-i);
        }
        ret=min(ret,este);
    }
    cout << ret;

    return 0;
}



Measured memory_bytes: 256
use proconio::*;
fn main(){
input!{t:usize}
for _ in 0..t{
input!{n:usize,mut a:[(usize,i64,i64);n]}
let mut z=0;
a.sort();
for(_,l,r)in a.iter(){z+=std::cmp::min(l,r);}
let mut s=std::collections::BinaryHeap::new();
let mut i=0;
for j in 1..=n{
while i<a.len()&&a[i].0==j{let x=a[i].2-a[i].1;if x<=0{s.push(x)};i+=1}
while s.len()>j{s.pop();}
}
z-=s.iter().sum::<i64>();
s.clear();
let mut i=n;
for j in 1..=n{
while i>0&&a[i-1].0==n{i-=1}
while i>0&&a[i-1].0==n-j{let x=a[i-1].1-a[i-1].2;if x<0{s.push(x)};i-=1}
while s.len()>j{s.pop();}
}
z-=s.iter().sum::<i64>();
println!("{}",z);
}
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

int main() 
{
    fastio();

    string s;
    cin>>s;

    int n = s.size();

    ll inv10 = 202;

    ll now = 0, pow10 = 1;
    map<int,int>cnt;
    cnt[0]++;

    ll answer = 0;
    for(int i=n-1;i>=0;i--)
    {
        now = mod( now + pow10*(s[i]-'0'), 2019 );

        answer += cnt[now];

        cnt[now]++;
        pow10 = mod( 10*pow10, 2019 );
    }
    cout<<answer,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3780
n=gets.to_i
hash={}

n.times{
   str=gets.chomp
   if hash[str]
       hash[str]+=1
   else
       hash[str]=1
   end
}


hash=hash.sort{|a,b| a[1]<=>b[1]}.reverse

i=0
max=hash[0][1]
ll=hash.length

ll.times {
    if hash[i][1]==max
        i+=1
    else
        break
    end
}

hash=hash[0..i-1].sort{|a,b| a[0]<=>b[0]}

j=0
i.times {
     puts hash[j][0]
    j+=1
}

Measured memory_bytes: 43368
#include<bits/stdc++.h>
#define MAX 3003
using namespace std;

string A,B,ans="";
int dp[MAX][MAX],dir[MAX][MAX];

///O(n*m)
int LCS(int i, int j)
{
    if(i==A.size() || j==B.size())
        return 0;
    if(~dp[i][j]) return dp[i][j];
    if(A[i]==B[j])
    {
        dir[i][j]=1;
        return dp[i][j]=1+LCS(i+1, j+1);
    }
    int x=LCS(i,j+1);
    int y=LCS(i+1, j);
    if(x>=y)
    {
        dir[i][j]=2;
        dp[i][j]=x;
    }
    else
    {
        dir[i][j]=3;
        dp[i][j]=y;
    }
    return dp[i][j];
}

void solution(int i, int j)
{
    if(i==A.size() || j==B.size())
        return;
    if(dir[i][j]==1)
    {
        ans+=A[i];
        solution(i+1, j+1);
    }
    else if(dir[i][j]==2)
        solution(i,j+1);
    else
        solution(i+1, j);
}

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

    cin>>A>>B;
    memset(dp,-1,sizeof dp);
    int x = LCS(0,0);
    solution(0,0);
    cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 71040
import numpy as np

cs = np.zeros((3,3))

cs[0,:] = input().split()
cs[1,:] = input().split()
cs[2,:] = input().split()

cs = cs.astype(int)

flag = True
x1 = cs[0,0]-cs[1,0]
x2 = cs[0,1]-cs[1,1]
x3 = cs[0,2]-cs[1,2]

y1 = cs[0,0]-cs[2,0]
y2 = cs[0,1]-cs[2,1]
y3 = cs[0,2]-cs[2,2]

if (x1!=x2)|(x2!=x3)|(y1!=y2)|(y2!=y3):
  flag = False

if flag:
  for a1 in range(0,100+1):
    a2 = a1 - (cs[0,0] - cs[1,0])
    a3 = a1 - (cs[0,0] - cs[2,0])
    x1 = cs[0,0] - a1
    x2 = cs[1,0] - a2
    x3 = cs[2,0] - a3

    y1 = cs[0,1] - a1
    y2 = cs[1,1] - a2
    y3 = cs[2,1] - a3

    z1 = cs[0,2] - a1
    z2 = cs[1,2] - a2
    z3 = cs[2,2] - a3

    if (x1!=x2)|(x2!=x3)|(y1!=y2)|(y2!=y3)|(z1!=z2)|(z2!=z3):
      flag = False
    else:
      flag = True
      break

if flag:
  print('Yes')
else:
  print('No')


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

using namespace std;

int n, i, a[105];
vector<int> ans;
int main()
{
 //   freopen("input", "r", stdin);

    cin >> n;
    for(i=1; i<=n; ++i) cin >> a[i];

    while(n)
    {
        int pos = -1;

        for(i=1; i<=n; ++i)
            if(a[i] == i) pos = i;

        if(pos == -1)
        {
            cout << "-1\n";
            return 0;
        }

        for(i=pos; i<n; ++i) a[i] = a[i+1];
        --n;
        ans.push_back(pos);
    }

    reverse(ans.begin(), ans.end());
    for(auto it : ans) cout << it << '\n';

    return 0;
}


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

int main() {
  int N , A , B;
  cin >> N >> A >> B ;

  if (N * A < B ) {
    cout << N * A << endl;
  }  
  if (N * A > B ) {
      cout << B << endl;
  }
  if (N * A == B ) {
      cout << B << endl;  
  }
}

Measured memory_bytes: 3640
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] a = new int[N];
        int[] b = new int[N];
        for(int i = 0; i<N; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0; i<N; i++) {
            b[i] = Integer.parseInt(sc.next());
            b[i] = a[i] - b[i];
        }
        Arrays.sort(b);
        int ans = 0;
        for(int i = 0; i<N; i++) {
            if(b[i] >0) ans += b[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
  string o, e;
  cin >> o >> e;
  while(true)
  {
    if(o.size() > 0){
      cout << o.at(0);
      o = o.substr(1, o.size()-1);
    }else{
      cout << endl;
      return 0;
    }
    if(e.size() > 0){
      cout << e.at(0);
      e = e.substr(1, e.size()-1);
    }else{
      cout << endl;
      return 0;
    }
  }
  return 0;
}


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

int n,k;

vector<int> v;

int main(){
  	cin >> n >> k;
  	for(int i = 0; i < n; i++){
    	int x;
      	cin >> x;
  	    v.push_back(x);
  	}
  	long long sum = 0LL;
  	sort(v.rbegin(),v.rend());
  	for(int i = k; i < v.size(); i++) sum += v[i];
  	cout << sum;
	return 0;  
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
typedef long long ll;

// Morris-Pratt
// https://youtu.be/9MphwmIsO7Q?t=7283
template<typename T>
struct MP {
  int n;
  T t;
  vector<int> a;
  MP() {}
  MP(const T& t): t(t) {
    n = t.size();
    a = vector<int>(n+1);
    a[0] = -1;
    int j = -1;
    for (int i = 0; i < n; ++i) {
      while (j != -1 && t[j] != t[i]) j = a[j];
      j++;
      a[i+1] = j;
    }
  }
  int operator[](int i) { return a[i];}
  vector<int> findAll(const T& s) {
    vector<int> res;
    int j = 0;
    for (int i = 0; i < s.size(); ++i) {
      while (j != -1 && t[j] != s[i]) j = a[j];
      j++;
      if (j == n) {
        res.push_back(i-j+1);
        j = a[j];
      }
    }
    return res;
  }
};


vector<int> f(vector<int>& in){
    vector<int> out;
    int n = in.size();
    for (int i = 0; i < n; i++) out.push_back(in[i]^in[(i+1)%n]);
    return out;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    vector<int> wa = f(a);
    vector<int> wb = f(b);
    wb.insert(wb.end(), wb.begin(), wb.end());
//    show(wa);
//    show(wb);
    struct MP<vector<int>> mp(wa);
    vector<int> res = mp.findAll(wb);
//    show(res);
    vector<int> k;
    rep(i, res.size()) k.push_back(n-res[i]);
    sort(k.begin(), k.end());
    rep(i, k.size()){
        if (k[i] == n) continue;
        int ans = a[k[i]]^b[0];
        cout << k[i] << " " << ans << endl;
    }

    return 0;
}



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

int main(){
   int N, K;
   cin >> N >> K;
   vector<long long> H(N);
   for (int i=0; i<N; i++){
      cin >> H.at(i);
   }

   sort(H.begin(), H.end());
   reverse(H.begin(), H.end());
   long long sum = 0;
   for (int i=K; i<N; i++){
      sum += H.at(i);
   }
   cout << sum << endl;
}



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

int main()
{
  int N ;
  cin >> N ;
  int a;
  
  if(N>=100){
    a=N*1/10;
  	N-=10*a;}
  if(N>=10){
    a=N*1/10;
  	N-=10*a;}
  
  if(N==2||N==4||N==5||N==7||N==9)
    cout << "hon" << endl;
  else if(N==0||N==1||N==6||N==8)
    cout << "pon" << endl;
  else
    cout << "bon" << endl;
  
   

return 0;
}


Measured memory_bytes: 3596
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

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

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int x, n, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> x >> n;
    FOR(i,1,n) cin >> a[i];
    int Min = 1000000000, res = -1000000000;
    FOR(i,-100,200) {
        bool co = false;
        FOR(j,1,n)
            if (i == a[j]) co = true;
        if (!co) {
            int diff = abs(x - i);
            if (diff < Min) {
                Min = diff;
                res = i;
            }
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 3652
// VC, WIP

#include <bits/stdc++.h>
using namespace std;

// Utility
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
namespace std {
template<class ...Ts>        istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { i >> x.first >> x.second; return i; }
template<class T>            istream& operator>>(istream& i, vector<T>& x)    { for (auto& y : x) { i >> y; } return i; }
}

// Debugging
#define DD(X) std::cout << #X ": " << (X) << std::endl << std::flush
namespace std {
template<class ...Ts>        ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; apply([&](auto&& y, auto&&... ys){ o << y; ((o << ", " << ys), ...); }, x); o << ")"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { o << tie(x.first, x.second); return o; }
template<class T>            ostream& operator<<(ostream& o, const vector<T>& x)    { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const set<T1, T2>& x)  { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& x)  { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
}

// Main
void mainCase() {
  ll n, k; // n <= 10^6
  cin >> n >> k;

  vector<ll> ls(n, 0);
  cin >> ls;
  for (auto& x : ls) { x--; } // zero-based

  // Identify loop
  vector<ll> ts(n, -1);
  ll x = 0;
  ll t = 0;
  while (true) {
    if (ts[x] != -1) { break; }
    ts[x] = t;
    x = ls[x];
    t++;
  }
  ll period = t - ts[x];
  // DD(tie(x, period, ts));

  ll m, y;
  if (k < t) {
    // Done before loop so just do it again
    m = k;
    y = 0;
  } else {
    // Shortcut loop
    m = (k - t) % period;
    y = x;
  }
  // DD(tie(m, y));

  FOR(i, 0, m) { y = ls[y]; }
  cout << (y + 1) << endl;
}

int main() {
  mainCase();
  return 0;
}


Measured memory_bytes: 6384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];

void push(int x) {
    S[++top] = x;
}

int pop(){
    top--;
    return S[top+1];
}

int main(){
    int a,b;
    top = 0;
    char s[100];
    while(scanf("%s",s)!=EOF){
        if(s[0] == '+'){
            a = pop();
            b = pop();
            push(a+b);
        } else if (s[0] == '-'){
            b = pop();
            a = pop();
            push(a-b);
        } else if(s[0] ==  '*'){
            a = pop();
            b = pop();
            push(a*b);
        } else {
            push(atoi(s));
        }
    }
    
    printf("%d\n",pop());
    
    return 0;
}


Measured memory_bytes: 2692
# input
N, K, C = map(int, input().split())
S = input()

# process
l = [i+1 for i in range(N) if S[i] == 'o']
left = [l[0]]
right = [l[-1]]
for i in range(1, len(l)):
    if l[i] > left[-1]+C:
        left.append(l[i])
    if l[-i-1] < right[-1]-C:
        right.append(l[-i-1])

# output
# print(l)
# print(left)
# print(right)
if len(left) == K:
    for i in range(len(left)):
        if left[i] == right[-i-1]:
            print(left[i])


Measured memory_bytes: 15808
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    int l, r, d;
    cin >> l >> r >> d;

    int res = 0;
    rep (i, l, r) {
        res += (i % d == 0);
    }
    cout << res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 3608
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n, k;
        cin >> n >> k;
        vector<ll> a(n);
        rep(i, n) cin >> a[i];
        ll dp[n + 1];
        dp[0] = 0;
        for (int i = 1; i <= n; ++i) {
            dp[i] = dp[i - 1] + a[i - 1];
        }
        vector<ll> v;
        rep(i, n + 1) {
            for (ll j = i + 1; j <= n; ++j) {
                v.emplace_back(dp[j] - dp[i]);
            }
        }

        vector<bool> use(v.size());
        rep(i, use.size()) use[i] = true;
        repr(i, 40) {
            ll temp = 0;
            for (int j = 0; j < v.size(); ++j) {
                if (use[j] && (v[j] >> i & 1)) temp++;
            }

            if (temp >= k) {
                for (int j = 0; j < v.size(); ++j) {
                    if (!(v[j] >> i & 1)) use[j] = false;
                }
            }
        }
        ll ans = 0;
        rep(i, v.size()) if (use[i]) ans = (ans == 0 ? v[i] : ans & v[i]);
        cout << ans << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

const int INF = 100000;

int h, w;
//vector<int> s(1000001, vector<int>(2));
vector<int> s(0);
int cnt = 0;
int res; //答え = h*w - 1 - 最短手数 -　元からあった黒マスの数
char fld[1010][1010];
int dist[1010][1010];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
queue<int> qx, qy;

int bfs(){
  
  while(qx.size()){
    int x = qx.front(); qx.pop();
    int y = qy.front(); qy.pop();
    //if(x == w-1 && y == h-1) break;

    rep(i, 4){
      int nx = x + dx[i], ny = y + dy[i];
      if(nx >= 0 && ny >= 0 && nx < w && ny < h &&  
         fld[ny][nx] != '#'){
        qx.push(nx); qy.push(ny);
        fld[ny][nx] = '#';
        dist[ny][nx] = dist[y][x] + 1;
      }
    }
  }
  //cout << dist[w-1][h-1] << " ";
  return 0;
}   

int main(){
  cin >> h >> w;
  rep(i, h){
    rep(j, w){
      cin >> fld[i][j];
      dist[i][j] = INF;
      if(fld[i][j] == '#'){
        qx.push(j);
        qy.push(i);
        dist[i][j] = 0;
      }
    }
  }
  //cout << cnt << " ";
  bfs();
  int res = dist[h-1][w-1];
  rep(i, h){
    rep(j, w){
      res = max(dist[i][j], res);
    }
  }
      
  //rep(i, h){rep(j, w){cout << maze[j][i];}cout << endl;}
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact(2000010);
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int x;
vector<P>v;
signed main(){
    cin>>x;
    v.pb({0,0});
    for(int i=1;i<=200;i++){
        v.pb({i,i*i*i*i*i});
    }
    for(P a:v){
        for(P b:v){
            if(a.se-b.se==x){
                cout<<a.fi<<" "<<b.fi<<endl;
                return 0;
            }
            if(a.se+b.se==x){
                cout<<a.fi<<" "<<-b.fi<<endl;
                return 0;
            }
            if(-a.se-b.se==x){
                cout<<-a.fi<<" "<<b.fi<<endl;
                return 0;
            }
            if(-a.se+b.se==x){
                cout<<-a.fi<<" "<<-b.fi<<endl;
                return 0;
            }
            
        }
    }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstring>
using namespace std;
int n, w, h;
 
int funcw(int x){
  if(x < 0) return 0;
  if(w < x) return w;
  return x;
}
 
int funch(int x){
  if(x < 0) return 0;
  if(h < x) return h;
  return x;
}
 
int main(){
  cin >> n >> w >> h;
 
  int wifi_x[w + 1], wifi_y[h + 1];
  memset(wifi_x, 0, sizeof(wifi_x));
  memset(wifi_y, 0, sizeof(wifi_y));
  for (int i = 0; i < n; i++){
    int x, y, W;
    cin >> x >> y >> W;
     
    wifi_x[funcw(x - W)] += 1;
    wifi_x[funcw(x + W)] += -1;
    wifi_y[funch(y - W)] += 1;
    wifi_y[funch(y + W)] += -1;
  }
  int mx, my, tmp = 0;
  mx = my = 1e9;
  for (int i = 0; i < w; i++){
    tmp += wifi_x[i];
    mx = min(tmp, mx);
  }
  tmp = 0;
  for (int i = 0; i < h; i++){
    tmp += wifi_y[i];
    my = min(tmp, my);
  }
  if(mx > 0 || my > 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
     
  return 0;
}

Measured memory_bytes: 1944
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut ab: Vec<(i64, i64)> = (0..n).map(|_| (input(), input())).collect();
    ab.sort_by_key(|&(_, b)| b);

    let mut ok = true;
    let mut t = 0;
    for &(a, b) in &ab {
        if t + a > b {
            ok = false;
            break;
        }
        t += a;
    }
    println!("{}", if ok { "Yes" } else { "No" });
}


Measured memory_bytes: 10492
#include<stdio.h>
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	int l, r;
	int min, max;
	min = 0;
	max = 100005;
	for (i = 0; i < m; i++)
	{
		scanf("%d %d", &l, &r);
		if (l > min)
			min = l;
		if (r < max)
			max = r;
	}
	if (min <= max)
		printf("%d\n", max - min + 1);
	else
		printf("0\n");
	return 0;
}

Measured memory_bytes: 128
N = int(input())
A = []
afirst = 0
asecond = 0
for _ in range(N):
	a = int(input())
	A.append(a)
	if(afirst < a):
		asecond = afirst
		afirst = a
	elif(asecond<a):
		asecond = a

for a in A:
	if(a == afirst):
		print(asecond)
	else:
		print(afirst)

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

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

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    int N;
    cin>>N;
    vector<vector<int>> v(N,vector<int>(2));
    rep(i,N) cin>>v[i][0]>>v[i][1];
    vector<vector<int>> w(N,vector<int>(2));
    rep(i,N) {
        w[i][0] = v[i][0] + v[i][1];
        w[i][1] = v[i][0] - v[i][1];
    }
    sort(w.begin(),w.end());
    int ans = 0;
    int t = -INF;
    rep(i,N){
        if(t<=w[i][1]){
            ans++;
            t = w[i][0];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 14340
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  string S;
  cin >> S;
  int c = 0;
  for (int i = 0; i < 4; i++) {
    if (S[i] == '2') {
      c++;
    }
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main()
{
  int n,m;
  scanf("%d %d",&n,&m);
  ll fib[n+4];
  fib[0]=1;
  fib[1]=1;
  for(int i=2;i<=n;i++)
  fib[i]=(fib[i-1]+fib[i-2])%mod;
  int val=-1;
  ll total=1;
  for(int i=0;i<m;i++)
  {
    int temp;
    scanf("%d",&temp);
    if(temp-val==1)
    {
        printf("%d",0);
        return 0;
    }
    total=(total*fib[temp-2-val])%mod;
    val=temp;
  }
  total=(total*fib[n-1-val])%mod;
  printf("%lld",total);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define ft front()
#define bk back()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
    template <class C>
    static char test(typename C::const_iterator*);
    template <class C>
    static int test(...);
    static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
    static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
                                                             const C& c) {
    o << '{';
    for (auto it = c.begin(); it != c.end();)
        o << *it << (++it != c.end() ? ", " : "}");
    return o;
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
    return o << '(' << p.fi << ", " << p.se << ')';
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N, W;
    cin >> N >> W;
    vii items(N);
    F0R (i, N)
        cin >> items[i].fi >> items[i].se;

    vvi dp(W + 1, vi(N, -1));
    fill(ALL(dp[0]), 0);
    dp[items[0].fi][0] = items[0].se;

    F0R (w, W + 1)
        FOR (n, 1, N) {
            dp[w][n] = dp[w][n - 1];
            if (w >= items[n].fi && ~dp[w - items[n].fi][n - 1])
                ckmax(dp[w][n], dp[w - items[n].fi][n - 1] + items[n].se);
        }

    int best = 0;
    R0F (w, W)
        ckmax(best, dp[w][N - 1]);

    cout << best << endl;

    return 0;
}


Measured memory_bytes: 82304