akhauriyash/Code-Regression huggingface dataset:
/*#include<bits/stdc++.h>
using namespace std;
const double PI=3.14159265358979323846;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int r; cin>>r;
	cout<<fixed<<setprecision(10)<<2*r*PI<<"\n"s;
}*/
/*
#include<bits/stdc++.h>
using namespace std;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int64_t n,m; cin>>n>>m;
	int64_t sum=0;
	for(int i=0;i<m;++i){
		int64_t a; cin>>a;
		sum+=a;
	}
	cout<<(n-sum<0?-1:n-sum)<<"\n"s;
}*/
/*
#include<bits/stdc++.h>
using namespace std;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n);
	for(int i=0;i<n-1;++i){
		int A; cin>>A;
		++a.at(A-1);
	}
	for(auto&i:a)cout<<i<<"\n"s;
}*/

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	const int mod=1e9+7;
	int64_t n,k; cin>>n>>k;
	int64_t mn=(k-1)*k/2;
	int64_t mx=(n+(n-k+1))*k/2;
	int64_t ans=0;
	for(int64_t i=k;mx>=mn;++i){
		mx=(n+(n-i+1))*i/2;//cout<<"mx="s<<mx<<"\n"s;cout<<"mn="s<<mn<<"\nmx-mn="s<<mx-mn<<"\n"s;
		ans+=mx-mn+1;
		ans=ans%mod;
		mn=(i+1)*i/2;
	}
	ans=ans%mod;
	cout<<ans<<"\n"s;
}

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

#define pb push_back
#define mod 1000000007
typedef int integer;
#define int long long
using namespace std;

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

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

const integer NN = 200005;
int ar[NN];
int n, m, k;
string s;

bool pal(int i, int j){
    while (i < j){
        if (s[i] != s[j]) return false;
        i++; j--;
    }
    return true;
}


integer main() {
    ios_base::sync_with_stdio(false);

    double l;
    cin >> l;
    cout << fixed << setprecision(10) << pow(l/3.0, 3) << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){

  long A,B,K;
  scanf("%ld%ld%ld", &A, &B, &K);
  long AK, BK;
  long ansA, ansB;
  AK = int(K/2)+1;
  BK = int(K/2);

  for(int i=0; i<BK; i++){
    if(A%2!=0)A=A-1;
    A/=2;
    B+=A;
    if(B%2!=0)B=B-1;
    B/=2;
    A+=B;
  }


  if(K%2 != 0) {
    if(A%2!=0)A=A-1;
    A/=2;
    B+=A;
  }
  ansA=A;
  ansB=B;

  printf("%ld %ld\n", ansA, ansB);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using ld = long double; 
int INF = 1e9;

vector<int> cnt(200005);
vector<bool> seen(200005);
void dfs(const vector<vector<int>> &G,int v){
  for(int nv : G[v]){
    if(seen[nv]) continue;
    seen[nv] = true;
    cnt[nv] += cnt[v];
    dfs(G,nv);
  }
  return;
}
int main(){
  int n,q;cin >> n >> q;
  vector<vector<int>> G(200005);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a;--b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  rep(i,q){
    int p,x;cin >> p >> x;
    --p;
    cnt[p] += x;
  }
  rep(i,n) seen[i] = false;
  seen[0] = true;
  dfs(G,0);
  rep(i,n) cout << cnt[i] << " ";

}

Measured memory_bytes: 27440
#include <bits//stdc++.h>
using namespace std;
typedef bitset<64> b64;
int main(){
	b64 b;
	int q,a,x;
	for(cin>>q;q--;){
		cin>>a;
		if(a==0)cin>>x,cout<<b[x]<<endl;
		if(a==1)cin>>x,b[x]=1;
		if(a==2)cin>>x,b[x]=0;
		if(a==3)cin>>x,b[x]=b[x]^1;
		if(a==4)cout<<b.all()<<endl;
		if(a==5)cout<<b.any()<<endl;
		if(a==6)cout<<b.none()<<endl;
		if(a==7)cout<<b.count()<<endl;
		if(a==8)cout<<b.to_ulong()<<endl;
	}
}



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

int main() {
	// your code goes here
	int n;cin>>n;
	int arr[107];
	int sum=0;
	for(int i=0; i<n; i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	
	sort(arr,arr+n);
	// cout<<sum<<endl;
	if((sum-arr[n-1])>arr[n-1])
		cout<<"Yes"<<endl;
	else {
		cout<<"No"<<endl;
	}
	
	return 0;
}

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

#define ll long long
#define INF 2147483647

int inp(){
    char c = getchar();
    while(c < '0' || c > '9')
        c = getchar();
    int sum = 0;
    while(c >= '0' && c <= '9'){
        sum = sum * 10 + c - '0';
        c = getchar();
    }
    return sum;
}

int a[300010], n;
ll sum[300010];
int ans[300010];

bool check(int num, int lim){
    int mid = std::lower_bound(a + 1, a + n + 1, lim) - a;
    num -= n - mid + 1;
    // printf("mid = %d\n", mid);
    return sum[mid - 1] >= num * lim;
}

int main(){
    n = inp();
    for(int i = 1; i <= n; i++)
        a[inp()]++;
    std::sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; i++)
        sum[i] = sum[i - 1] + a[i];
    for(int i = n; i >= 1; i--){
        ans[i] = ans[i + 1];
        while(check(i, ans[i] + 1))
            ans[i]++;
    }
    for(int i = 1; i <= n; i++)
        printf("%d\n", ans[i]);
}

Measured memory_bytes: 5504
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main()
{
    let s=input_line_str().to_charvec();
    for i in s{
        if i==','{
            print!(" ");
        }else{
            print!("{}",i);
        }
    }
    println!("");
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a[10],b,q=0;
  for(int i=0;i<5;i++){
    cin>>a[i];
  }
  cin>>b;
  for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++){
      if(abs(a[i]-a[j])>b){
	cout<<":(\n";
	q=1;
	break;
      }
      if(q==1) break;
    }
  }
  if(q==0) cout<<"Yay!\n";
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		out.println(-ir.nextInt()+2*ir.nextInt()-ir.nextInt()==0?"YES":"NO");
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

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

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    ios();
    int n;
    cin >> n;
    deque<ll> deq;
    REP(i, n){
        int a;
        cin >> a;
        if(i%2 == 0){
            deq.push_back(a);
        }else{
            deq.push_front(a);
        }
    }
    if(n%2 == 1){
        reverse(all(deq));
    }
    for(auto i : deq){
        cout << i << " ";
    }
    cout << endl;

    return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    string s;
    cin>>s;
    int ans=0;
    for(int i=0; i<s.size()/2; i++){
        int j = s.size()-i-1;
        //DEBUG2(i,j);
        //if(i==j) break;
        if(s[i]!=s[j]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import collections


n = int(input())
w_l = [input() for _ in range(n)]

counter = collections.Counter(w_l)

c_l = counter.most_common()
max_v = c_l[0][1]
ans_l = []
for i in range(len(c_l)):
    word, num = c_l[i]
    if max_v != num:
        break
    ans_l.append(word)

ans_l.sort()
for ans in ans_l:
    print(ans)







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

int N;
int cnt[9];
 
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) {
        int a; cin >> a;
        a = min(3200ll, a);
        cnt[a/400]++;
    }
    int ans = 0;
    rep(i, 8) ans += cnt[i]>0;
    if (cnt[8]==0) cout << ans << " " << ans << endl;
    else {
        if (ans==0) cout << 1 << " " << cnt[8] << endl;
        else cout << ans << " " << ans+cnt[8] << endl;
    }
}

Measured memory_bytes: 256
//K-th Common Divisor
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<(x)<<endl
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll inf=1e18;
const int N=2e5+10;
ll factorial(ll x){//階乗の計算
    if(x==0||x==1) return 1;
    return x*factorial(x-1);
}
ll gcd(ll a ,ll b){return b ? gcd(b,a%b) : a;}//最大公約数
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}//最小公倍数
int num_digit(ll a){//桁数を求める
    int num_dig = 0;
    while(a!=0){
        a /= 10;
        ++num_dig;
    }
    return num_dig;
}
vector<ll> digit(ll a){//桁の数字を求める
    vector<ll> dig(num_digit(a));
    for(int i=num_digit(a)-1; i>=0; --i){
        dig[i] = a%10;
        a /= 10; 
    }
    return dig;
}

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

    int keta = 0;
    int ans = 100;
    ll b = n; 
    for(ll a=1; a<=sqrt(n); ++a){
        if(n%a != 0) continue;
        b = n/a;
        keta = max(num_digit(a),num_digit(b));
        if(keta<ans) ans = keta;
    }
    cout(ans);
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val N = readLine()!!.toInt()
  val A = readLine()!!.split(" ").map(String::toInt).toMutableList()

  var cnt = 0
  (0 until N).forEach { i ->
    var minX = i
    (i until N).forEach { j ->
      if (A[j] < A[minX]) {
        minX = j
      }
    }
    if (A[i] != A[minX]) {
      val tmp = A[i]
      A[i] = A[minX]
      A[minX] = tmp
      cnt += 1
    }
  }
  println(A.joinToString((" ")))
  println(cnt)
}


Measured memory_bytes: 32236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct mint {
    const int mod = 998244353;
    long long x;
    
    mint (long long x = 0) : x((x % mod + mod) % mod) {
        
    }
    
    mint& operator=(const long long a) {
        x = a % mod;
        return *this;
    }
    
    mint& operator=(const mint a) {
        x = a.x % mod;
        return *this;
    }
    
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    
    mint& operator-=(const mint a) {
        if ((x += (mod - a.x)) >= mod) x -= mod;
        return *this;
    }
    
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    
    mint inv() const {
        return pow(mod - 2);
    }
    
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<vector<mint>> dp(c + 1, vector<mint>(d + 1, 0));
    dp[a][b] = 1;
    reps(h, a, c + 1) {
        reps(w, b, d + 1) {
            if (h > a) dp[h][w] += dp[h - 1][w] * w;
            if (w > b) dp[h][w] += dp[h][w - 1] * h;
            if ((h > a) && (w > b)) dp[h][w] -= dp[h - 1][w - 1] * (w - 1) * (h - 1);
        }
    }
    cout << dp[c][d].x << endl;
    return 0;
}


Measured memory_bytes: 144096
# read https://img.atcoder.jp/abc172/editorial.pdf

def to_binary_array(num)
  bin = num.to_s(2).chars.map(&:to_i)
  bin = [0] * (ARRAY_SIZE - bin.size) + bin
  bin.reverse!
end

def binary_array_to_int(arr)
  ans = 0
  arr.size do |i|
    ans += 2**i if arr[i] == 1
  end
  ans
end

ARRAY_SIZE = 42
N = gets.chomp.to_i
AS = gets.chomp.split.map(&:to_i)

S = AS[0] + AS[1]
X = AS[2..-1].inject(0) { |result, n| result^n }

s_bin = to_binary_array(S)
x_bin = to_binary_array(X)
a_x_bin = to_binary_array(X)

if X > S || s_bin[0] != a_x_bin[0]
  puts "-1"
  exit
end

fix = [false] * ARRAY_SIZE
a = 0
0.upto(39) do |i|
  if x_bin[i].zero?
    fix[i] = true
    next if a_x_bin[i + 1] == s_bin[i + 1]
    a += 2**i
    a_x_bin = to_binary_array(a + (a^X))
  else
    next if a_x_bin[i + 1] == s_bin[i + 1]
    puts "-1"
    exit
  end
end

if AS[0] < a
  puts "-1"
  exit
end

40.downto(0) do |i|
  next if fix[i] || a + 2**i > AS[0]
  a += 2**i
end

if a.zero?
  puts -1
  exit
end

puts AS[0] - a


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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
  int a, b, x;
  cin >> a >> b >> x;
  double res = 3;
  if ((a * b) / 2 * a > x) {//半分以下
    double a2 = (double) x * 2 / a / b;
    double tana2 = a2 / b;
    res = 90 - (atan(tana2) * 180.0 / M_PI);
  } 
  else{//半分以上
    double b2 = ((double) x * 2 / a / a) - b;
    double tanb2 = a / (b - b2);
    res = 90 - (atan(tanb2) * 180.0 / M_PI);
  }

  cout << fixed << setprecision(20) << res << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner scan =new Scanner(System.in);
		int N=scan.nextInt();
		int candy=0;

		for(int i=0;i<=N;i++)
		{
			candy+=i;
		}
		System.out.println(candy);

	}
}

Measured memory_bytes: 21844
N,Y = map(int, input().split())
a,b,c = -1,-1,-1
for i in range(N + 1):
    for j in range(N + 1 - i):
        k = N - i - j
        if 10000*i + 5000*j + 1000*k == Y:
            a,b,c = i,j,k

print(a,b,c)

Measured memory_bytes: 3060
n=int(input())
arr=list(map(int,input().split()))
dp=[[0]*n for _ in range(n)]
for i in range(n):
  if n%2==0:
    dp[i][i]=-arr[i]
  else:
    dp[i][i]=arr[i]
for i in range(1,n):
  for j in range(n-i):
    if (n-i)%2==0:
      dp[j][j+i]=min(dp[j][j+i-1]-arr[j+i],dp[j+1][j+i]-arr[j])
    else:
      dp[j][j+i]=max(dp[j][j+i-1]+arr[j+i],dp[j+1][j+i]+arr[j])
print(dp[0][n-1])

Measured memory_bytes: 144812
#include<stdio.h>

int main(){
    int H, W, N, count = 0;
    int loop_bool = 0, loop_count = 0;
    int a[10000];
    int a_dash[10000];
    int c[100][100];
    scanf("%d%d", &H, &W);
    scanf("%d", &N);
    for(int i = 0; i < N; i++){
        scanf("%d", &a[i]);
        for(int j = 0; j < a[i]; j++){
            a_dash[count++] = i + 1;
        }
    }
    for(int i = 0, j = 0; i < count; i++){
        if(loop_bool == 0){
            c[j][loop_count] = a_dash[i];
            loop_count++;
            if(loop_count == W){
                loop_bool = 1;
                loop_count--;
                j++;
            }
        }else{
            c[j][loop_count] = a_dash[i];
            loop_count--;
            if(loop_count < 0){
                loop_bool = 0;
                loop_count++;
                j++;
            }
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            printf("%d ", c[i][j]);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
	static void Main()
	{
		Console.ReadLine();
		var a = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => long.Parse(number));

		var b = new LinkedList<long>();
		for (var i = 0; i < a.Length; ++i) {
			if (i % 2 == 0) {
				b.AddLast(a[i]);
			} else {
				b.AddFirst(a[i]);
			}
		}

		var c = a.Length % 2 == 0 ? b : b.Reverse();

		var builder = new StringBuilder();
		foreach (var n in c) {
			builder.Append($"{n} ");
		}

		Console.WriteLine(builder.ToString().TrimEnd());
	}
}


Measured memory_bytes: 83112
n = int(input())
ls = list(map(int, input().split()))
cnt = 0

for i in range(n-2):
    l = []
    l.append(ls[i])
    l.append(ls[i+1])
    l.append(ls[i+2])
    l.sort()
    if l[1] == ls[i+1]:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
import sys

input = sys.stdin.readline

def main():
    ans = []
    b = "#"
    h, w = map(int, input().split())
    s = [input().rstrip('\n') for _ in range(h)]
    for y in range(h):
        ans.append([])
        for x in range(w):
            if s[y][x] == b:
                ans[y].append(b)
            else:
                ans[y].append(0)
    for y in range(h):
        for x in range(w):
            if s[y][x] == b:
                if y > 0 and x > 0 and ans[y-1][x-1] != b:
                    ans[y-1][x-1] += 1
                if y > 0 and ans[y-1][x] != b:
                    ans[y-1][x] += 1
                if y > 0 and x < w - 1 and ans[y-1][x+1] != b:
                    ans[y-1][x+1] += 1
                if x > 0 and ans[y][x-1] != b:
                    ans[y][x-1] += 1
                if x < w - 1 and ans[y][x+1] != b:
                    ans[y][x+1] += 1
                if y < h - 1 and x > 0 and ans[y+1][x-1] != b:
                    ans[y+1][x-1] += 1
                if y < h - 1 and ans[y+1][x] != b:
                    ans[y+1][x] += 1
                if y < h - 1 and x < w - 1 and ans[y+1][x+1] != b:
                    ans[y+1][x+1] += 1
    for y in range(h):
        for x in range(w):
            if ans[y][x] == 0 and s[y][x] == b:
                ans[y][x] = "#"
            else:
                ans[y][x] = str(ans[y][x])
        print(''.join(ans[y]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9296
#include <cstdio>
#include <cstring>
using namespace std;
int sum;
char ch[200005];
int main(){
	scanf("%s",ch);
	int t=(int)strlen(ch);
	for(int i=0;i<t;++i)sum+=ch[i]-'0';
	if(sum%9)printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1796
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
using namespace std; 



int main(){
    ll p,n,ans=1,copy;
    cin>>p>>n;
    copy=n;
    vector <long long > vc(sqrt(n));
    int count = 0;  
    while (!(n % 2)) { 
        n >>= 1;
        count++; 
    } 
    if (count>=p) 
        ans=pow(2,(count/p));
    for (long long i = 3; i <= sqrt(n); i += 2) { 
        count = 0; 
        while (n % i == 0) { 
            count++; 
            n = n / i; 
        } 
        if (count>=p){
            ans*=pow(i,(count/p));
            // cout<<i<<endl;
        }
    }
    if(p!=1) cout<<ans;
    else cout<<copy;
} 


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

using ll = long long;


int main() {

    int n;
    ll k;
    scanf("%d %lld", &n, &k);
    vector<ll> a(n);

    for (int i = 0; i < n; ++i) {
        scanf("%lld", &a[i]);
    }

    ll cur = 0LL;
    for ( ll d = 41; d >= 0; --d) {
        ll b = (1LL << d);
        if ((cur ^ b) > k) continue;
        int zeros = 0;
        for (ll x : a) {
            if ((x & b) == 0) {
                ++zeros;
            }
        }

        int ones = n - zeros;
        // zeroの方が多いならビットを立てる
        if (zeros > ones) {
            cur ^= b;
        }
    }

    ll res = 0LL;
    for (ll x : a) {
        res += (x ^ cur);
    }

    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] str=br.readLine().split(" ");
		int n=Integer.parseInt(str[0]);
		int m=Integer.parseInt(str[1]);
		int l=Integer.parseInt(str[2]);
		int[][] a=new int [n][m];
		int[][] b=new int [m][l];
		long c;

		for(int i=0;i<n;i++){
    		str=br.readLine().split(" ");
            for(int j=0;j<m;j++){
                a[i][j]=Integer.parseInt(str[j]);
            }
        }//配列a[][]に格納
                 
        for(int i=0;i<m;i++){
            str=br.readLine().split(" ");
            for(int j=0;j<l;j++){
            	b[i][j]=Integer.parseInt(str[j]);
            }
        }//配列b[][]に格納
		
        StringBuilder outArray=new StringBuilder();
		for(int i=0;i<n;i++){
			for(int j=0;j<l;j++){
				c=0;
				for (int k=0;k<m;k++){
					c += a[i][k]*b[k][j];
				}
				outArray.append(c + " ");
			}
			outArray.deleteCharAt(outArray.length()-1);
			outArray.append("\n");
		}
		outArray.deleteCharAt(outArray.length()-1);
		System.out.println(outArray);
	}

}

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

long long pow10(int n){ return n == 0 ? 1 : 10 * pow10(n - 1); }

void solve(int n, int k, int keta){
  long long cnt = keta * (9 * pow10(keta - 1));
  if(k == 0) return;
  if(n > cnt) solve(n - cnt, k, keta + 1);
  else{
    int start = pow10(keta - 1) + (n - 1) / keta;
    int pos   = ((n - 1) % keta);
    int last  = pow10(keta);

    {
      char buff[20]; sprintf(buff, "%d", start);
      for(int i = pos; buff[i] && k; i++){k--; putchar(buff[i]);}
      start++;
    }

    while(k >= keta && start < last){
      printf("%d", start);
      k -= keta;
      start++;
    }

    if(k > 0 && start != last){
      int num = keta - (k - 1);
      printf("%d", (int)(start / pow10(num - 1)));
      k = 0;
    }

    if(k > 0) solve(1, k, keta + 1);
  }
}

int main(){
  int n, k;
  while(scanf("%d%d", &n, &k), n + k){
    solve(n, k, 1);
    puts("");

    //#define DEBUG
#ifdef DEBUG
    stringstream ss;
    for(int i = 0; i < 10000; i++){
      ss << i;
    }
    string s = ss.str();
    printf("debug: (size: %d)\n", s.size());
    for(int i = 0; i < k; i++){
      putchar(s[i + n]);
    }
    puts("");
#endif
  }
  return 0;
}

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

#define ll long long
#define ld long long

int main() {
    int A, B, C, D; cin >> A >> B >> C >> D;
    while (A > 0 && C > 0) {
        C -= B;
        if (C > 0) {
            A -= D;
        }
    }
    if (A <= 0) {
        cout << "No" << endl;;
    }
    else {
        cout << "Yes" << endl;;
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int a[100010],n;char s[100010];
int main(){
	scanf("%s",s);
	n = strlen(s);
	for(int i=1; i<=n; i++)a[i] = (s[i-1] == '1');
	int res = n;
	for(int i=n; i>=1; i--){
		a[i] ^= a[i-1];
		if(a[i])
			res = min(res, max(i-1, n+1-i));
	}
	printf("%d\n",res);
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  int count=0;
  int amax=0;
  bool ans=true;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G'){
        count++;
        amax=max(count,amax);
    }else{
        count=0;
    }
  }
  
    cout << amax << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define pf pop_front
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=3005;
const ll inf=1e9+7;
double dp[maxn][maxn];
double p[maxn];
ll n;
map<ll,ll> m;
ll a[200005];
int main()
{
    while(cin>>n)
    {
        rep(i,n)
        {cin>>a[i];m[a[i]]++;}
        ll sum=0;
        for(auto i:m) sum+=i.S*(i.S-1)/2;
        rep(i,n)
        {
            ll tmp=m[a[i]];
            cout<<sum-tmp*(tmp-1)/2+(tmp-1)*(tmp-2)/2<<"\n";
        }

    }
}


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

int main(){
  int b,e;
  string s;
  cin >> s;
  r(i,s.length()){
    if(s.at(i)=='A'){
      b=i;
      break;
    }
  }
  for(int i = s.length()-1; i>=0; i--){
    if(s.at(i)=='Z'){
      e=i;
      break;
    }
  }
  cout << e-b+1<<endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

void solve() {
  int N, Z, W; cin >> N >> Z >> W;
  vi64 a(N); cin >> a;
  
  vi64 dp0(N), dp1(N);
  rrep(i, N) {
    dp0[i] = -1e9;
    i64 Y = (i ? a[i - 1] : W);
    amax(dp0[i], abs(Y - a[N - 1]));
    repi(j, i + 1, N) amax(dp0[i], dp1[j]);

    dp1[i] = 1e9;
    i64 X = (i ? a[i - 1] : Z);
    amin(dp1[i], abs(X - a[N - 1]));
    repi(j, i + 1, N) amin(dp1[i], dp0[j]);
  }
  cout << dp0[0] << '\n';
}


Measured memory_bytes: 256
import heapq
K = int(input())
visited=[0]*100001
visited[1]=1
queue=[(1,1)]

while queue and queue[0][1] != 0:
    cost, value = heapq.heappop(queue)
    cand1 = value*10 % K
    cand2 = (value+1) % K
    if not visited[cand1]:
        visited[cand1] = 1
        heapq.heappush(queue,(cost, cand1))
    if not visited[cand2]:
        visited[cand1] = 1
        heapq.heappush(queue,(cost+1, cand2))

print(queue[0][0])


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

int main() {
 int n;
 cin >> n;
 if(n%2==0) cout << "0.5" << endl;
 else{int k=n+1,p=2*n;
 double ans=(double)k/(double)p;
 cout << fixed << setprecision(20);
 cout << ans << endl;}
}


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

bool is_prime(unsigned long v)
{
  if (v == 2) {
    return true;
  }
  if (v <= 1 || v % 2 == 0)
  {
    return false;
  }

  unsigned long divisor = 3;
  while (divisor * divisor <= v)
  {
    if (v % divisor == 0)
    {
      return false;
    }
    divisor += 2;
  }
  return true;
}

int main()
{
  int n {};
  int count {0};
  std::cin >> n;
  for (int i = 0; i < n; ++i)
  {
    int number {};
    std::cin >> number;
    if (is_prime(number))
    {
      ++count;
    }
  }
  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 1164
<>;@D=(1)x2e6;$D[0]=.5;($%^=$_)?$P[$%]+=$D[$%]+=$P[$%]*(-${*y=-$%}+($y=$0))%$=:($D[!++$0]*=2)%=$==1e9+7for split$",<>;$D[0]+=$_ for@P;print$D[$%]%$=

Measured memory_bytes: 270208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){    
  ll N,K;
  cin >> N >> K;
  ll a = 0;
  while(N >= K){
    N /= K;
    a++;
  }
  cout << a + 1 << endl;
}


Measured memory_bytes: 256
n = int(input())
ans = ""

#あまりが0になった時にaになるようにする。そうしないと最後の方で狂う。
for i in range(1,15):
    if n <= 26 ** i:
        n -= 1
        for j in range(i):
            ans += (chr(n % 26 + 97))
            n //= 26
        break
    n -= 26 ** i

print(ans[::-1])


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;


void solve(){
	ll a,b,c;
	cin>>a>>b>>c;
	if(a&1^1 || b&1^1 || c&1^1)
		cout<<0;
	else 
		cout<<min({a*b,b*c,c*a});
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
//	ll t;cin>>t;while(t--)
	solve();

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL); \
    cout.tie(NULL)
#define inc(x, y, i) for (int i = x; i <= y; i++)
#define dec(x, y, i) for (int i = x; i >= y; i--)
#define repeat(n) for (int i = 0; i<n;i++)

#define ll long long
#define ld long double
#define ull unsigned long long
#define infl LONG_MAX
#define infi INT_MAX
#define nl cout<<'\n'

#define all(v) v.begin(),v.end()
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define mkpr make_pair
#define pq priority_queue
/*void show(auto v){
    for(auto t : v)cout << t <<" ";cout <<endl;
}

void printAr(int a[],int n)  // print the array
{
    for(int *i = a; i!=a+n; ++i)cout << *i << " ";
    cout << endl;
}*/
const int N = 2000+6;
const int mod = pow(10,9)+7;
int a[N][N];

int main()
{
    fastio;
    int n;
    cin >> n;
    repeat(N){a[0][i] = 1;}
    inc(1,n+1,i){
        inc(1,n+1,j){
            a[i][j] = (a[i-1][j-1]+a[i][j-1])%mod;
        }
    }
    ll ans = 0LL;
    for(int k = 1; 3*k<=n;k++){
        ans = (ans + a[k-1][n-2*k-1])%mod;
    }
    cout << ans <<endl;



}


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

bool is_no_need(int ex, std::vector<int>& a, int K){
  int n = (int)a.size();
  std::vector<std::vector<int>> no_good(n + 1, std::vector<int>(K, 0));
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < K; j++){
      if(i == ex){
        no_good[i + 1][j] = no_good[i][j];
        continue;
      }
      
      if(j + a[i] < K) no_good[i + 1][j + a[i]] = std::max(no_good[i][j] + a[i], no_good[i + 1][j + a[i]]);
      no_good[i + 1][j] = std::max(no_good[i][j], no_good[i + 1][j]);
    }
  }
  
  return no_good[n][K - 1] + a[ex] < K;
}

int count_no_need(std::vector<int>& a, int K){
  int n = (int)a.size();
  
  int need = n;
  int no_need = -1;
  while(need - no_need > 1){
    int mid = (need + no_need) / 2;
    (is_no_need(mid, a, K) ? no_need : need) = mid;
  }
  
  return no_need + 1;
}

int main(){
  int N, K;
  std::cin >> N >> K;
  
  std::vector<int> a(N);
  for(int i = 0; i < N; i++) std::cin >> a[i];
  std::sort(a.begin(), a.end());
  
  std::cout << count_no_need(a, K) << std::endl;
  
  return 0;
}

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

if a <= b <= c:
    print(a,b,c)
elif a <= c < b:
    print(a,c,b)
elif b < a <= c:
    print(b,a,c)
elif b <= c < a:
    print(b,c,a)
elif c < a <= b:
    print(c,a,b)
elif c < b < a:
    print(c,b,a)



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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

  int n;
  cin >> n;

  REP(i, 9) {
    if (n <= i * 111) {
      cout << i * 111 << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

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

int GCD(int x,int y){
  if(x<y){
    swap(x,y);
  }
  while(x%y!=0){
    int temp=x;
    x=y;
    y=temp%y;
  }
  return y;
}

int digitsum(int x){
  int sum=0;
  while(x>0){
    sum+=(x%10);
    x/=10;
  }
  return sum;
}

int main() {
  int n;
  cin>>n;
  int ans=0;
  for(int i=1;i<=n-1;i++){
    ans+=(n-1)/i;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3624
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int D[31][31];
const ll INF=1e12;

int main(){
  int n,c;
  cin>>n>>c;
  
  map<int,int> m1,m2,m0;
  for(int i=1;i<=c;i++){
    for(int j=1;j<=c;j++) cin>>D[i][j];
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      int x;
      cin>>x;
      if((i+j)%3==1) m1[x]++;
      else if((i+j)%3==2) m2[x]++;
      else m0[x]++;
    }
  }
  
  ll ans=INF;
  for(int i=1;i<=c;i++){
    for(int j=1;j<=c;j++){
      if(j==i) continue;
      for(int k=1;k<=c;k++){
        if(k==i || k==j) continue;
        ll sum=0;
        for(auto x:m1) sum+=D[x.first][i]*x.second;
        if(sum>ans) continue;
        for(auto x:m2) sum+=D[x.first][j]*x.second;
        if(sum>ans) continue;
        for(auto x:m0) sum+=D[x.first][k]*x.second;
        ans=min(ans,sum);
      }
    }
  }
  cout<<ans<<endl;
    
  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool c1(const int &a,const int &b){return a<b;}
int n,a[100010],su;
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){cin>>a[i];su+=abs(a[i]);}
	sort(a+1,a+n+1,c1);
	if (a[1]>0){
		cout<<su-a[1]-a[1]<<endl;
		for (int i=2;i<n;i++){cout<<a[1]<<' '<<a[i]<<endl;a[1]-=a[i];}
		cout<<a[n]<<' '<<a[1]<<endl;
	}else{
		if (a[n]<0){
			cout<<su+a[n]+a[n]<<endl;
			for (int i=1;i<n;i++){cout<<a[n]<<' '<<a[i]<<endl;a[n]-=a[i];}
		}else{
			cout<<su<<endl;
			int l=1,r=n;
			while (l+1<r){
				if (a[l+1]<0){cout<<a[r]<<' '<<a[l]<<endl;a[r]-=a[l];l++;}else{cout<<a[l]<<' '<<a[r]<<endl;a[l]-=a[r];r--;}
			}
			cout<<a[l+1]<<' '<<a[l]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2304
MOD = 998244353
class mint:
    def __init__(self, i):
        self.i = i
    def __add__(self, m):
        t = self.i + (m.i if isinstance(m, mint) else m)
        if t > MOD:
            t -= MOD
        return mint(t)
    def __radd__(self, m):
        t = self.i + (m.i if isinstance(m, mint) else m)
        if t > MOD:
            t -= MOD
        return mint(t)
    def __mul__(self, m):
        return mint(self.i * (m.i if isinstance(m, mint) else m) % MOD)
    def __sub__(self, m):
        t = self.i - (m.i if isinstance(m, mint) else (m % MOD))
        if t < 0:
            t += MOD
        return mint(t)
    def __pow__(self, m):
        i = self.i
        return mint(pow(i, m, MOD))
    def __truediv__(self, m):
        return mint(self.i * pow(m, MOD - 2, MOD) % MOD)
    def __repr__(self):
        return repr(self.i)


n, s = map(int, input().split())
dp = [mint(0)] * (s + 1)
dp[0] = mint(2) ** n
i2 = mint(2) ** (MOD-2)
for a in map(int, input().split()):
    for i in range(s, -1, -1):
        if a + i <= s:
            dp[a + i] += dp[i] * i2
print(dp[s])


Measured memory_bytes: 78160
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [D, N] = input[0].map(Number);

  return 100 ** D * (N === 100 ? N + 1 : N);
};

console.log(main(read()));


Measured memory_bytes: 29608
def is_prime(n):
    for i in range(2, int(n**(1/2))+1, 1):
        if n%i == 0:
            return False
    return n != 1

def lnum(n):  # Like number
    if is_prime(n) and is_prime((n+1)//2):
        return True
    else:
        return False

MAX = 101010
a = [0]*MAX
for i in range(MAX):
    if lnum(i):
        a[i] = 1
    else:
        continue

s = [0]*MAX
for i in range(MAX-1):
    s[i+1] = s[i] + a[i]
    
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(s[r+1]-s[l])

Measured memory_bytes: 8916
#include <iostream>
#include <queue>
using namespace std;
const int INF = 1e9+1;
int cnt = 0;
queue<int> merge(queue<int> a,queue<int> b){
    queue<int> ans;
    a.push(INF); b.push(INF);
    while(a.front() != INF || b.front() != INF){
        if(a.front() <= b.front()){
            ans.push(a.front());
            a.pop(); cnt++;
        }
        else if(b.front() < a.front()){
            ans.push(b.front());
            b.pop(); cnt++;
        }
    }
    return ans;
}
queue<int> mergeSort(queue<int> q){
    if(q.size() == 1) return q;
    queue<int> left,right,a,b;
    int size = q.size();
    for(int i =0; i < size; ++i){
        if(i < size/2){
            left.push(q.front());
            q.pop();
        }
        else{
            right.push(q.front());
            q.pop();
        }
    }
    a = mergeSort(left);
    b = mergeSort(right);
    return merge(a,b);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    queue<int> a; 
    for(int i = 0; i < n; ++i){
        int x; cin >> x;
        a.push(x);
    }
    queue<int> ans = mergeSort(a);
    int i = 0;
    while(!ans.empty()){
        if(i) cout << " ";
        cout << ans.front(); ans.pop();
        i++;
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}


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

int n,k;
vector<ll> h(200000);

int main(){
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> h.at(i);
  }
  sort(h.begin(),h.begin()+n,greater<int>());
  for(int i=0;i<k;i++){
    h.at(i)=0;
  }
  ll ans=0;
  if(n>k){
    for(int i=0;i<n;i++){
      ans+=h.at(i);
    }
  }
  cout << ans << endl;
}

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

int main(){
    ll x,y;
    cin>>x>>y;
    ll z = y/x;
    int ans = 0;
    while(z>=1){
        z/=2;
        ans++;
    }
    cout << ans << endl;
    
    
    return 0;
}



Measured memory_bytes: 256
//ABC156A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n, r;
	cin >> n >> r;
	int ans;
	if(n >= 10){
		ans = r;
	}else{
		ans = r + 100*(10-n);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
 using namespace std ;
 int main()
{
 int A,B,C;
 cin>>A;
 cin>>B;
 cin>>C;
 if ((A+B)>=C)
 {
 cout << "Yes"<< endl;
 }
 else {
 cout <<"No" << endl;
 }
 
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N,M;
    cin >> N >> M;
    ll a,b;
    ll i,j;
    vector <ll> to,from;
    for(i=0;i<M;i++){
        cin >> a >> b;
        if(a==1)to.push_back(b);
        if(b==N)from.push_back(a);
    }
    if(!to.empty()&&!from.empty()){
        sort(to.begin(),to.end());
        sort(from.begin(),from.end());
        auto itr2=from.begin();
        for(auto itr1=to.begin();itr1!=to.end();++itr1){
            while(*itr2<=*itr1&&itr2!=from.end()){
                if(*itr2==*itr1){cout << "POSSIBLE" <<endl;return 0;}
                ++itr2;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 2004
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	string s;cin>>s;
	int n=s.size(),a=0,b=0;
	rep(i,n){
		if(s[i]=='0') a++;else b++;
	}
	cout<<min(a,b)*2<<endl;
}


Measured memory_bytes: 512
#define L(a,b)((a)<(b)?(a):(b))
N,C[498][201],D[1000][201],i,j,k;W(int c[][201]){for(k=N;k;c[k][k]=0,k--)for(i=N;i;i--)for(j=N;j;j--)c[i][j]=L(c[i][j],c[i][k]+c[k][j]);}x,y,t,s;main(M){for(;scanf("%d%d",&N,&M)*N;printf("%d\n",s)){for(memset(C,1,4e5);M--;C[s+x][y]=C[s+y][x]=L(C[s+x][y],t))scanf("%d%d%d%s",&x,&y,&t,&s),s=s%2*N;W(C);W(C+N);memset(D,1,1e3);scanf("%d%d",&M,&x);D[0][x]=0;for(i=1;i<M;i++,x=y)for(scanf("%d",&y),s=1e9,j=N;j;s=L(s,t),D[i][j--]=t)for(t=D[i-1][j]+C[x][y],k=N;k;k--)t=L(t,D[i-1][k]+C[x][k]+C[N+k][j]+C[j][y]);}}

Measured memory_bytes: 1596