akhauriyash/Code-Regression huggingface dataset:
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// main function
int main()
{
	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll ret = INF32;

	cin >> N >> A >> B >> C;
	vector<ll> l(N, 0);
	Rep(i, N) {
		cin >> l[i];
	}

	for (ll bamboo_A = 1; bamboo_A < (1 << N); ++bamboo_A) {
		for (ll bamboo_B = 1; bamboo_B < (1 << N); ++bamboo_B) {
			if ((bamboo_A & bamboo_B) != 0) {
				continue;
			}
			for (ll bamboo_C = 1; bamboo_C < (1 << N); ++bamboo_C) {
				if ( ((bamboo_A & bamboo_C) != 0) || ((bamboo_B & bamboo_C) != 0)) {
					continue;
				}

				// bamboo_A
				ll tmp_MP = 0;
				ll cnt = 0;
				ll tmp = 0;
				for (int i = 0; i < N; ++i) {
					if ( (bamboo_A & (1 << i)) != 0) {
						tmp += l[i];
						cnt++;
					}
				}
				tmp_MP += 10 * (cnt - 1);
				tmp_MP += abs(A - tmp);

				// bamboo_B
				cnt = 0;
				tmp = 0;
				for (int i = 0; i < N; ++i) {
					if ((bamboo_B & (1 << i)) != 0) {
						tmp += l[i];
						cnt++;
					}
				}
				tmp_MP += 10 * (cnt - 1);
				tmp_MP += abs(B - tmp);

				// bamboo_C
				cnt = 0;
				tmp = 0;
				for (int i = 0; i < N; ++i) {
					if ((bamboo_C & (1 << i)) != 0) {
						tmp += l[i];
						cnt++;
					}
				}
				tmp_MP += 10 * (cnt - 1);
				tmp_MP += abs(C - tmp);

				ret = min(ret, tmp_MP);
			}
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    char a;
    cin >> a;
    char b;
    cin >> b;
    char c;
    cin >> c;
    char d;
    cin >> d;
    char e;
    cin >> e;
    char f;
    cin >> f;
    if (c == d && e == f){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

vector<vi> G;
vi prenum, parent, lowest;
vector<bool> visited;
int timer = 1;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

void dfs(int current, int prev) {
  prenum[current] = lowest[current] = timer++;
  visited[current] = true;
  for (auto &&next : G[current]) {
    if (!visited[next]) {
      parent[next] = current;
      dfs(next, current);
      lowest[current] = min(lowest[current], lowest[next]);
    } else if (next != prev) {
      lowest[current] = min(lowest[current], prenum[next]);
    }
  }
}

void art_points() {
  auto n = G.size();
  dfs(0, -1);

  set<int> ap;
  int np = 0;
  FOR(i, 1, n) {
    auto p = parent[i];
    if (p == 0)
      np++;
    else if (prenum[p] <= lowest[i])
      ap.insert(p);
  }
  if (np > 1) ap.insert(0);
  for (auto it = ap.begin(); it != ap.end(); it++) cout << *it << endl;
}

int main() {
  int n, m, s, t;
  cin >> n >> m;
  G.resize(n);
  prenum.resize(n);
  parent.resize(n);
  lowest.resize(n);
  visited.resize(n, false);
  REP(i, m) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  art_points();
}


Measured memory_bytes: 4512
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 10000000;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 2005;
const int MM = 1000000007;

int W[MX][MX], B[MX][MX];
int N, K, wc = 0, bc = 0;

int get_sum(int A[MX][MX], int sx, int ex, int sy, int ey){
	sx = max(1, sx);
	sy = max(1, sy);
	ex = min(2*K, ex);
	ey = min(2*K, ey);
	if( sx > ex || sy > ey )return 0;

	return A[ex][ey] - A[ex][sy-1] - A[sx-1][ey] + A[sx-1][sy-1];
}

int main()
{
	scanf("%d%d", &N, &K);
	for(int i = 1; i <= N; i++){
		int a, b;
		char c[2];
		scanf("%d%d%s", &a, &b, c);
		a %= 2*K, b %= 2*K;
		if( c[0] == 'W' ) W[a+1][b+1] += 1, wc++;
		else B[a+1][b+1] += 1, bc++;
	}

	for(int i = 1; i <= 2*K; i++){
		for(int j = 1; j <= 2*K; j++){
			W[i][j] += W[i-1][j] + W[i][j-1] - W[i-1][j-1];
			B[i][j] += B[i-1][j] + B[i][j-1] - B[i-1][j-1];
		}
	}
	int ans = 0;
	for(int i = 1; i <= K; i++){
		for(int j = 1; j <= K; j++){
			int u = 0, v = 0;
			for(int k = -1; k <= 1; k++){
				for(int l = -1; l <= 1; l++){
					if((k+l)%2) u += get_sum(W, i+k*K, i+k*K+K-1, j+l*K, j+l*K+K-1);
					else v += get_sum(B, i+k*K, i+k*K+K-1, j+l*K, j+l*K+K-1);
				}
			}
			ans = max(ans, u+v);
			u=v=0;
			for(int k = -1; k <= 1; k++){
				for(int l = -1; l <= 1; l++){
					if((k+l)%2 == 0) u += get_sum(W, i+k*K, i+k*K+K-1, j+l*K, j+l*K+K-1);
					else v += get_sum(B, i+k*K, i+k*K+K-1, j+l*K, j+l*K+K-1);
				}
			}
			ans = max(ans, u+v);
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 31616
Scanf.scanf "%d" (fun n ->
    let xy = Array.init n (fun _ -> Scanf.scanf " %f %f" (fun x y -> x, y)) in

    let dist a b =
        let x1, y1 = xy.(a) in
        let x2, y2 = xy.(b) in
        sqrt ((x1 -. x2) *. (x1 -. x2) +. (y1 -. y2) *. (y1 -. y2))
    in

    let rec loop1 i1 acc =
        let rec loop2 i2 acc =
            if i2 = n then acc else
                loop2 (i2 + 1) (acc +. dist i1 i2)
        in
        if i1 = n then acc else
            loop1 (i1 + 1) (loop2 (i1 + 1) acc)
    in
    let s = loop1 0 0. *. 2. /. float n in
    Printf.printf "%.8f\n" s
)

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    int h,w,k;
    cin >> h >> w >> k;
    bool c[h][w];
    int cnt=0;
    for(int i = 0; i < h; i++) {
        string tmp;
        cin >> tmp;
        for(int j = 0; j < w; j++) {
            if(tmp[j]=='#'){
                c[i][j]=true;
                cnt++;
            }
            else c[i][j]=false;
        }
    }

    int ans=0;
    for(int rbit = 0; rbit < (1<<h); rbit++) {
    for(int cbit = 0; cbit < (1<<w); cbit++) {
        int change=0;
        for(int row = 0; row < h; row++) {
            if(rbit & (1<<row)){
                for(int col = 0; col < w; col++) {
                    if(c[row][col]) change++;
                }
            }
        }
        for(int col = 0; col < w; col++) {
            if(cbit & (1<<col)){
                for(int row = 0; row < h; row++) {
                    if(c[row][col]==true && (rbit&(1<<row))==false) change++;
                }
            }
        }
        if(cnt==k+change) ans++;
    }
    }
    cout <<  ans << "\n";

    return 0;
}

Measured memory_bytes: 3568
open Scanf
open Printf

let () =
  let s,t = scanf "%s %s" (fun s t -> (s, t)) in
  let s_length = String.length s in
  let rec loop s t i =
    if i > s_length -1 then 0
    else if s.[i] <> t.[i] then 1 + loop s t (i + 1)
                           else loop s t (i + 1)
  in
    printf "%d\n" (loop s t 0)

Measured memory_bytes: 7856
<?php
list($h, $w, $k) = ints();
$cnt = 1;
for ($i = 0; $i < $h; ++$i) {
    list($s) = strs();
    $t[$i] = [];
    $pos = 0;
    $npos = strpos($s, '#', $pos);
    while ($npos !== false) {
        $t[$i] = array_merge($t[$i], array_fill(0, $npos - $pos + 1, $cnt));
        $pos = $npos + 1;
        $npos = strpos($s, '#', $pos);
        if ($npos === false) $t[$i] = array_merge($t[$i], array_fill(0, $w - 1 - $pos + 1, $cnt));
        $cnt++;
    }
}
for ($i = 0; $i < $h - 1; ++$i)
    if (count($t[$i + 1]) === 0) $t[$i + 1] = $t[$i];
for ($i = $h - 1; $i >= 1; --$i)
    if (count($t[$i - 1]) === 0) $t[$i - 1] = $t[$i];
for ($i = 0; $i < $h; ++$i) echo implode(' ', $t[$i]) . PHP_EOL;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 21264
import math

rad = math.radians(60)

class coordinates:
  def __init__(self, x, y):
    self.x = x
    self.y = y
 
def koch(n, a, b):
  if n == 0:
    return
  s = coordinates((2.0*a.x + b.x)/3.0, (2.0*a.y + b.y)/3.0)
  t = coordinates((a.x + 2.0*b.x)/3.0, (a.y + 2.0*b.y)/3.0)
  ux = (t.x - s.x)*math.cos(rad) - (t.y - s.y)*math.sin(rad) + s.x
  uy = (t.x - s.x)*math.sin(rad) + (t.y - s.y)*math.cos(rad) + s.y
  u = coordinates(ux, uy)
  
  koch(n-1, a, s)
  print  s.x, s.y
  koch(n-1, s, u)
  print  u.x, u.y
  koch(n-1, u, t)
  print  t.x, t.y
  koch(n-1, t, b)
  
n = input()
  
p1 = coordinates(0.0, 0.0)
p2 = coordinates(100.0, 0.0)
  
print p1.x, p1.y
koch(n, p1, p2)
print p2.x, p2.y

Measured memory_bytes: 6720
#include <stdio.h>
int main(){
  int i,j,N,v,A[1000],k;
  
  scanf("%d",&N);
  
  for(i=0;i<=N-1;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<=N-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(k=0;k<N-1;k++){
      printf("%d ",A[k]);
    }
    printf("%d\n",A[N-1]);
  }
  return 0;
}

Measured memory_bytes: 604
main(){float d,e,f,g,h,i,m,n,p;for(;~scanf("%f%f%f%f%f%f%f%f",&d,&e,&f,&g,&h,&i,&m,&n);puts(p*(f-d)*(n-e)>p*(m-d)*(g-e)&&p*(d-h)*(n-i)>p*(m-h)*(e-i)?"YES":"NO"))p=(h-f)*(n-g)-(m-f)*(i-g);}

Measured memory_bytes: 0
a,b,c = map(int,input().split())

if b-a+1 > 2*c:
    for i in range(a,a+c):
        print(i)
    for i in range(b-c+1,b+1):
        print(i)
else:
    for i in range(a,b+1):
        print(i)


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

int main(){
    int n;
    cin >> n;
    
    for(int i=1; i<=n; i++){
        if(i%3==0){
            cout << " " << i;
            continue;
        }
        int x=i;
        while(x!=0){
            if(x%10 == 3){
                cout << " " << i;
                break;
            }
            x/=10;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3076
<>=~$";
@HW=($`+1,$'+1);
@p=map[<>+0,0],1..$`;
@q=map[<>+0,1],1..$';
for(sort{@$a[0]-@$b[0]}@p,@q){
	$x+=@$_[0]*($-=$HW[!@$_[1]]);
	--$HW[@$_[1]]
}
print$x


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

using namespace std;

using int64 = long long;

constexpr int DEBUG = 0;

vector<int> FindMatchAllByRollingHash(const string& s, const string& key) {
  if (s.length() < key.length()) return {};

  constexpr int64 P1 = 1000000007;
  constexpr int64 P2 = 999999937;
  constexpr int64 B = 257;

  int m = key.length();
  int64 bm1 = 1;
  int64 bm2 = 1;
  for (int i = 0; i < m; i++) {
    bm1 = bm1 * B % P1;
    bm2 = bm2 * B % P2;
  }
  int64 kh1 = 0;
  int64 kh2 = 0;
  for (int i = 0; i < m; i++) {
    kh1 = (kh1 * B + key[i]) % P1;
    kh2 = (kh2 * B + key[i]) % P2;
  }

  vector<int> positions;
  int64 h1 = 0;
  int64 h2 = 0;
  for (int i = 0; i < m; i++) {
    h1 = (h1 * B + s[i]) % P1;
    h2 = (h2 * B + s[i]) % P2;
  }

  if (DEBUG) cout << "s.length: " << s.length() << endl;
  if (DEBUG) cout << "m: " << m << endl;

  if (h1 == kh1 && h2 == kh2) {
    if (DEBUG) cout << "push_back: " << 0 << endl;
    positions.push_back(0);
  }

  for (int i = 1; i + m <= s.length(); i++) {
    if (DEBUG) cout << "i: " << i << endl;
    if (DEBUG) {
      cout << "h1: " << h1 << endl;
      cout << "h2: " << h2 << endl;
    }
    h1 = (h1 * B + s[i + m - 1]) % P1;
    h1 = (h1 + P1 - (bm1 * s[i - 1] % P1)) % P1;
    h2 = (h2 * B + s[i + m - 1]) % P2;
    h2 = (h2 + P2 - (bm2 * s[i - 1] % P2)) % P2;
    if (h1 == kh1 && h2 == kh2) {
      if (DEBUG) cout << "push_back: " << i << endl;
      positions.push_back(i);
    }
  }
  return positions;
}

int Max(const vector<int>& xs) {
  int value = INT32_MIN;
  for (int x : xs) value = max(x, value);
  return value;
}

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

  string s, t;
  cin >> s >> t;
  string extended_s(s);
  while (extended_s.length() < s.length() + t.length()) {
    extended_s.append(s);
  }

  vector<int> matches = FindMatchAllByRollingHash(extended_s, t);
  vector<int> is_match(s.length());
  for (int match : matches) {
    if (match < s.length()) {
      is_match[match] = 1;
    }
  }

  vector<int> visited(s.length(), -1);
  vector<int> dp(s.length(), -1);
  function<void(int)> dfs = [&](int v) {
    if (visited[v] == 1) return;

    if (visited[v] == 0) {
      visited[v] = 1;
      dp[v] = INT32_MAX;
      return;
    }

    if (is_match[v] == 0) {
      visited[v] = 1;
      dp[v] = 0;
      return;
    }

    visited[v] = 0;
    int next_v = (v + t.length()) % s.length();
    dfs(next_v);
    if (dp[next_v] == INT32_MAX) dp[v] = INT32_MAX;
    else dp[v] = dp[next_v] + 1;
    visited[v] = 1;
  };
  for (int i = 0; i < s.length(); i++) dfs(i);
  if (DEBUG) {
    for (int i = 0; i < matches.size(); i++) cout << matches[i] << " ";
    cout << endl;
    for (int i = 0; i < s.length(); i++) cout << is_match[i] << " ";
    cout << endl;
    for (int i = 0; i < s.length(); i++) cout << dp[i] << " ";
    cout << endl;
  }
  int max = Max(dp);
  cout << ((max == INT32_MAX) ? -1 : max) << endl;
}


Measured memory_bytes: 35984
#include <bits/stdc++.h>
#define int unsigned long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

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

    int x;
    int bal = 100;
    cin >> x;
    int cnt = 0;
    while (bal < x) {
        bal += (bal / 100);
        cnt++;
    }
    cout << cnt << '\n';

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 3580
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	N := nextInt()
	pos := make([]pair, N)
	for i := 0; i < N; i++ {
		pos[i].a = nextInt()
		pos[i].b = nextInt()
	}
	par := (abs(pos[0].a) + abs(pos[0].b)) % 2
	for i := 0; i < N; i++ {
		par2 := (abs(pos[i].a) + abs(pos[i].b)) % 2
		pos[i] = pair{pos[i].a + pos[i].b, pos[i].a - pos[i].b}
		if par2 != par {
			fmt.Println("-1")
			return
		}
	}

	d := make([]int, 0)
	for i := 30; i >= 0; i-- {
		tmp := int(1 << uint(i))
		d = append(d, tmp)
	}
	log.Println(d)
	if par%2 == 0 {
		d = append(d, 1)
	}
	fmt.Println(len(d))
	for j := 0; j < len(d); j++ {
		fmt.Print(d[j])
		if j < len(d)-1 {
			fmt.Print(" ")
		}
	}
	fmt.Println("")

	for i := 0; i < N; i++ {
		var xdir, ydir int
		var xsum, ysum int
		for j := 0; j < len(d); j++ {
			if xsum <= pos[i].a {
				xdir = 1
				xsum += d[j]
			} else {
				xdir = -1
				xsum -= d[j]
			}
			if ysum <= pos[i].b {
				ydir = 1
				ysum += d[j]
			} else {
				ydir = -1
				ysum -= d[j]
			}

			if xdir == 1 && ydir == 1 {
				fmt.Print("R")
			} else if xdir == 1 && ydir == -1 {
				fmt.Print("U")
			} else if xdir == -1 && ydir == -1 {
				fmt.Print("L")
			} else {
				fmt.Print("D")
			}
		}
		fmt.Println("")
	}
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 1280
def main():
    K,N = map(int,input().split())
    A = list(map(int,input().split()))
    Aa = []
    for i in range(1,N):
        Aa.append(A[i]-A[i-1])
    Aa.append(K-A[N-1]+A[0])
    print(sum(Aa)-max(Aa))

if __name__ == "__main__":
    main()

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

int main() {
	char base = 0;

	cin >> base;

	if (base == 'A') cout << "T" << endl;
	if (base == 'T') cout << "A" << endl;
	if (base == 'C') cout << "G" << endl;
	if (base == 'G') cout << "C" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <list>
#include <map>
#include <cmath>
#include <string>
#include <iterator>
#include <vector>
 
using namespace std;

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 26;

int largest(int a, int b){
	return (a<b)?b:a;
}


int main() {
	int n = 0;
	cin >> n;
	vector<int> a(n);
	bool ok = true;
	int ans = 0;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		if(a[i] == i+1){
			ok = false;
		}
	}
	if(ok){
		cout << 0 << endl;
		return 0;
	}
	for(int i = 0; i < n; ++i){
		if(a[i] == i+1){
			swap(a[i+1], a[i]);
			++ans;
		}
	}
	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
main() {
	int n;
	cin >> n;
	bool c[4][13] = {};
	for (int i=0; i<n; i++) {
		char m;
		int r;
		cin >> m >> r;
		c[m=='S'?0 : m=='H'?1 : m=='C'?2 : 3][r-1] = true;
	}
	for (int i=0; i<4; i++) {
		for (int j=0; j<13; j++) {
			if (!c[i][j])
				cout << (i==0?'S' : i==1?'H' : i==2?'C' : 'D') << " " << j+1 << endl;
		}
	}
}

Measured memory_bytes: 3068
#include<iostream>


using namespace std;

int main(void){

    int n, b, f, r, v;
    int x, y, z, i;
    int cnt = 0;
    int a[4][3][10];
    for(x = 0;x < 4;x++){
        for(y = 0;y < 3;y++){
            for(z = 0;z < 10;z++)
            a[x][y][z] = 0;
        }
    }

    cin >> n;

    for(i = 0;i <n;i++){

        cin >> b >> f >> r >> v;

        b = b - 1;
        f = f - 1;
        r = r - 1;
        


         a[b][f][r] = a[b][f][r] + v;


    }

    for(x = 0;x < 4;x++){
        for(y = 0;y < 3;y++){
            for(z = 0;z < 10;z++){
            cout <<" "<< a[x][y][z];
            }
             cout << endl;
        }
        cnt++;
        if(cnt < 4){
            for(i = 0;i < 20;i++){
            cout << "#" ;
            }
            cout << endl;
            }
    }
    
    return 0;
}


Measured memory_bytes: 3092
import sys

N = int(input())
X = sorted([int(i) for i in input().split()])
ub = X[N - 1]
lb = X[0]

ans = sys.maxsize
for i in range(lb, ub + 1):
    t = 0
    for j in X:
        t += (j - i) ** 2
    if t < ans:
        ans = t

print(ans)



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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    rep(i, N-2){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
l = list(map(int, input()))
mod = 10 ** 9 + 7

ln = len(l)
dp = [[0] * 2 for _ in range(2)]
dp[0][1] = 1

for e in l:
    dp_new = [[0] * 2 for _ in range(2)]
    for i in range(2):
        # same -> same
        if i == e:
            dp_new[i][1] += (dp[0][1] + dp[1][1]) * (1 + i)

        # same -> small
        if i == 0 and e == 1:
            dp_new[0][0] += dp[0][1] + dp[1][1]

        # small -> small
        dp_new[i][0] += (dp[0][0] + dp[1][0]) * (1 + i)

    dp = dp_new
    for i in range(2):
        for j in range(2):
            dp[i][j] %= mod

ans = 0
for row in dp:
    ans += sum(row)
    ans %= mod

print(ans)


Measured memory_bytes: 4084
max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

import sys
from itertools import product
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def solve(bombs,H,W):

    X = [0]*H
    Y = [0]*W

    for x,y in bombs:
        X[x] += 1
        Y[y] += 1

    mx = max(X)
    my = max(Y)

    x_ind = [i for i,c in enumerate(X) if c==mx]
    y_ind = [i for i,c in enumerate(Y) if c==my]

    if len(x_ind)*len(y_ind) > len(bombs):
        return mx+my

    bombs = set(bombs)
    candidates = set(product(x_ind,y_ind))

    return mx+my-1 if bombs >= candidates else mx+my


if __name__ == '__main__':
    H,W,M = map(int,readline().split())

    t = map(lambda x: int(x)-1, read().split())

    bombs = list(zip(t,t))

    print(solve(bombs,H,W))

Measured memory_bytes: 176396
using System;
using System.Linq;

public class AtCoder_161_A
{
    public static void Main()
    {
        int[] line1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int a = line1[0];
        int b = line1[1];
        int c = line1[2];

        Console.WriteLine(string.Format("{0} {1} {2}", c, a, b));
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  static int N,X[200010],Y[200010];
  cin>>N;
  for(int t=1;t<=N;t++){
    cin>>X[t];
    Y[t]=X[t];
  }

  sort(Y+1,Y+1+N);

  for(int t=1;t<=N;t++){
    if(X[t]<=Y[N/2]){
      cout<<Y[N/2+1]<<"\n";
    }else if(X[t]>=Y[N/2+1]){
      cout<<Y[N/2]<<"\n";
    }
  }

  return 0;
}


Measured memory_bytes: 5376
import sys

K, N = map(int,input().split())
A = list(map(int,input().split()))
L = [0]*(2*N)
MIN = 1e18

for i in range(0,N):
	L[i] = A[i]
for i in range(N,2*N):
	L[i] = A[i-N]+K
for i in range(N-1,2*N):
	MIN = min(MIN,L[i]-L[i-(N-1)])

print(MIN)

Measured memory_bytes: 32352
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
// #include<vor>
using namespace std;
typedef long long int ll;
#define pb push_back
ll mod = 1e9+7;

ll powm(ll a , ll b , ll mod)
{
  ll res = 1;
  while(b)
  {
    if(b & 1)
    res = (res *a)%mod;
    a = (a*a)%mod;
    b>>1;
  }
  return res;
}
ll gcd(ll a , ll b);
ll power(ll x , ll y , ll m);

ll modInverse(ll a , ll m)
{
  ll g = gcd(a,m);
  if(g != 1)
  return 1;
  else
  return power(a,m-2,m);

}

ll power(ll x , ll y , ll m)
{
  if(y == 0)
  return 1;
  ll p = power(x , y/2 , m)%m;
  p = (p*p)%m;

  return (y%2 == 0) ? p : (x *p) % m;
}

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

vector<int>adj[1000001] , ans;
int dis[1000001] , cnt[1000001];
bool vis[1000001];



int freq[1000001];
void solve()
{
    double r;
    double pi = 6.28318530717958623200/2;
    cin>>r;
    cout<<2*pi*r<<"\n";

}

int main()
{
  int tc;
  // cin>>tc;
  tc = 1;
  while(tc--)
  {
    solve();
  }
}


Measured memory_bytes: 27228
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		boolean f2 = true;
		for(int i = 0 ; i < s.length() ; ++i){
			char c = s.charAt(i);
			boolean f = false;
			if(i % 2 == 0){
				if(c == 'R' || c == 'U' || c == 'D'){
					f = true;
				}
			}else{
				if(c == 'L' || c == 'U' || c == 'D'){
					f = true;
				}				
			}
			if(!f){
				f2 = false;
				break;
			}
		}
		if(f2){
			System.out.println("Yes");
		}else{
			System.out.println("No");			
		}
	}
}


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

int main(){
    int d,n;
    cin>>d>>n;
    switch(d){
        case 0: if(n!=100){
            cout<<n<<endl;
            break;
        }else{
            cout<<101<<endl;
            break;
        }
        case 1: if(n!=100){
            cout<<n*100<<endl; 
            break;
        }else{
            cout<<10100<<endl;
            break;
        }    
        case 2: if(n!=100){
            cout<<n*10000<<endl; 
            break;
        }else{
            cout<<1010000<<endl;
            break;
        }    
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n, x;
    cin >> n >> x;
    vll l(n);
    rep(i, n){
        cin >> l[i];
    }
    vll d;
    d.emplace_back(0);
    ll acc = 0;
    rep(i, n){
        acc += l[i];
        d.emplace_back(acc);
    }
    ll ans = distance(d.begin(), upper_bound(ALL(d), x));
    cout << ans << endl;
    return 0;
}

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

int main(){
  long long n,a,b; cin>>n>>a>>b;
  long long ans=(n/(a+b))*a;
  long long q=n%(a+b);
  if (q!=0);
    ans+=min(a,q);
  cout<<ans<<endl;
}

Measured memory_bytes: 384
n,m=map(int,input().split())
min = 1
max = n
for i in range(m):
    l,r=map(int,input().split())
    if min < l :
        min=l
    if r < max:
        max=r
if max - min >= 0:
    print(str(max - min + 1))
else:
    print(0)

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

int main()
{
  int n, a;
  cin >> n >> a;
  int mod;
  mod = n % 500;
  if(mod <= a) cout << "Yes" <<endl;
  else cout << "No" <<endl;
  return 0;
}


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

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

vector<bool> is_prime(MAX, true);
vector<LL> prime_list;

void eratos(){
    is_prime[0]=false;
    is_prime[1]=false;
    for(LL i=2; i<MAX; i++){
        if(is_prime[i]==true){
            LL j=i+i;
            while(j<=MAX){
                is_prime[j]=false;
                j=j+i;
            }
            if(i%5==1){
                prime_list.push_back(i);
            }
        }
    }
}

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

    eratos();
    for(LL i=0; i<n; i++){
        cout << prime_list[i];
        if(i!=n-1){
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(),greater<int>());
#define INF 999999999
#define MOD 1000000007
#define M_PI 3.14159265358979323846
#define ALL(X) (X).begin(),(X).end()

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

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

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<int> A,B,C;

void input(){
  #ifdef __LOCAL
    fs::path p = __FILE__;
    fs::path input,output;
    input = output = p.parent_path();
    input += string("/input/") + string(p.stem()) + string(".txt");
    output += string("/output/") + string(p.stem()) + string(".txt");
    freopen(input.c_str(), "r", stdin);
    freopen(output.c_str(), "w", stdout);
  #endif
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    int a,b,c;
    cin >> a >> b >> c;
    A.push_back(a);
    B.push_back(b);
    C.push_back(c);
  }
}

int act(int i, int x){
  if(x==0) return A[i];
  if(x==1) return B[i];
  if(x==2) return C[i];
}

int solve(){
  vector<map<int,int>> dp(N);
  for (int x = 0; x < 3; x++)
  {
    dp[0][x] = act(0,x);
  }
  
  for (int i = 0; i < N-1; i++)
  {
    for (int x = 0; x < 3; x++)
    {
      dp[i+1][x] = max(dp[i][(x+1)%3], dp[i][(x+2)%3])+act(i+1,x);
    }
  }
  cout << max({dp[N-1][0],dp[N-1][1],dp[N-1][2]}) << endl;

  return 0;
}

int main()
{
  input();
  solve();
  // test();
  return 0;
}


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

int main(){


    int n,a,b;

    cin >> n >> a >> b;
    int ans = 0;

    for(int i = 1;i <=n;i++){

        int tmp = 0,t=i;
        for(int j = 0;j < 5;j++){
            tmp += t%10;
            t /= 10;
        }
        if(tmp >=a && tmp <= b){
            ans+=i;
        }
       
    }
    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int read() { return readln.chomp.to!int; }
int[] reads() { return readln.split.to!(int[]); }

struct Cake {
    long x, y, z;
}

void solve() {
    int n, m;
    readf("%d %d\n", &n, &m);
    auto cakes = new Cake[n];
    foreach (i; 0..n)
        readf("%d %d %d\n", &cakes[i].x, &cakes[i].y, &cakes[i].z);

    long res;
    foreach (k; 0..1<<3) {
        long[] a;
        foreach (cake; cakes) {
            long t;
            t += (k>>0 & 1 ? cake.x : -cake.x);
            t += (k>>1 & 1 ? cake.y : -cake.y);
            t += (k>>2 & 1 ? cake.z : -cake.z);
            a ~= t;
        }
        sort!("a>b")(a);
        res = max(res, a[0..m].sum);
    }
    writeln(res);
}

void main() {
    solve();
    readln;
}

Measured memory_bytes: 380
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
//void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
													 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 998244353;
const ll maxn = 1000005;
const ll mm = 1e+18;
void solve()
{
	int n;
	cin>>n;
	map<int,int>mp;
	while(n%2==0){
		mp[2]++;
		n/=2;
	}
	for(int i=3;i<=sqrt(n);i+=2){
		while(n%i==0){
			n/=i;
			mp[i]++;
		}
	}
	if(n>1) mp[n]++;
	int ans=0;
	for(auto p:mp){
		int f=0;
		int l=1;
		int r=100;
		while(l<r){
			int mid=(l+r)>>1;
			if((mid*(mid+1))/2<=p.s){
				f=mid;
				l=mid+1;
			}
			else r=mid;
		}
		ans+=f;
	}
	pr(ans);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define pb push_back
const ll mod=1e9+7;
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
const ll N=1e6+8;
const ll INF=1e18;
ll n=408;
ll a[500],sum[500]={0};
ll dp[500][500];
ll naruto(ll l,ll r){
  if(l==r)
  return 0;
  if(dp[l][r]!=-1)
  return dp[l][r];
    ll res=INF;
  for(ll i=l;i<r;i++){
    res=min(res,sum[r]-sum[l-1]+naruto(l,i)+naruto(i+1,r));
  }
  return dp[l][r]=res;
}
int main(){
  IOS;
 cin>>n;
  for(ll i=1;i<=n;i++){
    cin>>a[i];
     sum[i]+=sum[i-1]+a[i];
  }
  memset(dp,-1,sizeof(dp));
  cout<<naruto(1,n);
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, M = N << 1;

int h[N], e[M], ne[M], idx;
int q[N], n;
int temp[N], g;
int res[N];

void add(int a, int b) {
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

int b_s(int l, int r, int x) {
	while(l < r) {
		int mid = l + r >> 1;
		if(q[temp[mid]] >= x) r = mid;
		else l = mid + 1;
	}
	return l;
}

void dfs(int u, int fa) {
	for(int i = h[u]; i != -1; i = ne[i]) {
		int v = e[i];
		if(v == fa) continue;
		
		int flag = 0, prep = 0, prev = 0;
		if(q[temp[g]] < q[v]) {
			flag = 1;
			temp[++g] = v;
		}
		else if(q[v] < q[temp[g]]) {
			int t = b_s(1, g, q[v]);
			flag = 2, prep = t, prev = temp[t];
			temp[t] = v; 
		}
		res[v] = g;
		dfs(v, u);
		if(flag == 1) temp[g--] = 0;
		else if(flag == 2) {
			temp[prep] = prev;
		}
	}
}

void solve() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &q[i]);
	
	for(int i = 1; i < n; i++) {
		int a, b; scanf("%d%d", &a, &b);
		add(a, b), add(b, a); 
	}
	
	res[1] = 1;
	temp[++g] = 1;
	dfs(1, 0);
	for(int i = 1; i <= n; i++) printf("%d\n", res[i]);
}

int main()
{
	int T = 1;
	//scanf("%d", &T);
	
	while(T--) {
		memset(h, -1, sizeof h); idx = 0;
		solve();
	}
}

Measured memory_bytes: 23656
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int h,w,x,c[10][10];
map<int,int>m;
int ans;

int32_t main(){_
    //freopen("input","r",stdin);
	cin >> h >> w;
	for(int i = 0;i <= 9;i++)
	{
		for(int j = 0;j <= 9;j++)
		{
			cin >> c[i][j];
		}
	}
	for(int i = 1;i <= h;i++)
	{
		for(int j = 1;j <= w;j++)
		{
			cin >> x;
			m[x]++;
		}
	}
	int n = 9;
	for(int k = 0;k <= n;k++)
	{
		for(int i = 0;i <= n;i++)
		{
			for(int j = 0;j <= n;j++)
			{
				if(i != j && c[i][k] + c[k][j] < c[i][j])
					c[i][j] = c[i][k] + c[k][j];
			}
		}
	}
	for(int j = 0;j <= 9;j++) ans += c[j][1] * m[j];
	rc(ans);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n>=400 && n<600){
        cout<<"8"<<endl;
    }
    else if(n>=600 && n<800){
        cout<<"7"<<endl;
    }
    else if(n>=800 && n<1000){
        cout<<"6"<<endl;
    }
    else if(n>=100 && n<1200){
        cout<<"5"<<endl;
    }
    else if(n>=1200 && n<1400){
        cout<<"4"<<endl;
    }
    else if(n>=1400 && n<1600){
        cout<<"3"<<endl;
    }
    else if(n>=1600 && n<1800){
        cout<<"2"<<endl;
    }
    else{
        cout<<"1"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3624
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func floatSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scan()
	if s == "RRR" {
		fmt.Println(3)
	} else if s == "SRR" || s == "RRS" {
		fmt.Println(2)
	} else if s == "SSS" {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  int n, k;
  cin >> n >> k;
  cout << n - k + 1 << endl;
}


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

int main(void) {
	long long N, A, B;
	scanf("%lld %lld %lld", &N, &A, &B);
	long long set = N / (A + B);
	if (N - (A + B) * set >= A) {
		printf("%lld", A * set + A);
	} else {
		printf("%lld", A * set + (N - ( A + B ) * set));
	}

	return 0;
}


Measured memory_bytes: 3768
import sys
try:
	while 1:
		temp = input()
		if (temp==0):
			break
		N = temp
		a = []
		for i in range(N):
			a.append(map(int, raw_input().split())+[0])
		a.append([0 for i in range(0,temp+1)])
		for i in range(0,temp):
			for j in range(0,temp):
				a[i][temp] += a[i][j]
		for k in range(0,temp+1):
			for l in range(0,temp):
				a[temp][k] += a[l][k]
		for m in range(0,temp+1):
			for n in range(0,temp+1):
				sys.stdout.write(str(a[m][n]).rjust(5))
			print ""
except(RuntimeError):
	pass

Measured memory_bytes: 6308
n = int(input())
s = [input() for i in range(n)]
d = {}
for i in s:
    if i in d.keys():
        d[i]=d[i]+1
    else:
        d[i]=1
d_sorted = sorted(d.items(), key=lambda x:x[1])
d_name = [x[0] for x in d_sorted if x[1] == d_sorted[-1][1]]
d_name.sort()
print("\n".join(d_name))

Measured memory_bytes: 49936
#include<iostream>
//#include<bits/stdc++.h>
#include<vector>
#include<math.h>

using namespace std;

int main()
{
   long long h, w;

   cin >> h >> w;

   if(h == 1 || w == 1)
   {
      cout << 1;
   }

   else
   {
      cout << (h*w+1)/2;
   }
   
}

Measured memory_bytes: 3624
#include <iostream>
#include<cstdio>
using namespace std;
int main() {
	int s;
	int a[4];
	cin >> s;
	a[0] = s / 1000;
	a[1] = s % 1000 / 100;
	a[2] = s % 100 / 10;
	a[3] = s % 10;

	if (a[0] + a[1] + a[2] + a[3] == 7) 
		cout << a[0] << "+" << a[1] << "+" << a[2] << "+" << a[3] << "=" << 7 << endl;
	else if (a[0] + a[1] + a[2] - a[3] == 7)
		cout << a[0] << "+" << a[1] << "+" << a[2] << "-" << a[3] << "=" << 7 << endl;
	else if (a[0] + a[1] - a[2] + a[3] == 7)
		cout << a[0] << "+" << a[1] << "-" << a[2] << "+" << a[3] << "=" << 7 << endl;
	else if (a[0] + a[1] - a[2] - a[3] == 7)
		cout << a[0] << "+" << a[1] << "-" << a[2] << "-" << a[3] << "=" << 7 << endl;
    else if (a[0] - a[1] + a[2] + a[3] == 7)
		cout << a[0] << "-" << a[1] << "+" << a[2] << "+" << a[3] << "=" << 7 << endl;
	else if (a[0] - a[1] + a[2] - a[3] == 7)
		cout << a[0] << "-" << a[1] << "+" << a[2] << "-" << a[3] << "=" << 7 << endl;
	else if (a[0] - a[1] - a[2] + a[3] == 7)
		cout << a[0] << "-" << a[1] << "-" << a[2] << "+" << a[3] << "=" << 7 << endl;
	else if (a[0] - a[1] - a[2] - a[3] == 7)
		cout << a[0] << "-" << a[1] << "-" << a[2] << "-" << a[3] << "=" << 7 << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	
	while(	cin>>s){
		if(s=="#")break;
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--,b--,c--,d--;
		char ma[10][10];
		int y=0,x=0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='b'){
				ma[y][x++]='b';
			}else if(s[i]=='/'){
				y++;
				x=0;
			}else{
				int k=s[i]-'0';
				for(int j=0;j<k;j++)
					ma[y][x++]='.';
			}
		}
		y++;
		ma[a][b]='.';
		ma[c][d]='b';
		string t;
		for(int i=0;i<y;i++){
			for(int j=0;j<x;j++){
				t+=ma[i][j];
			}
			if(i!=y-1)t+='/';
		}
		//cout<<t<<endl;
		for(int i=0;i<t.size();i++){
			if(t[i]=='b'||t[i]=='/')cout<<t[i];
			else {
				int sum=1;
				while(1){
					if(i>=t.size()-1)break;
					if(t[i+1]!='.')break;
					sum++;
					i++;
				}
				cout<<sum;
			}
		}
		cout<<endl;
	}
	return 0;
}



Measured memory_bytes: 3224
#include<stdio.h>
 
long max(long a,long b){
	if(a>b){
    	return a;
    }else{
    	return b;
    }
}
 
long min(long a,long b){
	if(a<b){
    	return a;
    }else{
    	return b;
    }
}
 
int f(long a,long b){
  long c=max(a,b);
  int keta=1;
  for(int i=0;i<10;i++){
  	if(c/10>0){
    	keta++;
      	c/=10;
    }
  }
  return keta;
}
 
 
 
int main(void){
  
  long N;
  int minnum=11;
  scanf("%ld",&N);
  
  for(long a=1;a*a<=N;a++){
    long b=0;
  	if(N%a == 0){
      b=N/a;
      int res=f(a,b);
      minnum=min(minnum,res);
    }
  }
  
  printf("%ld",minnum);
  
 
return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
	int a[4];
	int b[4];
	int m, n;

	while(cin >> a[0] >> a[1] >> a[2] >> a[3]){
		
	int hit=0;
	int blow=0;
	for(int i=0; i<4; i++){
		cin >> b[i];
	}
	for(m=0; m<4; m++){
		for(n=0; n<4; n++){
			if(a[m] == b[n] && m == n){
				hit = hit + 1;
			}
			else if(a[m] == b[n]){
				blow = blow + 1;
			}
		}
	}
		
	cout << hit << " " << blow << endl;
}
}

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

/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const int INF = 1 << 29;
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
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; }
/**************************************/

/******** User-defined Function *******/
vector<int> a,b;
int dp[1005][10005];
/**************************************/

/********** Main()  function **********/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h,n; cin >> h >> n;
  a.resize(n);
  b.resize(n);
  rep(i,n) cin >> a[i] >> b[i];

  rep(i,h+1) dp[0][i] = INF;

  for(int i=0; i<n; ++i){
    for(int j=0; j<=h; ++j){
      if(j - a[i] >0) dp[i+1][j] = min(dp[i][j], dp[i+1][j - a[i]] + b[i]);
      else dp[i+1][j] = min(dp[i][j],b[i]);
    }
  }
  
  cout << dp[n][h] << endl;

  // rep(i,30){
  //   rep(j,6){
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  return 0;
}
/********  Main() Ends Here *************/


Measured memory_bytes: 42748