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

int main(){
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int64_t>> a(n, vector<int64_t>(m));
  vector<vector<int64_t>> b(m, vector<int64_t>(l));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a.at(i).at(j);
    }
  }
  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
      cin >> b.at(i).at(j);
    }
  }
  vector<vector<int64_t>> c(n, vector<int64_t>(l));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
      for(int k = 0; k < m; k++){
        c.at(i).at(j) += a.at(i).at(k) * b.at(k).at(j);
      }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
      if(j == l - 1){ 
        cout << c.at(i).at(j) << endl;
      }
      else{
        cout << c.at(i).at(j) << " ";  
      }
    }
  } 
}



Measured memory_bytes: 3256
/*
Insertion Sort
ALDS1_1_A

挿入ソートプログラム
*/
package main

import (
	"fmt"
)

// 配列(スライス)を表示する
func disp_array(arr []int) {
	for i := 0; i < len(arr); i++ {
		fmt.Print(arr[i])
		if i != len(arr)-1 {
			fmt.Print(" ")
		}
	}
	fmt.Println("")
}

func ins_sort(arr []int, n int) []int {
	disp_array(arr)

	for i := 1; i <= n-1; i++ {
		v := arr[i]
		j := i - 1

		for j >= 0 && arr[j] > v {
			arr[j+1] = arr[j]
			j--
		}
		arr[j+1] = v

		disp_array(arr)
	}
	return arr
}

func main() {
	var n int
	var num int
	var data []int

	fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &num)
		data = append(data, num)
	}

	ins_sort(data, n)
}


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

int main(){
    int d;
    while(scanf("%d",&d) == 1){
        int area = 0;
        for(int i = 0; i < 600; i += d){
            area += i*i * d;
        }
        printf("%d\n",area);
    }
}

Measured memory_bytes: 2672
#include <bits/stdc++.h>
#define rep(i, N) for(ll i = 0; i < N; i++)
using ll = long long;
using namespace std;
#define MOD 1000000007
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;

int main() {
    int n;
    cin >> n;
    ll a[202020];
    rep(i,n) scanf("%lld", &a[i]);

    ll sum = 0, ans = 0;
    rep(i,n) {
        sum += a[i];
        if(sum >= MOD) sum %= MOD;
    }
    rep(i,n-1){
        sum -= a[i];
        if(sum < 0) sum = (sum + MOD) % MOD;
        ans += (a[i] * sum)%MOD;
        if(ans >= MOD) ans %= MOD;
    }

    cout << ans;
    printf("\n");
}


Measured memory_bytes: 5332
a,b = map(int,input().split())
L1 = [0]*a
L2 = [0]*a
acc,wac = 0,0
for i in range(b):
    c,d = input().split()
    if d == "AC" and L2[int(c)-1] == 0:
        acc +=1
        L2[int(c)-1] = 1
        wac += L1[int(c)-1]
        continue
    
    else:
         L1[int(c)-1] += 1
print(acc,wac)

Measured memory_bytes: 4596
open Batteries
(* 出てきたsの個数をカウント *)
let rec count_string s text =
  let rec slicing str target =
    match str with
    | t when String.length t = String.length target -> if t = target then 1 else 0
    | t -> if get (String.length str) target = str then 1 + slicing str (cut 1 target) else slicing str (cut 1 target)
  in slicing s text
and get num str = String.init num (fun a -> String.get str a)
and cut st str = String.init (String.length str - st) (fun a -> String.get str (a+st))

let n = read_int ()
let s = read_line ()

let _ = Printf.printf "%d\n" @@ count_string "ABC" s 

Measured memory_bytes: 1024
n, k, q = map(int, input().split())
As = [int(input()) for i in range(q)]
points = {i: k for i in range(n)}
accepted = [0] * n

for i in range(q):
    accepted[As[i]-1] += 1

for i in range(n):

    if k - q + accepted[i] <= 0:
        print("No")
    else:
        print("Yes")






Measured memory_bytes: 62548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec a(n),b(n);
  for(ll i=0;i<n;i++) cin >> a[i] >> b[i];
  ll mi=inf;
  ll ans=0;
  for(ll i=0;i<n;i++) {
    if(a[i]>b[i]) {
      mi=min(mi,b[i]);
    }
    ans+=a[i];
  }
  ans-=mi;
  if(mi==inf) ans=0;
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;
const long long INFll = (1ull<<62) - 1;

struct Edge
{
	int to;
	double cost;
};

struct Dijkstra
{
	using P = pair<double, int>;
	int V;
	int s;
	const vector<vector<Edge>> &g;
	vector<double> dist;
	vector<int> previous;

	Dijkstra(const vector<vector<Edge>> &g) : V(g.size()), g(g) {}

	void calc(int start) {
		s = start;
		dist.assign(V, INFll);
		previous.assign(V, -1);
		dist[s] = 0;
		priority_queue<P, vector<P>, greater<P>> pque;
		pque.push(P(0, s));
		while (!pque.empty()) {
			P p = pque.top(); pque.pop();
			int v = p.second;
			if (p.first > dist[v]) continue;
			for (Edge e : g[v]) {
				if (dist[e.to] > dist[v] + e.cost) {
					dist[e.to] = dist[v] + e.cost;
					previous[e.to] = v;
					pque.push(P(dist[e.to], e.to));
				}
			}
		}
	}
};

struct T
{
	long long x, y, r;
};

double dist(T &a, T &b) {
	const double dx = a.x - b.x, dy = a.y - b.y;
	return max((double)0, sqrt(dx*dx + dy*dy) - a.r - b.r);
}

int main() {
	T s, t;
	cin >> s.x >> s.y >> t.x >> t.y;
	s.r = t.r = 0;
	int n;
	cin >> n;
	vector<T> v(n+2);
	v[0] = s, v[1] = t;
	for (int i = 0; i < n; i++) {
		cin >> v[i+2].x >> v[i+2].y >> v[i+2].r;
	}
	vector<vector<Edge>> g(n+2);
	for (int i = 0; i < n+2; i++) {
		for (int j = i+1; j < n+2; j++) {
			double d = dist(v[i], v[j]);
			g[i].push_back({j, d});
			g[j].push_back({i, d});
		}
	}
	Dijkstra D(g);
	D.calc(0);
	double ans = D.dist[1];
	cout << fixed << setprecision(20) << ans << endl;
	return 0;
}

Measured memory_bytes: 23204
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int max = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int l = sc.nextInt();
            max = Math.max(max, l);
            sum += l;
        }
        System.out.println(max < sum - max ? "Yes" : "No");
    }
}


Measured memory_bytes: 23636
#include<stdio.h>

#define Max 100
#define Inf (1<<21)
#define W 0
#define G 1
#define B 2

int n, M[Max][Max];

void dik(){
  int minv,i,v;
  int d[Max],col[Max];

  for(i=0;i<n;i++){
    d[i] = Inf;
    col[i]=W;
  }

  d[0] = 0;
  col[0] = G;

  while(1){
    minv = Inf;
    int u = -1;

    for(i=0;i<n;i++){
      if(minv > d[i] && col[i] != B){
        u = i;
        minv = d[i];
      }
    }
    if(u==-1)break;
    col[u] = B;
    for(v = 0;v<n;v++){
      if(col[v] != B && M[u][v] != Inf){
        if(d[v]> d[u] + M[u][v]){
          d[v] = d[u] + M[u][v];
          col[v] = G;
         }
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%d ",i );
    if(d[i] == Inf)printf("-1\n" );
    else printf("%d\n",d[i]);
  }
}

int main(){
  int i,j,k,c,u,v;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j] = Inf;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j = 0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
    }

    dik();
    return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
//debug
#define vecprint(v) rep(i,v.size())cout << v[i] << " ";cout << endl;
#define setprint(s) for(auto i=s.begin();i!=s.end();i++)cout << *i << " ";cout << endl;
#define mappairprint(s) for(auto i=s.begin();i!=s.end();i++)cout << i->first << " " << i->second << endl;cout << endl;
//reader
#define r1(a) cin>>(a)
#define r2(a,b) cin>>(a)>>(b)
#define r3(a,b,c) cin>>(a)>>(b)>>(c)
//writer
#define w1(a) cout<<(a)<<" "
#define w2(a,b) cout<<(a)<<" "<<(b)<<" "
#define w3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "
#define wl1(a) cout<<(a)<<endl
#define wl2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wl3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
//variable definition
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
//roop
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define all(c) c.begin(),c.end()
//term
#define elif else if
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
using namespace std;
using ll = long long;
//const
constexpr double PI = 3.141592653589793238462643383279;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};


int main() {
  //input
  int a, b, c,d,e;
  cin >> a >>  b >> c >> d >> e;
  
  //process
  if(a == 0) cout << "1" << endl;
  else if(b == 0) cout << "2" << endl;
  else if(c == 0) cout << "3" << endl;
  else if(d == 0) cout << "4" << endl;
  else if(e == 0) cout << "5" << endl;
  
  //output
}

Measured memory_bytes: 3600
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1};
vl dy={1,-1,0,0};

//素因数分解O(√n)
map<ll,ll>prime_factor(ll n){
  map<ll,ll>res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}

const ll MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
//finvが階乗の逆元

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll mod) {
  
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll n;cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  vl sum(61);
  rep(k,61){
    rep(i,n){
      if(bit(a[i],k))sum[k]++;
    }
  }
  ll pows=1;
  ll len=a.size();
  ll ans=0;
  rep(bit,61){
    ans+=((len-sum[bit])*sum[bit])%MOD*pows%MOD;
    ans%=MOD;
    pows*=2;
    pows%=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5568
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 11/13/2018, 7:47:50 AM
# Powered by Visual Studio Code
#

a, b = gets.chomp.split(" ").map{|i| i.to_s}
n = (a + b).to_i

for i in 0...1000 do
  if n == i ** 2
    puts "Yes"
    exit
  end
end

puts "No"


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();
		sc.close();
		
		int moveX = tx - sx, moveY = ty - sy;
		StringBuilder forwardX = new StringBuilder();
		StringBuilder forwardY = new StringBuilder();
		StringBuilder backwardX = new StringBuilder();
		StringBuilder backwardY = new StringBuilder();
		while(moveX != 0) {
			if(moveX < 0) {
				forwardX.append('L');
				backwardX.append('R');
				moveX++;
			} else {
				forwardX.append('R');
				backwardX.append('L');
				moveX--;
			}
		}
		while(moveY != 0) {
			if(moveY < 0) {
				forwardY.append('D');
				backwardY.append('U');
				moveY++;
			} else {
				forwardY.append('U');
				backwardY.append('D');
				moveY--;
			}
		}
		
		String firstPath = "", secondPath = "";
		if(!(tx - sx == 0 || ty - sy == 0)) {
			firstPath = forwardX.toString() + forwardY.toString() + backwardX.toString() + backwardY.toString();
			if(tx - sx > 0 && ty - sy > 0)
				secondPath = "D" + forwardX.toString() + "R" + forwardY.toString() + "ULU" + backwardX.toString() + "L" + backwardY.toString() + "DR";
			else if(tx - sx < 0 && ty - sy > 0)
				secondPath = "D" + forwardX.toString() + "L" + forwardY.toString() + "URU" + backwardX.toString() + "R" + backwardY.toString() + "DL";
			else if(tx - sx < 0 && ty - sy < 0)
				secondPath = "U" + forwardX.toString() + "L" + forwardY.toString() + "DRD" + backwardX.toString() + "R" + backwardY.toString() + "UL";
		} else if(tx - sx == 0) {
			firstPath = forwardY.toString() + "R" + backwardY.toString() + "L";
			if(ty - sy > 0)
				secondPath = "L" + forwardY.toString() + "RURR" + backwardY.toString() + "DDLLU";
			else
				secondPath = "L" + forwardY.toString() + "RDRR" + backwardY.toString() + "UULLD";
		} else if(ty - sy == 0) {
			firstPath = forwardX.toString() + "U" + backwardX.toString() + "D";
			if(tx - sx > 0)
				secondPath = "D" + forwardX.toString() + "URUU" + backwardX.toString() + "LLDDR";
			else
				secondPath = "D" + forwardX.toString() + "ULUU" + backwardX.toString() + "RRDDL";
		}
		System.out.println(firstPath + secondPath);
	}
	
}


Measured memory_bytes: 23380
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2001>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int n,m,a;
int solve(){
    int res = 0;
    vector<int> amida(n,0); iota(amida.begin(),amida.end(),0);
    a--;
    
    vector<pair<int,pii>> query(m);
    for(int i = 0; i < m;i++){
        int h,p,q; cin >> h >> p >> q;
        query[i] = {h,{p-1,q-1}};
    }
    sort(query.begin(),query.end());
    for(int i = 0; i < m;i++){
        swap(amida[query[i].second.first],amida[query[i].second.second]);
    }
    return res = amida[a]+1;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> n >> m >> a,n|a|m){
        cout << solve() << endl;
    }
    return 0;
}



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

using namespace std;

vector<char> tag[2];
vector< vector<int> > e[2];

int v[100][100];
bool f[100][100] = {0};

bool dp(int a, int b, int score) {
	if (tag[0][a] == tag[1][b]) ++score;

	if (score <= v[a][b]) return false;
	if (f[a][b]) return true;
	v[a][b] = score;

	f[a][b] = true;
	if (tag[0][a] != tag[1][b]) {
		for (int i = 0; i < e[0][a].size(); ++i) {
			if ( dp(e[0][a][i], b, score) ) return true;
		}
		for (int i = 0; i < e[1][b].size(); ++i) {
			if ( dp(a, e[1][b][i], score) ) return true;
		}
	}
	else {
	for (int i = 0; i < e[0][a].size(); ++i) {
		for (int j = 0; j < e[1][b].size(); ++j) {
			if ( dp(e[0][a][i], e[1][b][j], score) ) return true;
		}
	}
	}
	f[a][b] = false;
	return false;
}

int main() {
	fill(&v[0][0], &v[0][0]+100*100, -1);

	for (int t = 0; t < 2; ++t) {
		int N, M; cin >> N >> M;
		tag[t].resize(N);
		for (int i = 0; i < N; ++i) {
			cin >> tag[t][i];
		}
		e[t].resize(N);
		for (int i = 0; i < M; ++i) {
			int a, b; cin >> a >> b; --a, --b;
			e[t][a].push_back(b);
		}
	}

	for (int a = 0; a < tag[0].size(); ++a) for (int b = 0; b < tag[1].size(); ++b) {
		if ( dp(a, b, 0) ) {
			cout << -1 << endl;
			return 0;
		}
	}
	int ans = 0;
	for (int a = 0; a < tag[0].size(); ++a) for (int b = 0; b < tag[1].size(); ++b) {
		ans = max(ans, v[a][b]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1456
# coding: utf-8

import sys
import math

import array
import bisect
import collections
from collections import Counter, defaultdict
import fractions
import heapq
import re

sys.setrecursionlimit(1000000)


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

def argsort(l, reverse=False):
    return sorted(range(len(l)), key=lambda i: l[i], reverse=reverse)

def argmin(l):
    return l.index(min(l))

def YESNO(ans, yes="YES", no="NO"):
    print([no, yes][ans])

II = lambda: int(input())
MI = lambda: map(int, input().split())
MIL = lambda: list(MI())
MIS = lambda: input().split()


def prev_multi(num, multi):
    return math.floor(num / multi) * multi

def next_multi(num, multi):
    return math.ceil(num / multi) * multi


def main():
    A, B = MI()
    if B == 0: return 0
    ans = (math.ceil(B/2) - math.floor(A/2)) % 2
    for i in range(1, math.ceil(math.log2(B)) + 1):
        p = 2**i

        na = next_multi(A, p)
        if (na > B):
            d = 0 if (na / p) % 2 else B - A + 1
        else:
            da = 0 if (na / p) % 2 else na - A
            pb = prev_multi(B, p)
            db = 0 if (pb / p) % 2 == 0 else B - pb + 1
            d = da + db
        ans += d % 2 * p

    return ans

if __name__ == "__main__":
    print(main())


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

using namespace std;

int a[200005];

int main(){

	int n;
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a,a+n);
	long long ans = abs(a[n-1]-a[0]);
	int r=n-1,l=0;
	r--;
	l++;
	int c = a[n-1],d=a[0];
	while(l<r){
		ans += max(abs(a[l]-c),abs(a[r]-c));
		ans += max(abs(a[l]-d),abs(a[r]-d));
		c = a[l];
		d = a[r];
		l++;
		r--;
		
	}
	if(n%2)
		ans += max(abs(c-a[r]),abs(d-a[r]));
	cout << ans;

}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll n; cin >> n;
    map<ll,ll> mp;

    for(int i = 1; i<= 100; i++){
        for(int j = 1; j<= 100; j++){
            for(int k = 1; k<= 100; k++){
                mp[i*i + j*j + k*k + i*j + j*k + k*i]++;        
            }
        }
    }

    rep(i,n){
        cout << mp[i+1] << endl;
    }


}

Measured memory_bytes: 6008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using ll = long long;
int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    rep(i, n) scanf("%d", &a[i]);
    ll ans = 0;
    int max_num = 0;
    rep(i, n) {
        max_num = max(max_num, a[i]);
        ans += max_num - a[i];
    }

    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4044
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std; 
 
#define NOT_FOUND -1
#define rep(i,n) for(int i=0;i<(int)(n); i++)
/*for文のマクロ定義
rep(i,回数){
    処理
}
*/
 
void swap(int *a, int *b){
	*b=*a-*b;
	*a-=*b;
	*b+=*a;
}
 
int sosu_judge(int N){
	/*素数ならば1
	  素数でなければ0を返す
	*/
	int i,j;
 
	if(N==2)   return 1;
	if(N%2==0) return 0;
 
	for(i=3;i<N && N%i!=0;i+=2);
 
	if(i>=N) return 1;
	
	return 0;
}
 
int factorial(int N){  //Nの階乗を求める関数
	int ans=1;
 
	while(N--) ans*=(N+1);
	return ans;
}
 
//クイックソートをする関数
void q_sort(int a[], int first, int last){
    int i,j;
    int x,t;
 
    x = a[(first + last) / 2];
    i = first; j=last;
 
    while(1){
        while( a[i] < x) i++;
        while( x < a[j]) j--;
        
        if( i >= j) break;
        
        swap(&a[i],&a[j]);
        i++; j--;
    }
    if(first < i-1) q_sort(a, first,i-1 );
    if(last > j+1)  q_sort(a, j+1,  last);
}
 
int b_search(int target, int array[],int right, int left){
    /*二分探索を行う関数である。
      戻り値は探索したい値の格納されている位置である。
      もし値が存在しない場合、NOT_FOUND(-1)を返す
    */
    int mid;
    while(left<right){
        mid=(right+left)/2;
        if(array[mid]<target) left =mid+1;
        else                  right=mid;
    }
    if(array[mid]==target) return mid;
    return NOT_FOUND;
}
 
unsigned long combination(int n, int r){
    /*nCrの値を求める関数である。
      値が巨大になる可能性があるため、戻り地はunsigned longである
    */
    int i,j;
    unsigned long a[17];
 
    if(n-r<r) r=n-r;
    if(r==0 ) return 1;
    if(r==1 ) return n;
    if(r>17 ) return 0;
    for(i=1;i<r;i++) a[i]=i+2;
    for(i=3;i<=n-r+1;i++){
        a[0]=i;
        for(j=1;j<r;j++)a[j]+=a[j-1];
    }
    return a[r-1];
}

int main(){
    long double L;
    long double S;

    cin>>L;

    L=L/3;
    S=L*L*L;
    printf("%10.12Lf\n",S);
    return 0;
}


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

int main() {
    int n;cin>>n;
    string s;
    ll a=1;
    while (n) {
        if (n%(a*2)) {
            s+='1';
            n-=a;
        } else
            s+='0';
        a*=-2;
    }
    reverse(s.begin(),s.end());
    if (s.empty())
        s="0";
    cout<<s<<endl;
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fr(i,k) for(i=0;i<k;i++)
#define ALL(c) (c).begin(),(c).end()
#define deb(x) cerr<<#x<<"  = "<<x<<endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}


int main() {
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t;
	t = 1;

	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


void solve()
{
	ll n, W, i, j, ans, maxVal;
	cin >> n >> W;

	ll w[n + 1], p[n + 1];

	for (i = 1; i <= n; i++)
	{
		cin >> w[i] >> p[i];
	}


	maxVal = n * 1000;
	vector<vector<ll>> dp(n + 1, vector<ll>(maxVal + 1));

	for (i = 0; i <= maxVal; i++)
	{
		dp[1][i] = INF;
	}

	dp[1][0] = 0;
	dp[1][p[1]] = w[1];

	for (i = 2; i <= n; i++)
	{
		for (j = 0; j <= maxVal; j++)
		{
			dp[i][j] = dp[i - 1][j];

			if (p[i] <= j)
			{
				dp[i][j] = min(dp[i][j], w[i] + dp[i - 1][j - p[i]]);
			}
		}
	}

	for (i = 0; i <= maxVal; i++)
	{
		if (dp[n][i] <= W)
			ans = i;
	}

	cout << ans << endl;

}


Measured memory_bytes: 83156
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long x, y, ans = 1LL << 60;
	cin >> x >> y;
	if (x == y) ans = 0;
	if (x == -y) ans = 1;
	if (x < y) ans = min(ans, y - x);
	if (-x < y) ans = min(ans, 1 + y + x);
	if (x < -y) ans = min(ans, 1 -y - x);
	if (-x < -y) ans = min(ans, 2 -y + x);

	cout << ans << "\n";

	return 0;
}



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

#define INF 999999999

typedef long long ll;
typedef pair<int, string> P;

int N, M, R;
int r[10];
int d[202][202];


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

	for (int i = 0; i < 202; i++) {
		for (int j = 0; j < 202; j++) {
			if (i == j) d[i][j] = 0;
			else d[i][j] = INF;
		}
	}

	cin >> N >> M >> R;
	for (int i = 0; i < R; i++) {
		int tmp;
		cin >> tmp;
		r[i] = tmp-1;
	}

	for (int i = 0; i < M; i++) {
		int from, to, cost;
		cin >> from >> to >> cost;
		from--; to--;
		if (d[from][to] < cost) continue;
		d[from][to] = cost;
		d[to][from] = cost;
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}

	sort(r, r+R);

	ll mi = INF;
	do {
		ll sum = 0;
		for (int i = 0; i < R-1; i++) {
			sum += d[r[i]][r[i+1]];
		}
		mi = min(sum, mi);
	} while(next_permutation(r, r+R));

	cout << mi << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] like = new int[M+1];
    for (int i = 0; i < N; i++) {
      int K = sc.nextInt();
      for (int j = 0; j < K; j++) {
        like[sc.nextInt()]++;
      }
    }
    
    int ans = 0;
    for (int i = 1; i <= M; i++) {
      if (like[i] == N) {
        ans++;
      }
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int ans;
  int m=max({a,b,c});
  if((3*m+a+b+c)%2==0){
    ans=(3*m-(a+b+c))/2;
  }
  else{
    ans=(3*(m+1)-(a+b+c))/2;
  }
  cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    int n, m;
    cin >> n >> m;
    int s[10];
    char c[10];
    string str(n, 'a');
    REP(i, m) {
        cin >> s[i] >> c[i];
    }
    REP(i, m) {
        if(str[s[i]-1] != 'a' && str[s[i]-1] != c[i]) {
            cout << -1 << endl;
            return 0;
        }
        str[s[i]-1] = c[i];
    }
    if(n > 1 && str[0] == 'a') str[0] = '1';
    for(int i = 0; i < n; i++) {
        if(str[i] == 'a') str[i] = '0';
    }
    if(n > 1 && str[0] == '0') {
        cout << -1 << endl;
        return 0;
    }
    cout << str << endl;




}


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

#define loop(i,a,b) for(ll i=a; i<b; i++)
#define rloop(i,a,b) for(ll i=a; i>b; i--)
#define all(var) var.begin(), var.end()
#define eloop(var) for(auto elem : var)
#define debug(x) cerr<<#x<<" ----> "<<x<<endl;
#define TC ll tt; cin>>tt; while(tt--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ size()
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define MOD 1000000007
#define MAX 100005
typedef long long ll;
typedef long double ld;
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpl vector< pll >

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

    // TC
    {
        ll x, n;
        cin>>x>>n;
        vll ar(n);
        loop(i,0,n) cin>>ar[i];

        sort(all(ar));

        ll c=0;
        ll ans = x;
        while(1) {
            if(binary_search(all(ar), x-c)==false) {
                ans = x-c;
                break;
            }
            else if(binary_search(all(ar), x+c)==false){
                ans = (x+c);
                break;
            }
            c++;
        }
        cout<<ans<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>

#define MAX 2000001
#define VMAX 10000

int main(void)
{
  unsigned short *A, *B;
  
  int C[VMAX+1];
  int n, i, j;
  scanf("%d",&n);
  
  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  
  for(i=0;i<=VMAX;i++) C[i] = 0;
  
  for(i=0;i<n;i++) {
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }
  
  for(i=1;i<=VMAX;i++) C[i] = C[i] + C[i-1];
  
  for(j=1;j<=n;j++) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
  for(i=1;i<=n;i++) {
    if(i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  int ans;
  int i = 111;
  while (i < 1000) {
    if (i >= n) {
      ans = i;
      break;
    }
    i += 111;
  }

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


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>

std::vector<std::set<int>> set_vec;
bool *done;
std::vector<int> *vv;

void con_sets(int x);
void insert_set(int x);

int main()
{
	int n, m, x, y, *p, count{};

	scanf("%d%d", &n, &m);
	p = new int[n];
	done = new bool[n];
	vv = new std::vector<int>[n];
	std::fill(done, done + n, false);

	for (int i = 0; i < n; ++i)
	{
		scanf("%d", p + i);
		p[i]--;
	}
	for (int i = 0; i < m; ++i)
	{
		scanf("%d%d", &x, &y);
		vv[x - 1].push_back(y - 1);
		vv[y - 1].push_back(x - 1);
	}
	for (int i = 0; i < n; ++i)
	{
		if (done[i]) continue;
		con_sets(i);
	}


	for (int i = 0; i < n; ++i)
	{
		if (done[i] || i != p[i]) continue;
		count++;
	}
	for (const auto& e : set_vec)
	{
		for (const auto& f : e)
		{
			if (e.find(p[f]) != e.end()) count++;
		}
	}

	printf("%d\n", count);

	delete[] p;
	delete[] done;
	delete[] vv;

	return 0;
}

void con_sets(int x)
{
	done[x] = true;
	set_vec.push_back({ x });

	for (auto e : vv[x])
	{
		insert_set(e);
	}
}

void insert_set(int x)
{
	if (done[x]) return;
	done[x] = true;
	set_vec.back().insert(x);

	for (auto e : vv[x])
	{
		insert_set(e);
	}
}

Measured memory_bytes: 14760
// {{{ Templates
#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

// }}}

constexpr int MAX = 100000;
int num[MAX + 1];

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

    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        num[a[i]]++;
        if (a[i] > 0) {
            num[a[i] - 1]++;
        }
        num[a[i] + 1]++;
    }
    int maxi = 0;
    for (int X = 0; X <= MAX; X++) {
        maxi = max(maxi, num[X]);
    }
    cout << maxi << endl;

    return 0;
}


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

int main(void){
  int n,k; cin >> n >> k;
  int d[k];
  int a[k][n];
  int ans[n];
  rep(i,n){
    ans[i] = 0;
  }
  rep(i,k){
    cin >> d[i];
    rep(j,d[i]){
      cin >> a[i][j];
      ans[a[i][j]-1]++;
    }
  }
  int count = 0;
  rep(i,n){
    if(ans[i] == 0){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3596
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	a := make([]int, N)
	for i := range a {
		fmt.Scan(&a[i])
	}
	m := make(map[int]int)
	for _, v := range a {
		m[v]++
	}
	cnt := 0
	if len(m) > K {
		va := make([]int, len(m))
		for _, v := range m {
			va = append(va, v)
		}
		sort.Ints(va)
		for i := 0; i < len(va)-K; i++ {
			cnt += va[i]
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 21760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const int A = 1000005;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int memo[1001000] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    memo[a[i]]++;
  }

  int gcdd = a[0];

  for (int i = 1; i < n; i++) {
    gcdd = __gcd(gcdd, a[i]);
  }
  // setwise coprime

  bool pairwise = true;

  for (int i = 2; i < A; i++) {
    int cnt = 0;
    for (int j = i; j < A; j += i) {
      cnt += memo[j];
    }
    if (cnt > 1) {
      pairwise = false;
      cout << (gcdd == 1 ? "setwise coprime" : "not coprime") << endl;
      return 0;
    }
  }

  cout << "pairwise coprime" << endl;
}

Measured memory_bytes: 11036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll n; cin >> n;
    vector<vector<pair<ll, ll>>> node(n+1);
    rep(i, 1, n+1){
        ll tu, tv, tw;
        cin >> tu >> tv >> tw;
        node[tu].push_back({tv, tw});
        node[tv].push_back({tu, tw});
    }

    vector<ll> seen(n+1, false);
    vector<ll> ans(n+1);
    queue<pair<ll,ll>> que;
    que.push({1,0});
    while(!que.empty()){
        auto t = que.front();
        que.pop();
        if(seen[t.first]) continue;
        ans[t.first] = t.second;
        seen[t.first] = true;
        for(auto p : node[t.first]){
            if(seen[p.first]) continue;
            que.push({p.first, (t.second+p.second)%2});
        }
    }
    rep(i, 1, n+1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 11264
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef gp_hash_table < int, int > fast;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void test();

int main() {
    fast_io();
    cout << fixed << setprecision(15);
    test();
    return 0;
}

void test() {
    ll a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << "\n";
}


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

using namespace std;

constexpr int MAXN = 4e5 + 5, MOD = 1e9 + 7;

template<typename T>
inline void read(T& x, T f = 1, char ch = getchar()) {
    x = 0;
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

int n, m;
array<int, MAXN> fa, sz;

inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }

inline void Union(int a, int b) {
    int r1 = find(a), r2 = find(b);
    if (r1 != r2) fa[r1] = r2, sz[r2] += sz[r1];
}

signed main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) fa[i] = i, fa[i + n] = i + n, sz[i] = 1;
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        Union(u, v);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, sz[fa[i]]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8356
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int h,w;

void solve(){
    vector<vector<int>> a(h,vector<int>(w));
    rep(i,h) rep(j,w) cin >> a[i][j];

    int ans = 0;
    for(int x1=0;x1<h;x1++){
        for(int y1=0;y1<w;y1++){
            for(int x2=x1;x2<h;x2++){
                for(int y2=y1;y2<w;y2++){
                    int mn = 100;
                    for(int y=y1;y<=y2;y++){
                        mn = min({mn,a[x1][y],a[x2][y]});
                    }
                    for(int x=x1;x<=x2;x++){
                        mn = min({mn,a[x][y1],a[x][y2]});
                    }

                    bool ok = true;
                    int cnt = 0;
                    for(int x=x1+1;x<x2;x++){
                        for(int y=y1+1;y<y2;y++){
                            if(a[x][y] >= mn){
                                ok = false;
                                break;
                            }
                            cnt += mn - a[x][y];
                        }
                    }

                    if(!ok) continue;

                    ans = max(ans,cnt);
                }
            }
        }
    }
    cout << ans << endl;
}

int main(){
    while(cin >> h >> w){
        if(!h and !w) break;
        solve();
    }
}



Measured memory_bytes: 3132
""" sum(kA)%B = C"""
a,b,c = map(int,input().split())
mod = []
k=0
s = a
while(k<100):
    if s%b == c:
        print("YES")
        exit()
    k+=1
    s=k*a
    if k>=100:
        print("NO")
        exit()


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

#define MOD 1000000007

typedef long long ll;

ll fact[2002], ifact[2002];
ll ans[2002];

ll pow (ll a, ll n) {
	if (n==0)
		return 1;
	if (n==1)
		return a;

	ll tmp = pow (a, n/2) % MOD;
	ll tmp2 = tmp*tmp % MOD;
	if (n%2==0)
		return tmp2;
	return tmp2*a % MOD;
}

ll comb (ll a, ll b) {
	if (a==0 && b==0)
		return 1;
	if (a<b || a<0)
		return 0;
	ll tmp = ifact[a-b] * ifact[b] % MOD;
	return tmp * fact[a] % MOD;
}

ll ccomb (ll a, ll b) {
	return comb (a+b-1, b);
}



int main () {
	fact[0] = fact[1] = 1;
	ifact[0] = ifact[1] = 1;
	for (int i=2; i<2002; i++) {
		fact[i] = fact[i-1]*i % MOD;
		ifact[i] = ifact[i-1]*pow(i, MOD-2) % MOD;
		ans[i] = -1;
	}
	ans[0] = ans[1] = ans[2] = 0;
	ans[3] = ans[4] = ans[5] = 1;

	ll S;
	cin >> S;

	for (int i=6; i<=S; i++) {
		ans[i] = ans[i-1] + ans[i-3];
		ans[i] %= MOD;
	}
	
	cout << ans[S] << endl;
	return 0;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define lo o<<1
#define ro o<<1|1
using namespace std;
typedef long long LL;
int read(){
	int x=0;char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return x; 
} 
const LL N=2e5+5,inf=0x3f3f3f3f3f3f;
LL a[N<<2][3],lzy[N<<2][3];
void push_up(int o){for(int i=0;i<=2;i++)a[o][i]=min(a[lo][i],a[ro][i]);}
void push_down(int o){for(int i=0;i<=2;i++){LL k=lzy[o][i];if(!k)continue ;a[lo][i]+=k;a[ro][i]+=k;lzy[lo][i]+=k;lzy[ro][i]+=k;lzy[o][i]=0;}}
void build(int o,int l,int r){
	if(l==r){for(int i=0;i<=2;i++)a[o][i]=inf;return ;}
	int mid=l+r>>1;
	build(lo,l,mid);build(ro,mid+1,r);
	push_up(o); 
}
void upd(int o,int l,int r,int p,LL k){
	if(l==r){a[o][0]=k,a[o][1]=k+l,a[o][2]=k-l;return ;}
	push_down(o);
	int mid=l+r>>1;
	if(mid>=p)upd(lo,l,mid,p,k);
	else upd(ro,mid+1,r,p,k);
	push_up(o); 
}
void add(LL k){
	for(int i=0;i<=2;i++)a[1][i]+=k,lzy[1][i]+=k;
}
LL query(int o,int l,int r,int ll,int rr,int md){
	if(l>rr||r<ll)return inf;
	if(l>=ll&&r<=rr)return a[o][md];
	push_down(o);
	int mid=l+r>>1;
	return min(query(lo,l,mid,ll,rr,md),query(ro,mid+1,r,ll,rr,md));
}
LL n,m,A,B,x[N],ans=inf;
int main(){
	n=read(),m=read(),A=read(),B=read();
	for(int i=1;i<=m;i++)x[i]=read();
	build(1,1,n);
	upd(1,1,n,B,abs(A-x[1]));upd(1,1,n,A,abs(B-x[1])); 
	for(int i=2;i<=m;i++){
		LL tmp=min(query(1,1,n,x[i],n,1)-x[i],min(query(1,1,n,1,x[i],2)+x[i],query(1,1,n,x[i-1],x[i-1],0)+abs(x[i]-x[i-1])));
		add(abs(x[i]-x[i-1]));
		upd(1,1,n,x[i-1],tmp);
	}
	cout<<a[1][0];
	return 0;
}

Measured memory_bytes: 29732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 定型ループ
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();

		int max = 0;
		if (a >= b) {
			if (a >= c) {
				max = a;
			} else if (b >= c) {
				max = b;
			} else {
				max = c;
			}
		} else {
			if (b >= c) {
				max = b;
			} else {
				max = c;
			}
		}
		int tmp = max;
		for (int i = 0; i < k; i++) {
			tmp = tmp * 2;
		}
		int ans = a + b + c - max + tmp;
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
n = gets.to_s.to_i
L = gets.to_s.split.map{|t|t.to_i}.sort

ans = 0
n.times do |l|
  l.times do |m|
    # L[l] - L[m] < L[s] < L[m]
    s = L[l] - L[m]
    idx = L.bsearch_index{ |x| s < x } || n
    # idx.nil? ? next : idx.not_nil!
    d = m - idx
    ans += d if d > 0
  end
end

puts ans


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    ll sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
    string res="";
    rep(i,tx-sx) res.push_back('R');
    rep(i,ty-sy) res.push_back('U');
    rep(i,tx-sx) res.push_back('L');
    rep(i,ty-sy) res.push_back('D');
    res.push_back('D');
    rep(i,1+tx-sx) res.push_back('R');
    rep(i,1+ty-sy) res.push_back('U');
    res.push_back('L');
    res.push_back('U');
    rep(i,1+tx-sx) res.push_back('L');
    rep(i,1+ty-sy) res.push_back('D');
    res.push_back('R');
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
#define INF 50

int main() {
  int K; cin >> K;
  vector<int> dist(K, INF);
  dist[1] = 1;
  deque<int> deq = {1};
  while (!deq.empty()) {
    int v = deq.front(); deq.pop_front();
    int u = (v * 10) % K, t = (v + 1) % K;
    if (dist[u] > dist[v]) {
      dist[u] = dist[v];
      deq.push_front(u);
    }
    if (dist[t] > dist[v] + 1) {
      dist[t] = dist[v] + 1;
      deq.push_back(t);
    }
  }
  cout << dist[0] << endl;
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a, b;
        double f;

        a = sc.nextInt();
        b = sc.nextInt();

         f = (double)a / (double)b;



        System.out.printf("%d %d %.5f\n", a/b, a%b, f);
    }
}


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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    bool prime = true;
    for (int j = 2; j < sqrt(N + i); j++) {
      if ((N + i) % j == 0) {
        prime = false;
        break;
      }
    }
    
    if (prime == true) {
      cout << N + i << endl;
      break;
    }
  }
}
  
    


Measured memory_bytes: 256
#include <stdio.h>

typedef struct{int p,l,r;}Node;

int getD(int);
int getH(int);
int getS(int);
void print(int);

Node T[10000];
int H[10000],n;

int main(){
	int i,v,left,right,root=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		T[i].p=-1;
	}
	for(i=0;i<n;i++){
		scanf("%d%d%d",&v,&left,&right);
		T[v].l=left;
		T[v].r=right;
		if(left != -1)T[left].p=v;
		if(right != -1)T[right].p=v;
	}
	for(i=0;i<n;i++){
		if(T[i].p == -1) root = i;
	}

	getH(root);
	for(i=0;i<n;i++){
		print(i);
	}
  return 0;
}

int getD(int u){
  int d=0;
  while(T[u].p != -1){
    u = T[u].p;
    d++;
  }
  return d;
}

int getH(int u){
  int h1 = 0,h2 = 0;
  if(T[u].l != -1){
    h1 = getH(T[u].l)+1;
  }
  if(T[u].r != -1){
    h2 = getH(T[u].r)+1;
  }
  if(h1>h2) return H[u] = h1;
  else return H[u] = h2;
}

int getS(int u){
  if(T[u].p == -1)return -1;
  if(T[T[u].p].l != u && T[T[u].p].l != -1)
    return T[T[u].p].l;
  if(T[T[u].p].r != u && T[T[u].p].r != -1)
    return T[T[u].p].r;
  return -1;
}

void print(int u){
  int i;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("sibling = %d, ",getS(u));
  int deg = 0;
  if(T[u].l != -1) deg++;
  if(T[u].r != -1) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",getD(u));
  printf("height = %d, ",H[u]);
  if(T[u].p == -1){
  	printf("root\n");
  }
  else if(T[u].l == -1 && T[u].r == -1){
  	printf("leaf\n");
  }
  else
  	printf("internal node\n");
}




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

using namespace std;

int main() {
	long long n, k, tp, tn;
	cin >> n >> k;
	
	tp = n - n / k * k;
	tn = n - (n / k + 1) * k;
	
	cout << min(tp, -tn);
	
	return 0;
}


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

char a[600], b[600][600], r[600][600];
int main() {
	int h, w; scanf("%d%d", &h, &w);
	rep(i, h)rep(j, w) {
		if (j == 0 || (i % 2 == 0 && j != w - 1))b[i][j] = '#';
		else b[i][j] = '.';
		if (j == w - 1 || (i % 2 == 1 && j != 0))r[i][j] = '#';
		else r[i][j] = '.';
	}
	rep(i, h) {
		scanf("%s", a);
		rep(j, w) {
			if (a[j] == '#')b[i][j] = '#', r[i][j] = '#';
		}
	}
	rep(i, h)puts(b[i]);
	puts("");
	rep(i, h)puts(r[i]);
}

Measured memory_bytes: 1280
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop


#read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)


S = input()
l = len(S) - 1
h = len(S) // 2
ans = 0

for i in range(h):
    if S[i] == S[l-i]:
        continue

    ans += 1

print(ans)


Measured memory_bytes: 12504