akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;

const int MAXN = 1e5 + 10;

vector<int> graph[MAXN];
bool was_here[MAXN];
bool in_stack[MAXN];
int cnt[MAXN];
vector<pair<int, int>> res_edges;

void dfs(int node, int prev)
{
    was_here[node] = true;
    in_stack[node] = true;
    // cout << node + 1 << ' ' << prev + 1 << endl;
    for (int next : graph[node])
    {
        // cout << node << " -> " << next << ' ' << in_stack[next] << ' ' << was_here[next] << endl;
        if (not was_here[next])
        {
            dfs(next, node);
            if (cnt[next] % 2 == 0)
            {
                cnt[node] += 1;
                res_edges.emplace_back(node, next);
            }
            else
            {
                res_edges.emplace_back(next, node);
                cnt[next] += 1;
            }
        }
        else if (in_stack[next] and next != prev)
        {
            cnt[node] += 1;
            res_edges.emplace_back(node, next);
        }
    }
    // cout << "out " << node + 1 << ' ' << cnt[node] << endl;
    in_stack[node] = false;
}

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

    for (int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    if (m % 2 == 1)
    {
        cout << -1 << endl;
        return 0;
    }

    dfs(0, -1);
    // for (int i = 0; i < n; ++i)
    //     cout << cnt[i] << ' ';
    // cout << endl;

    // assert(not dfs(0));
    // assert(res_edges.size() == m);

    for (int i = 0; i < (int)res_edges.size(); ++i)
        cout << res_edges[i].first + 1 << ' ' << res_edges[i].second + 1 << endl;
}


Measured memory_bytes: 14580
H,W = map(int,input().split())
S = [list(input()) for i in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j]=="#":
            continue
        else:
            count = 0
            for k in range(-1,2,1):
                for l in range(-1,2,1):
                    if j+k<0 or i+l<0 or j+k>=W or i+l>=H:
                        continue
                    if S[i+l][j+k]=="#":
                        count+=1
            S[i][j]=str(count)

for i in range(H):
    print("".join(S[i]))


Measured memory_bytes: 68468
#include <iostream>

using namespace std;

int main(){
  int Wr,Hr,N;
  cin >>  Wr >> Hr >>  N;
  int Wl=0,Hl=0;
  int x,y,a;
  for(int i=0;i<N;i++){
    cin >> x >> y >> a;
    switch(a){
    case 1:
     if(Wl<=x){
        Wl=x;
      }
      break;
    case 2:
      if(x<=Wr){
        Wr=x;
      }
      break;
    case 3:
      if(Hl<=y){
        Hl=y;
      }
      break;
    case 4:
      if(y<=Hr){
        Hr=y;
      }
      break;
    }
  }
  int ans;
  ans=(Wr-Wl)*(Hr-Hl);
  if(ans<0||(Wr-Wl<0&&Hr-Hl<0)){
    ans=0;
  }
  cout <<ans<< endl;
}


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

int main() {
    int n, m, l;
    long sum;
    int a[102][102], b[102][102], c[102][102];

    cin >> n >> m >> l;
    for(int i=1; i<=n; i++) {
	for(int j=1; j<=m; j++) {
	    cin >> a[i][j];
	}
    }

    for(int i=1; i<=m; i++) {
	for(int j=1; j<=l; j++) {
	    cin >> b[i][j];
	}
    }

    for(int i=1; i<=n; i++) {
	for(int j=1; j<=l; j++) {
	    sum = 0;
	    for(int k=1; k<=m; k++) {
		sum += a[i][k] * b[k][j];
	    }
	    if(j != 1) {
		cout << " ";
	    }
	    cout << sum;
	}
	cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1240
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;


#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, y, z) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, z, 0)
#define trav(x, y) for(auto&x:y)

const string nl = "\n";
using ll = int64_t;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;


template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void usaco(string x=""){
    ios_base::sync_with_stdio(0); cin.tie(0); x=x;
#ifndef D
    if(siz(x)){
        freopen((x+".in").c_str(), "r", stdin);
        freopen((x+".out").c_str(), "w", stdout);
    }
#endif
}


str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { 
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { 
    str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { 
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }


#ifdef D 
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif



signed main(){
    usaco("");
    int n; cin >> n;
    vpll a(n); trav(A, a) cin >> A.f >> A.s;
    sort(all(a));
    ll mn = 1e18, mx = -1e18;
    ll ans = 0;
    F0R(i, n){
        ckmax(ans, a[i].f + a[i].s - mn);
        ckmax(ans, a[i].f - a[i].s + mx);
        ckmax(mx, a[i].s - a[i].f);
        ckmin(mn, a[i].s + a[i].f);
    }
    cout << ans << nl;
}
/*
 * Stuff I should try:
 * Is it Monotonic? -> Binary Search
 * Is N small? -> Bitsets or other exponential
 * Edge Cases? Look Carefully 
 * Can't figure anything out? Brute Force and see patterns
 * Try to prove greedies
 * Prefix Sums, Amortization, DP, Data Structures
*/



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

char n[12][12];
char figure[7][4][5] = {
	{"1100","1100","0000","0000"},
	{"1000","1000","1000","1000"},
	{"1111","0000","0000","0000"},
	{"0100","1100","1000","0000"},
	{"1100","0110","0000","0000"},
	{"1000","1100","0100","0000"},
	{"0110","1100","0000","0000"}
};


void clear(){
	for(int i=0; i<12; i++)
			n[i][8]='0';
}

int main(){
	for(int i=0; i<12; i++)
		for(int j=0; j<12; j++)
			n[i][j]='0';

	while(~scanf("%8s\n%8s\n%8s\n%8s\n%8s\n%8s\n%8s\n%8s\n\n", n[0], n[1], n[2], n[3], n[4], n[5], n[6], n[7])){
		clear();
		for(int i=0; i<7; i++){
			for(int j=0; j<8; j++){
				for(int k=0; k<8; k++){
					bool flag=true;
					
					for(int x=0; x<4; x++){
						for(int y=0; y<4; y++){
							if(figure[i][x][y] != n[j+x][k+y]) flag = false;
						}
					}
					
					if(flag){
						cout << (char)('A'+i) << endl;
					}

				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();
		int ans = 0;

		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			}
		}

		System.out.println(ans);

	}

	private static int gcd(int a, int b) {
		int c = 0;
		int r = 1;

		if (a > b) {

			while (r > 0) {
				r = a % b;
				a = b;
				b = r;
			}
			c = a;

		} else if (b > a) {
			while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			}
			c = b;
		} else {
			c = a;
		}

		return c;
	}

}


Measured memory_bytes: 27264
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)*}
    };
}

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

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

fn main() {
    input! {
        n: usize,
        v: [i32; n],
    }
    
    let v = v.iter().filter(|x| *x % 2 == 0 ).filter(|x| *x % 3 != 0 && *x % 5 !=0).collect::<Vec<&i32>>();

    if v.is_empty() {
        println!("APPROVED")
    } else {
        println!("DENIED")
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>

int main() {
	int N;
	char S[100];
	int AC = 0, WA = 0, TLE = 0, RE = 0;
	scanf("%d", &N);
	
	for (int i = 0; i < N; i++) {
		scanf("%s", &S);
		
		if(strcmp("AC", S) == 0) {
			AC += 1;
		} else if(strcmp("WA", S) == 0) {
			WA += 1;
		} else if(strcmp("TLE", S) == 0) {
			TLE += 1;
		} else if(strcmp("RE", S) == 0) {
			RE += 1;
		}
	} 
	printf("AC x %d\n", AC);
	printf("WA x %d\n", WA);
	printf("TLE x %d\n", TLE);
	printf("RE x %d\n", RE);
	
	return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
int main()
{long long i,k,sum,x,y,z,n,t,d,l,m,j;
cin>>n>>m>>x;
y=0;
for(i=n;i<=m;i++)
{if(i%x==0)y=y+1;}
cout<<y;
return 0;
}


Measured memory_bytes: 3616
using System;

namespace _0554
{
    class Program
    {
        static void Main(string[] args)
        {
            int input = int.Parse(Console.ReadLine()) + int.Parse(Console.ReadLine()) + int.Parse(Console.ReadLine()) + int.Parse(Console.ReadLine());
            Console.WriteLine(input / 60);
            Console.WriteLine(input % 60);
        }
    }
}

Measured memory_bytes: 9120
# -*- coding: utf-8 -*-
# input
a = input()
o1 = o2 = 0
# calc
if a[:2] in ('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'):
    o1 = 1
if a[2:4] in ('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'):
    o2 = 1
# output
if o1 == o2 == 1:
    print('AMBIGUOUS')
elif o1 == o2 == 0:
    print('NA')
elif o1 == 1:
    print('MMYY')
else:
    print('YYMM')

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

double e[2];
double res[4][2];

int main()
{
  while(cin >> e[0] >> e[1]){
    rep(i, 2){
      if(e[i] >= 1.1) res[0][i] += 1;
      else if(e[i] >= 0.6 && e[i] < 1.1) res[1][i] += 1;
      else if(e[i] >= 0.2 && e[i] < 0.6) res[2][i] += 1;
      else res[3][i] += 1;
    }
  }

  rep(i, 4) cout << res[i][0] << ' ' << res[i][1] << endl;

  return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() { // 問題文はしっかり読め!!!
	int k; string s;
	cin >> k >> s;
	int n = s.size();
	if (n <= k) {
		cout << s << endl;
	}
	else {
		cout << s.substr(0, k) << "..." << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
//Sum of gcd of Tuples (Easy)

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

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

int main (){
    int K,Ans=0;
    cin >> K;
    for(int i=1;i<=K;i++){
        for(int j=1;j<=K;j++){
            for(int k=1;k<=K;k++){
                Ans += gcd(i,gcd(j,k));
            }
        }
    }
    cout << Ans << endl;
    return 0;
}

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


int main(void){

  int dp[200][200];
  int N,D;
  int A[200];
  int B[200];
  int C[200];
  int H[200];
  int v=0;
  int max=0;
  int max_id=0;
  int ans=0;

  cin>>D>>N;
  for(int i=0;i<D;i++)cin>>H[i];
  for(int i=0;i<N;i++)cin>>A[i]>>B[i]>>C[i];

  for(int i=0;i<D;i++)
    for(int j=0;j<N;j++)
      if(H[i]<A[j] || H[i] > B[j])
	dp[i][j]=-1;

  for(int i=1;i<D;i++){
    for(int j=0;j<N;j++){
      if(dp[i][j] != -1){
	v=0;
	max=0;
	for(int k=0;k<N;k++){
	  if(dp[i-1][k]==-1)
	    continue;
	  v = C[j] - C[k];
	  if(v<0)v=-v;
	  v += dp[i-1][k];
	  if(max<v){
	    max=v;  
	  }
	}
	dp[i][j]=max;
	    
      }
    }
  }
  
  for(int i=0;i<N;i++){
    if(ans< dp[D-1][i])
      ans=dp[D-1][i];
  }
  cout<<ans<<endl;
  return 0;
}
		   
	  
	  
	
	 
    
  

  

Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    REP(i, 0, n) {
        cin >> a[i];
    }
    REP(i, 0, n) {
        cin >> f[i];
    }
    sort(f.begin(), f.end());
    sort(a.rbegin(), a.rend());
    ll l = 0, r = 1LL << 60;
    ll ans = 0;
    while (l <= r) {
        ll mid = (l + r) / 2;
        ll sum = 0;
        REP(i, 0, n) {
            ll t = mid / f[i];
            sum += max(0LL, a[i] - t);
        }
        dump(sum);
        if (sum <= k) {
            ans = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<int> a(N),b(N),c(N),dpa(N+1),dpb(N+1),dpc(N+1);
  for(int i=0;i<N;i++)cin>>a[i]>>b[i]>>c[i];

  for(int i=0;i<N;i++){
    dpa[i+1]=max(dpb[i],dpc[i])+a[i];
    dpb[i+1]=max(dpa[i],dpc[i])+b[i];
    dpc[i+1]=max(dpa[i],dpb[i])+c[i];
  }

  cout<<max({dpa[N],dpb[N],dpc[N]})<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 1e18  

int main() {
  int n; cin >> n;
  int arr[n];
  for(int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  ll dp[n][n];
  ll sum[n];
  sum[0] = arr[0];
  for(int i = 1; i < n; i++) {
  	sum[i] = sum[i - 1] + arr[i];
  }
  for(int i = n - 1; i >= 0; i--) {
	for(int j = i; j < n; j++) {
    	if(i == j) dp[i][j] = 0;
      	else {
        	dp[i][j] = INF;
          	for(int p = i; p < j; p++) {
                ll left = (i - 1) >= 0 ? sum[i - 1] : 0;
                ll right = sum[j];
                ll temp = right - left;
                dp[i][j] = min(dp[i][j], dp[i][p] + dp[p + 1][j] + temp);
            }
		}
    }
  }
  cout << dp[0][n - 1] << endl;
}

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

int main()
{
    int N;
    cin>>N;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;

    vector<int> ZN(N+1);
    ZN[N-1] = A[N-1]==0 ? 1 : 0;
    for (int i=N-2; i>=0; i--)
        if (A[i]==0)
            ZN[i] = ZN[i+1]+1;

    long long ans = 0;
    for (int i=0; i<N; i++)
    {
        int x = 0;
        int s = 0;
        int p = i;
        while (true)
        {
            if (p>=N)
                break;
            if (A[p]==0)
                p += ZN[p];
            if (p>=N)
                break;
            x ^= A[p];
            s += A[p];
            if (x!=s)
                break;
            p++;
        }
        ans += p-i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n, k, x;
    cin >> n >> k;
    int ans=0;
    for(int i=1; i<=n; i++){
      cin >> x;
      ans += min(2*x, 2*abs(k-x));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>
#include <set>


using namespace std;

template<class T> inline bool chmin(T& a, T b) {
  //aの方が大きければbに値を更新、そうでなければ何もしない
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
bool compare_a_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが小さい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second < r.second;
  }
}
bool compare_a_b_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが大きい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second > r.second;
  }
}
bool compare_b_small(pair<int,int> l,pair<int,int> r){
  //secondが小さい方からソート、firstが同じならfirstが小さい方から
  if(l.second != r.second){
    return l.second<r.second;
  }
  else{
    return l.first < r.first;
  }
}
const int INF = 1e9;




int main(){
  int n,k;
  cin >> n >> k;

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

  sort(a,a+n);
  int ans = INF;

  for(i=0;i<=n-k;i++){
    chmin(ans,a[i+k-1]-a[i]);
  }

  cout << ans << endl;



}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            while (sc.hasNext()) {
                String[] abcs = {"abc", "acb", "bac", "bca", "cab", "cba"};
                System.out.println( (Arrays.asList(abcs).contains(sc.nextLine()))?"Yes":"No"); 
            }
        }
    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
#define h_p 1110111110111;
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
const int N = 3*five;
ll bit[N],bit1[N];
void update(int i,int val)
{
       if(i >= N){return ;}
       bit[i] += val;
       update(i+(i&(-i)),val);
}
ll get(int i)
{
       if(i == 0){return 0;}
       return (bit[i] + get(i-(i&(-i))));
}
int main()
{
       int n,k;
       cin>>n>>k;
       bool ff[n+1];
       memset(ff,false,sizeof ff);
       fri(i,0,k)
       {
              int x;
              cin>>x;
              fri(j,0,x)
              {
                     int y;
                     cin>>y;
                     ff[y] = true;
              }
       }
       int xx = 0;
       fri(i,1,n+1){xx += (ff[i] == false); }
       cout<<xx<<endl;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

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

const int maxn = 1e6 + 5;

int v[5][5];

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

  for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) {
      cin>>v[i][j];
    }
  }

  for (int a=0; a<=100; a++) {
    int x = v[0][0]-a;
    int y = v[0][1]-a;
    int z = v[0][2]-a;

    int b = v[1][0]-x;
    int c = v[2][0]-x;

    if (b+y != v[1][1]) continue;
    if (b+z != v[1][2]) continue;
    if (c+y != v[2][1]) continue;
    if (c+z != v[2][2]) continue;

    out("Yes");
  }

  out("No");
  

  return 0;
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var AL=Arr.shift();
for(var i=0;i<AL;i++){
   var arr=Arr[i].split("").map(Number);
   arr.sort(function(a,b){return b-a;});
   var a=arr.join("");
   arr.sort(function(a,b){return a-b;});
   var b=arr.join("");
   console.log(parseInt(a,10)-parseInt(b,10));
}

Measured memory_bytes: 7644
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;


int main() {
    vel2d c(3,vel(3)); rep0(i,3){rep0(j,3){cin>>c[i][j];}}
    bool flag=false;
    rep0(j,2){
        rep0(i,3){
            ll d=c[0][1+j]-c[0][0+j];
            if(d!=c[i][1+j]-c[i][0+j]){flag=true; break;}
           }
    }
    rep0(j,2){
        rep0(i,3){
            ll d=c[1+j][0]-c[0+j][0];
            if(d!=c[1+j][i]-c[0+j][i]){flag=true; break;}
        }
    }
    if(flag){cout<<"No"<<endl;}
    else{cout<<"Yes"<<endl;}
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#define PI 3.14159265359

using namespace std;

int main(){
  int a,b,h,m;
  cin >> a >> b >> h >> m;
  double kekka = 0.0;
  double x,y,z;
  x = 6 * m;
  y = 30 * h + 0.5 * m;
  z = x-y;

  if(z>180) z=360-z;
  
  kekka = sqrt(a*a + b*b - 2*a*b*cos(z*PI/180));
  printf("%.16f", kekka);
 
return 0;
}

Measured memory_bytes: 3604
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var b = parseInt(tmp[0], 10);
	var c = parseInt(tmp[1], 10);
	console.log(b/c);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 26052
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	bool yes = true;
	for(int i = 0; i < 1000; ++i) {
		c -= b;
		
		if( c <= 0 ) break;
		
		a -= d;
		
		if( a <= 0 ) {
			yes = false;
			break;
		}
	}
	
	if( yes ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int a;
    int b;
    int c;
    scanf("%d %d %d", &a, &b, &c);
    if (a<b){
        if (b<c){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
}



Measured memory_bytes: 3156
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=2e5+10;
const ll MOD=998244353;

ll pw3 (int x){
	if(x==0) return 1;
	ll p=pw3(x/2);
	if(x%2==0) return (p*p)%MOD;
	if(x%2==1) return 3*((p*p)%MOD)%MOD;
}

int main(){
	string S;
	cin>>S;
	int N=sz(S);
	int s[MAX];
	rep(i,N){
		if(S[i]=='a')s[i]=0;
		if(S[i]=='b')s[i]=1;
		if(S[i]=='c')s[i]=2;
	}
	
	ll dp[MAX][3][3];
	rep1(k,N){
		if(k==1){
			dp[k][0][0]=1;
			dp[k][1][0]=0;
			dp[k][2][0]=0;
			
			dp[k][0][1]=0;
			dp[k][1][1]=1;
			dp[k][2][1]=0;
			
			dp[k][0][2]=0;
			dp[k][1][2]=0;
			dp[k][2][2]=1;
		}
		else{
			dp[k][0][0]=(dp[k-1][0][1]+dp[k-1][0][2])%MOD;
			dp[k][1][0]=(dp[k-1][1][1]+dp[k-1][1][2])%MOD;
			dp[k][2][0]=(dp[k-1][2][1]+dp[k-1][2][2])%MOD;
			
			dp[k][0][1]=(dp[k-1][2][2]+dp[k-1][2][0])%MOD;
			dp[k][1][1]=(dp[k-1][0][2]+dp[k-1][0][0])%MOD;
			dp[k][2][1]=(dp[k-1][1][2]+dp[k-1][1][0])%MOD;
			
			dp[k][0][2]=(dp[k-1][1][0]+dp[k-1][1][1])%MOD;
			dp[k][1][2]=(dp[k-1][2][0]+dp[k-1][2][1])%MOD;
			dp[k][2][2]=(dp[k-1][0][0]+dp[k-1][0][1])%MOD;
		}
	}
	ll dpd[MAX][3];
	rep1(k,N){
		dpd[k][0]=(dp[k][0][0]+dp[k][0][1]+dp[k][0][2])%MOD;
		dpd[k][1]=(dp[k][1][0]+dp[k][1][1]+dp[k][1][2])%MOD;
		dpd[k][2]=(dp[k][2][0]+dp[k][2][1]+dp[k][2][2])%MOD;
	}
	
	bool same=true;
	rep(i,N-1)if(s[i]!=s[i+1]) same=false;
	if(same){
		cout<<1<<endl;
		return 0;
	}
	
	if(N==2) cout<<2<<endl;
  	else if(N==3){
    	if((s[0]+s[1]+s[2])%3==0)cout<<3<<endl;
      	else if(s[0]==s[2]) cout<<7<<endl;
      	else cout<<6<<endl;
    }
	else{
		int z=0;
		rep(i,N)z+=s[i];
		z=z%3;
		
		bool dif=true;
		rep(i,N-1)if(s[i]==s[i+1]) dif=false;
		ll p3=pw3(N-1);      
		if(dif) cout<<(p3-dpd[N][z]+1+MOD)%MOD<<endl;
		else cout<<(p3-dpd[N][z]+MOD)%MOD<<endl;
	}
}

Measured memory_bytes: 20100
X, Y = map(int, input().split())
mod = 10 ** 9 + 7


# modしながらコンビネーションを求める
def mod_cmb(n, r, mod):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return p * mod_inverse(q, mod) % mod


# modしたa^bを求める
def mod_pow(a, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 1:
        return a * mod_pow(a, p - 1, mod)
    else:
        return (mod_pow(a, p // 2, mod) % mod) ** 2 % mod


# aで割りたいときはa^(p-2)をかければよい（pは素数かつmodで使うやつ）
def mod_inverse(a, mod):
    return mod_pow(a, (mod - 2), mod)


# 移動1, 2を使う回数
n, m = 0, 0

for i in range(10 ** 6):
    if X - i == (Y - 2 * i) * 2 == 0 or X - i == (Y - 2 * i) * 2 != 0:
        n = i
        m = Y - 2 * n
        break
else:
    print(0)
    exit()

print(mod_cmb(n + m, n, mod))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
int INF = 1e9+7;
signed main() {
    int N;
    cin >> N;
    vector<int>cnt(N+1,1);
    for(int i = 2; i <= N; i++) {
        int X = i;
        for(int j = 2; j*j <= i; j++) {
            int Y = j;
            if(X%Y == 0) {
                while(X%Y == 0) {
                    cnt[Y]++;
                    X/=Y;
                }
            }
        }
        if(X != 1) {
            cnt[X]++;
        }
    }
    int ans = 1;
    for(int i = 2; i <= N; i++) {
        ans*=cnt[i];
        ans = ans%INF;
    }
    cout << ans << endl;
}

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

int main(){
  string a, b;
  cin >> a >> b;
  if(a=="H"){
    if(b=="H"){
      cout << "H" << endl;
    }else if(b=="D"){
      cout << "D" << endl;
    }
  }else if(a=="D"){
    if(b=="H"){
      cout << "D" << endl;
    }else if(b=="D"){
      cout << "H" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
str_a, str_b, str_c = input().split()
a = int(str_a)
b = int(str_b)
c = int(str_c)
if a > b:
    tmp = a
    a = b
    b = tmp
if b > c:
    tmp = b
    b = c
    c = tmp
if a > b:
    tmp = a
    a = b
    b = tmp
print(str(a), str(b), str(c))


Measured memory_bytes: 5596
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
#define ALL(X) X.begin(), X.end()
using lint = long long;
template <typename T>
void print_container(std::vector<T> vec)
{
    for (auto iter = vec.begin(); iter != vec.end(); ++iter)
    {
        std::cout << *iter << " ";
    }
    std::cout << std::endl;
}

int main()
{
    lint n;
    scanf("%lld", &n);

    std::vector<lint> num_vec(n, 1);

    for (int i = 2; i <= n; ++i)
    {
        for (int j = i; j <= n; j += i)
        {
            num_vec[j - 1]++;
        }
    }

    lint ans = 0;

    for (int i = 1; i <= n; ++i)
    {
        ans += num_vec[i - 1] * i;
    }

    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 81024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define DEB 0
#define EPS 1e-8
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back

int t,n,X,Y,sx,sy;
int x[1024],y[1024];
int ti[1024];

double sqr(int x){ return (double)x*x; }

int main(){
  cin>>t;
  while(t--){
    memset(ti,-1,sizeof(ti));
    cin>>n>>X>>Y;
    cin>>sx>>sy;
    rep(i,n){
      cin>>x[i]>>y[i];
    }
    /*
    if( X>=Y ){
      puts("You're always welcome!");
      continue;
    }
    */
    int sum = 0;
    bool ok = true;
    vector<int> v;
    // ÈÂßüXÌA[Nbh£10Èà
    rep(i,n){
      if( sqrt(sqr(sx-x[i])+sqr(sy-y[i])) <= 10.0+EPS ){
	ti[i] = X;
	v.pb(i);
      }
    }
#if DEB
    puts("first irassahai");
    rep(i,v.size()){
      printf("(%d,%d)\n",x[v[i]],y[v[i]]);
    }
    puts("------------");
#endif
    if( v.size()>0 ) sum += X;
    // dg·é¢çÁµá¢Ü¹III
    for(;v.size();){
      vector<int> tmp;
      rep(i,v.size()){ //©ñÅé©í¢»¤Èl
	rep(j,n)if( v[i]!=j ){ //©Ô±ÆÉÈé©í¢»¤Èl
	  if( sqrt(sqr(x[v[i]]-x[j])+sqr(y[v[i]]-y[j])) <= 50.0+EPS ){
	    if( ti[j]==-1 ){
#if DEB
	      printf("(%d,%d)  %d - %d ,%d\n",v[i],j,sum,ti[j],Y);
#endif
	      ti[j] = sum + X;
	      tmp.pb(j);
	    }else if( sum - ti[j] > Y ){
#if DEB
	      printf("%d : %d   , sum:%d  ti[cur][i]:%d\n",v[i],j,sum,ti[j]);
#endif
	      ok = false;
	      break;
	    }
	  }
	}
	if( !ok ) break;
      }
      if( !ok ) break;
      v.swap(tmp);
      if( v.size()==0 )break;
      sum += X;
#if DEB
      printf("sum:%d\n",sum);
      rep(k,v.size()){
	printf("(%d,%d) :%d\n",x[v[k]],y[v[k]],ti[v[k]]);
      }
      puts("--------------");
#endif
    }
    if( ok ){
      printf("%d\n",sum);
    }else{
      puts("You're always welcome!");
    }
  }
  return 0;
}

Measured memory_bytes: 940
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

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

    int a, b, c;
    cin >> a >> b>> c;
    cout << (a == b && b == c ? "Yes" : "No") << endl;

}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      int h = sc.nextInt();
      int a = sc.nextInt();
      if(h<=a){
        System.out.println(1);
      }else if(h%a==0){
        System.out.println(h/a);
      }else{
        System.out.println((h/a)+1);
      }

    }
}


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

int main(){
	int d[1500] = {}, c[1500] = {}, mini[1500] = {};
	int n, m;
	cin >> n >> m;
	for(int i = 1;i<=n;i++){
		cin >> d[i];
	}
	for (int i = 1; i <= m; i++) {
		cin >> c[i];
		mini[i] = 2000000000;
	}
	mini[0] = 0;
	for(int i = 1;i<=m;i++){
		for(int j = i;j>0;j--){
			mini[j] = min(mini[j], mini[j - 1] + d[j] * c[i]);
		}
	}
	cout << mini[n] << endl;
	return 0;

}

Measured memory_bytes: 3128
import collections
s = input()
t = input()

d = {}
flag = True
for i in range(len(s)):
    if s[i] in d.keys():
        if t[i] == d[s[i]]:
            continue
        else:
            flag=False
            break
    elif t[i] in d.values():
        if d.get(s[i]) == t[i]:
            continue
        else:
            flag=False
            break
    else:
        d[s[i]] = t[i]

print("Yes" if flag else "No")

Measured memory_bytes: 4144
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val status = BooleanArray(n){false}
    val wa = IntArray(n){0}
    var ac = 0L
    repeat(m) {
        val (p, s) = readLine()!!.split(' ')
        if (!status[p.toInt()-1]) {
            when(s) {
                "AC" -> {
                    status[p.toInt()-1] = true
                    ac++
                }
                "WA" -> wa[p.toInt()-1]++
            }
        }
    }
    var waTotal = 0L
    repeat(n) {
        if (status[it]) waTotal += wa[it]
    }
    println("$ac $waTotal")
}


Measured memory_bytes: 51316
fun main(args: Array<String>) {
    readLine()
    val list = readLine()!!.split(' ').map { it.toInt() }
    println(countInversion(list))
}

private fun countInversion(list: List<Int>): Long {

    var cnt = 0L

    val intArray = list.toIntArray()
    val leftArray = IntArray(list.size / 2 + 2)
    val rightArray = IntArray(list.size / 2 + 2)

    fun merge(left: Int, mid: Int ,right: Int) {
        val leftSize = mid - left
        for (i in 0 until leftSize) {
            leftArray[i] = intArray[left + i]
        }
        leftArray[leftSize] = Int.MAX_VALUE

        val rightSize = right - mid
        for (i in 0 until rightSize) {
            rightArray[i] = intArray[mid + i]
        }
        rightArray[rightSize] = Int.MAX_VALUE

        var l = 0
        var r = 0

        for (i in left until right) {
            if (leftArray[l] <= rightArray[r]) {
                intArray[i] = leftArray[l++]
            } else {
                cnt += leftSize - l
                intArray[i] = rightArray[r++]
            }
        }
    }

    fun sort(left: Int, right: Int) {
        if (left + 1 < right) {
            val mid = (left + right) / 2
            sort(left, mid)
            sort(mid, right)
            merge(left, mid, right)
        }
    }

    sort(0, list.size)

    return cnt
}


Measured memory_bytes: 75612
local n, a, b, mod = io.read("*n", "*n", "*n", "*n")

local function badd(x, y) return (x + y) % mod end
local function bsub(x, y) return (mod + x - y) % mod end
local function bmul(x, y) return (x * y) % mod end
local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res, pow = bmul(res, src), pow - 1
    end
    src, pow = bmul(src, src), pow // 2
  end
  return res
end

local function func(i)
  local c, z = 0, a + b * (i - 1)
  while 0 < z do
    c, z = c + 1, z // 10
  end
  return c
end

local function getright(d, left)
  local min = left
  local max = n
  if d < func(min) then return left - 1 end
  if func(max) == d then return max end
  while 1 < max - min do
    local mid = (min + max) // 2
    if d < func(mid) then max = mid
    else min = mid
    end
  end
  return min
end

local function solve1(d, n)
  if n == 1 then return 1 end
  local add = 0
  local tend = modpow(10, d)
  if n % 2 == 1 then
    add = modpow(tend, n - 1)
    n = n - 1
  end
  n = n // 2
  local v = solve1(d, n)
  v = bmul(v, badd(1, modpow(tend, n)))
  return badd(add, v)
end

local function solve2(d, n)
  if n == 1 then return 0 end
  local add = 0
  local tend = modpow(10, d)
  if n % 2 == 1 then
    add = bmul((n - 1) % mod, modpow(tend, n - 1))
    n = n - 1
  end
  n = n // 2
  local v1 = solve2(d, n)
  v1 = bmul(v1, badd(1, modpow(tend, n)))
  local v2 = solve1(d, n)
  v2 = bmul(v2, bmul(n % mod, modpow(tend, n)))
  return badd(add, badd(v1, v2))
end
local cur_digsum = 0
local left = 1
local ret = 0
for d = 1, 18 do
  local right = getright(d, left)
  if left <= right then
    local s1 = solve1(d, right - left + 1)
    local v1 = bmul(a % mod, s1)
    local v2 = bmul(b % mod, (right - 1) % mod)
    v2 = bmul(v2, s1)
    local v3 = bmul(b % mod, solve2(d, right - left + 1))
    local tend = modpow(10, d)
    ret = bmul(ret, modpow(tend, right - left + 1))
    ret = badd(ret, badd(v1, bsub(v2, v3)))
    cur_digsum = cur_digsum + (right - left + 1) * d
    left = right + 1
  end
  if n < left then break end
end
print(ret)


Measured memory_bytes: 2728
/*input
1
*/

#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define mod 998244353
#define int long long
#define N 10004

map<int,int> H;//[N];
map<int, int> ok;
signed main() {
	int n; cin>>n;
	for(int i=-1009;i<N;i++) {
		H[i] = i*i*i*i*i;
		int j=i-1;
		if(H[i] - H[j] <0) continue;
		while(H[i]-H[j] <= n) {
			if(H[i] - H[j] == n) {
				cout<<i<<" " <<j<<endl;exit(0);
			}
			j--;
		}
	}
}

Measured memory_bytes: 3652
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=100100,M=2002000;
int i,j,k,n,m,ch,En,tm,nm,dn;
int A[N],B[N],b[N],d[N],z[N],p[N],pp[N],h[N];
struct cc {
	int x,y;
	bool operator < (const cc &n) const {
		return x<n.x;
	}
} P[N],Ls[N];
struct edge { int s,n;} E[M];
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
int find_upper(int x) {
	int l=1,r=m,mid;
	if (Ls[r].x<x) return m+1;
	while (l<r) {
		mid=(l+r-1)>>1;
		if (Ls[mid].x<x) l=mid+1;
		else r=mid;
	}
	return l;
}
int find_lower(int x) {
	int l=1,r=m,mid;
	if (Ls[l].x>x) return 0;
	while (l<r) {
		mid=(l+r+1)>>1;
		if (Ls[mid].x>x) r=mid-1;
		else l=mid;
	}
	return l;
}
void E_add(int x,int y) {
	E[++En].s=y;E[En].n=h[x];h[x]=En;
}
void T_build(int L,int R,int k) {
	if (L==R) {
		if (Ls[L].y<=n) pp[k]=n+Ls[L].y;
		else pp[k]=Ls[L].y-n;
		return;
	}
	int mid=(L+R)>>1;
	T_build(L,mid,k<<1);
	T_build(mid+1,R,k<<1|1);
	pp[k]=m+k;
	E_add(pp[k],pp[k<<1]);
	E_add(pp[k],pp[k<<1|1]);
}
void T_add(int L,int R,int l,int r,int x,int k) {
	if (L==l && R==r) {
		E_add(x,pp[k]);
		return;
	}
	int mid=(L+R)>>1;
	if (r<=mid) T_add(L,mid,l,r,x,k<<1);
	else {
		if (l>mid) T_add(mid+1,R,l,r,x,k<<1|1);
		else T_add(L,mid,l,mid,x,k<<1),T_add(mid+1,R,mid+1,r,x,k<<1|1);
	}
}
void Tj(int x) {
	A[x]=B[x]=++tm;
	d[++dn]=x;z[x]=1;
	for (int k=h[x];k;k=E[k].n) {
		if (!A[E[k].s]) {
			Tj(E[k].s);
			B[x]=min(B[x],B[E[k].s]);
		}
		else if (z[E[k].s]) B[x]=min(B[x],A[E[k].s]);
	}
	if (A[x]==B[x]) {
		int now=0;
		nm++;
		while (now!=x) {
			now=d[dn--];
			b[now]=nm;
			z[now]=0;
		}
	}
}
bool check(int x) {
	memset(h,0,sizeof h);
	memset(b,0,sizeof b);
	memset(A,0,sizeof A);
	memset(z,0,sizeof z);
	dn=tm=nm=En=0;
	T_build(1,m,1);
	int i,j,k;
	for (i=1;i<=n;i++) {
		int l=find_upper(P[i].x-x+1),r=find_lower(P[i].x+x-1);
		if (l<p[i]) T_add(1,m,l,p[i]-1,i,1);
		if (p[i]<r) T_add(1,m,p[i]+1,r,i,1);
		l=find_upper(P[i].y-x+1),r=find_lower(P[i].y+x-1);
		if (l<p[n+i]) T_add(1,m,l,p[n+i]-1,n+i,1);
		if (p[n+i]<r) T_add(1,m,p[n+i]+1,r,n+i,1);
	}
	for (i=1;i<=m+1;i++) if (!A[i]) Tj(i);
	for (i=1;i<=n;i++) if (b[i]==b[n+i]) return 0;
	return 1;
}
int main() {
	R(n);m=n+n;
	for (i=1;i<=n;i++) {
		R(P[i].x),R(P[i].y);
		Ls[i].x=P[i].x;Ls[i].y=i;
		Ls[n+i].x=P[i].y;Ls[n+i].y=n+i;
	}
	sort(Ls+1,Ls+m+1);
	for (i=1;i<=m;i++) p[Ls[i].y]=i;
	int l=0,r=1000000000,mid;
	while (l<r) {
		mid=(l+r+1)>>1;
		if (check(mid)) l=mid;
		else r=mid-1;
	}
	printf("%d\n",l);
}

Measured memory_bytes: 14848
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int a,b,c,d;
  a = N/1000;
  b = (N-1000*a)/100;
  c = (N-1000*a-100*b)/10;
  d = N-1000*a-100*b-10*c;
  if(a==b&&b==c){
  		cout << "Yes" << endl;
  }else if(b==c&&c==d){
      cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int d[N];
  for(int i=0; i<N; i++){
    cin >> d[i];
  }
  int ans = 0;
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
//#define ivorysi
#define MAXN 200005
typedef long long int64;
using namespace std;
template<class T>
void read(T &res) {
	res = 0;char c = getchar();T f = 1;
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int N;
int64 a[MAXN],sum[MAXN];
int64 get_abs(int l1,int r1,int l2,int r2) {
	return abs((sum[r1] - sum[l1 - 1]) - (sum[r2] - sum[l2 - 1]));
}
void Solve() {
    read(N);
	for(int i = 1 ; i <= N ; ++i) {
		read(a[i]);sum[i] = sum[i - 1] + a[i];
	}
	int l = 1,p = 2,r = p + 1;
	int64 ans = sum[N];
	while(p <= N - 2) {
		while(l + 1 < p && get_abs(1,l,l + 1,p) > get_abs(1,l + 1,l + 2,p)) ++l;
		r = max(r,p + 1);
		while(r + 1 < N && get_abs(p + 1,r,r + 1,N) > get_abs(p + 1,r + 1,r + 2,N)) ++r;
		int64 m[] = {sum[l],sum[p] - sum[l],sum[r] - sum[p],sum[N] - sum[r]};
		int64 tmp = 0;
		for(int i = 0 ; i <= 3 ; ++i) {
			for(int j = i + 1 ; j <= 3 ; ++j) {
				tmp = max(tmp,abs(m[j] - m[i]));
			}
		}
		ans = min(ans,tmp);
		++p;
	}
	out(ans);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
	return 0;
}


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

int main(){
	long long n, maxi = 100000000005;
	cin >> n;

	for( int i = 1; i <= n/2; ++i ){
		long long x = i, y = n-i, sum = 0;

		while( x > 0 ){
			sum += x%10;
			x -= x%10;
			x /= 10;
		}
		while( y > 0 ){
			sum += y%10;
			y -= y%10;
			y /= 10;
		}
		maxi = min(maxi, sum);
		//cout << maxi << " " << i << endl;
	}
	cout << maxi << endl;
	return 0;
}

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

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


    vector <vector <int>> m(h, vector <int> (w)),m2(h, vector <int> (w));

    int c,k,j,l;
    k=0;
    c=0;
    rep(i,h*w){
        j=i/w;
        l=i%w;
        if(k==a[c]){
            k=0;
            ++c;
        }
        m[j][l]=c+1;
        ++k;
    }

m2=m;
rep(i,h){
    if(i%2==1){
        rep(j,w){
            m[i][j]=m2[i][w-j-1];
        }
    }
}

rep(i,h){
    rep(j,w){
        cout << m[i][j] << " ";
    }
    cout << endl;
}
    

    return 0;
}

Measured memory_bytes: 384
CONST   fi='';
        fo='';
VAR
    f:text;
    a,s:array[0..100001] of int64;
    n,m:longint;
    ds,d:int64;
PROCEDURE input;
  var i:longint;
  begin
    Assign(f,fi);reset(f);
      readln(f,n,m);
      for i:=1 to n do read(f,a[i]);
    Close(f);
  end;

procedure sort(l,r: longint);
      var
         i,j: longint;
         x,y:int64;
      begin
         i:=l;
         j:=r;
         x:=s[(l+r) div 2];
         repeat
           while s[i]<x do
            inc(i);
           while x<s[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=s[i];
                s[i]:=s[j];
                s[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;

PROCEDURE main;
  var i:longint;
  begin
    s[0]:=0;
    for i:=1 to n do s[i]:=s[i-1]+a[i];
    for i:=1 to n do s[i]:=s[i] mod m;
    sort(1,n);
    d:=0;
    s[n+1]:=m+1;
    for i:=1 to n+1 do
      if s[i]<>s[i-1] then begin ds:=ds+(i-d)*(i-d-1) div 2; d:=i; end;
  end;

PROCEDURE output;
  begin
    Assign(f,fo);rewrite(f);
      writeln(f,ds);
    Close(f);
  end;

BEGIN
   input; main; output;
END.


Measured memory_bytes: 1664