akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    while (1) {
        int n;
        cin >> n;
        if (n == 0)break;
        int u = 0, ans = 0;
        VI k(n);
        FOR(i, 0, n) {
            int in;
            cin >> in;
            if (in == 0)continue;
            k[u++] = --in;
            ans++;
        }
        k.resize(u);
        n = k.size();
        SORT(k);
        if (k.back() == 0)cout << "NA\n";
        else cout << ans + 1 << "\n";
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  sort(A.rbegin(), A.rend());
  vector<bool> used(N,false);
  int t = 1LL<<30;
  int ans = 0;
  while(t > 1){
    int j = N-1;
    for(int i = 0; i < N; ++i){
      if(used[i]) continue;
      int r = t - A[i];
      while(j > i and (used[j] or A[j] < r)) --j;
      if(j > i and A[j] == r){
        ++ans;
        used[i] = true;
        used[j] = true;
      }
    }
    t /= 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cout << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)            \
    cerr << #v << ": ";         \
    REP(__i, (v).size())        \
    cerr << ((v)[__i]) << ", "; \
    cerr << endl

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

const ll BIGINT = 1e9 + 7;


int main()
{
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int n = s.size();
    vl dp_marginal(n + 1);
    vl dp_free(n + 1);

    assert(s[0] == '1');
    dp_marginal[0] = 2;
    dp_free[0] = 1;

    for (int i = 1; i < n; ++i)
    {
        if (s[i] == '1')
        {
            dp_marginal[i] = (2 * dp_marginal[i - 1]) % BIGINT;
            dp_free[i] = (3 * dp_free[i - 1] + dp_marginal[i - 1]) % BIGINT;
        }
        else
        {
            dp_marginal[i] = dp_marginal[i - 1];
            dp_free[i] = (3 * dp_free[i - 1]) % BIGINT;
        }
    }

    cout << (dp_marginal[n - 1] + dp_free[n - 1]) % BIGINT << endl;
    return 0;
}


Measured memory_bytes: 2000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            StringBuilder line = new StringBuilder();
            while(true){
                String data[] = br.readLine().split(" ");
                int a = Integer.parseInt(data[0]);
                int b = Integer.parseInt(data[1]);
                if(a == 0 && b == 0) {
                	break;
                }
                for(int i = 0; i < a; i++) {
                for(int j = 0; j < b; j ++) {
                	if(i == 0 || i == a-1 || j == 0 || j == b-1)
                		line.append("#");
                    else
                    	line.append(".");
                }
                line.append("\n");
	            }
	            line.append("\n");
	            }
            System.out.print(line);
        }
    }

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

int solver(int num);

int main(void){
  int A,B;
  int i,j;
  int ans=0;
  scanf("%d",&A);
  scanf("%d",&B);
  
  for(i=A;i<B+1;i++){
    if(solver(i)==1)
      ans++;
  }
  printf("%d\n",ans);
  return 0;
}

int solver(int num){
  int temp,reverse=0;
  temp = num;
  while(temp!=0){
    reverse = reverse*10 + temp%10;
    temp/=10;
  }
  if(reverse==num)
    return 1;
  else
    return 0;
}

Measured memory_bytes: 128
n, m = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _  in range(m)]

for i in range(n-m+1):
  if B[i] in A[i]:
    for j in range(m-1):
      if B[i+j] not in B[i+j]:
        print("No")
        exit()
    print("Yes")
    exit()
  else:
    print("No")
    exit()

Measured memory_bytes: 62268
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <numeric>
#define ll long long
using namespace std;
int main() {
  ll X,Y,ans=0;
  cin>>X>>Y;
  if(X<=3) ans+=(4-X)*100000;
  if(Y<=3) ans+=(4-Y)*100000;
  if(X==1&&Y==1) ans+=400000;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

vector<ll> l,p;

ll rec(ll n, ll x){
  if(n == 0) return 1;
  if(x == 1) return 0;
  if(2 <= x && x <= 1+l[n-1]) return rec(n-1,x-1);
  if(x == 2+l[n-1]) return p[n-1]+1;
  if(3 + l[n-1] <= x && x <= 2*l[n-1] + 2) return p[n-1] + 1 + rec(n-1, x - l[n-1] - 2);
  if(x == 2*l[n-1] + 3) return 2*p[n-1] + 1;

  return 0;
}

int main(){
  ll n;
  ll x;
  cin >> n >> x;
  l.pb(1LL); p.pb(1LL);
  rep(i, n){
    l.pb(2*l[i]+3);
    p.pb(2*p[i]+1);
  }

  std::cout << rec(n, x) << '\n';
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void){
  cout << std::fixed << std::setprecision(16);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  int a[30];
  int b[30];
  int c[30];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  for(int i=0;i<n-1;i++){
    cin>>c[i];
  }
  int result=0;
  for(int i=0;i<n;i++){
    result+=b[a[i]-1];
    if(i>0&&a[i-1]+1==a[i]){
      result+=c[a[i-1]-1];
    }
  }
  cout<<result<<endl;



  return 0;
}


Measured memory_bytes: 256
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = readline().decode().strip()
K = int(readline())
cnt = 0
tmp = 0

for i in N:
    if i == '1':
        cnt += 1
        continue
    else:
        tmp = int(i)
        break
ans = N[tmp-1] if K <= cnt else tmp

print(ans)


Measured memory_bytes: 13292
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if(n==1) {
      cout << 1 << endl;
      cout << 0 << endl;
    }
    else if(n==2){
      cout << 2 << endl;
      cout << 0 << endl;
      cout << 11 << endl;
    }
    else{
      cout << n-1 << endl;
      string s = "";
      cout << 11 << endl;
      rep(i,n-2){
        s += "0";
        cout << "1" << s << "1" << endl; 
      }
    }
}


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


int main()
{
    long double l,a;
    long double v;
    cin>>l;
    if(l<0 || l>1000)
        return 0;
    a=l/3.0;

    v=a*a*a;
    cout << fixed << setprecision(12) << v;
    return 0;
}


Measured memory_bytes: 256
def main():
    X, N = map(int, input().split())
    if N != 0:
        A = list(map(int, input().split()))
    else:
        A = []
    min_diff = 1e5
    for i in range(0, 102):
        if i not in A:
            min_diff = min(min_diff, abs(i - X))
    
    for i in range(0, 102):
        if i not in A and abs(i - X) == min_diff:
            print(i)
            return 
  
if __name__ == '__main__':
    main()

Measured memory_bytes: 9140
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		
		if (S.charAt(0) != 'A') {
			System.out.println("WA");
			return;
		}
		
		int count = 0;
		for (int i = 2; i < S.length() - 1; i++) {
			if (S.charAt(i) == 'C') 
				count++;
		}
		
		if (count != 1) {
			System.out.println("WA");
			return;
		}
		
		for (int i = 1; i < S.length(); i++) {
			char c = S.charAt(i);
			if (c != 'C' && S.charAt(i) != Character.toLowerCase(S.charAt(i))) {
				System.out.println("WA");
				return;
			}
		}
		
		System.out.println("AC");
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF=1e18+1;
const int mod = 1000000007;

int main(){
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
    a[i]--;
  }
  vector<bool>seen(N,false);
  int s=0;
  for(int i=0;i<N;i++){
    if(seen[s]){cout<<-1<<endl;return 0;}
    if(s==1){cout<<i<<endl;return 0;}
    seen[s]=true;
    s=a[s];
  }
  return 0;                       
}

Measured memory_bytes: 3740
#include<iostream>
using namespace std;
int n;
int main()
{
  cin>>n;
  bool can = false;
  for(int i=0;4*i<=n;i++)
  {
    for (int j = 0; 4*i+7*j<=n;j++)
    {
      if(n==4*i+7*j)
      {
        can = true;
        break;
      }
        
    }
  }
  if(can)
    cout << "Yes" << endl;
    else
      cout << "No" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	int edge[51] = {};
	int n, m, a, b;
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		cin >> a >> b;
		a--;
		b--;
		edge[a]++;
		edge[b]++;
	}

	for(int i = 0;i < n;i++){
		cout << edge[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

int main()
{
    long long int dp[110][100010] = {},sum=0,ans=0;
    int N, W;
    cin >> N >> W;
    vector<int>w(N), v(N);
    for (int i = 0; i < N; i++){cin >> w[i] >> v[i];sum+=v[i];}
        for (int j = 1; j <= sum; j++)
        {
        	dp[0][j]=1000000000;
        }
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= sum; j++)
        {
        	dp[i][j]=dp[i-1][j];
        	if(j-v[i-1]>=0)dp[i][j]=min(dp[i][j],dp[i-1][j-v[i-1]]+w[i-1]);
        	if(dp[i][j]<=W)ans=(ans>j?ans:j);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 86144
import java.util.Scanner;
public class Main{
	
	public void solve(){
		Scanner sc = new Scanner(System.in);
		int a;
		int b;
		a = sc.nextInt();
		b = sc.nextInt();
		
		System.out.println((a*b)+" "+((a+b)*2));
	}
	public static void main(String[] args){
		Main obj = new Main();
		obj.solve();
	}
}

Measured memory_bytes: 17352
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cstring>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) begin(x),end(x)

using namespace std;

#define MAX_V 1024

vector<int> g[MAX_V], rg[MAX_V], vs;
bool used[MAX_V];
int cmp[MAX_V];

void add_edge(int from, int to) {
  g[from].push_back(to);
  rg[to].push_back(from);
}

void dfs(int v) {
  used[v] = true;
  for (int i : g[v]) if (!used[i]) dfs(i);
  vs.push_back(v);
}

void rdfs(int v, int k) {
  used[v] = true; cmp[v] = k;
  for (int i : rg[v]) if (!used[i]) rdfs(i, k);
}

int scc(int V) {
  memset(used, 0, sizeof(used));
  vs.clear();
  REP(v, V) if (!used[v]) dfs(v);
  memset(used, 0, sizeof(used));
  reverse(ALL(vs));
  int k = 0;
  for (int i : vs) if (!used[i]) rdfs(i, k++);
  return k;
}

vector<vector<int>> buildGraph(int V, int K) {
  vector<set<int>> s(K);
  vector<vector<int>> res(K,vector<int>(K));
  REP(i,V) for (int j : g[i]) s[cmp[i]].insert(cmp[j]);
  REP(i,K) for (int j : s[i]) ++res[i][j];
  return res;
}

void dfs2(vector<vector<int>>& dag, int i, vector<int64_t>& dp, vector<bool>& vis) {
  int n=dag.size();
  vis[i] = true;
  REP(j,n) {
    if (dag[j][i]==0)continue;
    if (j==i) continue;
    if (!vis[j])
      dfs2(dag, j, dp, vis);
    dp[i] *= dp[j];
    dp[i] %= 1000000007;
  }
  ++dp[i];
  dp[i] %= 1000000007;
}

int main() {
  int n,m;
  cin>>n>>m;
  REP(i,m){
    int s,d;
    cin>>s>>d;
    --s;--d;
    add_edge(s,d);
  }
  int k = scc(n);
  auto dag = buildGraph(n, k);
  vector<int64_t> dp(k, 1);
  vector<bool> vis(k);
  int64_t sum = 1;
  REP(i,k) {
    if(!vis[i]) {
      bool ok = true;
      REP(j,k){
        if(j==i)continue;
        if(dag[i][j] != 0){
          ok=false;
          break;
        }
      }
      if (ok) {
        dfs2(dag, i, dp, vis);
        sum *= dp[i];
        sum %= 1000000007;
      }
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 5228
#include <bits/stdc++.h>
#define ll long long
#define INF (1LL << 60)
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 1001;
const int MAX_M = 2001;

struct edge
{
	int from,to;
    ll cost;
};

int n,m;
ll d[MAX_N];
edge es[MAX_M];
bool flag;	//負の有向閉路の判定

void shortest_path(int s)
{
	int cnt = 0;
	d[s] = 0;
	while(cnt < n){
		bool update = false;
		rep(i,m){
			edge e = es[i];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if(!update) break;
		cnt++;
	}
	if(cnt == n){
		flag = true;
	}
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        es[i] = (edge){a-1,b-1,-c};
    }
    fill(d,d+n,INF);
    shortest_path(0);
    ll pre = -d[n-1];
    shortest_path(0);
    if(-d[n-1] > pre){
        cout << "inf\n";
    }else{
        cout << -d[n-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var bb = ToIntArray(input.ReadLine(), n);
        
        var nodes = new LinkedList<int>();
        foreach(var b in bb) {
            nodes.AddLast(b);
        }

        var stack = new Stack<int>();

        for(int i=n; i>0; i--) {
            var node = nodes.Last;
            int j = i;
            while(node != null) {
                if(j == node.Value) {
                    stack.Push(j);
                    nodes.Remove(node);
                    break;
                }
                node = node.Previous;
                j--;
            }

            if(j <= 0) return -1;
        };

        StringBuilder sb = new StringBuilder();
        while(stack.Any()) sb.AppendLine(stack.Pop().ToString());

        return sb;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 11348
function main() {
  const sec = parseInt(input[0], 10);
  const h = Math.floor(sec / 3600);
  const m = Math.floor((sec -(3600 * h)) / 60);
  const s = sec - (3600 * h) - (60 * m);
  console.log(h + ':' + m + ':' + s);
}

var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n')
  main();
});


Measured memory_bytes: 15280
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let v = read_vec::<f64>();
    let mut v = v.into_iter().map(|x| Total(-x)).collect::<BinaryHeap<_>>();
    while v.len() >= 2 {
        let a = -v.pop().unwrap().0;
        let b = -v.pop().unwrap().0;
        v.push(Total(-(a + b) / 2.0));
    }
    println!("{}", -v.pop().unwrap().0);
}
#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2172
import java.util.*;
 
public class Main{
 
    void solve(){
        Scanner sc = new Scanner(System.in);
 
        while(true){
            int n = sc.nextInt();
            if(n==0) break;
 
            int[] h = new int[200];
            int[] r = new int[200];
 
            int idx = 0;
            for(; idx<n; idx++){
                h[idx] = sc.nextInt();
                r[idx] = sc.nextInt();
            }
            int m = sc.nextInt();
            for(; idx<n+m; idx++){
                h[idx] = sc.nextInt();
                r[idx] = sc.nextInt();
            }
 
            int[] dp = new int[n+m];
            Arrays.fill(dp,1);
            for(int k=0; k<n+m; k++){
                for(int i=0; i<n+m; i++){
                    for(int j=0; j<n+m; j++){
                        if(h[i]<=h[j] || r[i]<=r[j]) continue;
                        dp[i] = Math.max(dp[i],dp[j]+1);
                    }
                }
            }
 
            int ans = 0;
            for(int i=0; i<n+m; i++) ans = Math.max(ans, dp[i]);
 
            System.out.println(ans);
        }
    }
 
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 24148
#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(var,init,end) for(int var=init;var<end;var++)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int facctorialMethod(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int main() {
	int b,a,s;
	cin >> a >> b;
	s = b - a;

	int ans = 0;
	REP(i, s) {
		ans += (i + 1);
	}
	cout << ans - b;

	return 0;
}

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

using namespace std;

int main() {
    int sum = 0;
    int mini = 101;
    for (int i = 0; i < 4; ++i) {
        int s;
        cin >> s;
        sum += s;
        mini = min(s, mini);
    }
    int s1, s2;
    cin >> s1 >> s2;
    cout << sum - mini + max(s1, s2) << '\n';
}


Measured memory_bytes: 3084
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"29"# => "Yes",
// r#"24"# => "No",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        mut abc: [isize; 3],
    }
    abc.sort();

    if abc[0] == abc[1] {
        abc[2]
    } else {
        abc[0]
    }.to_string()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    double x[n],y[n];
    for(int i=0;i<n;i++) cin >> x[i];
    for(int i=0;i<n;i++) cin >> y[i];
    
    double p1=0.0,p2=0.0,p3=0.0,pINF=0.0;
    
    for(int i=0;i<n;i++){
        p1+=abs(x[i]-y[i]);
        p2+=pow(abs(x[i]-y[i]), 2);
        p3+=pow(abs(x[i]-y[i]), 3);
        pINF=max(pINF, abs(x[i]-y[i]));
    }
    p2=pow(p2, 1/2.0);
    p3=pow(p3, 1/3.0);
    
    cout << fixed << setprecision(6) << p1 << endl;
    cout << fixed << setprecision(6) << p2 << endl;
    cout << fixed << setprecision(6) << p3 << endl;
    cout << fixed << setprecision(6) << pINF << endl;
    return 0;
    
}


Measured memory_bytes: 3448
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;
char str[101];
map<char, char> kako = { {'(',')'},{'[',']'} };

int main() {
	int m;
	scanf("%d", &m);
	REP(i, m) {
		set<string> denshas;
		char s [73];
		scanf("%s", s);

		for (int j = 1; strlen(s) > j; j++) {
			string str(s);
			string str1 = str.substr(0, j), str2 = str.substr(j,str.size()-j);
			denshas.insert((str2+str1));
			denshas.insert((str1 + str2));
			reverse(str1.begin(), str1.end());
			denshas.insert((str2 + str1));
			denshas.insert((str1 + str2));
			reverse(str1.begin(), str1.end());
			reverse(str2.begin(), str2.end());
			denshas.insert((str2 + str1));
			denshas.insert((str1 + str2));
			reverse(str1.begin(), str1.end());
			denshas.insert((str2 + str1));
			denshas.insert((str1 + str2));
		}
		printf("%d\n",denshas.size());
	}
	return 0;
}

Measured memory_bytes: 3364
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n = int(input())
    s = []
    t = []
    for i in range(n):
        x,y = input().split()
        s.append(x)
        t.append(int(y))
    x = input()
    sleep = False
    ans = 0
    for i in range(n):
        if s[i]==x:
            sleep = True
            continue
        if sleep:
            ans += t[i]
    print(ans)
    return

if __name__=='__main__':
    main()


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    vector<pair<int, int>> path;
    rp(i, 0, m) {
        int a, b;
        cin >> a >> b;
        path.emplace_back(a, b);
    }

    UnionFind UF(n+10);
    vector<ll> res(m+10);
    res[m-1] = n*(n-1) / 2ll;
    for(int i = m-1; i >= 1; i--) {
        int a = path[i].first;
        int b = path[i].second;
        // aとbのグループのサイズをもらう
        ll a_size = UF.size(a);
        ll b_size = UF.size(b);
        // aとbをくっつける
        if(UF.merge(a, b)){
            // res更新
            ll ab_size = a_size + b_size;
            res[i-1] = res[i] - ab_size * (ab_size-1) / 2ll + a_size * (a_size-1) / 2ll + b_size * (b_size-1) / 2ll;
        }
        else res[i-1] = res[i];
        // printf("a = %d b = %d a_size = %lld b_size = %lld res = %lld\n", a, b, a_size, b_size, res[i-1]);
    }
    rp(i, 0, m) {
        cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 6392
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int ans;
    if (n%k == 0) ans = 0;
    else ans = 1;
    printf("%d\n", ans); 
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(30);
#define ll long long
#define pi 3.14159265359
using namespace std;

int main()
{
    IOS;
    int a,b;
    cin>>a>>b;
    cout<<a*b;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n;
int main(){
	cin >> n;
	LL x = (LL)sqrt((double)n);
	while(x > 0 && x){
		if(n%x == 0) break;
		x--;
	}
	cout << (n/x) + x -2 << endl;

	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		int[] arr = new int[t];
		int type = scan.nextInt();
		for (int count = 0; count < t; count++)
			arr[count] = scan.nextInt();
		Arrays.sort(arr); int sum = 0;
		for (int count = 0; count < type; count++)
			sum += arr[count];
		System.out.println(sum);
		scan.close();
	}
}


Measured memory_bytes: 38848
#include<iostream>

#define loop(i,a,b) for(int i = a; i < b; i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(void){
	int l[10];
	int v[2];
	char tmp;
	double x;
	while(cin>>l[0]){
		cin>>tmp;
		loop(i,1,10)cin>>l[i]>>tmp;
		cin>>v[0]>>tmp>>v[1];
		
		int sum = 0;
		rep(i,10)sum+=l[i];
		
		x = sum * v[0]/(v[0] + v[1]);
		
		sum = 0;
		int cnt=0;
		rep(i,10){
			sum+=l[i];
			cnt++;
			if(sum>=x){
				cout<<cnt<<endl;
				break;
			}		
		}
	}

}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,a,n) for(int i=a;i<n;i++)
using namespace std;
string s[12];
int n,a[11],an[11];
double v[12],w[12];
main(){
  while(cin>>n,n){
    double ans=1e9,t,x,y;
    r(i,n)a[i]=i;
    r(i,n)cin>>s[i]>>w[i]>>v[i];
    do{
      int f=0;
      r(i,n){t=0;
        R(j,i+1,n)t+=w[a[j]];
        if(v[a[i]]<t)f++;
      }
      if(f)continue;
      y=x=0;
      r(i,n)x+=w[a[i]]*(i+1),y+=w[a[i]];
      if(x/y<ans){
        ans=x/y;
        r(i,n)an[i]=a[i];
      }
    }while(next_permutation(a,a+n));
    r(i,n)cout<<s[an[i]]<<endl;
  }
}

Measured memory_bytes: 3252
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <bitset>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int t, n;
int dx[] = {0, 1, 1, 0, -1, -1};
int dy[] = {1, 1, 0, -1, -1, 0};
struct node{
    int x;
    int y;
    int step;
};
bool inrange(int x, int y){
    return x >= 0 && y >= 0 && x <= 200 && y <= 200;
}
bool jam[201][201];
int main(){
    while(cin >> t >> n, t||n){
        memset(jam, 0, sizeof(jam));
        rep(i, n){
            int bx, by;
            cin >> bx >> by;
            bx += 100;
            by += 100;
            jam[bx][by] = true;
        }
        int sx, sy;
        cin >> sx >> sy;
        sx += 100;
        sy += 100;
        queue<node> q;
        set<pair<int, int> > st;
        q.push((node){sx, sy, 0});
        while(!q.empty()){
            int x = q.front().x;
            int y = q.front().y;
            int step = q.front().step;
            q.pop();
            //      cout << x << " " << y << " " << step << endl;
            if(st.find(mp(x, y)) != st.end()) continue;
            if(step >= t+1) break;
            st.insert(mp(x, y));
            rep(i, 6){
                int nx = x + dx[i];
                int ny = y + dy[i];
                if(inrange(nx, ny) && !jam[nx][ny]){
                    q.push((node){nx, ny, step+1});
                }
            }
            
        }
        cout << st.size() << endl;
    }
}

Measured memory_bytes: 1404
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
	int a, b;
	cin >> a >> b;
	
	cout << (1 + b - a) * (b - a) / 2 - b << endl;
}

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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

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

    loop {
        int N = 1000 - next<int>(), ans = 0;
        if(N == 1000) break;

        for(int coin : {500, 100, 50, 10, 5, 1}) {
            ans += N / coin;
            N %= coin;
        }

        cout << ans ln;
    }

    return 0;
}

Measured memory_bytes: 1192
n = int(input())
h = list(map(int, input().split()))
tmpcnt = 0
maxcnt = 0
for i in range(0, n - 1):
    if h[i] >= h[i+1]:
        tmpcnt += 1
    elif h[i] < h[i+1]:
        tmpcnt = 0
    
    if tmpcnt >= maxcnt:
        maxcnt = tmpcnt
print(maxcnt)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
int main (){
    int N, result = 0, maxp = 0;
    cin >> N;
    int p[N];
    for (int i = 0; i < N;i++){
        cin >> p[i];
        result += p[i];
        if(maxp < p[i])
            maxp = p[i];
    }
    cout << result - (maxp / 2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#define FUP(i,x,y) for(int i=(x);i<=(y);i++)
#define FDW(i,x,y) for(int i=(x);i>=(y);i--)
#define MAXN 100010
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define ll long long
#define db double
using namespace std;
int read(){
    int w=0,flg=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')flg=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){w=w*10-'0'+ch,ch=getchar();}
    return w*flg;
}
char c[7];
int main(){
	scanf("%s",c+1);
	if(c[3]==c[4]&&c[5]==c[6]) puts("Yes");
	else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    char s[4];
	scanf("%s",s);
	if(s[1]=='B') {
		s[1] = 'R';
		printf("%s\n",s);
	}
	else {
		s[1]= 'B';
		printf("%s\n",s);
	}
	return 0;
	}

Measured memory_bytes: 1624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;

template<class T> inline bool chmin(T &a,T b){
    if (a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){
        a=b;
        return true;
    }
    return false;
}
const ll INF=1000000000;

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    rep(i,M){
        ll a,b;
        cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
    }
    int S,T;
    cin >> S >> T;
    S--,T--;
    vector<vector<int>> d(N,vector<int>(3,INF));
    queue<Pii> que;
    que.push(Pii(S,0));
    d[S][0]=0;
    while(!que.empty()){
        Pii p=que.front();
        que.pop();
        int v=p.first;
        for (auto nv:G[v]){
            int x=(p.second+1)%3;
            if (d[nv][x]>d[v][p.second]+1){
                d[nv][x]=d[v][p.second]+1;
                que.push(Pii(nv,x));
            }
        }
    }
    if (d[T][0]==INF){
        d[T][0]=-3;
    }
    cout << d[T][0]/3 << endl;
}

Measured memory_bytes: 11136
h, w = map(int,input().split())

ans = h*w
if h % 3 == 0 or w % 3 == 0:
    ans = 0
else:
    ct = h
    for cy in range(1, w):
        c0 = ct * cy
        c1 = (w-cy) * (ct//2)
        c2 = h*w - c0 - c1
        cmax = max(c0, c1, c2)
        cmin = min(c0, c1, c2)
        #print(c0, c1, c2)
        if cmin > 0:
            ans = min(ans, cmax - cmin)
    ct = w
    for cy in range(1, h):
        c0 = ct * cy
        c1 = (h-cy) * (ct//2)
        c2 = h*w - c0 - c1
        cmax = max(c0, c1, c2)
        cmin = min(c0, c1, c2)
        #print(c0, c1, c2)
        if cmin > 0:
            ans = min(ans, cmax - cmin)

print(min(ans, h, w))



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

int n,k,h[10000000],dp[10000000],mn;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	for(int i=2;i<n;i++){
		mn=INT_MAX;
		for(int j=1;j<=k;j++){
			if(i-j<0)
				break;
			if(dp[i-j]+abs(h[i]-h[i-j])<mn)
				mn=dp[i-j]+abs(h[i]-h[i-j]);
		}
		dp[i]=mn;
	}
	cout<<dp[n-1];
	return 0;
}

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

using namespace std;

const int N = 1e5 + 2;
const int mod = 1e9 + 7;

int n, k, a[N];
long long dp[4][N];

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

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

      for(int i = 0; i <= a[1]; i ++){
            dp[1][i] = 1;
      }

      for(int i = 2; i <= n; i ++){
            int cur = i % 2;
            int pre = cur ^ 1;
            memset(dp[cur], 0, sizeof(dp[cur]));
            for(int j = 0; j <= k; j ++){
                  if(j){
                        dp[2][j] = dp[pre][j] + dp[2][j - 1];
                  } else {
                        dp[2][j] = dp[pre][j];
                  }
            }
            for(int j = 0; j <= k; j ++){
                  int ret;
                  if(j <= a[i]){
                        ret = dp[2][j] % mod;
                  } else {
                        ret = (dp[2][j] - dp[2][j - a[i] - 1]) % mod;
                  }
                  dp[cur][j] = ret;
            }
      }

      cout << dp[n % 2][k] << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define INF 1000000001

int main(){
    int n, k;
    vector<int> p;
    cin >> n >> k;

    for(int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    
    sort(p.begin(), p.end());

    int mindiff = INF;

    for(int i = 0; i < p.size() - (k - 1); i++)
    {
        mindiff = min(mindiff, p[i+(k-1)] - p[i]);       
    }
    
    cout << mindiff << endl;

}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;
const string nyan("(=^・ω・^=)");

int N, V[20], C[20], res;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> V[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> C[i];
	}
	for (int i = 0; i < N; ++i) {
		res += max(0, V[i] - C[i]);
	}
	cout << res << endl;
}


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

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

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<bool> can(n, true);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        int si = (i + k) % n;
        int sj = (j - k + n) % n;
        if (a[i][j] != a[si][sj]) {
          can[(i - sj + n) % n] = 0;
        }
      }
    }
  }
  cout << n * accumulate(can.begin(), can.end(), 0) << '\n';
  return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <string>
using namespace std;
int main(void){
  for(;;){
    string g;
    int y, m, d;
    cin >> g;
    if(g == "#"){ return 0; }
    cin >> y >> m >> d;
    if( y < 31 || (y == 31 && m <= 4) ){
      cout << "HEISEI " << y << " " << m << " " << d << endl;
    }else{
      cout << "? " << y - 30 << " " << m << " " << d << endl; 
    }
  }
}



Measured memory_bytes: 3176
#include <stdio.h>

int main() {
  int h, w, h_roop, w_roop;

  while(scanf("%d %d", &h, &w)) {
    if(h == 0 && w == 0) {
      break;
    } else {
      for(h_roop = 0; h_roop < h; h_roop++) {
        for(w_roop = 0; w_roop < w; w_roop++) {
          printf("#");
        }
        puts("");
      }
      puts("");
    }
  }

  return 0;
}

Measured memory_bytes: 588
#include<stdio.h>
main(){
   
  int x,y,c;
   
  while(1){
    scanf("%d%d",&x,&y);
 
    if( x == 0 && y == 0)
      break;
     
    if( x > y ){
      c = y;
      y = x;
      x = c;
    }
    printf("%d %d\n", x, y);
 
  }
 
  return 0;
 
}

Measured memory_bytes: 600
import heapq

nv, ne, r = map(int, input().split())

edges = [set() for _ in range(nv)]
costs = [-1] * nv

while ne:
    s, t, d = map(int, input().split())
    edges[s].add((d, t))
    ne -= 1

queue = list(edges[r])
heapq.heapify(queue)
costs[r] = 0

while queue:
    total_cost, idx = heapq.heappop(queue)
    if costs[idx] > -1:
        continue
    costs[idx] = total_cost
    for cost, idx2 in edges[idx]:
        if costs[idx2] == -1:
            heapq.heappush(queue, (total_cost + cost, idx2))

for cost in costs:
    print(cost if cost > -1 else 'INF')

Measured memory_bytes: 128452