akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(ll i=s;i<n;i++)
	
//昇順クイックソート aを元にする
void Qsort(ll a[],ll b[],ll left,ll right){
	ll i=left,j=right,p=a[(left+right)/2];
	
	while(1){
		while(a[i]<p) i++;
		while(p<a[j]) j--;
		if(i>=j) break;
		swap(a[i],a[j]);
		swap(b[i],b[j]);
		i++;
		j--;
	}

	if(left<i-1) Qsort(a,b,left,i-1);
	if(j+1<right) Qsort(a,b,j+1,right);
}
	
int main(){
	ll N;
	cin >> N;
	ll A[N],B[N];
	For(i,0,N) cin >> A[i] >> B[i];
	
	Qsort(B,A,0,N-1);
	
	ll time=0;
	For(i,0,N){
		time+=A[i];
		if(time>B[i]){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pi        acos(-1)
#define     ll        long long int
#define     fopen     freopen("input.txt","r",stdin)
#define     fwrite    freopen("output.txt","w",stdout)
#define     f0(n)     for(int i=0;i<n;i++)
#define     mem(a)    memset(a,0,sizeof(a))
#define     mems(a)   memset(a,-1,sizeof(a))

int main()
{
    __
    //fopen;
    //fwrite;
    int n;
    cin>>n;
    if(n==7 || n==5 || n==3) cout<<"YES";
    else cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
from pprint import pprint
import sys

n, k = map(int, sys.stdin.readline().strip().split(" "))
h = list(map(int, sys.stdin.readline().strip().split(" ")))
# pprint(h)

inf = 10 ** 10
costs = [inf] * n

costs[0] = 0
for i in range(n):
    # print("i", i)
    for j in range(i-k, i):
        # print("j", j)
        if j < 0:
            continue
        costs[i] = min(costs[i], costs[j] + abs(h[i] - h[j]))


# pprint(costs)
print(costs[n-1])

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

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

    cout << n * (n-1) / 2 + m * (m-1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; i++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	ll N, A, B; cin >> N >> A >> B;

	ll ans = 0;
	for (int n = 1; n <= N; n++) {
		ll sum = 0;
		ll tmp = n;
		while (tmp) {
			sum += tmp % 10;
			tmp /= 10;
		}
		if (sum >= A && sum <= B)ans += n;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-12
#define int long long
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
    int ans = 1;
    for (; b; b >>= 1, a = a * a % mod)
        if (b & 1)
            ans = ans * a % mod;
    return ans;
}

int a[300][300];
int n;
int ans = -1e9;
int cnt = 0;
int vis[300];
int f = 0;
void dfs(int x)
{
    queue<int> q;
    q.push(x);
    while (!q.empty())
    {
        int x = q.front();
        q.pop();
        rep(i, 1, n)
        {
            if (a[x][i])
            {
                // cout<<x<<" "<<i<<" "<<vis[x]<<" "<<vis[i]<<endl;
                if (vis[i] && abs(vis[i] - vis[x]) != 1)
                    f = 0;
            }
        }
        if(f==0)return ;
        rep(i, 1, n)
        {
            if (a[x][i] && !vis[i])
            {
                vis[i] = vis[x] + 1;
                q.push(i);
                cnt = max(cnt, vis[i]);
            }
        }
    }
}

signed main()
{
    io;
    cin >> n;
    rep(i, 1, n)
    {
        rep(j, 1, n)
        {
            char s;
            cin >> s;
            a[i][j] = s - '0';
        }
    }
    rep(i, 1, n)
    {

        memset(vis, 0, sizeof vis);
        vis[i] = 1;
        cnt = 1;
        f = 1;
        dfs(i);
        if (f)
            ans = max(ans, cnt);
    }
    if (ans == -1000000000)
        cout << -1;
    else
        cout << ans;
    cout << endl;
    getchar(); //
    getchar();
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int l[20];
int main(){
	int n;cin>>n;
	rep(i,n)cin>>l[i];
	sort(l,l+n);
	int sum=0;
	rep(i,n-1)sum+=l[i];
	if(sum>l[n-1])puts("Yes");
	else puts("No");
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}
ll myceil(ll x,ll y){//yがいくつ集まったらx以上になるか
	if(x<=y) return 1;
	else if(x%y==0) return x/y;
	else return x/y+1;
}

//a,b x
int main(){
	ll N,M;
	string s;
	cin>>N>>s>>M;
	if(s[0]=='+') cout<<N+M;
	else cout<<N-M;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;




int main()
{
	int N,M,K;
	int ans = 0;;
	int a;

	cin >> N >> M;

	vector<int> list(M,0);

	for (int ni = 0; ni < N; ni++) {
		cin >> K;
		for (int ki = 0; ki < K; ki++) {
			cin >> a;
			list[a-1]++;
		}
	}

	for (int mi = 0; mi < M; mi++) {
		if (list[mi] == N) ans++;
	}


	printf("%d", ans);

	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
 const int mod=1000000007;

 int main(){
 	string s,t;
	cin>>s>>t;
	map<char,char> mp;
	map<char,char> mp2;
	int l=s.length();
	FOR(i,0,l){
		if(mp[s[i]]==0){
			mp[s[i]]=t[i];
		}else{
			if(mp[s[i]]==t[i]){

			}else{
				cout<<"No"<<endl;
				return 0;
			}
		}
		if(mp2[t[i]]==0){
			mp2[t[i]]=s[i];
		}else{
			if(mp2[t[i]]==s[i]){

			}else{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
   return 0;
 }


Measured memory_bytes: 1020
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  string O,E; cin >> O >> E;
  string ans;
  for(int i = 0; i < (int)E.size(); i++) {
    ans += O[i];
    ans += E[i];
  }
  if(O.size() > E.size()) {
    ans += O[O.size() - 1];
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <list>
#include <set>
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
using namespace std;
using ll = long long;
const int INF = 1e9 + 1;
ll MOD = 1e9+7;
ll dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
ll dy[9] = {-1,  0,  1,-1, 0, 1,-1, 0, 1};

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

    ll dp[100002];
    REP(i, 100002){
        dp[i] = 0;
    }
    dp[0]=1;
    int N,M;
    cin >> N >> M;
    map<int, bool> br;
    REP(i, M){
        int a;
        cin >> a;
        br[a] = true;
    }
    REP(i, N){
        if(br[i]==false){
            if(br[i+1]==false&&i+1<=N){
                dp[i+1] += dp[i];
                dp[i+1] %= MOD;
            }
            if(br[i+2]==false&&i+2<=N){
                dp[i+2] += dp[i];
                dp[i+2] %= MOD;
            }
        }
    }
    cout << dp[N]%MOD << endl;
    return 0;
}


Measured memory_bytes: 5760
char m[7*14],v[7*14];
C(i,c){
	if(m[i]==c&&!v[i]){
		v[i]=1;
		return 1+C(i+1,c)+C(i-1,c)+C(i+7,c)+C(i-7,c);
	}
	return 0;
}
E(i,c){
	if(m[i]=='O')
		m[i]='.';
	else if(m[i]==c){
		m[i]='.';
		E(i+1,c),E(i-1,c),E(i+7,c),E(i-7,c);
	}
}
main(){
	int N,i,j,e,n;
	scanf("%d\n",&N);
	for(;N--;){
		for(i=0;i<7*12;i++)
			m[7+i]=getchar();
		for(n=0;;n++){
			e=0;
			memset(v,0,sizeof(v));
			for(i=0;i<7*12;i++){
				if(strchr("RGBYP",m[7+i])&&C(7+i,m[7+i])>=4){
					e=1;
					E(7+i,m[7+i]);
				}
			}
			if(!e)
				break;
			for(i=0;i<11;i++){
				for(j=7*12;j--;){
					if(m[7+j]=='.'){
						m[7+j]=m[j];
						m[j]='.';
					}
				}
			}
		}
		printf("%d\n",n);
	}
	exit(0);
}

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

int main()
{
  int N, M;
  int p[110000];
  string s[110000];
  int res=0;
  int res_ac=0;
  cin >> N >> M;
  int penalties[110000];
  bool ac[110000];

  rep(i,M) {
    cin >> p[i] >> s[i];
    p[i]--;
  }

  rep(i,N) penalties[i]=0;
  rep(i,N) ac[i]=false;

  rep(i,M){
    int n = p[i];
    if(s[i]=="WA" && ac[n]==false) penalties[n]++;
    else if(s[i]=="AC" && ac[n]==false) {
      res_ac++;
      ac[n] = true;
    }
  }

  rep(i,N){
    if(ac[i]) {
      res += penalties[i];
    }
  }
  cout << res_ac << " " << res <<endl;
}

Measured memory_bytes: 6656
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
int main(void){
    int n,k;cin>>n>>k;string s;cin>>s;
    if(s[k-1]=='A')s[k-1]='a';
    if(s[k-1]=='B')s[k-1]='b';
    if(s[k-1]=='C')s[k-1]='c';
    cout<<s<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			final int C = sc.nextInt();
			
			int[] bs = new int[M];
			for(int i = 0; i < M; i++) {
				bs[i] = sc.nextInt();
			}
			
			int cnt = 0;
			for(int i = 0; i < N; i++) {
				int sum = C;
				for(int j = 0; j < M; j++) {
					sum += bs[j] * sc.nextInt();
				}
				
				if(sum > 0) { cnt++; }
			}
			
			System.out.println(cnt);
		}
	}

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

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

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

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

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

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

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

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

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

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

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

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

int64_t calc_attack_count(int64_t hp)
{
  if (hp <= 1)
  {
    return 1;
  }
  return 1 + calc_attack_count(hp / 2) * 2;
}

int main()
{
  int64_t H;
  cin >> H;
  int64_t ans = 1;
  cout << calc_attack_count(H) << endl;
}


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

using namespace std;

#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    FAST();
    string s;
    cin >> s;
    if(s[0] == 'R'  &&  s[1] == 'R'  &&  s[2] == 'R')cout << "3";
    else if(s[0] == 'R'  &&  s[1] == 'R')cout << "2";
    else if(s[1] == 'R'  &&  s[2] == 'R')cout << "2";
    else if(s[0] == 'R'  ||  s[1] == 'R'  ||  s[2] == 'R')cout << "1";
    else cout << "0";
    return 0;
}


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

int main(){
	int N;
	cin >> N;
	vector<int> d(N);
	for(auto &i:d)cin >> i;
	int ans=0;
	for(int i=0;i<N-1;i++)for(int j=i+1;j<N;j++)ans+=d[i]*d[j];
	cout << ans << endl;
	return 0;
}

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

using namespace std;
 
// macro
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define MOD 1000000007
#define M_PI 3.14159265358979323846
#define ll long long
#define ull unsigned long long
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define SORT(ary) sort(begin(ary), end(ary))
#define VL vector<ll>
#define VVL vector<VL>
#define PL pair<ll, ll>
#define VC vector<char>
#define VVC vector<VC>

// Factorial
// need init
ll factorial_memo[5001];
ll factorial(ll n) {
  factorial_memo[0] = 1;
  if(factorial_memo[n] != -1) return factorial_memo[n];
  factorial_memo[n] = (factorial(n-1) * n) % MOD;
  return factorial_memo[n];
}
 
// Combination(nCr)
// need init
ll nCr_memo[5001][5001];
ll nCr(ll n, ll r) {
  if(r*2 > n) r = n-r;
  if(r == 1) return n;
  if(r == 0) return 1;
  if(nCr_memo[n][r] != -1) return nCr_memo[n][r];
  nCr_memo[n][r] = (nCr(n-1, r) + nCr(n-1, r-1)) % MOD;
  return nCr_memo[n][r];
}

ll dfs(VVL& g, vector<PL>& res, ll v, ll& count, ll from, VL& low, VL& pre) {
  pre[v] = count++;
  low[v] = pre[v];
  for(auto to:g[v]) {
    if (pre[to] == -1) {
      low[v] = min(low[v], dfs(g, res, to, count, v, low, pre));
      if(low[to] == pre[to]) res.push_back(make_pair(v, to));
    } else {
      if(from == to) continue;
      low[v] = min(low[v], low[to]);
    }
  }
  return low[v];
}

vector<PL> bridges(VVL& g, ll N) {
  vector<PL> res;
  if (N > 0) {
    VL low(N, -1);
    VL pre(N, -1);
    ll count = 0;
    dfs(g, res, 0, count, -1, low, pre);
  }
  return res;
}

void solve() {
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B) cout << C << "\n";
  else if(A==C) cout << B << "\n";
  else cout << A << "\n";
}



int main() {
  // init
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}

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

#define long long long int
using namespace std;


#ifdef JUDGE
std::ifstream cin("input.txt");
std::ofstream cout("output.txt");
#else
using std::cin;
using std::cout;
#endif

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(6);


    string s;
    cin >> s;
    cout << (s[2] == s[3] and s[4] == s[5] ? "Yes" : "No");
    return 0;


}


Measured memory_bytes: 256
// 問題の URL を書いておく
// https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_b

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

int main(int, const char**)
{
    int n;
    cin >> n;
    if(n == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    struct Info
    {
        int64_t x;
        int64_t y;
    };
    vector<Info> p(n);
    rep(i, n)
    {
        int64_t x, y;
        cin >> x >> y;
        p[i] = {x, y};
    };
    auto compare = [](const Info& a, const Info& b)
    {
        if(a.x == b.x)
        {
            return a.y < b.y;
        }
        return a.x < b.x;
    };

    sort(p.begin(), p.end(), compare);

    map<Info, int, decltype(compare)> data{compare};

    rep(i, n - 1)
    {
        for(int j = i + 1; j < n; ++j)
        {

            Info diff = {p[j].x - p[i].x, p[j].y - p[i].y};
            if(data.find(diff) == data.end())
            {
                data[diff] = 0;
            }
            data[diff]++;
        }
    }
    int mc = 1;
    for(auto d : data)
    {
        mc = max(mc, d.second);
    }
    cout << n - mc << endl;
    return 0;
}


Measured memory_bytes: 3716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println(power_socket(scanner.nextInt(), scanner.nextInt()));
		scanner.close();
	}
	
	public static int power_socket(int a, int b) {
		int taps = 0;
		int sockets = 1;
		while(sockets < b) {
			sockets += a - 1;
			taps++;
		}
		return taps;
	}

}

Measured memory_bytes: 23124
/*
 * ID: ITP2_10_B
 * Problem: Bit Operation II
 */

#include <stdio.h>

void print_bits(unsigned int a)
{
    int i;
    for (i = 0; i < 32; i++) {
        printf("%c", (a & 0x80000000) == 0 ? '0' : '1');
        a <<= 1;
    }
    printf("\n");
}

int main(void)
{
    unsigned int a, b;

    scanf("%d %d", &a, &b);

    print_bits(a & b);
    print_bits(a | b);
    print_bits(a ^ b);

    return 0;
}



Measured memory_bytes: 2052
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
using namespace std;
int main(){
	vector<int> high;
	int n;
	for(int i=0; i<10; i++){
		cin >>n;
		high.push_back(n);
	}
	sort(high.begin(),high.end(),greater<int>());
	cout <<high[0]<<endl<<high[1]<<endl<<high[2]<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n,m;
vector<int> g[100001],ord;
bool used[100001];
int par[100001],cord[100001];
int root;
bool visit(int v,vector<int> &ord,vector<int> &color){
    color[v]=1;
    for(auto it:g[v]){
        if(color[it]==2) continue;
        if(color[it]==1) return false;
        if(!visit(it,ord,color)) return false;
    }
    ord.pb(v);color[v]=2;
    return true;
}
bool topologicalsort(vector<int> &ord){
    vector<int> color(n);
    ord.reserve(n);
    visit(root,ord,color);
    reverse(ord.begin(),ord.end());
    return true;
}
void dfs(int p,int v){
    used[v]=true;
    rep(i,g[v].size()){
        if(!used[g[v][i]]){
            par[g[v][i]]=v;
            dfs(v,g[v][i]);
        }
        else if(cord[par[g[v][i]]]<cord[v]){
            par[g[v][i]]=v;
        }
    }
}
int main(){
    cin>>n>>m;
    int ai,bi;
    rep(i,n-1+m){
        cin>>ai>>bi;
        --ai,--bi;
        g[ai].pb(bi);
        used[bi]=true;
    }
    rep(i,n)if(!used[i]){
        root=i;
        break;
    }
    topologicalsort(ord);
    rep(i,ord.size()){
        cord[ord[i]]=i;
    }
    memset(used,0,sizeof(used));
    used[root]=true;
    par[root]=-1;
    dfs(-1,root);
    rep(i,n){
        cout<<par[i]+1<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

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

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  ll a,b;
  while(scanf("%lld %lld",&a,&b) != -1){
    cout << __gcd(a,b) << " " << (a*b/__gcd(a,b)) << endl;
  }
  return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<ll> a(3*n);
	rep(i,3*n) cin >> a[i];
	
	sort(all(a));
	
	ll ans =0;
	int r=3*n-1;
	rep(i,n){
		r--;
		ans += a[r];
		//cout <<r<<":"<<a[r] <<"  ";
		r--;
		
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int ans[10005];

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

    for (int x = 1; x <= 105; x++){
        for (int y = 1; y <= 105; y++){
            for (int z = 1; z <= 105; z++){
                int s = x*x + y*y + z*z + x*y + y*z + z*x;
                if(s<10003) ans[s]++;
            }
        }
    }

    repr(i, 1, n){
        cout << ans[i] << endl;
    }
    
    return 0;
}

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

#define ALL(c) (c).begin(), (c).end()

int main(void) {
    string s;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    sort(ALL(s));
    cout << (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]? "Yes" : "No") << "\n";
    return 0;
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return abs(x-y)/gcd(x,y); }


int main() {
  int n,k; cin >> n >> k;
  double p=0;

  for(int i=1;i<=n;i++) {
    double p0 = 1/((double)n);
    int score=i;

    while(score<k) {
      score *= 2;
      p0 /= 2;
    }

    p += p0;
  }

  printf("%.10lf\n",p);
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
using namespace std;
char s[200010],t[200010];
int read()
{
	int x=0;char c=getchar(),flag='+';
	while(!isdigit(c)) flag=c,c=getchar();
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
	return flag=='-'?-x:x;
}
ll ggcd(ll a,ll b)
{
	if(b==0) return a;
	return ggcd(b,a%b);
}
int main()
{
	int n=read(),m=read();
	scanf("%s",s+1);
	scanf("%s",t+1);
	ll gg=1ll*n*m/ggcd(n,m);
	ll a=gg/n,b=gg/m;
	ll tt=1ll*a*b/ggcd(a,b);
	int noans=0;
	for(int i=1,j=1;i<=n&&j<=m;i+=tt/a,j+=tt/b)
	{
		if(s[i]!=t[j]) noans=1;
	}
	if(!noans) cout<<gg;
	else puts("-1");
	return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);	
  int A, B;
  cin >> A >> B;
  int sockets = 1;
  int f = 0;
  while(sockets < B) {
    f++;
    sockets += A - 1;
  }
  cout << f;
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>

using namespace std;

int main(){

    int N,M,K;cin>>N>>M>>K;
    bool can[N*M+1];
    fill_n(can,N*M+1,false);

    REP(i,N+1){
        REP(j,M+1){
            can[i*M + j*N -2*i*j]=true;
        }
    }
    if(can[K])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
	int n;
	long long l[87];
	cin >> n;
	l[0] = 2, l[1] = 1;
	for (int i = 2; i <= n; i++) {
		l[i] = l[i - 2] + l[i - 1];
	}
	cout << l[n] << endl;
	return 0;
}

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

using namespace std;

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

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  double ans = 0.0;
  for (int i = 0; i < n - 3; i++) {
    ans = max(ans, (double)(a[n - 2] + a[n - 1]) / (a[i + 1] - a[i]));
  }
  ans = max(ans, (double)(a[n - 2] + a[n - 4]) / (a[n - 2] - a[n - 3]));
  ans = max(ans, (double)(a[n - 3] + a[n - 4]) / (a[n - 1] - a[n - 2]));

  printf("%.10f\n", ans);

  return 0;
}


Measured memory_bytes: 3232
#!/usr/bin/env python
S = input()
x = y = ''
for i in range(len(S)):
    if i % 2 == 0:
        x += S[i]
    else:
        y += S[i]

c1 = x.count('1') + y.count('0')
c2 = x.count('0') + y.count('1')
print(min(c1, c2))

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
 
int main(){
   int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=n-1;i>=0;i--){
        if(i==0){
            cout<<a[i]<<endl;
        }else{
            cout<<a[i]<<" ";
        }
    }
    return(0);
}

Measured memory_bytes: 3076
#include <cstdio>
#include <utility>
using namespace std;

int main(){
    int r,g,b,n;
    int count = 0;
    scanf("%d%d%d%d",&r,&g,&b,&n);
    for(int i = 0;i<2;i++){
        if(r>g){
            swap(r,g);
        }
        if(g>b){
            swap(g,b);
        }
    }

    for(int i = 0;i<n/b+1;i++){
        for(int j = 0;j < (n-i*b)/g+1;j++){
            if((n-b*i-g*j)%r == 0){
                count++;
            }
        }
    }

    printf("%d",count);

    return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
int kumi(int n){
    int a,b,c,d,cnt=0;
    for(a=0;a<=9;a++){
        for(b=0;b<=9;b++){
            for(c=0;c<=9;c++){
                for(d=0;d<=9;d++){
                    if(a+b+c+d==n){
                        cnt++;
                    }
                }
            }
        }
    }
    return cnt;
    
}
int main(void){
    int n,result;
    while(scanf("%d",&n)!=EOF){
        result=kumi(n);
        printf("%d\n",result);
    }
    return 0;
}

Measured memory_bytes: 596
import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();
		sc.close();
		
		for (int i=1 ; i<=n ; i++) {
			//System.out.printf("");
			int x=i;
			
			if (x%3==0) {
				System.out.printf(" "+i);
			}else {
				while(true) {
					if (x==0) {
						break;
					}
					if (x%10==3) {
						System.out.printf(" "+i);
						break;
					}
					x/=10;
				}
			}
		}
		System.out.printf("\n");
	}

}



Measured memory_bytes: 31536
def A():
    n, x, t = map(int, input().split())
    print(t * ((n+x-1)//x))

def B():
    n = list(input())
    s = 0
    for e in n:
        s += int(e)
    print("Yes" if s % 9 == 0 else "No")

def C():
    int(input())
    a = list(map(int, input().split()))
    l = 0
    ans = 0
    for e in a:
        if e < l: ans += l - e
        l = max(l, e)
    print(ans)

C()


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





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	bool ok = true;
	rep(i,n - 1){
		if(a.at(i + 1) > a.at(i)) a.at(i + 1)--;
		else if(a.at(i + 1) < a.at(i)) ok = false;
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
    int n;
    while(cin>>n&&n!=0){
        int x,a=0,b=0,c=0,d=0,e=0,f=0,g=0;
        for(int i=0;i<n;i++){
            cin>>x;
            if(x<10){
                a++;
            }
            else if(x>=10&&x<20){
                b++;
            }
            else if(x>=20&&x<30){
                c++;
            }
            else if(x>=30&&x<40){
                d++;
            }
            else if(x>=40&&x<50){
                e++;
            }
            else if(x>=50&&x<60){
                f++;
            }
            else if(x>=60){
                g++;
            }
        }
        cout<<a<<endl<<b<<endl<<c<<endl<<d<<endl<<e<<endl<<f<<endl<<g<<endl;
    }
    return 0;
}

Measured memory_bytes: 3072
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.List;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.Scanner;
import java.util.HashMap;
import java.util.stream.Collectors;
import java.util.function.Function;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int[] ABC = new int[]{in.nextInt(), in.nextInt(), in.nextInt()};
            HashMap<Integer, List<Integer>> collect = Arrays.stream(ABC).mapToObj(Integer::valueOf).collect(Collectors.groupingBy(Function.identity(), HashMap::new, Collectors.toList()));
            out.println(collect.getOrDefault(5, new ArrayList<>()).size() == 2 && collect.getOrDefault(7, new ArrayList<>()).size() == 1 ? "YES" : "NO");
        }

    }
}



Measured memory_bytes: 27348
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class ERotationMatching {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll n, m; cin >> n >> m;
      set<ll> st;
      set<ll> used;
      ll a = 1;
      ll b = n;
      rep(i, m) {
        auto k = min(abs(b-a), n-abs(b-a));
        if (st.find(k) != st.end() || k*2 == n) {
          b--;
          k = min(abs(b-a), n-abs(b-a));
        }
        assert(st.find(k) == st.end());
        assert(used.find(a) == used.end());
        assert(used.find(b) == used.end());
        assert(a != b);
        assert(1 <= a && a <= n);
        assert(1 <= b && b <= n);
        st.insert(k);
        used.insert(a); used.insert(b);
        cout << a << ' ' << b << '\n';
        a++; b--;
      }
    }
};

signed main() {
  ERotationMatching solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 16088
#include<bits/stdc++.h>
using namespace std;
long long  pow(long long  a,long long b)
{
    int re=0;
    for(int i=1;i<=b;i++)
        re+=a;
    return re;
}
int main()
{
  long long a,b,base,s;
  cin>>base>>a>>b;
  for(long long i=1;;i++)
  {s=pow(base,i);
   if(s>=a&&s<=b){cout<<"OK"<<endl;break;}
   else if(s>b){cout<<"NG"<<endl;break;}
  }
}


Measured memory_bytes: 3596
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	string s, t, u; cin >> s >> t >> u;
	cout << (s.back() == t[0] && t.back() == u[0] ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    //final List<Long> list = new ArrayList<>();
    //final List<Long> list2 = new ArrayList<>();

    int n = sc.nextInt();
    int x = sc.nextInt();
    int t = sc.nextInt();

    int a = n / x ;
    if(n % x == 0){
        System.out.println(n / x * t);
    }else{
        System.out.println((n / x + 1) * t);
    }

    





}
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> h(n);
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    bool flag = true;
    for(int i=n-1; i>=1; i--){
        if(h[i]-h[i-1]==-1){
            h[i-1] -= 1;
        }else if(h[i-1]>h[i]){
            flag = false;
            break;
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var test = new Test();
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            Console.WriteLine(test.CountContainWords(s, "ABC"));
        }

        public int CountContainWords(string source, string word)
        {
            var count = 0;
            var loopCount = source.Length - (word.Length - 1);
            for (var i = 0; i < loopCount; i++)
            {
                if (source.Substring(i, word.Length) == word)
                {
                    count++;
                }
            }
            return count;
        }
    }
}

Measured memory_bytes: 11092
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);


int n;
string s, ss;
int ans;
int main() {
	cin >> n >> s;
	REP(i, n) {
		cin >> ss;
		bool ok = false;
		REP(first, ss.size())FOR(haba, 1, ss.size())REP(num, s.size()) {
			if (first + haba*num >= ss.size())break;
			if (s[num] != ss[first + haba*num])break;
			if (num == s.size() - 1 && !ok) {
				ans++;
				ok = true;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3144
from itertools import permutations

import numpy as np
from numba import njit, i8


@njit(i8[:, :](i8, i8, i8[:, :], i8[:, :]), cache=True)
def calc_cost(N, C, D, c):
    cost = np.zeros((C, 3), dtype=np.int64)
    for i in range(N):
        for j in range(N):
            for k in range(C):
                cost[k][(i + j) % 3] += D[c[i][j] - 1][k]
    return cost


N, C, *Dc = map(int, open(0).read().split())
D = np.array(Dc[: C * C], dtype=np.int64).reshape(C, C)
c = np.array(Dc[C * C :], dtype=np.int64).reshape(N, N)
cost = calc_cost(N, C, D, c)

ans = min(
    sum(cost[c][i] for i, c in enumerate(colors))
    for colors in permutations(range(C), 3)
)
print(ans)


Measured memory_bytes: 126696
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	ll x,y; cin>>x>>y;
	ll x_ = -x, y_ = -y;
	ll ans = INF;
	ll t;
	t = y-x; if(t<0)t = INF;
	ans = min(ans, t);
	t = y_ - x_ + 2; if(t<0)t = INF;
	ans = min(ans, t);
	t = y - x_ + 1; if(t<0)t = INF;
	ans = min(ans, t);
	t = y_ - x + 1; if(t<0)t = INF;
	ans = min(ans, t);
	cout<<ans<<endl;
}

// int main(){
// 	ll x,y; cin>>x>>y;
// 	if(abs(x)<abs(y)){
// 		if(x<0 && y<0){
// 			cout<<abs(y)-abs(x)+2<<endl;
// 		}else{
// 			cout<<abs(y)-abs(x) + (x<0 || y<0)<<endl;
// 		}
// 	}else if(abs(y) > abs(x)){
// 		if(x>=0 && y>=0){cout<<abs(x)+abs(y)+1<<endl;}
// 		else if(x>=0 && y<0){cout<<x+y+1<<endl;}
// 		else if(x<0 && y>=0){cout<<abs(x)+abs(y)<<endl;}
// 		else if(x<0 && y<0){cout<<abs(x)-abs(y)<<endl;}
// 	}else{
// 		if((x>=0 && y>=0) || (x<0 && y<0))cout<<0<<endl;
// 		else cout<<1<<endl;
// 	}
// 	return 0;
// }

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define M  1046527
#define L  14
char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}



long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
    return key % M;
    }
    
int h2(int key){
    return 1+(key % (M-1));
    }
    
int find(char str[]){
    long long i, key, h;
    key = getKey(str);
    for(i = 0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str) == 0){
            return 1;
        }else if(strlen(H[h]) == 0){
            return 0;
        }
    }
    return 0;
}
int insert(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i = 0;;i++){
        h = (h1(key) + i * h2(key) ) % M;
        if(strcmp(H[h],str) == 0){
            return 1; 
        }else if(strlen(H[h]) == 0){
            strcpy(H[h], str);
            return 0; 
        }
    }
    return 0; 
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  cin>>n;
  for ( i = 0; i < n; i++ ){
   cin>>com>>str;

    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str) ){
        cout<<"yes"<<endl;
      } else {
        cout<<"no"<<endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 17424
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;

int main() {
#ifdef kvutxdy
    freopen("C:/Users/khanh/OneDrive/RoadtoPurple/Code/test/input.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, D, A, res = 0;
    cin >> n >> D >> A;
    vector<pair<ll, ll>> m(n);
    for (auto &i : m) cin >> i.fi >> i.se;
    sort(m.begin(), m.end());
    queue<pair<ll, ll>> Q;
    ll debuff = 0LL;
    for (auto &mons : m) {
        while (!Q.empty() && Q.front().se < mons.fi) {
            debuff -= Q.front().fi;
            Q.pop();
        }
        mons.se -= debuff;
        if (mons.se > 0) {
            ll k = mons.se / A;
            if (mons.se % A) ++k;
            Q.push(make_pair(k * A, mons.fi + 2LL * D)); 
            debuff += k * A;
            res += k;
        }
    }
    cout << res;
}

Measured memory_bytes: 4992
N = int(input())
xpy = [0]*N
xmy = [0]*N
for i in range(N):
  x,y = map(int, input().split())
  xpy[i] = x+y
  xmy[i] = x-y
xpy.sort()
xmy.sort()
print(max(xpy[-1]-xpy[0],xmy[-1]-xmy[0]))

Measured memory_bytes: 25724
#include<stdio.h>
int main(void){
  int i,f=1;
  char n,f_n;
  scanf("%c",&f_n);
  for(i=0;i<3;i++){
    scanf("%c",&n);
    if(f_n==n){
      f=0;
    }
    f_n=n;
  }
  if(f==1){
    printf("Good");
  }else{
    printf("Bad");
  }
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void) {
	int x, y, i;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	scanf("%d%d", &x, &y);
	if (x > y) {
		printf("a > b\n");
	}else if(x < y){
		printf("a < b\n");
	}
	else {
		printf("a == b\n");
	}







	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 2104
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const long long INF = 1e18;
const double PI = 2 * asin(1);

int main(){
  int N; cin >> N;
  vector <int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  int ans = 0, now = 1;

  for (int i = 0; i < N; i++){
    if (A[i] == now){
      now++;
    }else{
      ans++;
    }
  }
  
  if (ans == N){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
  


  return 0;
}


Measured memory_bytes: 1024
count,ans,point = 1,0,0
n = int(input())
t = list(map(int,input().split()))
for i,j in enumerate(t):
	if j == count:
		ans += i - point
		point = i + 1
		count += 1
if not point == n:
	ans += n - point
if count == 1:
	try:
		t.index(1)
	except:
		ans = -1
print(ans)


Measured memory_bytes: 26140
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//WA

int main(void){
	int a,b;
	cin>>a>>b;
	if(a==0 || b==0){
		printf("Zero\n");
	}else if(a>0){
		printf("Positive\n");
	}else if(b>0){
		printf("Zero\n");
	}else{
		if((b-a)%2==1){
			printf("Positive\n");
		}else{
			printf("Negative\n");
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

int f[N],d[N],color[N],id[N][N],time,n;

void visit(int u){
  int i;
  color[u] = GRAY;
  d[u] = ++time;
  for(i=1 ; i<=n ; i++){
    if(id[u][i] == 1){
      if(color[i] == WHITE) visit(i);
    }}
  color[u] = BLACK;
  f[u] = ++time;
} 



void dfs(void){
  int i;
  for(i=1 ; i<=n ; i++){
    color[i] = WHITE;
  }
  time = 0;
  for(i=1 ; i<=n ; i++){
    if(color[i] == WHITE) visit(i);
  }
}

 
int main(){
  int u,k,v,i,j;
    
  scanf("%d",&n);
  for(i=1 ; i<=n ; i++){
    for(j=1 ; j<=n ; j++){
      id[i][j] = 0;
    }}
    
  for(i=1 ; i<=n ; i++){
    scanf("%d%d",&u,&k);
    for(j=1 ; j<=k ; j++){
      scanf("%d",&v);
      id[u][v] = 1;
    }
  }

  dfs();
  
  for(i=1 ; i<=n ; i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}

  



Measured memory_bytes: 2048