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

#define FOR(i,m,n) for(ll i=(m);i<(n);++i)
typedef vector<int> vi;
inline int in() { int x; cin >> x; return x; }
int MOD = 1000000007;

void solve() {
	int n = in(), m = 0;
	vi v(n); for (auto &i : v) i = in();
	FOR(i,0,60) {
		int odd = 0, even = 0;
		for (auto j : v) (((j>>i)&1) ? odd : even)++;
		int k = (int)1 << i;
		k %= MOD;
		k *= (odd*even) % MOD;
		m += k;
		m %= MOD;
	}
	cout << m << endl;
}

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


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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,M;
  cin >> N >> M;
  vector<vector<pair<int,ll>>> graph(N);
  REP(i,1,N)  graph.at(i).p_b(m_p(i-1,0));
  rep(i,M){
    int l,r,c;
    cin >> l >> r >> c;
    l--;
    r--;
    graph.at(l).p_b(m_p(r,c));
  }

  vector<ll> dist(N,1e18);
  priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
  dist.at(0)=0;
  pq.push(m_p(0,0));
  while(!pq.empty()){
    ll c=pq.top().fi;
    int v=pq.top().se;
    pq.pop();
    rep(i,sz(graph.at(v))){
      int nv=graph.at(v).at(i).fi;
      ll nc=c + graph.at(v).at(i).se;
      if(dist.at(nv) <= nc) continue;
      dist.at(nv)=nc;
      pq.push(m_p(nc,nv));
    }
  }
  ll ans=dist.at(N-1);
  if(ans==1e18)  ans=-1;
  cout << ans << endl;

  return 0;
}

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

int main()
{
    int n, m, num, even_num;
    even_num = 0;
    cin >> n >> m;
    num = n + m;
    int *p = new int[num];

    for (int i = 0; i < n; i++)
    {
        p[i] = 2;
    }
    for (int i = n; i < num; i++)
    {
        p[i] = 1;
    }

    for (int i = 0; i < num; i++)
    {
        for (int j = i + 1; j < num; j++)
        {
            if ((p[i] + p[j]) % 2 == 0)
                even_num++;
        }
    }

    cout << even_num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<ll> A(N+1);
    vector<ll> B(N);
    ll a;
    for(size_t i=0;i<N+1; i++)
    {
        cin >> A[i];
    }
    for(size_t i=0;i<N; i++)
    {
        cin >> B[i];
    }
    ll count = 0;
    for(size_t i=0;i<N; i++)
    {
        count += min(A[i], B[i]);
        if(A[i] < B[i])
        {
            count+=min(A[i+1], B[i] - A[i]);
            A[i+1] -= min(A[i+1], B[i] - A[i]);
        }
    }
    cout << count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> dp(n,-1);
  dp[0] = 0;
  dp[1] = abs(a[0] - a[1]);

  for (int i = 2; i < n; i++) {
    dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
  }

  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

int main(){
  string s;
  cin >> s;
  int n=s.size();
  vector<bool> a(4,false);
  rep(i,n){
    if(s[i]=='N')a[0]=true;
    if(s[i]=='S')a[1]=true;
    if(s[i]=='E')a[2]=true;
    if(s[i]=='W')a[3]=true;
    if(a[0]&&a[1]&&a[2]&&a[3])break;
  }
  if((a[0]&&a[1])||(!a[0]&&!a[1]))
    if((a[2]&&a[3])||(!a[2]&&!a[3])){
      cout << "Yes" << endl;return 0;
    }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int sum = 0;
        for (int i = 1; i <= n; i++) {
          sum += i;
        }
      
       
            System.out.println(sum);
        
            
        
    }

}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <queue>
#define INF 1000000
using namespace std;

class vertex{
public:
  class edge{
  public:
    int to;
    int weight;
    edge(int to, int weight){
      this->to = to;
      this->weight = weight;
    }
  };

  vector<edge> edges;
  int num;
  int dis;

  vertex(){
    n++;
    vertexes.push_back(this);
  }

  bool operator< (const vertex& v) const{
    return dis < v.dis;
  }

  bool operator> (const vertex& v) const{
    return dis > v.dis;
  }

  static void dijkstra(int start){
    //距離の初期化
    for(int i=0; i<n; i++) vertexes[i]->dis=INF;
    vertexes[start]->dis=0;

    //プライオリティキューを初期化、始点を格納
    priority_queue<vertex, vector<vertex>, greater<vertex> > pq; pq.push(*vertexes[start]);


    while(!pq.empty()){
      vertex now = pq.top(); pq.pop(); //キューの先頭をポップ
      if(now.dis>vertexes[now.num]->dis) continue;

      //ポップしたキューの頂点集合について最短距離更新
      for(int i=0; i<now.edges.size(); i++){
        int newDis = now.dis+now.edges[i].weight;
        vertex* next = vertexes[now.edges[i].to];
        if(newDis < next->dis){
          next->dis = newDis;
          pq.push(*next);
        }
      }

    }


  }

  static void print(){
    for(int i=0; i<n; i++){
      cout << vertexes[i]->num << " " << vertexes[i]->dis << endl;
    }
  }
private:
  static int n;
  static vector<vertex*> vertexes;
};

int vertex::n=0;
vector<vertex*> vertex::vertexes;

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

  vertex graph[n];

  //入力を隣接リストのようなものに格納
  int v, k, to, weight;
  for(int i=0; i<n; i++){
    cin >> v >> k;
    graph[i].num=v;
    for(int j=0; j<k; j++){
      cin >> to >> weight;
      vertex::edge e(to, weight);
      graph[v].edges.push_back(e);
    }
  }

  vertex::dijkstra(0); //0始点のダイクストラ法

  vertex::print();

  return 0;
}



Measured memory_bytes: 40732
n, k = map(int, input().split())
xn = list(map(int, input().split()))
if 0 in xn:
  k -= 1
xm = [-1 * x for x in xn[::-1] if x < 0]
xp = [x for x in xn if x > 0]

if k == 0:
  print(0)
  exit()
elif len(xm) == 0:
  print(xp[k-1])
  exit()
elif len(xp) == 0:
  print(xm[k-1])
  exit()
  
if k > len(xm):
  nm = len(xm)
  np = k-len(xm)
  sm = xm[-1]
  sp = xp[np-1]
else:
  nm = k
  np = 0
  sm = xm[nm - 1]
  sp = 0
s_min = min(sm, sp) * 2 + max(sm, sp)

for i in range(min(k, len(xp), len(xm), n-k)):
  sm = xm[nm - i - 2]
  sp = xp[np + i]
  s_min = min(s_min, min(sm, sp) * 2 + max(sm, sp))
               
print(s_min)


Measured memory_bytes: 14480
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());

        var map = new Dictionary<string, int>();
        var ans = 0L;

        for (int i = 0; i < n; i++)
        {
            var s = sort(Console.ReadLine());

            if (map.ContainsKey(s)) map[s]++;
            else map[s] = 0;

            ans += map[s];
        }

        Console.WriteLine(ans);
    }

    static string sort(string s)
    {
        var array = s.ToCharArray();
        Array.Sort(array);
        return new string(array);
    }
}


Measured memory_bytes: 30168
#include<stdio.h>
#include<math.h>

int main(void)
{
	double x1,y1,x2,y2;
	double a,b,c;
	scanf( "%lf %lf %lf %lf", &x1,&y1,&x2,&y2 );
	
	b = fabs( x1-x2 );
	c = fabs( y1-y2 );
	
	a = sqrt( pow( b, 2 ) + pow( c, 2 ) );
	printf( "%f\n", a );
	
	return 0;
}



Measured memory_bytes: 2088
n, d = map(int, input().split())
X = []
for i in range(n):
    a = list(map(int, input().split()))
    X.append(a)

count = 0
for i in range(n):
    for j in range(i + 1, n):
        norm = 0
        for k in range(d):
            diff = abs(X[i][k] - X[j][k])
            norm += diff * diff
        can = False
        for k in range(1, norm + 1):
            if(k * k == norm):
                can = True
        if(can):
            count += 1

print(count)


Measured memory_bytes: 9204
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}

const int INF = 1000000000+7;

int main(){
    string s, t;
    int a, b;
    string u;
    cin >> s >> t >> a >> b >> u;

    int ans1 = a, ans2 = b;
    if(u == s){
        ans1--;
    }else {
        ans2--;
    }

    cout << ans1 << " " <<  ans2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n,d;
    cin >> n >> d;
    cout << (n + d * 2) / (d * 2 + 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int n;
    cin >> n;
    vector<pii> va, vb;
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        va.push_back({x, i});
    }
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        vb.push_back({x, i});
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    vector<pii> v[n];
    for(int i = 0; i < n; i++){
        int aind = va[i].second, bind = vb[i].second;
        if(i > 0){
            v[aind].push_back({va[i-1].second, va[i].first-va[i-1].first});
            v[bind].push_back({vb[i-1].second, vb[i].first-vb[i-1].first});
        }
        if(i+1 < n){
            v[aind].push_back({va[i+1].second, va[i+1].first-va[i].first});
            v[bind].push_back({vb[i+1].second, vb[i+1].first-vb[i].first});
        }
    }
    vector<ll> dp(n, 1ll<<60);
    priority_queue<pair<ll,int>> pq;
    pq.push({-0, 0});
    dp[0] = 0;
    while(!pq.empty()){
        auto p = pq.top();  pq.pop();
        ll cost = -p.first;
        int ind = p.second;
        if(dp[ind] != cost) continue;
        for(pii P : v[ind]){
            if(dp[P.first] > dp[ind] + P.second){
                dp[P.first] = dp[ind] + P.second;
                pq.push({-dp[P.first], P.first});
            }
        } 
    }
    for(int i = 0; i < n; i++)  cout << dp[i] << endl;
    return 0;
}


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

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

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

    vector<int> a(N + 1);
    vector<int> b(N + 1, -1);
    int M = 0;

    rep(i, N) {
        cin >> a[i + 1];
    }

    for(int i = N; i >= 1; i--) {
        IFD cout << "i: " << i << endl;
        int c = 0;
        for(int j = N / i; j >= 1; j--) {
            int v = j * i;
            IFD cout << v << endl;
            if(i == v) {
                b[v] = a[v] ^ c;
                //b[v] = (a[v] + c) % 2;
                if(b[v] == 1) {
                    M++;
                }
            } else {
                c ^= b[v];
                //c = (c + b[v]) % 2;
            }
        }
    }
    IFD cout << endl;

    IFD {
        rep(i, N) {
            cout << b[i + 1] << " ";
        }
        cout << endl << endl;
    }

    cout << M << endl;
    if(M != 0) {
        rep(i, N) {
            if(b[i + 1] == 1) {
                cout << i + 1 << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i < int(n); ++i)
#define repx(i, x, n) for (int i = int(x); i < int(n); ++i)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) ((a) <= (x) && (x) < (b))
#define OUT(a, x, b) ((x) < (a) || (x) < (b))
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const ll MOD = 1000000007;

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


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
char s[60];
long long dp[60];
int a[60];
const int MD=1000000007;
int main()
{
    int n;
    scanf("%d",&n);
    int t=0;
    scanf("%s",s+1);
    for(int i=1; i<=n; i++)
        if(s[i]==s[i-1])
            a[t]++;
        else
            a[++t]++;
    if(a[1]==1)dp[1]=3;
    else dp[1]=6;
    for(int i=2; i<=t; i++)
    {
        if(a[i-1]==2)
        {
            if(a[i]==2)
                dp[i]=dp[i-1]*3%MD;
            else if(a[i]==1)
                dp[i]=dp[i-1];
        }
        else if(a[i-1]==1)
        {
            if(a[i]==2||a[i]==1)
            dp[i]=dp[i-1]*2%MD;
        }
    }
    scanf("%s",s+1);
    cout<<dp[t];
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		long n = Long.parseLong(line);
		long ans = 0;
		
		for (long k = Math.min(n, 10000); k >= 1; k--) {
			long i = n/k - 1;
			if (i > 0 && n / i == n % i) {
				ans+=i;
				//System.out.println("i=" + i);   //////////
			}
		}
		for (long i = 1; i < n/10000 - 1; i++) {
			if (n / i == n % i) {
				ans+=i;
				//System.out.println("i=" + i);   //////////
			}
		}
		System.out.println(ans);
	}
}


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

#define DEBIT 100000

int main(){
	int debit = DEBIT, y;
	cin >> y;
	for(int i = 0; i < y; i++){
		debit *= 1.05;
		if(debit % 1000 > 0){
			debit = (debit / 1000 + 1) * 1000;
		}
	}
	cout << debit << endl;
	return 0;
}


Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner= new Scanner(System.in);
		int a, b ,n;
		
		n = scanner.nextInt();
		a = scanner.nextInt();
		b = scanner.nextInt();
		
		int taxi = b;
		int train = n * a;
		int answer;
		
		if(taxi < train) {
			answer = taxi;
		}else {
			answer = train;
		}
		
		System.out.println(answer);
		
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
char s[12345];
int main ()
{
    cin>>s;
    int len = strlen(s);
    long long ans = 0;
    for (int i =0 ; i<(1<<(len-1));i++){
        long long num = s[0]-'0';
    
    for (int j = 0; j < len-1; ++j)
    {
        if (i&(1<<j))
        {
            ans+=num;
            num=0;
        }
        num=num*10+s[j+1]-'0';
    }
    ans+=num;
}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    char s[15],t[15],u[15];
    int a,b,l1,l2,l3;
    scanf("%s%s",s,t);
    scanf("%d%d",&a,&b);
    getchar();
    scanf("%s",u);
    if(!strcmp(s,u)){a--;}
    else if(!strcmp(t,u)){b--;}
    printf("%d %d\n",a,b);
}


Measured memory_bytes: 256
from collections import defaultdict

def solve():
    dic = defaultdict(int)
    n = int(input())
    ans = 0
    for _ in range(n):
        a = int(input())
        dic[a] = (dic[a] + 1) % 2
    print(sum(dic.values()))

if __name__ == '__main__':
    solve()

Measured memory_bytes: 15460
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	string s,t;
	cin >> s >> t;
	string mins="", maxt="";
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(),greater<int>());
	rep(i, s.size()) {
		mins += s[i];
	}
	rep(i, t.size()) {
		maxt += t[i];
	}
	if (mins < maxt) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc043/tasks/arc059_b
//a_a,aa を探索?
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    string s; cin>>s;
    FOR(i,0,s.size()-1){
        if(s.at(i)==s.at(i+1)){
            cout<<i+1<<" "<<i+2<<endl;
            return 0;
        }
    }
    FOR(i,0,s.size()-2){
        if(s.at(i)==s.at(i+2)){
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
    }
    cout<<-1<<" "<<-1;
    return 0;
}

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

int main()
{
    int sx,sy,tx,ty;
    int j;
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    for(j=1;j<=ty-sy;j++)
    {
        printf("U");
    }
    for(j=1;j<=tx-sx;j++)
    {
        printf("R");
    }
    for(j=1;j<=ty-sy;j++)
    {
        printf("D");
    }
    for(j=1;j<=tx-sx;j++)
    {
        printf("L");
    }
    printf("L");
    for(j=0;j<=ty-sy;j++)
    {
        printf("U");
    }
    printf("R");
    for(j=1;j<=tx-sx;j++)
    {
        printf("R");
    }
    printf("D");
    printf("R");
    for(j=0;j<=ty-sy;j++)
    {
        printf("D");
    }printf("L");
    for(j=1;j<=tx-sx;j++)
    {
        printf("L");
    }
    printf("U\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int n; cin >> n;
    vector<int> P(n),Q(n),perm(n);
    REP(i,n){
        int p; cin>>p;
        P[i] = p;
        perm[i] = i+1;
    }
    REP(i,n){
        int q; cin >>q;
        Q[i]=q;
    }

    int turnp, turnq;
    int itr =0;
    do{
        if(P == perm) turnp = itr;
        if(Q==perm) turnq =itr;
        itr++;
    }while(next_permutation(ALL(perm)));

    cout <<abs(turnp-turnq) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		System.out.println(a < b && b < c ? "Yes" : "No");
	}
}



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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)

#define lli long long
#define li long
#define vi vector<int>
#define vli vector<li>
#define vlli vector<lli>
#define pi pair<int,int>
#define pli pair<li, li>
#define vpi vector<pi>

using namespace std;

int main() {

    int n;

    cin >> n;

    printf("%d\n", (n-2) * 180);

}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

s = input()
t = input()
ls = len(s)

ss = s+s

#table[ord(t)-97][i] = 文字tがi番目orそれ以降で登場する最初のindex
table = [[-1]*(ls*2) for _ in range(26)]
prev = [-1]*26
for i,c in enumerate(ss):
    cind = ord(c)-97
    table[cind][prev[cind]+1:i+1] = [i]*(i-prev[cind])
    prev[cind] = i

#print(table)

ans = 0
now = 0
for i in t:
    pos = table[ord(i)-97][now]
    if pos == -1:
        print(-1)
        exit()
    diff = pos +1 - now 
    ans += diff
    now = (now+diff)%ls


print(ans)    



Measured memory_bytes: 103772
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;

long P = 10^^9+7;
long[10^^5*5+50] F, RF;

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

long inv(long x)
{
    return pow(x, P-2);
}

void init()
{
    F[0] = F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}

long comb(N)(N n, N k)
{
    if (k > n) return 0;
    auto n_b = F[n];    // n!
    auto nk_b = RF[n-k]; // 1 / (n-k)!
    auto k_b = RF[k];    // 1 / k!

    auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!

    return (n_b * nk_b_k_b) % P;  // n! / (n-k)!k!
}

long perm(N)(N n, N k)
{
    if (k > n) return 0;
    auto n_b = F[n];
    auto n_k_b = RF[n-k];
    return (n_b * n_k_b) % P;
}

void main()
{
    init();
    auto nm = readln.split.to!(long[]);
    auto N = nm[0];
    auto M = nm[1];

    long r;
    foreach (s; 0..N+1) {
        auto d = comb(N, s) * perm(M, s) % P * pow(perm(M-s, N-s), 2) % P * (-1)^^s;
        (r += d + P) %= P;
    }
    writeln(r);
}

Measured memory_bytes: 10524
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 1000000007, INF = 1111111111;
const double EPS = 1e-9;


int main() {

	cin.tie(0);

	string A, B, C;
	cin >> A >> B >> C;

	cout << (((A[A.length() - 1] == B[0]) && (B[B.length() - 1] == C[0])) ? "YES" : "NO");

	return 0;
}

Measured memory_bytes: 256
def min_cost(n, heights):
    inf = 1e9
    if n == 1:
        return 0
    dp = [inf] * n
    dp[0] = 0
    dp[1] = abs(heights[1] - heights[0])
    for i in range(2, n):
        dp[i] = min(dp[i - 1] + abs(heights[i] - heights[i - 1]),
                    dp[i - 2] + abs(heights[i] - heights[i - 2]))
    return dp[-1]


if __name__ == '__main__':
    n = int(input())
    heights = [int(_) for _ in input().split()]
    print(min_cost(n, heights))


Measured memory_bytes: 13928
def get(s,t):
    return s // (10 ** (t - 1)) % 10


A,B = map(int,input().split())

count = 0

for i in range(A,B+1):
    one = get(i,1)
    two = get(i,2)
    four = get(i,4)
    five = get(i,5)

    if one == five and two == four:
        count += 1

print(count)

Measured memory_bytes: 9192
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s1 = SS()
    s2 = SS()

    l1 = len(s1)
    l2 = len(s2)
    dp = [[0] * (l2 + 1) for _ in range(l1 + 1)]

    for i in range(l1+1):
        dp[i][0] = i
    for i in range(l2+1):
        dp[0][i] = i

    for i in range(l1):
        for j in range(l2):
            r_cost = 0 if s1[i] == s2[j] else 1
            dp[i+1][j+1] = min(dp[i][j] + r_cost, dp[i+1][j] + 1, dp[i][j+1] + 1)

    print(dp[-1][-1])

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 43092
import           Control.Applicative
import           Text.Printf

main :: IO ()
main = do
    [a,b] <- map read . words <$> getLine :: IO [Int]
    let d = a `div` b
        r = a `rem` b
        f = fromIntegral a / fromIntegral b :: Double
    printf "%d %d %.5f\n" d r f


Measured memory_bytes: 3968
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(std::io::BufReader::new(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)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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,
        v: [usize; n]
    }
    let mut w = v;
    w.sort();
    let mut c = 0;
    for i in 1..n {
        if w[i] == w[i-1] {
            c += 1;
        }
    }
    c += c % 2;
    println!("{}", n - c);
}


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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N - 1);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
    rep(i, 0, N - 1) cin >> C[i];
    int ans = accumulate(B.begin(), B.end(), 0);
    rep(i, 0, N - 1) if(A[i] + 1 == A[i + 1]) ans += C[A[i] - 1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = 1
ul = pow(10, 18)
if 0 in a:
  print(0)
  exit(0)
for x in a:
  ans *= x
  if ans > ul:
    print(-1)
    exit(0)
print(ans)
  

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

typedef long long ll;

vector<int> adj[100010];

bool vis[100010];
int dis[100010];
int par[100010];

void bfs(int s) {
    vis[s] = true;
    dis[s] = 0;

    queue<int> q;
    q.push(s);

    while(!q.empty()) {
        int u = q.front();
        q.pop();

        for(auto v : adj[u]) {
            if(vis[v]) continue;

            vis[v] = true;
            dis[v] = dis[u] + 1;
            par[v] = u;

            q.push(v);
        }
    }
}

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

    int n, m;
    cin >> n >> m;

    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;

        u--, v--;

        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    bfs(0);
    cout << "Yes" << endl;

    for(int i = 1; i < n; i++) {
        cout << par[i] + 1 << endl;
    }
}


Measured memory_bytes: 11032
from enum import Enum
import sys
import math

# 0:中央 1:南 2:東 3:西 4:北 5:裏側


class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5

    def roll(self, loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3], self.work[1], self.work[0],
                           self.work[5], self.work[4], self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1], self.work[5], self.work[2],
                           self.work[3], self.work[0], self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4], self.work[0], self.work[2],
                           self.work[3], self.work[5], self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2], self.work[1], self.work[5],
                           self.work[0], self.work[4], self.work[3])

    def query(self, another_dice):

        self.save_data = [i for i in range(6)]
        # 元の値の保存
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        is_same_face = False
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if [f == s for f, s in zip(self.number, another_dice)].count(False) == 0:
                is_same_face = True
                break

        # 元の値の復元
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]
        return is_same_face


dice = Dice()
first_dice = list(map(int, input().split()))
dice.setNumber(first_dice[0], first_dice[1], first_dice[2], first_dice[3], first_dice[4], first_dice[5])

second_dice = list(map(int,input().split()))
if dice.query(second_dice) == True:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
bool is_prime(int a)
{
	for(int i=2;i*i<=a;i++)
		if(a%i==0)
			return false;
	return true;
}
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
//    fl();
	int n,k,s;
	scanf("%d%d%d",&n,&k,&s);
	for(int i=1;i<=k;i++)
		printf("%d ",s);
	for(int i=k+1;i<=n;i++)
		printf("%d ",s==999983?999984:999983);
	puts("");
	return 0;
}


Measured memory_bytes: 1280
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     long  a = sc.nextLong();
     long b = sc.nextLong();
     long  c = sc.nextLong();
     long d = sc.nextLong();
     long cd,x,y,z,ans;
     cd = lcm(c,d);
     x= b/c -(a-1)/c;
     y= b/d -(a-1)/d;
     z= b/cd -(a-1)/cd;
     ans= b-a+1-x-y+z;
     System.out.println(ans);
   }

   private static long gcd(long m, long n) {
       if(m < n) return gcd(n, m);
       if(n == 0) return m;
       return gcd(n, m % n);
   }

   private static long lcm(long m, long n) {
       return m * n / gcd(m, n);
   }
}


Measured memory_bytes: 21716
def examA():
    N = I()
    ans = N + N**2 + N**3
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 77100
#include <iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  n=n%10;
  if(n==3)
    cout<<"bon";
  else if(n==0 || n==1 || n==6 || n==8)
    cout<<"pon";
  else
    cout<<"hon";
  return 0;
}

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

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

int main(){
    int n;
    cin >> n;
    vector<P> v(n);
    ll ans = 0;
    for(int i=0; i<n; i++){
        ll a, b;
        cin >> a >> b;
        v[i].first = a + b;
        v[i].second = a;
        ans += b;
    }
    sort(v.rbegin(), v.rend());
    for(int i=0; i<n; i++){
        if(i%2 == 0) ans -= v[i].second + (v[i].first - v[i].second);
    }
    cout << -ans << endl;
    return 0;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll; 
 
int main(void){
	
	double T, X;
	
	cin >> T >> X;
	
	double ans;
	ans = T / X;
	
	printf("%.12f\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"Yes":"No")<<endl;

int main() {
    int x, n;
    cin >> x >> n;
    vector<bool> exist(300, false);
    for (int i=0; i<n; ++i) {
        int p; cin >> p;
        exist[p + 150] = true;
    }
    int ans;
    for (int i=0; i<=100; ++i) {
        if (!exist[x+150-i]) {
            ans = x-i;
            break;
        } else if (!exist[x+150+i]) {
            ans = x+i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

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

Measured memory_bytes: 256
N = int(input())
max_limit = 1000000000000001

now = 0
for i in range(1,20):
    now += 26**i
    if now >= N:
        keta = i
        break
    
for i in range(keta):
    if i != 0:
        N -= 26**(i)

N = N-1
answer_list = []
for i in range(keta-1):
    answer_list.append(N//26**(keta-(i+1)))
    N = N%26**(keta-(i+1))
    
answer_list.append(N)

for i in range(len(answer_list)):
    answer_list[i] = chr(answer_list[i]+97)
print("".join(str(n) for n in answer_list))

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

using namespace std;
int main() {
    int n;
    cin >> n;
    int x, min = 1000000001, maxp = -1000000001;
    rep(i, n) {
        cin >> x;
        
        if(maxp < (x - min) && min != (1000000001)) {
            maxp = (x - min);
        }
        
        if(min > x) {
            min = x;
        }
        
    }
    
    cout << maxp << endl;
   
}
    



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

using namespace std;
#define ff first
#define ss second
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int main() {

	long long n, T; cin >> n >> T;
	vector < pair<long long, long long>> v(n);
	for (long long i = 0; i <= n - 1; i++) cin >> v[i].ff >> v[i].ss;
	sort(v.begin(), v.end());

	vector<long long> dp(T + (*(max_element(v.begin(), v.end()))).ff + 1, -1);
	dp[0] = 0;

	for (long long i = 0; i <= n - 1; i++) {
		for (long long j = T - 1; j >= 0; j--) {
			if (dp[j] == -1) continue;
			dp[j + v[i].ff] = max(dp[j + v[i].ff], dp[j] + v[i].ss);
		}
	}
	cout << *max_element(dp.begin(), dp.end());

	return 0;
}

Measured memory_bytes: 3704
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define PrintArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;
#define PrintPairs(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i].fi <<"," << cont[__i].se<<")";} cout<<endl;
#define Print(v) cout<<v<<endl;
#define PDBG() cout<<"Line:"<<__LINE__<<endl;
#define PrintArray2D(cont, fh, th, fw, tw) for(int __i=fh;__i<th;++__i){for(int __j=fw;__j<tw;++__j) {cout<<cont[__i][__j]<<" ";} cout<<endl;}cout<<endl;
#define Resize(cont,W,V) cont.resize(W,V);
#define Resize2D(cont,H,W,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W,V);
#define Resize3D(cont,H,W,D,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W);for(int i=0;i<H;++i)for(int j=0;j<W;++j)cont[i][j].resize(D,V);
/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 * priority_queue<int,vector<int>, greater<int>> Q;
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
/*
struct PairComp{
    int operator()(P l, P r) const {
        return l.fi==r.fi?l.se<r.se:l.fi<r.fi;
    }
};*/
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
ll N,K;
vector<ll> A;
ll mod=1000*1000*1000+7;
int main() {
    cout.precision(15);
    cout << fixed;
    cin >> N;
    A.resize(N);
    REP(i,N){
        cin>>A[i];
    }
    sort(ALL(A),greater<ll>());
    ll rem=N-2;
    ll ans=A[0];
    ll it=1;
    while(rem>0) {
        if (rem>=2) {
            ans+=A[it]*2;
            it++;
            rem-=2;
        } else {
            ans+=A[it];
            it++;
            rem--;
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple


int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	map<char,int> m;
	string s; cin>>s;
	int len=s.length();
	for(int i=0;i<len;i++)
	{
	    m[s[i]]++;
	}
	bool ok=1;
	for(char i='a';i<='z';i++)
	{
	    if(m[i]&1){ ok=0; break; }
	}
	if(ok) cout<<"Yes";
	else cout<<"No";
	
	return 0;
}


Measured memory_bytes: 256
N, C = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(C)]
G = [list(map(int,input().split())) for _ in range(N)]
Z = [0]*C
O = [0]*C
T = [0]*C
for x in range(N):
    for y in range(N):
        if (x+y)%3 == 0:
            Z[G[x][y]-1] += 1
        elif (x+y)%3 == 1:
            O[G[x][y]-1] += 1
        else:
            T[G[x][y]-1] += 1

ans = 10**9
for c1 in range(C):
    for c2 in range(C):
        for c3 in range(C):
            if c1 == c2 or c2 == c3 or c3 == c1:
                continue
            temp = 0
            for k in range(C):
                temp += Z[k]*D[k][c1]
            for k in range(C):
                temp += O[k]*D[k][c2]
            for k in range(C):
                temp += T[k]*D[k][c3]
            ans = min(ans,temp)

print(ans)


Measured memory_bytes: 11592
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<stack>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const ll m = (1e+9) + 7;

int main() {
	int n, p, ans = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> p;
		if (p != (i + 1)) ans++;
		if (ans > 2) {
			cout << "NO" << endl;
			break;
		}
	}
	if (ans <= 2)
		cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

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

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

    int n;
    cin>>n;
    vector<pair<string,pii>> v(n);
    for(int i=0; i<n; i++){
        cin>>v[i].first>>v[i].second.first;
        v[i].second.second=i+1;
    }
    sort(v.begin(),v.end(),[](const pair<string,pii>& p1, const pair<string,pii>& p2)->bool{
        return (p1.first==p2.first)?p1.second.first>p2.second.first:p1.first<p2.first;
    });
    for(int i=0; i<n; i++) cout<<v[i].second.second<<"\n";

    return 0;
}


Measured memory_bytes: 256
st = gets.chomp

case st
when "SUN" then
  puts 7
when "MON" then
  puts 6
when "TUE" then
  puts 5
when "WED" then
  puts 4
when "THU" then
  puts 3
when "FRI" then
  puts 2
else
  puts 1
end



Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
const double PI = acos(-1);
typedef long long ll;


int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    FOR(i,a,a*b+1){
        if(i%b==c&&i%a==0){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}




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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int p, q, r;
    cin >> p >> q >> r;
    int ans = p + q + r - max(max(p, q), r);
    cout << ans << endl;
    return 0;
}


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

int main() {
    vector<vector<int>> a(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    int b;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> b;
        mp[b]++;
    }
    bool ok = false;
    for (int i = 0; i < 3; i++) {
        if (mp[a[i][0]] && mp[a[i][1]] && mp[a[i][2]]) ok = true;
    }
    for (int i = 0; i < 3; i++) {
        if (mp[a[0][i]] && mp[a[1][i]] && mp[a[2][i]]) ok = true;
    }
    if (mp[a[0][0]] && mp[a[1][1]] && mp[a[2][2]]) ok = true;
    if (mp[a[0][2]] && mp[a[1][1]] && mp[a[2][0]]) ok = true;
    cout << (ok ? "Yes" : "No");
    return 0;
}


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

using namespace std;

int main()
{
    int n,m;
    string memo[110];
    string str;
    map<string,int> s;

    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> str;
        memo[i] = str;
        s[str]++;
    }
    cin >> m;
    for(int i = 0;i < m;i++){
        cin >> str;
        s[str]--;
    }

    int maxi = 0;
    for(int i = 0;i < n;i++){
        maxi = max(s[memo[i]], maxi);
    }
    cout << maxi << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define bitcount    __builtin_popcountll
#define mod 1000000007
#define N 1000009
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss(s) cin>>s;
#define si(x)  scanf("%d",&x);
#define sl(x)  cin>>x;
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define ll long long 
//int some_primes[10] = {24443, 100271, 500179, 1000003, 1000333, 2000321, 5000321, 98765431, 1000000123};
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define mod         1000000007
#define PI          3.14159265358979323
ll power(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
string a,b,c;
int q,n,t;
int arr[N];
int brr[N];
map<char , ll > m;
int main(){
//fast                          //uncomment on submission
cin>>a;
for(auto x:a)m[x] = 0;
for(int i = a.size() - 1;i>=0;i--)m[a[i]]++;
ll ans = 1ll;
for(ll i = 0;i<a.size() ;i++){
	
	ans+=1ll*(a.size() - i -m[a[i]]);
	m[a[i]]--;
	}

cout << ans;
               











}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  int x=a-b,y=a-c;
  printf("%d\n",x==0?c:y==0?b:a);
  return 0;
}

Measured memory_bytes: 256