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

using namespace std;
void t(int n, int pspace, int nspace);

int main()
{
	int n, x, y;
	cin >> n;
	if (n == 2) {
		cout << -1 << endl;
	}else if (n % 3 == 0) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n / 3; j++) {
				switch(i % 3){
				case 0:
					cout << "aab";
					break;
				case 1:
					cout << "c.b";
					break;
				case 2:
					cout << "cdd";
					break;
				}
			}
			cout << endl;
		}
	}
	else {
		x = (n % 4) + 4;
		y = (n / 4) - 1;
		//cout << "x = " << x << ",y = " << y << endl;
		for (int i = 0; i < y * 4; i += 4) {
			t(4, i, n - 4 - i);
		}
		t(x, n - x, 0);
	}
	
	

	return 0;
}

void t(int n, int pspace, int nspace) {
	switch (n)
	{
	case 4:
		for (int i = 0; i < n; i++) {
			for (int k = 0; k < pspace; k++) {
				cout << ".";
			}

			switch (i % n) {
			case 0:
				cout << "aabc";
				break;
			case 1:
				cout << "ddbc";
				break;
			case 2:
				cout << "efgg";
				break;
			case 3:
				cout << "efhh";
				break;
			}

			for (int k = 0; k < nspace; k++) {
				cout << ".";
			}
			cout << endl;
		}

		break;
	case 5:
		for (int i = 0; i < n; i++) {
			for (int k = 0; k < pspace; k++) {
				cout << ".";
			}

			switch (i % n) {
			case 0:
				cout << "aabbc";
				break;
			case 1:
				cout << "edd.c";
				break;
			case 2:
				cout << "e..ij";
				break;
			case 3:
				cout << "f..ij";
				break;
			case 4:
				cout << "fgghh";
				break;
			}

			cout << endl;
		}

		break;
	case 6:
		for (int i = 0; i < n; i++) {
			for (int k = 0; k < pspace; k++) {
				cout << ".";
			}

			switch (i % n) {
			case 0:
				cout << "aabc..";
				break;
			case 1:
				cout << "ddbc..";
				break;
			case 2:
				cout << "..eefg";
				break;
			case 3:
				cout << "..hhfg";
				break;
			case 4:
				cout << "ij..kk";
				break;
			case 5:
				cout << "ij..ll";
				break;
			}

			cout << endl;
		}

		break;
	case 7:
		for (int i = 0; i < n; i++) {
			for (int k = 0; k < pspace; k++) {
				cout << ".";
			}

			switch (i % n) {
			case 0:
				cout << "aabbcc.";
				break;
			case 1:
				cout << "dd.dd.a";
				break;
			case 2:
				cout << "..d..da";
				break;
			case 3:
				cout << "..d..db";
				break;
			case 4:
				cout << "dd.dd.b";
				break;
			case 5:
				cout << "..d..dc";
				break;
			case 6:
				cout << "..d..dc";
				break;
			}

			cout << endl;
		}
		break;
	}
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 1e5+5;



signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    int n, d;
    cin >> n >> d;
    d = d * 2 + 1;
    cout << (n + d - 1)/d << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

use rand::{thread_rng, Rng};
use std::cmp::Reverse;

fn calc(v: &Vec<Vec<isize>>, plan: &Vec<usize>, c: &Vec<isize>) -> isize {
    let mut last = vec![0; 26];
    let mut res = 0_isize;
    for (i, &x) in plan.iter().enumerate() {
        res += v[i][x];
        last[x] = i as isize + 1;
        for (j, &y) in last.iter().enumerate() {
            res -= c[j] * (i as isize + 1 - y);
        }
    }

    res
}

fn main() {
    input! {
        d:usize,
        c:[isize;26]
    }
    let mut plan = vec![0; d];
    let mut v = vec![];
    for p in 0..d {
        input! {
            buf:[isize;26]
        }
        let mut max = 0;
        let mut max_idx = 0;
        for i in 0..buf.len() {
            if max < buf[i] {
                max = buf[i];
                max_idx = i;
            }
        }
        plan[p] = max_idx;
        v.push(buf);
    }
    let mut rng = rand::thread_rng();
    let mut prev_score = calc(&v, &plan, &c);

    let mut k = 551;

    let mut cc = vec![];
    for i in 0..c.len() {
        cc.push((c[i], i));
    }

    cc.sort_by_key(|k| Reverse(*k));

    for q in 0..200_000 {
        if q % 100 == 0 {
            let idx = rng.gen_range(d / 3, d * 2 / 3);
            let from = plan[idx];
            plan[idx] = cc[rng.gen_range(0, 10)].1;
            let next_score = calc(&v, &plan, &c);
            if next_score > prev_score {
                prev_score = next_score;
            } else {
                plan[idx] = from;
            }
        } else {
            let mut r = [rng.gen_range(0, d); 2];
            r.sort();
            if r[0] == r[1] {
                if r[0] == 0 {
                    r[1] += 1;
                } else {
                    r[0] = 0;
                }
            }
            let idx = vec![rng.gen_range(r[0], r[1]); k];
            let to = vec![rng.gen_range(0, 26); k];
            let mut from = vec![];
            for &i in &idx {
                from.push(plan[i]);
            }
            for i in 0..idx.len() {
                plan[idx[i]] = to[i];
            }
            let next_score = calc(&v, &plan, &c);
            if next_score > prev_score - 100 {
                prev_score = next_score;
            } else {
                for i in 0..idx.len() {
                    plan[idx[i]] = from[i];
                }
            }
            if k > 1 && q % 400 == 0 {
                k -= 1;
            }
        }
    }
    for i in plan {
        println!("{}", i + 1);
    }
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    string s; cin >> s;
    int n = s.size();
    int ans1 = 0;
    int ans2 = 0;

    rep(i, n) {
        if( i % 2  == 0) {
            if(s[i] != '0') {
                ans1++;
            }
        } else {
            if(s[i] != '1') {
                ans1++;
            }
        }
        if( i % 2  == 0) {
            if(s[i] != '1') {
                ans2++;
            }
        } else {
            if(s[i] != '0') {
                ans2++;
            }
        }
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}


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

int main(){
  int n;
  int max=0;
  int seq[101];
  int i;

  for(i=0; i<=100; i++) seq[i]=0;
  while(cin>>n){
    seq[n]++;
    if(max<seq[n]) max=seq[n];
  }
  for(i=0; i<=100; i++)
    if(seq[i]==max) printf("%d\n", i);

  return 0;
}

Measured memory_bytes: 0
import sys
lines = sys.stdin.readlines()
sizes = lines[0].split(" ")
N = int(sizes[0])
T = int(sizes[1])
line = lines[1].split(" ")
inp = []
for i in line:
    inp.append(int(i))

check = []
checkMax = []

#for i in range(len(inp)):
#i=0
#c = []
#for j in range(i+1,len(inp)):
    #if inp[i]<inp[j]:
#    c.append(inp[j]-inp[i])
#check.append(c)
#check=c
#checkMax.append(max(check))

#while (len(check)>1):
#    check.pop(0)
#    checkMax.append(max(check))


#for j in range(1,len(inp)):
#    checkMax[j-1] += inp[0]-inp[j]

count=0
for i in range(1,len(inp)):
    if i==1:
        mi = min(inp[0],inp[1])
        ma = inp[1]-inp[0]
        if ma>0:
            count+=1
    elif i>1:
        if ma<inp[i]-mi:
            count=1
            ma=inp[i]-mi
        elif ma==inp[i]-mi:
            count+=1
        mi = min(inp[i],mi)

print (count)


#print (check)
#print (checkMax)
#print (checkMax.count(max(checkMax)))


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int H, h, W, w;
    cin >> H >> W >> h >> w;
    cout << (H%h!=0 || W%w != 0?"Yes":"No") << endl;
    if(H%h!=0){
        int sam[H];
        int count = 0;
        REP(i, H){
            if(i%h==h-1){
                sam[i] = -1-count;
                count++;
            }else{
                sam[i] = 1000 - count;
            }
        }
        for(int i=H-1;i>0;i--){
            sam[i] -= sam[i-1];
        }
        REP(i, H){
            REP(j, W){
                cout << sam[i] << " ";
            }
            cout << endl;
        }
    }else if(W%w != 0){
        int sam[W];
        int count = 0;
        REP(i, W){
            if(i%w==w-1){
                sam[i] = -1-count;
                count++;
            }else{
                sam[i] = 1000 - count;
            }
        }
        for(int i=W-1;i>0;i--){
            sam[i] -= sam[i-1];
        }
        REP(i, H){
            REP(j, W){
                cout << sam[j] << " ";
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1536
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

// 2ケースWAなので答えを見た。

fn main() {
    input! {
        N: usize,
        mut As: [i64; N],
        mut Bs: [i64; N],
    }

    let sum_a: i64 = As.iter().sum();
    let sum_b: i64 = Bs.iter().sum();
    let cnt: i64 = sum_b - sum_a;

    let mut plus_one_cnt: i64 = 0;
    let mut plus_two_cnt: i64 = 0;
    for i in 0..N {
        let a = As[i];
        let b = Bs[i];

        if a > b {
            plus_one_cnt += a - b;
        } else if b > a {
            plus_two_cnt += (b - a + 1) / 2;
        }
    }

    if plus_one_cnt <= cnt && plus_two_cnt <= cnt {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2496
#include<bits/stdc++.h>
#define pii pair<int,int>
#define maxn 100005
#define endl '\n'
using namespace std;
struct node {
	int pos,state;
	bool operator < (const node &a) const{
		return pos < a.pos;
	}
}arr[maxn];
int state[maxn];
vector<pii> G[maxn];
int pa[maxn];
vector<int> ans;
bool dfs(int u) {
	for(pii e : G[u]) {
		int v = e.first , idx = e.second;
		if(pa[v] == 0) {
			pa[v] = u;
			if(dfs(v)) {
				ans.emplace_back(idx);
				state[u] ^= 1;
			}
		}
	}
	return state[u] == 1;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++)
		cin >> arr[i].pos >> arr[i].state;
	sort(arr+1,arr+1+n);
	for(int i=1;i<=n;i++)
		state[i] = arr[i].state ^ arr[i-1].state;
	for(int i=1,l,r;i<=m;i++) {
		cin >> l >> r;
		l = lower_bound(arr+1,arr+1+n,node{l,-1})-arr;
		r = upper_bound(arr+1,arr+1+n,node{r,-1})-arr-1;
		if(l <= r) {
			G[l].emplace_back(pii{r+1,i});
			G[r+1].emplace_back(pii{l,i});
		}
	}
	for(int i=n+1;i>=1;i--)
		if(pa[i] == 0) {
			if(dfs(pa[i] = i) && i != n + 1) {
				cout << -1 << endl;
				return 0;
			}
		}
	sort(ans.begin(),ans.end());
	cout << (int)ans.size() << endl;
	for(int i=0;i<(int)ans.size();i++) {
		if(i != 0)	cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 15484
#include<bits/stdc++.h>
#define re register
#define int long long
#define ll long long
#define M 1000000007
using namespace std;
inline int read() {
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0') {
		t=(t<<3)+(t<<1)+v-48;
		v=getchar();
	}
	return t;
}
inline int ksm(re int x,re int y){
	int sum=1;
	while(y){
		if(y&1)sum*=x,sum%=M;
		x*=x,x%=M;
		y>>=1;
	}
	return sum;
}
int n,k,q,ans,m,f[200005],g[200005],fac[200005],inv[200005];
inline int C(re int x,re int y){
	return fac[x]*inv[y]%M*inv[x-y]%M;
}
signed main() {
	n=read();
	k=read();
	if(k>=n)k=n;
	fac[0]=1;
	for(re int i=1;i<=n;++i)fac[i]=fac[i-1]*i%M;
	inv[n]=ksm(fac[n],M-2);
	for(re int i=n-1;i;--i)inv[i]=inv[i+1]*(i+1)%M;
	inv[0]=1;
	f[0]=1;
	for(re int i=1;i<=k;++i){
		f[i]=f[i-1]+C(n,i)*C(n-1,n-i-1)%M;
		f[i]%=M;
	}
	printf("%lld",f[k]);
}



Measured memory_bytes: 6528
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int n;
  cin >> n;
  
  vector<ld> p(n);
  vector<ld> q(n);
  
  rep(i,n){
  cin >> p[i] >> q[i];
  }

  ld sum = 0;
  
  rep(i,n){
    for(int j=i+1;j<n;j++){
    sum+=sqrt((p[i]-p[j])*(p[i]-p[j])+(q[i]-q[j])*(q[i]-q[j]));
    }
  }
  
  cout << fixed << setprecision (20);
  cout<< 2*sum/n << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

int main(){
  ll N;
  cin >> N;
  ll ans = 0;
  
  if(N==1) ans = 0;
  else{
    ans = (N-1)*N/2;
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{

    int x, y, z;

    cin >> x >> y >> z;

    cout << z <<" "<< x << " "<<y << endl;

    return 0;
    
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 3580
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);      
      int k = sc.nextInt();
      int s = sc.nextInt();
      int count = 0;
      for(int x=0;x<=k;x++){
        for(int y=0;y<=k;y++){
          int z =  s-x-y;
          if(0<=z && z<=k){
            count++;
          }
        }
      }
      System.out.println(count);
    }
}

Measured memory_bytes: 23764
#include<iostream>
using namespace std;
#define N 10
int flag;
int shunxu[N+5];
void dfs(int x1,int y1,int x2,int y2,int ans) {
	if (x2 < x1 || y2 < y1)
		return;
	if (ans == 10) {
		flag = 1;
		return;
	}
	dfs(x2, y1, shunxu[ans], y2, ans + 1);
	dfs(x1, y2, x2, shunxu[ans], ans + 1);
}
int main()
{
	int n;
	cin >> n;
	while (n--) {
		for (int i = 0; i < N; i++) {
			cin >> shunxu[i];
		}
		flag = 0;
		dfs(0, 0, 0, 0, 0);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}


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

int main(){
    int N;
    float T,A;
    cin >> N >> T >> A;

    float H[N];
    for(int i=0;i<N;i++){
        float tmp;
        cin >> tmp;
        H[i] = abs((T - 0.006*tmp)-A);
    }

    float a = H[0];

    int c = 1;

    for(int i=1;i<N;i++){
        if(a > H[i]){
            a = H[i];
            c = i + 1;
        }
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int S = sc.nextInt();
			final int W = sc.nextInt();
			
			System.out.println(S <= W ? "unsafe" : "safe");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32564
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        s: chars
    }

    let mut cnt = 0;
    let mut ret = 0;
    for i in 0..n {
        if s[i] == 'I' {
            cnt += 1;
        }
        if s[i] == 'D' {
            cnt -= 1;
        }
        ret = std::cmp::max(ret, cnt);
    }
    println!("{}", ret);
}

Measured memory_bytes: 4352
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    ans = float("inf")
    for i in range(n+1):
        m = 0
        k = i
        while k > 0:
            m += k%6
            k //= 6
        k = n-i
        while k > 0:
            m += k%9
            k //= 9
        ans = min(ans,m)
    print(ans)
#D
def D():
    n,C = LI()
    f = LIR(C)
    c = LIR(n)
    d = [defaultdict(int) for i in range(3)]
    for i in range(n):
        for j in range(n):
            d[(i+j+2)%3][c[i][j]-1] += 1
    ans = float("inf")
    for i in range(C):
        for j in range(C):
            if i != j:
                for k in range(C):
                    if k != i and k != j:
                        m = 0
                        for a in d[0].keys():
                            m += d[0][a]*f[a][i]
                        for a in d[1].keys():
                            m += d[1][a]*f[a][j]
                        for a in d[2].keys():
                            m += d[2][a]*f[a][k]
                        ans = min(ans,m)
    print(ans)


#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 46428
n, m = map(int, input().split())

c = []
for i in range(10):
	row = list(input().split())
	for j in range(10):
		row[j] = int(row[j])
	c.append(row)
	
for k in range(10):
	for i in range(10):
		for j in range(10):
			c [i][j] = min(c[i][j], c[i][k] + c[k][j])

ans = 0
for i in range(n):
	row = list(input().split())
	for j in range(m):
		row[j] = int(row[j])
		if row[j] == 1 or row[j] == -1:
			continue
		ans += c[row[j]][1]
			
print(ans)

Measured memory_bytes: 40556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin >> n >> k;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	vector<vector<int>> dp1(n + 2, vector<int>(5010)), dp2(n + 2, vector<int>(5010));
	dp1[0][0] = 1;
	dp2[n][0] = 1;
	rep(i,n){
		rep(j,5001){
			if(j - a.at(i) >= 0) dp1[i + 1][j] |= dp1[i][j - a.at(i)];
			if(j - a.at(n - 1 - i) >= 0) dp2[n - 1 - i][j] |= dp2[n - i][j - a.at(n - 1 - i)];
			dp1[i + 1][j] |= dp1[i][j];
			dp2[n - 1 - i][j] |= dp2[n - i][j];
		}
	}
	int ans = n;
	rep(i,n){
		bool ok = false;
		rep(j,k + 1){
			if(dp1[i][j]){
				bool flg = false;
				for(int l = max(0,k - j - a.at(i)); l < k - j; l++){
					if(dp2[i + 1][l]){
						ok = true;
						flg = true;
						break;
					}
				}
				if(flg) break;
			}
		}
		if(ok) ans--;
	}
	cout << ans << endl;
}


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

int main(void) {
	int S;
	int h = 0,m = 0,s = 0;
	cin >> S;

	if (S >= 60)
	{
		m = S / 60;
		s = S % 60;
		if (m >= 60)
		{
			h = m / 60;
			m = m % 60;
		}		
	}
	else
	{
		s = S;
	}
	cout << h << ":" << m << ":" << s << endl;
	
	return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <string>

using namespace std;
typedef long long ll;

int main(void) {
	int sum = 0, i = 0;
	ll k;
	string s;
	cin >> s >> k;
	while (s[i] == '1') {
		sum++;
		i++;
	}
	if (k <= sum)
		printf("1\n");
	else
		cout << s[sum] << "\n";
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    a103(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}


fun a103(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val numList = args[0].split(" ").map { it.toInt() }.sortedDescending()
    println(numList.first() - numList.last())
}

Measured memory_bytes: 38304
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve()
{
	/*--------------------------*/

	int N; cin >> N;
	vi vec; rep(i, N) vec.pb(i);
	vi x(N), y(N);
	rep(i, N) cin >> x[i] >> y[i];
	int NN = 1, tmp = N;
	while (tmp > 0) {
		NN *= tmp;
		tmp--;
	}
	double sum = 0;
	do {
		rep(i, N - 1) {
			sum += sqrt(pow(x[vec[i]]-x[vec[i+1]], 2) + pow(y[vec[i]]-y[vec[i+1]], 2));
		}
	} while(next_permutation(all(vec)));
	cout << sum / NN << endl;

	/*--------------------------*/
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
ans=0
for loop in range(n):
  a=list(map(int,input().split()))
  re=c
  for i in range(m):
    re += a[i]*b[i]
  if re > 0:
    ans += 1
print(ans)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import numpy as np
     
[N, M, C] = [int(i) for i in input().split()]
B = np.array([int(i) for i in input().split()])
A_N = []
for n in range(N):
    A = np.array([int(i) for i in input().split()])
    A_N.append(A)

count = 0
for n in range(N):
    dot = np.dot(B, A_N[n])
    if dot + C > 0:
        count += 1

print(count)


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

int main() {
  char c[5];
  scanf("%s", c);
  int ans=700;
  for (int i=0; i<3; i++) {
    if ( c[i]=='o' ) ans+=100;
  }
  printf("%d\n", ans);
  return 0; 
}

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

int main() {
	int n, a[100];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = n - 1; i >= 0; i--)
		cout << a[i] << (i == 0 ? '\n' : ' ');
}


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

using namespace std;
typedef long long ll;

int main(){
  ll N;
  cin >> N;
  ll A[N];
  for(ll i=0;i<N;i++){
    cin >> A[i];
  }
  vector<ll> b(200010);
  vector<ll> c(200010);
  vector<bool> seen;
  for(ll j=0;j<N;j++){
    if(j+A[j]<N) b[j+A[j]]++;
    if(j-A[j]>=0) c[j-A[j]]++;
  }
  ll ans=0;
  seen.assign(200010, true); 
  for(ll j=0;j<N;j++){
    if(j+A[j]<N) {
      if(seen[j+A[j]]){
	//cout << j+A[j] << " " << b[j+A[j]] << " " << c[j+A[j]] << endl;
	ans+=b[j+A[j]]*c[j+A[j]];
	seen[j+A[j]] = false;
      }
    }
  }
  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n;cin>>n;
  ll dp[n+1];
  rep(i,0,n+1){
    dp[i]=i;
    for(ll six=6;six<=i;six*=6)dp[i]=min(dp[i],dp[i-six]+1);
    for(ll nine=9;nine<=i;nine*=9)dp[i]=min(dp[i],dp[i-nine]+1);
  }

  out(dp[n]);



  return 0;
}


Measured memory_bytes: 1024
import sys
n = int(input())

a = list(map(int, input().split()))

for i in range(n):
  if a[i] % 2 != 0:
    continue
  else:
    if a[i] % 3 == 0 or a[i] % 5 == 0:
      pass
    else:
      print('DENIED')
      sys.exit()
      

print('APPROVED')

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int r;
    cin >> r;
    print(r < 1200 ? "ABC" : r < 2800 ? "ARC" : "AGC");

    return 0;
}


Measured memory_bytes: 256
import math
S = input()
l = len(S)
cs = ["A","G","C","T"]
ma = 0
for i in range (l):
    for j in range(i,l+1):
        sub = S[i:j]

        for c in sub:
            if c not in cs:
                break
        else:
            if len(sub) > ma:
                ma = len(sub)
print(ma)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int A,B,C,D,a,b;
    while(~scanf("%d%d%d%d",&A,&B,&C,&D))
    {
    if(A>=1&&A<=10)
        if(B>=1&&B<=10)
            if(C>=1&&C<=10)
                if(D>=1&&D<=10)
                {
                    a=A+B;
                    b=C+D;
                    if(a>b)
                    {
                        printf("Left\n");
                    }
                    else
                    {
                        if(a<b)
                        {
                            printf("Right\n");
                        }
                        else
                        {
                            printf("Balanced\n");
                        }
                    }
                }
    }
    return 0;
}


Measured memory_bytes: 128
N = int(input())
A = [int(_n) for _n in input().split()]
res0 = 0
s = 0
for i, a in enumerate(A):
    s += a
    if i % 2 == 0 and s >= 0:
        res0 += s + 1
        s = -1
    elif i % 2 == 1 and s <= 0:
        res0 += -s + 1
        s = 1
res1 = 0
s = 0
for i, a in enumerate(A):
    s += a
    if i % 2 == 1 and s >= 0:
        res1 += s + 1
        s = -1
    elif i % 2 == 0 and s <= 0:
        res1 += -s + 1
        s = 1
print(min(res0,res1))

Measured memory_bytes: 63216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k,c;cin>>n>>k>>c;
  string s;cin>>s;
  lvector sv,b(n,1),f(n,1),bans,fans;
  rep(i,n) if(s[i]=='x') b[i]=0,f[i]=0;
  ll bpos=0;
  while(bans.size()<k&&bpos<n) {
    if(b[bpos]==1) {
      bans.emplace_back(bpos+1);
      for(ll i=1;i<=c;++i) if(bpos+i<n) b[bpos+i]=0;
    }
    bpos++;
  }
  ll fpos=n-1;
  while(fans.size()<k&&fpos>-1) {
    if(f[fpos]==1) {
      fans.emplace_back(fpos+1);
      for(ll i=1;i<=c;++i) if(fpos-i>-1) f[fpos-i]=0;
    }
    fpos--;
  }
  reverse(ALL(fans));
  ll lim=min(bans.size(),fans.size());
  rep(i,lim) if(bans[i]==fans[i]) print(bans[i]);
  return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int mod = 1e9+7;
const int N = 123;

long long p[N];
int H, W, K;
long long dp[N][8];

bool check(int x) {
  int prev = 0;
  while (x) {
    if ((x&1) && prev) return false;
    prev = x&1;
    x >>= 1;
  }
  return true;
}

long long rek(int h, int pos) {
  if (h == H) return pos == (K-1);
  long long &ret = dp[h][pos];
  if (ret != -1) return ret;
  ret = 0;
  for (int j = 0; j < 3; ++j) {
    if (pos == 0 && j == 1) continue;
    if (pos == W-1 && j == 2) continue;
    long long cur = 0;
    int lmt = pos-1;
    if (j == 1) --lmt;
    for (int i = 0; i < (1 << max(lmt, 0)); ++i) {
      if (!check(i)) continue;
      ++cur;
    }
    long long cur2 = 0;
    lmt = W-1-pos-1;
    if (j == 2) --lmt;
    for (int i = 0; i < (1 << max(lmt, 0)); ++i) {
      if (!check(i)) continue;
      ++cur2;
    }
    cur *= cur2;
    if (j == 1) {
      ret = (ret + cur*rek(h+1, pos-1)%mod) % mod;
    } else if (j == 2) {
      ret = (ret + cur*rek(h+1, pos+1)%mod) % mod;
    } else {
      ret = (ret + cur*rek(h+1, pos)%mod) % mod;
    }
  }
  return ret;
}

void solve() {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d%d", &H, &W, &K);
  printf("%lld", rek(0, 0));
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3860
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}



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


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

using namespace std;

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

  int n;
  cin >> n;

  int cnt = 0, tmp;
  for (int i = 1; i <= n; ++i) {
    cin >> tmp;
    if (i != tmp) {
      ++cnt;
    }
  }

  cout << (cnt <= 2 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const int N=1e5+10;
const int mod=1e9+7;
int fa[N],n,son[N],len[N];
bool cir[N];int vis[N];
int num[N];int dp[N];
template<class T>inline void Inc(T&x,int y){x+=y;if(x>=mod) x-=mod;return;}
inline int Mod(int x){if(x>=mod) x-=mod;return x;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&fa[i]),++son[fa[i]];
	for(int i=1;i<=n;++i) {
		if(vis[i]) continue;
		int u=i;
		while(!vis[u]) vis[u]=i,u=fa[u];
		if(vis[u]==i) {while(!cir[u]) cir[u]=1,u=fa[u];}
	}
	for(int i=1;i<=n;++i) if((cir[i]&&son[i]>2)||(!cir[i]&&son[i]>1)) return puts("0"),0;
	for(int i=1;i<=n;++i) {
		if(!son[i]) {
			int u=i,l=0;
			while(!cir[u]) ++l,u=fa[u];
			if(len[u]) return puts("0"),0;
			len[u]=l;
		}
	}int ans=1;
	for(int i=1;i<=n;++i){
		if(!cir[i]) continue;
		int size=0,fir=0,pfir=0,now=0;
		for(int u=i;cir[u];u=fa[u]){
			++size;cir[u]=0;
			if(len[u]) {
				if(!fir) fir=size,pfir=u,now=size;
				else {
					int pre=now;now=size;int d=now-pre;
					if(d>len[u]) Inc(ans,ans);
					else if(d<len[u]) {puts("0");return 0;}
				}
			}
		}
		if(!fir) ++num[size];
		else {
			int d=size-now+fir;
			if(d>len[pfir]) Inc(ans,ans);
			else if(d<len[pfir]) {puts("0");return 0;}
		}
	}
	for(int i=1;i<=n;++i){
		if(!num[i]) continue;dp[0]=1;
		for(int j=1;j<=num[i];++j) {
			dp[j]=dp[j-1];//keep the same
			if(i>1&&(i&1)) Inc(dp[j],dp[j]);//two kinds
			if(j>1) Inc(dp[j],(ll)dp[j-2]*(j-1)%mod*i%mod);// union
		}
		ans=(ll)ans*dp[num[i]]%mod;
	}
	printf("%d\n",ans%mod);
}


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

typedef long long ll;

using namespace std;

ll MAX = 1e9+1;
const int maxn = 300*3+1;
double dp[901][451][301];
int n;

double f(int i, int j, int k) {
    if (i == 0 && j == 0 && k == 0)
        return 0;
    if (dp[i][j][k] != 0)
        return dp[i][j][k];
    int l = n - i - j - k;
    double sol = 1 + (double) i/n * (i == 0 ? 0 : f(i-1,j,k))
        + (double) j/n * (j == 0 ? 0 : f(i+1, j-1, k))
        + (double) k/n * (k == 0 ? 0 : f(i, j+1, k-1));
    sol /= (1 - (double) l/n);

    dp[i][j][k] = sol;

    return sol;
}

void solve() {
    cin >> n;

    vector<int> counts(4);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        counts[x]++;
    }
    memset(dp, 0, sizeof(dp));

    // if f(i,j,k) ~ expected # of moves to finish i 1s, j 2s, and k 3s
    // f(i,j,k) = 1 + (N-i-j-k)/N f(i,j,k) + i/N f(i-1,j,k) + j/N f(i+1,j-1,k) + k/N f(i,j+1,k-1)
    //          (pick)  (pick 0 plate)       (pick 1 plate)     (pick 2 plate)   (pick 3 plate)
    // dp[i][j][k] ~ expected # of moves to finish from state (i,j,k)
    // if i'm at dp[i][j][k], then three states depend on me:
    //      - dp[i+1][j][k]
    //      - dp[i-1][j+1][k]
    //      - dp[i][j-1][k+1]

    //dp[1][0][0] = n;
    //for (int k = 0; k <= counts[3]; k++) {
    //    for (int j = 0; j <= counts[2] + counts[3]; j++) {
    //        for (int i = 0; i <= counts[1] + counts[2] + counts[3]; i++) {
    //            //cout << i << " " << j << " " << k << " ";
    //            if (j > 0)
    //                dp[i][j-1][k+1] += (double) n/(k+1) * dp[i][j][k];
    //            if (i > 0)
    //                dp[i-1][j+1][k] += (double) n/(j+1) * dp[i][j][k];
    //            dp[i+1][j][k] += (double) n/(i+1) * dp[i][j][k];
    //            //cout << dp[i][j][k] << endl;
    //        }
    //    }
    //}

    double ans = f(counts[1], counts[2], counts[3]);

    cout.precision(16);
    //cout << dp[counts[1]][counts[2]][counts[3]] << endl;
    cout << ans << endl;
}


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



Measured memory_bytes: 955904
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    X = input()
    cnt_init = X.count("1")
    x = int(X, 2)
    a = x % (cnt_init + 1)
    if cnt_init - 1 != 0:
        b = x % (cnt_init - 1)

    for i in range(n):
        if X[i] == "0":
            cnt = cnt_init + 1
            y = (a + pow(2, n - i - 1, cnt)) % cnt
        else:
            cnt = cnt_init - 1
            if cnt == 0:
                print(0)
                continue
            y = (b - pow(2, n - i - 1, cnt)) % cnt

        res = 1
        while y:
            cnt = bin(y).count("1")
            y %= cnt
            res += 1
        print(res)


if __name__ == '__main__':
    resolve()


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

int main() {
    int w, n;
    cin >> w >> n;
    vector<int> v(w);
    for(int i=0; i<w; ++i) {
        v[i] = i+1;
    }
    for(int i=0; i<n; ++i) {
        int a, b;
        scanf("%d,%d", &a, &b);
        a--; b--;
        swap(v[a], v[b]);
    }
    for(auto x : v) {
        cout << x << endl;
    }
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    while(1){
        int n, m; cin>>n>>m;
        if(n==0 && m==0) return 0;
        vector<ll> a(n+m);
        for(int i=0; i<n+m; i++) cin>>a[i];
        sort(a.begin(), a.end());
        ll gap=a[0];
        for(int i=0; i<n+m-1; i++){
            gap=max(gap, a[i+1]-a[i]);
        }
        cout << gap << endl;
    }
}


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

bool bfs(int s,int t,vector<vector<pair<int,int>>> graph,vector<int> &prev)
{
	int v,w;
	vector<bool> visit(201,false);
	queue<int> que;
	que.push(s);
	visit[s]=true;
	for (int i=0;i<prev.size();i++) prev[i]=0;
	while(!que.empty())
	{
		v=que.front();
		que.pop();
		for (int i=0;i<graph[v].size();i++)
		{

			if (graph[v][i].first!=0)
			{
				w=i;
				if (!visit[w])
				{
					visit[w]=true;
					prev[w]=v;
					que.push(w);
				}
			}
		}
	}
	return visit[t];
}

int main()
{
	int N;cin>>N;
	vector<pair<int,int>> red(N),blue(N);
	vector<vector<int>> capacity(2*N+2,vector<int> (2*N+2));
	vector<vector<int>> flow(2*N+2,vector<int> (2*N+2));
	vector<vector<pair<int,int>>> network(2*N+2,vector<pair<int,int>> (2*N+2));
	int x,y;
	for (int i=0;i<N;i++)
	{
		cin >> x >> y;
		red[i].first=x;
		red[i].second=y;
		capacity[0][i+1]=1;
	}
	for (int i=0;i<N;i++)
	{
		cin >> x >> y;
		blue[i].first=x;
		blue[i].second=y;
		capacity[N+i+1][2*N+1]=1;
	}
	for (int i=0;i<N;i++)
		for (int j=0;j<N;j++)
		{
			if ((red[i].first<blue[j].first) && (red[i].second < blue[j].second)) 
			{
				capacity[i+1][N+j+1]=1; 
			}
		}
	for (int i=0;i<2*N+2;i++)
		for (int j=0;j<2*N+2;j++)
		{
			if (capacity[i][j]>flow[i][j])
			{
				network[i][j].first=1;
				network[i][j].second=1;
			}
			if (flow[i][j]>0)
			{
				network[j][i].first=1;
				network[j][i].second=0;
			}
		}

	
	int to,from=-1;
	vector<int> prev(2*N+2);
	
	while (bfs(0,2*N+1,network,prev))
	{
		from =-1;
		to=2*N+1;
		while(from!=0)
		{
			from=prev[to];
			if (network[from][to].second==1)
			{
				flow[from][to]=1;
				network[from][to].first=0;
				network[to][from].first=1;
				network[from][to].second=1;
				network[to][from].second=0;
			}
			else
			{
				flow[from][to]=0;
				network[from][to].first=0;
				network[to][from].first=1;
				network[from][to].second=0;
				network[to][from].second=1;
			}
			to=from;	
		}
	}

	int ans=0;
	for (int i=1;i<2*N+1;i++) ans+=flow[i][2*N+1];
	cout << ans << endl;

return 0;
}

Measured memory_bytes: 1288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    vector<int> c(n-1),s(n-1),f(n-1);
    rep(i,n-1) cin>>c[i]>>s[i]>>f[i];

    rep(i,n-1){
        int ans=s[i]+c[i];
        for(int j=i+1;j<n-1;j++){
            if(ans<=s[j]) ans=s[j]+c[j];
            else{
                if((ans-s[j])%f[j]==0){
                    int x=(ans-s[j])/f[j];
                    ans=s[j]+f[j]*x+c[j];
                }
                else{
                    int x=(ans-s[j]+f[j]-1)/f[j];
                    ans=s[j]+f[j]*x+c[j];
                }
            }
        }

        cout<<ans<<endl;
    }

    cout<<0<<endl;
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<utility>
#include<queue>
using namespace std;


int
main(){
  int n,q,time,cnt_time = 0;
  string name;
  queue<pair<string,int> > que;
  cin >> n >> q;
  
  for(int i=0;i<n;i++){
    cin >> name >> time;
    que.push(make_pair(name,time));
  }
  
  while(!que.empty()){
    pair<string,int> top = que.front();
    que.pop();
    if(top.second <= q){
      cnt_time += top.second;
      cout << top.first << " " << cnt_time << endl;
    }else{
      cnt_time += q;
      que.push(make_pair(top.first,top.second-q));
    }
    
  }
}


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

int main() {
	int D;
	cin >> D;
	switch (D) {
		case 25: cout << "Christmas" << endl; break;
		case 24: cout << "Christmas Eve" << endl; break;
		case 23: cout << "Christmas Eve Eve" << endl; break;
		case 22: cout << "Christmas Eve Eve Eve" << endl; break;
	}
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, A: "List[int]"):

    # Aを0~N-1に付け直す
    dic = {}
    for i, a in enumerate(sorted(A)):
        dic[a] = i
    B = [dic[a] for a in A]

    # Bの内、偶数番目にある奇数の数だけ操作1が必要
    count = 0
    for i in range(0, N, 2):
        if B[i] % 2 == 1:
            count += 1
    print(count)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 60760
#include <bits/stdc++.h>
using namespace std;
int cnt;
int main(){
	int a,b;
	string s;
	cin>>a>>b>>s;
	if(s[a]=='-'){
		for(int i=0;i<a+b+1;i++){
			if(i!=a){
				cnt=0;
				for(int j=0;j<10;j++){
					if(j+'0'==s[i]){
						break;
					}
					else{
						cnt++;
					}
					if(cnt==10){
						cout<<"No"<<endl;
						return 0;
					}
				}
			}
		}
	}
	else{
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def comb_mod(n, r):
    res = 1
    r = min(n - r, r)

    for i in range(r):
        res *= (n - i)
        res %= MOD
        res *= pow((r - i), MOD - 2, MOD)

    return res


def main():
    k = int(readline())
    s = input()
    l = len(s)
    x = k + l

    comb = 1
    ans = 0
    for i in range(k + 1):
        ans += pow(26, k - i, MOD) * pow(25, i, MOD) * comb
        ans %= MOD
        comb *= (l + i)
        comb %= MOD
        comb *= pow(i + 1, MOD - 2, MOD)
        comb %= MOD

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 70604
#include<iostream>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
	int N=0,sum=0;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		sum+=i;
	}
	cout<<sum<<endl;
	return 0;	
}

Measured memory_bytes: 256