akhauriyash/Code-Regression huggingface dataset:
//  Christopher_Yan Move on!!!
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>

using namespace std;

inline void read(int &x)
{
	int k = 1; x = 0;
	char c = getchar();
	while (!isdigit(c)) 
		if (c == '-') c = getchar(), k = -1;
		else c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ 48),
		c = getchar();
	x *= k;
}

int n, a[220], maxa = -11111, d[220];

signed main()
{
	read(n);
	for (int i = 1; i <= n; ++i)
		read(a[i]), maxa = max(a[i], maxa), ++d[a[i]];
	if (d[maxa >> 1] != 1 && !(maxa & 1))
		{ puts("Impossible"); return 0; }
	if (d[1 + (maxa >> 1)] != 2 && (maxa & 1))
		{ puts("Impossible"); return 0; }
	for (int i = 1 + (maxa >> 1); i <= maxa; ++i)
		if (d[i] < 2)
			{ puts("Impossible"); return 0; }
	for (int i = 1; i <= ((maxa >> 1) - (maxa % 2 == 0)); ++i)
		if (d[i] > 0)
			{ puts("Impossible"); return 0; }
	puts("Possible");
	return 0;
}

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

int main() {
  int A, B, a, b, x, y, ans = 0;
  cin >> A >> B;
  
  for (int i = A; i <= B; i++) {
    a = i / 10000;
    b = i / 1000 % 10;
    x = i / 10 % 10;
    y = i % 10;
    
    if (a == y && b == x)
      ans ++;
  }
  
  cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
vector <int> v[100004];
int n,i,x,y,nr1,nr2,nr3,nr11,nr12,a[100004],e[100004],p[100004],pr[100004];
void g (int x)
{
    int i,k;
    k=v[x].size();
    for (i=0;i<=(k-1);i++)
    {
        if (a[v[x][i]]==0 && v[x][i]!=1)
        {
            nr1++;
            a[v[x][i]]=a[x]+1;
            p[v[x][i]]=x;
            g(v[x][i]);
        }
    }
    return;
}
int main()
{
    scanf ("%d", &n);
    for (i=1;i<=(n-1);i++)
    {
        scanf ("%d %d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for (i=1;i<=n;i++)
        a[i]=0;
    nr1=0;
    g(1);
    for (i=1;i<=n;i++)
        pr[i]=p[i];
    nr3=a[n]-1;
    for (i=1;i<=n;i++)
        a[i]=0;
    a[n]=1;
    a[p[n]]=1;
    nr1=0;
    g(n);
    nr2=nr1;
    nr1=0;
    for (i=1;i<=n;i++)
        a[i]=0;
    a[n]=1;
    g(n);
    nr11=n-2-nr1;
    nr12=nr2;
    for (i=1;i<=n;i++)
        a[i]=0;
    x=n;
    while (x!=1)
    {
        e[pr[x]]=x;
        x=pr[x];
    }
    x=1;
    for (i=1;i<=(nr3/2+nr3%2);i++)
    {
        a[x]=1;
        x=e[x];
        a[x]=1;
        nr1=0;
        a[e[x]]=1;
        g(x);
        nr11+=nr1;
        nr11++;
    }
    x=n;
    for (i=1;i<=(nr3/2);i++)
    {
        a[x]=1;
        x=pr[x];
        a[x]=1;
        a[pr[x]]=1;
        nr1=0;
        g(x);
        nr12+=nr1;
        nr12++;
    }
    if (nr11<=nr12)
        printf ("Snuke\n");
    else
        printf ("Fennec\n");
    return 0;
}


Measured memory_bytes: 11904
n = int(input())
A = list(map(int, input().split()))
q = int(input())
BC = [list(map(int, input().split())) for i in range(q)]

list=[0]*100001
sum=sum(A)
for i in A:
    list[i]+=1

for bc in BC:
    x=list[bc[0]]
    sum+=(bc[1]-bc[0])*x
    print(sum)
    list[bc[0]]-=x
    list[bc[1]]+=x

Measured memory_bytes: 32400
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

int n;

int cnt(int n){
  int res=0;
  while(n>0){
    res++;
    n=n/10;
  }
  return res;
}

int main(){
  scanf("%d",&n);
  int kq=0;
  for(int i=1;i<=n;i++)
    if (cnt(i)%2==1) kq++;
  cout<<kq;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<x<<endl
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
typedef vector<int> vi;

string a;

int main(void){
    cin>>a;
    int n=a.size(),ans=0;
    rep(i,n)repi(j,i,n){
        bool flag=1;
        rep(k,i,j+1){
            if(a[k]=='A' || a[k]=='T' || a[k] =='G' || a[k] == 'C')flag=1;
            else flag=0;
        }
        if(flag==0)break;
        ans=max(ans,j+1-i);
    }
    p(ans);
    return 0;
}



Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	b , c = IN()
	if b==1 or c== 1:
		return 1
	e=((b+1)//2)
	o=b//2
	ret=0
	ret+=e*((c+1)//2)
	ret+=o*(c//2)
	print(ret)

	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
while True:
    A, op, B = input().split(" ")
    if op == "?":
        break
    a, b = int(A), int(B)
    if op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(int(a * b))
    elif op == "/":
        print(int(a / b))



Measured memory_bytes: 5600
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
template<typename T>void read(T &x){
	x=0;int f(1);char c(getchar());
	for(;!isdigit(c);c=getchar())if(c=='-')f=-f;
	for(; isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c-'0');
	x*=f;
}
template<typename T>void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)write(x/10),x%=10;
	putchar(x+'0');
}
int main(){
	int a,b,k;
	read(k),read(a),read(b);
	puts((a-1)/k==b/k?"NG":"OK");
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
//ダイクストラ法:スタートから任意の地点での最短距離、最短パスを求める
//計算量:(頂点+辺)log(頂点) 
//始点,終点,隣接リスト(pathlist[edge.A]=(edgeB,legth))-->距離(notfound:INFLL),previous(notfound:INF);
vector<pair<long long,int>> Dikstra(int start,vector<vector<pair<int,long long>>>&pathlist){
	int edge=pathlist.size();
	pair<long long, int> cerching;
	priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q; //start to distance,[ditance ,islandNo.]
	vector<pair<long long,int>> D(edge,mp(INFLL,INF)); //distance (ans), preious path
	vector<bool>had(edge,false);
	D[start] = mp(0, -1); //distance ,Previous egdg
	q.emplace(0LL, start);
	while (!q.empty()){
		cerching = q.top();
		q.pop();
		if (had[cerching.second] == false){
			had[cerching.second] = true;
			for (auto i = pathlist[cerching.second].begin(); i != pathlist[cerching.second].end(); i++){
				if (had[i->first] == false){
					if(chmin(D[i->first].F, (cerching.first) + (i->second))){
						D[i->first].S=cerching.second;
					}
					q.emplace(D[i->first].F, i->first);
				}
			}
		}
	}
return D;
}
ll func(int at,int state,VV& dis,VV & dp){
	if(dp[at][state]==INFLL){
		rep(i,dis.size()){
			if(state & (1<<i)){
				chmin(dp[at][state],func(i,state&~(1<<i),dis,dp)+dis[at][i]);
			}
		}
	}	
	return dp[at][state];
}
int main(){
	int n,m,r;
	ll ans=INFLL;
	cin >>n>>m>>r;
	Vi com(r);
	rep(i,r){
		cin>>com[i];
		com[i]--;
	}
	int a,b;
	ll c;
	vector<vector<pair<int,ll>>> path(n);
	rep(i,m){
		cin>>a>>b>>c;
		a--;
		b--;
		path[a].emplace_back(b,c);
		path[b].emplace_back(a, c);
	}
	vector<pair<long long, int>>res;
	vector<vector<ll>> dis(r,V(r));
	rep(i,r){
		res.clear();
		res=Dikstra(com[i],path);
		rep(j,r){
			dis[i][j]=res[com[j]].F;
		//	clog<<dis[i][j]<<" ";
		}
	//	clog<<endl;
	}
	VV dp(r,V(1<<r,INFLL));
	rep(i,r){
		dp[i][0]=0LL;
	}
	rep(i,r){
		chmin(ans,func(i,(1<<r )-1,dis,dp));
	}
	cout << ans << endl;
}

Measured memory_bytes: 4648
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define ll long long 
inline ll read()
{
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            f=-1;
        }
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
int n;
struct node
{
    ll num,id;
    ll tot;
}s[100503];
inline bool cmp(node a,node b)
{
    return a.num<b.num;
}
ll ji,ou;
int main()
{
    n=read();
    for(rg int i=1;i<=n;++i)
        s[i].num=read(),s[i].id=i;
    stable_sort(s+1,s+1+n,cmp);
    for(rg int i=1;i<=n;++i)
        if(s[i].id%2==0)
            if(i%2==0)
                continue;
            else
                ou++;
        else 
            if(i%2!=0)
                continue;
            else
                ji++;
    ll h=min(ou,ji);
    cout<<h+abs(ou-ji);
;;;;;;;;;;
}

Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int n = sc.nextInt();
            int count = 0;
         for(int i = 0; i < 10; i++){
             for (int j = 0; j < 10; j++){
                 for (int k = 0; k < 10; k++){
                     for (int l = 0; l < 10; l++){
                         if(n == i + j + k + l){
                          count++;
                         }
                     }
                 }
             }
         }
         System.out.println(count);
        }
    }
}



Measured memory_bytes: 26280
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
    double x1,y1,x2,y2;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    printf("%.8lf\n",sqrt(pow(x1-x2,2)+pow(y1-y2,2)));
}


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

#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math,-ffp-contract=off")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long

const int N = 51, INF = 1e18;
int dp[N][N], ans;
int ch[N];
int n;
int a[N], b[N];

void hesab() {
	for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dp[i][j] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (j > i) {
				dp[i][j] = -1;
				continue;
			}
			if (i == j) {
				dp[i][j] = 0;
				continue;
			}
			dp[i][j] = INF;
			for (int l = 1; l < N; l++) {
				int lp = i % l;
				if (dp[lp][j] == -1) continue;
				if (ch[l]) dp[i][j] = min(dp[i][j], dp[lp][j] | (1ll << l));
				else dp[i][j] = min(dp[i][j], dp[lp][j]);
			}
		}
	}
	return;
}

int32_t main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 1; i < N; i++) ch[i] = 1;
	int cnt = 0;
	while (1) {
		cnt++;
		if (cnt == 50) {
			ans = -1;
			break;
		}
		hesab();
		int val = 0;
	   	int	id = 0;

		for (int i = 0; i < n; i++) {
			val = max(val, dp[a[i]][b[i]]);
			if (dp[a[i]][b[i]] == -1) return cout << -1, 0;
		}

		if (val == 0) break;

		for (int j = 0; j < N; j++) {
			if (val & (1ll << j)) id = j;
		}
	//	for (int i = 0; i < n; i++) {
	//		if (dp[a[i]][b[i]] & (1ll << id)) {
	//			a[i] = a[i] % id;
	//		}
	//	}
//		cout << val << ' ' << id << '\n';
		ans += (int)(1ll << id);
		ch[id] = 0;
	}
	cout << ans;
	return 0;
}

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

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

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> a(n);

  int d, e;
  rep(i, k) {
    std::cin >> d;
    rep(j, d) {
      std::cin >> e;
      --e;
      ++a[e];
    }
  }

  int cnt = 0;
  rep(i, n) if (a[i] == 0)++ cnt;

  std::cout << cnt << '\n';

  return 0;
}


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

long long ans=0;
int n,m,x,y,S,T,k[100005],siz[100005];
int s[100005],top;
bool odd;

vector<list<int> > graph;

void dfs1(int p,int fa)
{
	for(list<int>::iterator i=graph[p].begin();i!=graph[p].end();i++)
	{
		if(*i==fa) continue;
		if(siz[*i])
		{
			if(siz[p]==siz[*i]) odd=true;
			S=p,T=*i;
		}
		else
		{
			siz[*i]=-siz[p];
			dfs1(*i,p);
		}
	}
	return;
}

void dfs2(int p,int fa)
{
	for(list<int>::iterator i=graph[p].begin();i!=graph[p].end();i++)
	{
		if(*i==fa||(p==S&&*i==T)||(p==T&&*i==S)) continue;
		dfs2(*i,p);
		siz[p]+=siz[*i];
		k[p]+=k[*i];
	}
	return;
}

int main()
{
	scanf("%d%d",&n,&m);
	graph.resize(n+1);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	siz[1]=1,dfs1(1,0);
	int sum=0;
	for(int i=1;i<=n;i++) sum+=siz[i];
	if(m==n-1)
	{
		if(sum) return puts("-1"),0;
	}
	else if(odd)
	{
		if(sum&1) return puts("-1"),0;
		ans+=abs(sum>>1);
		siz[S]-=sum>>1,siz[T]-=sum>>1;
	}
	else if(sum) return puts("-1"),0;
		else k[S]=1,k[T]=-1;
	dfs2(1,0);
	for(int i=1;i<=n;i++)
	{
		if(k[i]) s[++top]=k[i]*siz[i];
		else ans+=abs(siz[i]);
	}
	s[++top]=0;
	sort(s+1,s+top+1);
	int mid=s[top+1>>1];
	for(int i=1;i<=top;i++) ans+=abs(s[i]-mid);
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  int S;
  cin >> S;
  
  int A = S/100;
  int B = S - S/100*100;
  bool Abool = false;
  bool Bbool = false;
  if (A > 0 && A < 13) Abool = true;
  if (B > 0 && B < 13) Bbool = true;
  if (Abool && Bbool) cout << "AMBIGUOUS" << endl;
  if (Abool && !Bbool) cout << "MMYY" << endl;
  if (!Abool && Bbool) cout << "YYMM" << endl;
  if (!Abool && !Bbool) cout << "NA" << endl;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define MOD (ll)(1e9+7)
#define INF INT32_MAX
#define INFL INT64_MAX
using namespace std;

void solve()	{
	ll n;
	cin >> n;
	cout << (n*(n-1))/2 << endl;
}

int main()	
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin >> t;
	for(int i=1; i<=t; i++)	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, int>;

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

    int h, w, m;
    cin >> h >> w >> m;

    vector< P > yx;
    vs32 row(h, 0);
    vs32 col(w, 0);
    rep (i, m)
    {
        int y, x;
        cin >> y >> x;
        --y, --x;
        yx.emplace_back(y, x);
        ++row[y];
        ++col[x];
    }


    int Mrow, Mcol;
    s64 rcnt, ccnt;
    Mrow = Mcol = 0;
    rcnt = ccnt = 0;
    rep (i, h)
    {
        if (Mrow < row[i])
        {
            Mrow = row[i];
            rcnt = 1;
        }
        else if (Mrow == row[i])
        {
            ++rcnt;
        }
    }
    rep (j, w)
    {
        if (Mcol < col[j])
        {
            Mcol = col[j];
            ccnt = 1;
        }
        else if (Mcol == col[j])
        {
            ++ccnt;
        }
    }

    int cnt = 0;
    rep (i, m)
    {
        int y = yx[i].first;
        int x = yx[i].second;
        if (row[y] == Mrow && col[x] == Mcol) ++cnt;
    }

    int ans = Mrow + Mcol - (rcnt * ccnt == cnt);
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 9752
fun main(args: Array<String>) {
    val N = readLine()!!.toLong()
    for (h in 1..3500) {
        for (n in 1..3500) {
            val p = N * h * n
            val q = 4L * h * n - N * n - N * h
            if (q != 0L && p % q == 0L && p / q > 0) {
                println("$h $n ${p / q}")
                return
            }
        }
    }
}

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

using namespace std;

template <typename T>
T lcs(const T &a, const T &b) {
  vector<vector<int>> dp(a.size() + 1, vector<int>(b.size() + 1, 0));
  for (size_t i = 0; i < a.size(); i++) {
    for (size_t j = 0; j < b.size(); j++) {
      if (a[i] == b[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
      dp[i + 1][j + 1] = max({dp[i + 1][j + 1], dp[i + 1][j], dp[i][j + 1]});
    }
  }

  T res;
  size_t i = a.size(), j = b.size();
  while (i > 0 && j > 0) {
    if (dp[i][j] == dp[i - 1][j]) {
      i--;
    } else if (dp[i][j] == dp[i][j - 1]) {
      j--;
    } else {
      res.push_back(a[i - 1]);
      i--, j--;
    }
  }
  reverse(res.begin(), res.end());
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S, T;
  cin >> S >> T;

  cout << lcs(S, T) << "\n";
  return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0, i##_len=(n); i<i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

int main(){
          string S,T;
          cin >> S >> T;
          if(S==T){
                    cout << "Yes" << endl;
                    exit(0);
          }

          REP(i,S.size()){
                    char c=S[0];
                    S.erase(S.begin());
                    S.insert(S.end(),c);
                    if(S==T){
                              cout << "Yes" << endl;
                              exit(0);
                    }
          }

          cout << "No" << endl;

          return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    from collections import defaultdict

    n, c = map(int, input().split())
    dt = [[int(e) for e in input().split()] for _ in range(c)]
    ct = [[int(e) for e in input().split()] for _ in range(n)]

    cd0 = defaultdict(int)
    cd1 = defaultdict(int)
    cd2 = defaultdict(int)
    for i in range(n):
        for j in range(n):
            if (i + 1 + j + 1) % 3 == 0:
                cd0[ct[i][j]] += 1
            if (i + 1 + j + 1) % 3 == 1:
                cd1[ct[i][j]] += 1
            if (i + 1 + j + 1) % 3 == 2:
                cd2[ct[i][j]] += 1

    ans = 500 ** 2 * 1000 * 30
    for c0 in range(1, c + 1):
        base = 0
        for d in cd0:
            if d == c0:
                continue
            base += dt[d - 1][c0 - 1] * cd0[d]
        for c1 in range(1, c + 1):
            if c0 == c1:
                continue
            base2 = 0
            for d in cd1:
                if d == c1:
                    continue
                base2 += dt[d - 1][c1 - 1] * cd1[d]
            base2 += base
            for c2 in range(1, c + 1):
                if c0 == c2 or c1 == c2:
                    continue
                tans = 0
                for d in cd2:
                    if d == c2:
                        continue
                    tans += dt[d - 1][c2 - 1] * cd2[d]
                ans = min(ans, tans + base2)
                
    print(ans)
    
if __name__=="__main__":
    solve()


Measured memory_bytes: 45532
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <climits>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define in1(n) cin>>n;
#define in2(n, k) cin>>n>>k;
#define in3(n, k, s) cin>>n>>k>>s;
#define scn(t) scanf("%d", &t)
#define scnld(t) scanf("%ld", &t)
#define scnlld(t) scanf("%lld", &t)
#define scnc(t) scanf("%c", &t)
#define scns(t) scanf("%s", t)
#define scnf(t) scanf("%f", &t)
#define scnlf(t) scanf("%lf", &t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define nloop(i, j, k, in) for (int i = j; i < k; i += in)
#define rloop(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rep(i, j) nloop(i, 0, j, 1)
#define rrep(i, j) rloop(i, j, 0, 1)
#define inar(n, a) \
    rep(i, n)\
        cin>>a[i];
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define MP make_pair
#define PB push_back
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)\
{\
return (a.second < b.second);\
}
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define fast  \
    ios_base::sync_with_stdio(false);\
    cin.tie(NULL);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

int main()
{
    fast
    int d,t ,s;
    in3(d,t,s)
    if(1.0*d/s > t) cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int input() {
	int r;
	scanf("%lld", &r);
	return r;
}
int f1(int a, int p) {
	if (p == 1)return a;
	if (p % 2)return f1(a, p - 1) * a % mod;
	else return f1(a * a % mod, p / 2) % mod;
}
int n, d; vector<int>a[123210];
signed main() {
	n = input(); for1(i, n) a[input()].push_back(i);
	for1(i, n) if (a[i].size() == 2) {
		d = n - (a[i][1] - a[i][0]); break;
	}
	int ans0 = 1, ans1 = 1, ans11 = 1, ans2 = 0;
	for1(i, n + 1) {
		if (i >= 2)ans2 = ans1;
		ans1 = ans0;
		ans0 *= n - i; ans0 %= mod; ans0 *= f1(i, mod - 2); ans0 %= mod;
		printf("%lld\n", (ans0 + ans1 * 2 - ans11 + ans2 + mod) % mod);
		ans11 *= d - i + 1; ans11 %= mod; ans11 *= f1(i, mod - 2); ans11 %= mod;
	}
}

Measured memory_bytes: 7168
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		long[]A = new long[N];
		int[]E = new int[100001];
		string[] str = Console.ReadLine().Split();
		long sum = 0;
		for(var i=0;i<N;i++){
			A[i] = long.Parse(str[i]);
			E[(int)A[i]-1]++;
			sum += A[i];
		}
		int Q = int.Parse(Console.ReadLine());
		for(var i=0;i<Q;i++){
			string[] str2 = Console.ReadLine().Split();
			int B = int.Parse(str2[0]);
			int C = int.Parse(str2[1]);
			sum -= (long)E[B-1]*B;
			sum += (long)E[B-1]*C;
			E[C-1] += E[B-1];
			E[B-1] = 0;
			Console.WriteLine(sum);
		}
	}
}

Measured memory_bytes: 30440
#include<iostream>
#include<cstring>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
#define ll long long
//快速求组合数的方法 
int main(){
	ll n,t;
	cin>>n;
	map<ll,ll> mp;
	int num[200008];
	for(int i=1;i<=n;i++){
		cin>>num[i];
		mp[num[i]]++;//计数 
	}
	ll sum=0;
	for(map<ll,ll>::iterator it=mp.begin();it!=mp.end();it++){
		sum=sum+(it->second)*(it->second-1)/2;
	}
	ll temp=sum;
	for(int i=1;i<=n;i++){
		int cnt=mp[num[i]];
		sum=sum-cnt*(cnt-1)/2;
		cnt--;
		sum=sum+cnt*(cnt-1)/2;
		cout<<sum<<endl;
		sum=temp;
	}
//	cout<<sum<<endl;
	return 0;
}

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

int toInt(vector<bool>& v){
    int res = 0;
    for(int i = 0;i < v.size();i++){
        res += v[i];
        res *= 2;
    }
    return res;
}

int rec(vector<bool>& went,vector<vector<int>>& t,map<int,int>& memo){
    if(memo[toInt(went)])return memo[toInt(went)];
    int N = went.size();
    int res = 1e9;
    bool flag = true;
    for(int i = 0;i < N;i++){
        if(!went[i]){
            flag = false;
            int cost = t[i][0];
            for(int j = 0;j < N;j++){
                if(went[j])cost = min(cost,t[i][j+1]);
            }
            went[i] = true;
            res = min(res,cost+rec(went,t,memo));
            went[i] = false;
        }
    }
    if(flag)return 0;
    return memo[toInt(went)] = res;
}

void solve(int N){
    vector<vector<int>> t(N,vector<int>(N+1));
    for(int i = 0;i < N;i++){
        for(int j = 0;j < N+1;j++){
            cin >> t[i][j];
        }
    }
    vector<bool> v(N,false);
    map<int,int> memo;
    cout << rec(v,t,memo) << endl;
}

int main(){
    int N;
    while(true){
        cin >> N;
        if(!N)return 0;
        solve(N);
    }
}


Measured memory_bytes: 6188
#include <bits/stdc++.h>
using namespace std;
bool is_prime(int x){
    int r=sqrt(x);
    for(int i=2; i<=r; ++i){
        if(x%i==0) return 0;
    }
    return 1;
}
int main(){
	int x; cin >> x;
    for(int i=x; ; ++i){
        if(is_prime(i)){
            cout << i <<endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  bool ok = true;
  for (int i = 0; i < N; i ++) {
    int a;
    cin >> a;
    if (!(a % 2)) {
      if ((a % 5) && (a % 3)) ok = false;
    }
  }
  cout << (ok ? "APPROVED" : "DENIED") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> a >> b >> n;
	while (n >= a) {
		ans += b;
		n -= a;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	if(a <= 0 && b >= 0){
		printf("Zero\n");
	}else if((a < 0 && b < 0) && ((b - a + 1) % 2)){
		printf("Negative\n");
	}else{
		printf("Positive\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
T chmin(T &a, T b) {
    a = (a < b ? a : b);
}

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, 0, N) {
        cin >> A[i];
    }
    const ll inf = 1LL << 60;
    auto dp = make_v(N + 1, 5, inf);
    dp[0][0] = 0;
    REP(i, 0, N) {
        ll m = dp[i][0];
        chmin(dp[i + 1][0], m + A[i]);

        chmin(m, dp[i][1]);
        chmin(dp[i + 1][1], m + A[i] % 2 + 2 * (A[i] == 0));

        chmin(m, dp[i][2]);
        chmin(dp[i + 1][2], m + !(A[i] % 2));

        chmin(m, dp[i][3]);
        chmin(dp[i + 1][3], m + A[i] % 2 + 2 * (A[i] == 0));

        chmin(m, dp[i][4]);
        chmin(dp[i + 1][4], m + A[i]);
    }

    ll ans = inf;
    REP(i, 0, 5) {
        chmin(ans, dp[N][i]);
    }

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


Measured memory_bytes: 15872
/* ( ε:)( ε:)(:ε )(:ε ) */
/* ( ε:)Give me AC(:ε ) */
/* ( ε:)( ε:)(:ε )(:ε ) */
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, lower, upper) for (long long i = lower; i < upper; i++)
#define ALL(list) (list.begin()), (list.end())

using namespace std;
typedef long long ll;
const int MOD = 10000007;
const long double PI = 3.14159265358979323846264338327950L;

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

int lcm(int a, int b) { 
  return a * b / gcd(a, b);
}

vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  return (ret);
}

template<typename T>
T input(){
  T _input;
  cin>>_input;
  return _input;
}


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

void execute() {
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  long double rad = PI * 2 * ( (long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);

  long double rsq = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(rad);

  cout<<fixed<<setprecision(20)<<sqrtl(rsq)<<endl;

}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);

  execute();

  return (0);
}


Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc097/tasks/abc097_b

int main() {
    int X; cin >> X;
    vector<int> expo(X+5, 0);
    expo[1] = true;

    for (int b = 2; b <= X; b++) {
        int v = b * b;
        while(v <= X) {
            expo[v] = 1;
            v *= b;
        }
    }

    for (int i = X; i > 0; i--) if (expo[i]){
            cout << i << "\n";
            return 0;
    }


    return 0;
}


Measured memory_bytes: 256
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_3_B
  * ???????????±???????????????
  * ???????????´??° x ???????????????????????????????????????????????????????????°?????????????????????????????????
  * ??\???????????°????????????????????????????§????????????????????????????????????????????????????????????´??° x ??????????????????????§?????????????????????????
  * x ??? 0 ?????¨?????\?????????????????????????????????????????????????????????????????????????????£????????????????????????
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).takeWhile(_ != "0").map(_.toInt)
      .zipWithIndex
      .foreach { case (v, i) => println(s"Case ${i + 1}: $v") }
  }
}

Measured memory_bytes: 53544
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    
    PriorityQueue<Integer> under = new PriorityQueue<>(Collections.reverseOrder());
    PriorityQueue<Integer> over = new PriorityQueue<>(Collections.reverseOrder());
    for (int i = 0; i < N; i++) {
      B[i] = sc.nextInt();
      if (B[i] > A[i]) {
        under.offer(B[i]-A[i]);
      } else if (A[i] > B[i]) {
        over.offer(A[i]-B[i]);
      }
    }
    
    int ans = 0;
    int remain = 0;
    while (under.size() > 0) {
      int au = under.poll();
      ans++; 
      while (au > 0) {
        if (remain == 0) {
          if (over.size() == 0) {
            break;
          }
          int ao = over.poll();
          remain = ao;
          ans++;
        }
        int dec = Math.min(au, remain);
        au -= dec;
        remain -= dec;
      }
      if (au > 0) {
        ans = -1;
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 66616
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
using namespace std;
typedef long long int ll;

int main() {
    ll N,P;
    scanf("%lld%lld",&N,&P);
    double c;
    double cc = 1.0/N;
    c = pow(P,cc);
    ll d;
    d = c;
    ll ans = 1;
    for (ll i=d+5;i>=1;i--){
        long double D;
        D = pow(i,N);
        ll DD;
        DD = D;
        if (P % DD == 0){
            ans = i;
            break;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

int	main()
{
	string	S;
	cin >> S;
	int	len_whole = S.size();
	int	max_len = 0;
	int	tmp_len = 0;
	char	c;
	for (int i = 0; i < len_whole; ++i) {
		c = S.at(i);
		if (c == 'A' || c == 'C' || c == 'G' || c == 'T')
			++tmp_len;
		else
			tmp_len = 0;
		if (max_len < tmp_len) max_len = tmp_len;
	}
	cout << max_len << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

class Myclass
{
	int h, m, s;

public:
	Myclass();		//?????????????????????
	~Myclass();		//??????????????????
	void Watch( long time );
	void Show();
};

Myclass::Myclass()
{
	//?????????
	h = 0;
	m = 0;
	s = 0;
}

Myclass::~Myclass()
{
	Show();
}

void Myclass::Watch( long time )
{
	h = time / 3600;
	m = ( time - ( h * 3600 ) ) / 60;
	s = time - ( h * 3600 ) - ( m * 60 );
}

void Myclass::Show()
{
	cout << h << ":" << m << ":" << s << endl; 
}

int main()
{
	Myclass mc;
	long S;

	cin >> S;

	mc.Watch( S );

	return 0;
}

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

/*離散型中間値の定理もどき*/
/*あるマスをとったとき、それよりも右(左)に2以上低い(高い)値があると×*/
/*これらは同じことを意味しているので、最大値を更新していく形で*/
int main(){
  int N;
  bool ans = true;
  cin >> N;
  vector<int> masu(N);

  for(int i = 0; i < N; i++)                   //計算量O(N)
    cin >> masu[i];

  int max = 0;                                         //走査マスより左に存在する最大マス値
  for(int i = 0; i < N; i++){                 //最悪計算量O(N)
    if(max - masu[i] >= 2){
      ans = false;                                     //単調非減少化は不可能
      break;
    }
    if(max < masu[i])
      max = masu[i];
  }
  

  if(ans)
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;

}

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

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

int main(){
  int h,w;
  cin >> h >> w;

  vector<vector<char>> grid(h, vector<char>(w));
  rep(i,h)rep(j,w) cin >> grid.at(i).at(j);
  
  vector<vector<int>> delta =  {{-1,0},{0,-1},{1,0},{0,1}};
  
  rep(i,h)rep(j,w){
    if(grid.at(i).at(j)=='.') continue;
    bool paint =  false;
    rep(k,4){
      int dx = delta.at(k).at(0);
      int dy = delta.at(k).at(1);
      if(i+dx>=0&&i+dx<h&&j+dy>=0&&j+dy<w&&grid.at(i+dx).at(j+dy)=='#') paint=true;
    }
    if(!paint) {cout << "No"; return 0;}
  }

  cout << "Yes";
  
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
int main() {
cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  vector<string> s(n);
  loop(i,n)cin>>s[i];
  map<char,ll> ans;
  loop(i,n){
    map<char,ll> count;
    ll t=s[i].size();
    loop(j,t){
      if(i==0){
        ans[s[i][j]]++;
      }
      else{
        count[s[i][j]]++;
      }
    }
    if(i!=0){
    loop(j,('z'-'a')+1){
      char al=(char)('a'+j);
      ans[al]=min(ans[al],count[al]);
    }
         }
  }
  loop(i,('z'-'a')+1){
      char al=(char)('a'+i);
      loop(j,ans[al])cout<<al;
    }
  
  
}

Measured memory_bytes: 256
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

N = int(input())
A = list(map(int,input().split()))

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
used = [False] * len(primes)
big = [0] * (10 ** 6)

g = A[0]
for v in A:
    g = gcd(v,g)
if g == 1:  
    works = 1
    for v in A:
        if v > 1:
            for i in range(len(primes)):
                if v % primes[i] == 0:
                    if used[i]:
                        works = 0
                        break
                    used[i] = True
                    while v % primes[i] == 0:
                        v //= primes[i]
                    if v == 1:
                        break
                    
            works -= big[v]
            big[v] = 1
            big[1] = 0
            
            if works != 1:
                break
    if works:
        print('pairwise coprime')
    else:
        print('setwise coprime')
else:
    print('not coprime')
    


Measured memory_bytes: 204556
#include <bits/stdc++.h>
#define DIM 23
#define INF 1000000000000000007LL
#define modulo 1000000007
using namespace std;

long long n,a[DIM][DIM],d[DIM][1<<21];

bool isbit(int mask,int num)
{
    return (mask>>(num-1))&1;
}
void sbit(int &mask,int num)
{
    mask^=1<<(num-1);
}
int main()
{
    cin>>n;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            cin>>a[i][j];

    d[0][0] = 1;
        for(int mask = 0; mask < (1<<n); ++mask){int i = __builtin_popcount(mask);
            for(int j = 1; j <= n; ++j)
                if(isbit(mask,j) && a[i][j])
                {

                    int nmask = mask;
                    sbit(nmask,j);
                    d[i][mask]+=d[i-1][nmask];
                    d[i][mask]%=modulo;
                }}

    cout<<d[n][(1<<n)-1];
    return 0;
}


Measured memory_bytes: 311552
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn diff(x: i32, y: i32) -> i32 {
    if x > y {
        x - y
    } else {
        y - x
    }
}

use std::cmp::max;

fn main() {
    let nm: Vec<u64> = read_vec();
    let n = nm[0];
    let m = nm[1];

    let mut dv: Vec<u64> = vec![];

    for i in 1..(((m as f64).sqrt() as u64) + 1) {
        if m % i == 0 {
            dv.push(i);
        }
    }

    let l = dv.len();

    if dv[l - 1] * dv[l - 1] != m {
        let tmp = m / dv[l - 1];
        dv.push(tmp);
    }
    for i in (0..(l - 1)).rev() {
        let tmp = m / dv[i];
        dv.push(tmp);
    }

    for d in dv {
        if d >= n {
            println!("{}", m / d);
            break;
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define pii pair<int,int>
#define x first
#define y second
#define int long long
using namespace std;
int n,p[100005],Size[100005];
vector <int> g[100005];
int used[100005];
void make_sets(){
    for(int k=1;k<=n;k++){
        p[k]=k;
        Size[k]=1;
    }
    return ;
}
int find_set(int v){
    if(p[v]==v) return v;
    return p[v]=find_set(p[v]);
}
void union_sets (int a, int b) {
a=find_set(a);
b=find_set(b);
if(a!=b){
if(Size[a]<Size[b])
swap(a,b);
p[b]=a;
Size[a]+=Size[b];
}
}
int col[100005];
void DFS(int v,int cl){
    used[v]=1;
    col[v]=cl;
    for(int k=0;k<g[v].size();k++)
    if(used[g[v][k]]==0)
        DFS(g[v][k],1-cl);
}
vector <pii> v;

main(){
cin>>n;
make_sets();
for(int k=1;k<n;k++){
    int a,b,c;
    cin>>a>>b>>c;
    if(c%2!=1){
        union_sets(a,b);
    }
        else{
         v.push_back(make_pair(a,b));
        }
}
int start=0;
for(int k=0;k<v.size();k++){
    int a=find_set(v[k].x);
    int b=find_set(v[k].y);
    g[a].push_back(b);
    g[b].push_back(a);
    start=a;
}
DFS(start,0);
for(int k=1;k<=n;k++)
    cout<<col[find_set(k)]<<endl;
return 0;
}
/*
3
1 2 1
2 3 1
*/


Measured memory_bytes: 10736
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<lint> a(n); std::cin>>a;
  auto cal = [&] (auto a) {
    debug(a);
    lint ans = 0;
    lint sum = 0;
    rep(i,0,n) {
      lint & x = a.at(i);
      sum += x;
      debug(i,sum);
      if (i%2 == 0 && sum <= 0) {
        lint z = -sum + 1;
        sum += z;
        ans += z;
        x += z;
        debug(z);
      }
      if (i%2 == 1 && 0 <= sum) {
        lint z = sum + 1;
        sum -= z;
        ans += z;
        x -= z;
        debug(z);
      }
      debug(sum);
    }
    auto b = a;
    std::partial_sum(all(b),b.begin());
    debug(ans,sum,a,b);
    return ans;
  };
  lint x = cal(a);
  for (lint & x : a) x = -x;
  lint y = cal(a);
  lint ans = std::min(x,y);
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 2656
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef struct union_find {
  int32_t *parent;
  int32_t size;
} union_find;

void init_union_find (union_find * const u) {
  for (int32_t i = 0; i < u->size; ++i){
    u->parent[i] = -1;
  }
}

union_find* new_union_find (const int32_t size) {
  union_find * const u = (union_find *) calloc (1, sizeof (union_find));
  u->parent = (int32_t *) calloc (size, sizeof (int32_t));
  u->size = size;
  init_union_find (u);
  return u;
}

void free_union_find (union_find * const u) {
  free (u->parent);
  free (u);
}

int32_t root (union_find * const u, int32_t x) {
  int32_t index[32];
  int32_t top = 0;
  while (u->parent[x] >= 0) {
    index[top++] = x;
    x = u->parent[x];
  }
  while (top > 0) {
    u->parent[index[--top]] = x;
  }
  return x;
}

int same (union_find * const u, const int32_t x, const int32_t y) {
  return root (u, x) == root (u, y);
}

int32_t get_size (union_find * const u, const int32_t x) {
  return - (u->parent[root (u, x)]);
}

void unite (union_find * const u, int32_t x, int32_t y) {
  x = root (u, x);
  y = root (u, y);
  if (x == y) return;
  if (u->parent[x] > u->parent[y]) {
    const int32_t swap = x;
    x = y;
    y = swap;
  }
  u->parent[x] += u->parent[y];
  u->parent[y] = x;
}

typedef int32_t i32;

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  i32 *p = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, p + i);
    p[i]--;
  }
  union_find *u = new_union_find (n);
  while (m--) {
    i32 x, y;
    scanf ("%" SCNi32 "%" SCNi32, &x, &y);
    unite (u, x - 1, y - 1);
  }
  i32 ans = 0;
  for (i32 i = 0; i < n; ++i) {
    if (same (u, i, p[i])) {
      ans++;
    }
  }
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 896