akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;

int main() {
  double n, m;
  cin>>n>>m;
  double c = 1 - pow(2,-m);
  cout << round((m*1900 + (n-m)*100)/pow(2,m)*(c/pow(1-c,2)+1/(1-c))) << endl;
  return 0;
}


Measured memory_bytes: 640
#include  <stdio.h>

int main()
{
    int a,b;
        scanf("%d %d",&a,&b);
    if(a<b || a==b) {
        int x = 1;
        printf("%d",x);
    }
    if(b<=a && a%b>0) {
        printf("%d",(a/b)+1);
    }
    if(a%b == 0 && a!=b) {
        printf("%d",a/b);
    }
    
    return 0;
}

Measured memory_bytes: 1708
N,M=map(int,input().split())
A=list(map(int,input().split()))
a=0
for i in A:
    a+=i
b=a/(4*M)
c=0
for n in range(0,N):
    if A[n]>=b:
        c+=1
if c>=M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define int long long 
signed main() {
int n;
cin>>n;
int a[n];
int mn=0;
for(int i=0;i<n;i++)
{
  cin>>a[i];
}
mn=a[0];
int flag=1;
for(int i=1;i<n;i++)
{
if(a[i]<a[i-1])
{
      if(a[i]<a[i-1]-1)
      {
           flag=0 ;
            break;
      }
      else
      {
        if(a[i-1]-1<mn)
        {
          flag=0;
          break;
        }
        mn=a[i-1]-1;
      }
}
}
if(flag)
{
  cout<<"Yes"<<endl;
}
else
{
  cout<<"No"<<endl;
}

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repe(i,n) for(int i=0;i<n;i++)
#define repa(i,j,n) for(int i=j;i<n;i++)
//#define v.all() v.begin(),v.end()
#define repr(i,n) for(int i=n;i>=0;i--)
#define int long long int
#define vi vector<int>
#define vpi vector<pair<int,int>>
int gcd(int a,int b){
	if(b==0) return a;
	else return gcd(b,a%b);
}

signed  main(){
	int t=1;
	//cin>>t;
	while(t--) {
		int n;
		cin>>n;
		vpi std(n);
		rep(i,n) {
			cin>>std[i].first;
			std[i].second=i+1;
		}
		sort(std.begin(), std.end());
		rep(i,n) cout<<std[i].second<<" ";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 4716
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(ix,a) for(auto& (ix) : (a) 
int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  ll ans =0;
  ans+=(a/(b+c))*b;
  ll mod = (a%(b+c));
  if(mod>b)ans+=b;
  else
  {ans+=mod;}
  
  cout<<ans<<endl;
}

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

typedef long long ll;

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

    int h, n, w = -1;
    for(h = 1; h <= 3500; h++){
        for(n = 1; n <= 3500; n++){
            ll a = N*h*n;
            ll b = 4*n*h - N*n - N*h;
            if(b && a/b > 0 && a/b <= 3500 && a%b == 0){
                w = (int)(a/b);
                break;
            }
        }
        if(w != -1) break;
    }

    cout << h << " " << n << " " << w << endl;

    return 0;
}

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

vector<int> lang[100001];
vector<int> can_talk[100000]; //人iが話せる言語のvector
bool use[100001] = {}; //言語iを使ったか
bool human[100001] = {}; //この人は見たか

void dfs(int p, int s){
    human[s] = true;
    rep(i, can_talk[s].size()){
        if(use[can_talk[s][i]]) continue;
        use[can_talk[s][i]] = true;
        int l = can_talk[s][i];
        rep(j, lang[l].size()){
            if(human[lang[l][j]]) continue;
            dfs(s, lang[l][j]);
        }
    }
}

int main(void){
    int N, M; cin >> N >> M;
    //言語iについて人から辺を伸ばしたとき、その言語に人がいれば会話ができる
    rep(i, N){
        int K; cin >> K;
        rep(j, K){
            int l; cin >> l;
            lang[l].push_back(i);
            can_talk[i].push_back(l);
        }
    }
    dfs(-1, 0);
    bool ok = true;
    rep(i, N) if(!human[i]) ok = false;
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int n,k;
  cin>>n>>k;
  ll ans = k;
  for(int i=1;i<n;i++){
  	ans*=(k-1);
  }
  cout<<ans<<endl;
}









Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)
def lcm(a, b):
    return (a * b // gcd(a, b))

l = A[0]
for i in range(1, N):
    l = lcm(l, A[i])

def my_pow(base, n, mod):
    if n == 0:
        return 1
    x = base
    y = 1
    while n > 1:
        if n % 2 == 0:
            x *= x
            n //= 2
        else:
            y *= x
            n -= 1
        x %= mod
        y %= mod
    return x * y % mod

ans = 0
for a in A:
    ans += my_pow(a, MOD - 2, MOD)
print((ans * l)% MOD)

Measured memory_bytes: 75888
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
*/
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)
 
#define pb              push_back
#define mp              make_pair
 
#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))
 
#define ff              first
#define ss              second
 
#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)
 
#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())
 
#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )
#define RFOR(i,e,s)     for( LL i = e ; i>=s ; i-- )
         
 
#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("WA.txt","w",stdout)
 
#define DEBUG(x)        cerr<<#x<<" = "<<x<<endl
#define PRINTALL(v)     {cerr<<endl<<"Printing: "<<#v<<endl;for(LL i = 0 ; i<v.size(); i++) DEBUG(v[i]); cerr<<endl;}
 
using namespace std;


char g[10][10];

int main(){
	
	LL N,M,K;
	SL(N);  SL(M); SL(K);
	
	FOR(i,0,N-1) scanf(" %s",&g[i][0]);
	
	LL ans = 0;
	for( LL row = 0 ; row<(1LL<<N) ; row++ ){
		for( LL col = 0 ;col<(1LL<<M); col++ ){
			LL cnt = 0;
			FOR(i,0,N-1)FOR(j,0,M-1){
				if( row&(1LL<<i) ) continue;
				if( col&(1LL<<j) ) continue;
				if(g[i][j]=='#') cnt++;
			}
			if(cnt==K) ans++;
		}
	}
	
	cout<<ans<<endl;
	
	
return 0;}





Measured memory_bytes: 3660
#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 <stack>
 #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.14159265358979323846264;
 const int mod=1000000007;

int main(){
	LL a,b,c;
	cin>>a>>b>>c;
	LL ans=0;
	LL t=min(b,c);
	ans+=2*t;
	b-=t;
	c-=t;
	if(c>0){
		if(a>=c){
			ans+=c;
			c=0;
		}else{
			ans+=a;
			c-=a;
		}
	}else{
		ans+=b;
	}
	if(c>0){
		ans+=1;
	}
	cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
# import sys
# from sys import stdin
# input = stdin.readline

INF = 10**9

s = input()
t = input()
ans = INF
for i in range(len(s) - len(t) + 1):
  cnt = 0
  for j in range(len(t)):
    if (s[i+j] != t[j]): 
      cnt += 1
  ans = min(ans, cnt)
print(ans)

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

int N;
int A[3][100001];
LL dp[3][100001] = {};

int main() {
    scanf("%d", &N);
    rep(j, 3) { rep(i, N) scanf("%d", &A[j][i]); A[j][N] = 1000000001; }
    rep(j, 3) sort(A[j], A[j] + N);
    rep(i, N + 1) dp[0][i] = i;
    rep(j, 2) {
        int p = 0;
        rep(i, N) {
            while (A[j][p] < A[j + 1][i]) p++;
            dp[j + 1][i + 1] += dp[j + 1][i] + dp[j][p];
        }
    }
    printf("%lld\n", dp[2][N]);
    return 0;
}

Measured memory_bytes: 7308
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main() {
  string s, t;
  cin >> s >> t;
  bool poss = true;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != t[i]) poss = false;
  }
  if (s.size() + 1 != t.size()) poss = false;
  cout << (poss ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int n = Integer.parseInt(s);
		
		int sum = 0;
		for(int i = 0; i < s.length(); i++) {
			int digit = Integer.parseInt(s.substring(i , i+1));
			sum += digit;
		}
		
		if((n % sum) == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}
}

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

using namespace std;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) {
            par[i] = i;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) {
            return x;
        }

        return par[x] = root(par[x]); 
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) {
            return; //xとyの根が同じ(=同じ木にある)時はそのまま
        }

        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main() {
    int N;
    cin >> N;
    
    long long x, y;
    vector<pair<long long, int>> X, Y;


    for(int i = 0; i < N; i++) {
        cin >> x >> y;
        X.push_back(make_pair(x, i));
        Y.push_back(make_pair(y, i));
    }

    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    // クラスカル法
    priority_queue<tuple<long long, int, int>> S;
    tuple<long long, int, int> tmp;

    for(int i = 0; i < N-1; i++) {
        S.push(make_tuple(-abs(X[i].first - X[i+1].first), X[i].second, X[i+1].second));
        S.push(make_tuple(-abs(Y[i].first - Y[i+1].first), Y[i].second, Y[i+1].second));
    }

    // UnionFind木を使って集合を管理
    UnionFind F(N);

    long long answer = 0;

    // クラスカル法
    while(S.empty() == false) {
        tmp = S.top();
        S.pop();

        // 違うUnion-Find木に属していた場合結合し、辺の重みを合計する
        if(F.same(get<1>(tmp), get<2>(tmp)) == false) {
            F.unite(get<1>(tmp), get<2>(tmp));
            answer += -get<0>(tmp);
        }
    }

    cout << answer << endl;

	return 0;
}

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

const int maxn = 3005;
const double pi = acos(-1), eps = 1e-10;

int n, L;
double alpha[maxn], ansx, ansy;

double midpoint(double x1, double x2)
{
	double len = x2 - x1;
	if (len < -eps) len += 2. * pi;
	len /= 2.;
	double mid = x1 + len;
	if (mid >= 2. * pi - eps) mid -= 2. * pi;
	return mid;
}

int main()
{
	scanf("%d%d", &n, &L);
	for (int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		alpha[i] = 2. * pi * x / L;
	}

	for (int i = 0; i < n; ++i) {
		double nowx = 0., nowy = 0.;
		for (int j = (i + 1) % n, k = 0; j != i; j = (j + 1) % n, ++k) {
			double m = midpoint(alpha[j], alpha[i]), arg = alpha[j] - alpha[i];
			double vecx = cos(alpha[i]) - cos(m), vecy = sin(alpha[i]) - sin(m);
			ansx += cos(m) * k, ansy += sin(m) * k;
			ansx += vecx * nowx - vecy * nowy, ansy += vecx * nowy + vecy * nowx;
			if (arg < -eps) arg += 2. * pi;
			nowx += cos(arg / 2.); nowy += sin(arg / 2.);
		}
	}

	ansx /= 0.5 * n * (n - 1) * (n - 2), ansy /= 0.5 * n * (n - 1) * (n - 2);
	printf("%.10lf %.10lf\n", ansx, ansy);
	
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
	int t[200000];
int main(){

	int N=0;//人数
	int T=0;//出る秒数
	int X=0;//出る総
	
	int i=0;
	
	cin>>N>>T;
	
	for(i=0;i<N;i++){
		cin>>t[i];
	}
	
	for(i=0;i<N-1;i++){
		if(T>t[i+1]-t[i]){
			X=X+t[i+1]-t[i];
		}else{
			X=X+T;
		}
	}
	X=X+T;	

        cout<<X;



}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if( a > b){
			System.out.println("a > b");
		}else
			if(a < b){
				System.out.println("a < b");
			}else{
				System.out.println("a == b");
			}
		sc.close();	
	}
}


Measured memory_bytes: 26232
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define prin(a) cout<<(a)<<endl
using ll=int64_t;
using namespace std;

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

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


int main(){
    int n;
    string s;
    cin>>n>>s;
    bool ok=true;
    if(n%2==1){
        ok=false;
    }
    else{
        string t,u;
        t=s.substr(0,(n/2));
        u=s.substr((n/2),(n/2));
        if(t!=u) ok=false;
    }
    cout<<(ok? "Yes": "No")<<endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

def count_diff2(a,b):
    cnt = 0
    for c1,c2 in zip(a, b):
        if c1 != c2:
            cnt += 1
    return cnt

temp = 0
ans = len(T)

for i in range(len(S)-len(T) + 1) :
    temp = count_diff2(T, S[i:len(T) + i])
    if temp < ans:
        ans = temp

print(ans)

Measured memory_bytes: 9000
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<cmath>
#define maxn 100010
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
int a[maxn];
map<int,int>ma;
bool check()
{
    for(int i=2;i<=n;i++)
    {
        if(a[i]!=a[i-1])  return false;
    }
    return true;
}
bool checkx()
{
    int p1=0,p2=0;
    int res=0;
    for(int i=1;i<=n;i++)
    {
        if(ma[a[i]]==0)
        {
            res++;
            ma[a[i]]=1;
            if(p1)  p2=a[i];
            else    p1=a[i];
        }
    }
    if(res>2)  return true;
    if(abs(p1-p2)==1&&res==2)  return false;
    if(res==1)  return false;
    return true;
}
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    if(checkx()==true)
    {
        puts("No");
        return 0;
    }
    if(check()==true)
    {
        if(a[1]==n-1){
            puts("Yes");
        }
        else{
            if(n/a[1]<2)  puts("No");
            else puts("Yes");
        }
        return 0;
    }
    int lim=0;
    for(int i=1;i<=n;i++)  lim=max(lim,a[i]);
    int sum=n;
    for(int i=1;i<=n;i++)  if(a[i]==lim-1)  sum--;
    if(lim-(n-sum)<=0){
        puts("No");
        return 0;
    }
    if(sum/(lim-(n-sum))<2)  puts("No");
    else puts("Yes");
    return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e5+5;
ll a[N];int n; 
bool chmn(ll x){
	for(int i=1;i<=n;i++){
		x -=x%a[i];
	}
	if(x>=2)return true;
	return false;
}
bool chmx(ll x){
	for(int i=1;i<=n;i++){
		x -=x%a[i];
	}
	if(x>2)return true;
	return false;
}
void solve(){
	cin>>n; 
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	ll st = 1;
	ll en = 1e18;
	while(st<=en){
		ll mid=  (st+en)/2;
		if(chmn(mid)){
			en = mid-1;
		}
		else{
			st = mid+1;
		}
	}
	ll mn = st;
	st = 1;
	en = 1e18;
	while(st<=en){
		ll mid=  (st+en)/2;
		if(chmx(mid)){
			en = mid-1;
		}
		else{
			st = mid+1;
		}
	}
	ll mx = st-1ll;
	if(mx<mn){
		cout<<-1<<endl;
		return ;
	}
	cout<<mn<<" "<<mx<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 4412
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
#define endl '\n'
#define F first
#define S second
const int MAX_N=55;
const ll MAX_K=1e18+18;
const int LOG_K=64;
const int MOD=1000000007;

int n;
ll K;
struct Mat
{
	int sz;
	vector<vector<ll>> a;
	Mat(){}
	Mat(int t):sz(t),a(t,vector<ll>(t)){}
	static Mat BASE(int t)
	{
		Mat rtn(t);
		for(int i=0;i<t;i++) rtn.a[i][i]=1;
		return rtn;
	}
	ll sum()
	{
		ll rtn=0;
		for(auto &i:a) for(auto &j:i) rtn=(rtn+j)%MOD;
		return rtn;
	}
} a, ans;
Mat operator + (const Mat &l, const Mat &r)
{
	Mat rtn(l.sz);
	for(int i=0;i<l.sz;i++) for(int j=0;j<l.sz;j++)
		rtn.a[i][j]=(l.a[i][j]+r.a[i][j])%MOD;
	return rtn;
}
Mat operator * (const Mat &l, const Mat &r)
{
	Mat rtn(l.sz);
	for(int i=0;i<l.sz;i++) for(int j=0;j<l.sz;j++) for(int k=0;k<l.sz;k++)
		rtn.a[i][j]=(rtn.a[i][j]+l.a[i][k]*r.a[k][j])%MOD;
	return rtn;
}
Mat fpw(Mat x, ll y)
{
	Mat rtn=Mat::BASE(x.sz);
	while(y)
	{
		if(y&1) rtn=rtn*x;
		x=x*x;
		y>>=1;
	}
	return rtn;
}

int main()
{
	scanf("%d%lld",&n,&K);
	a=Mat(n);
	ans=Mat::BASE(n);
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%lld",&a.a[i][j]);
	printf("%lld\n",fpw(a,K).sum());
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll ans = 0;
ll N;
vector<l_l> v;
ll Rmin[100050];
ll LLeft[100050], RLeft[100050], LRight[100050], RRight[100050];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    v.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> v[i].first >> v[i].second;
        //chmax(ans, v[i].second - v[i].first + 1);
        //v[i].second *= -1;
    }
    LLeft[0] = v[0].first;
    RLeft[0] = v[0].second;
    for(int i = 1; i <= N - 1; i++) {
        LLeft[i] = max(LLeft[i-1], v[i].first);
        RLeft[i] = min(RLeft[i-1], v[i].second);
    }
    LRight[N] = 0;
    RRight[N] = 2e9;
    for(int i = N - 1; i >= 0; i--) {
        LRight[i] = max(LRight[i+1], v[i].first);
        RRight[i] = min(RRight[i+1], v[i].second);
    }
    for(int i = 0; i <= N - 1; i++) {
        ll nowans = v[i].second - v[i].first + 1;
        ll Rmin = 2e9;
        ll Lmax = 0;
        if(i > 0) {
            chmin(Rmin, RLeft[i-1]);
            chmax(Lmax, LLeft[i-1]);
        }
        if(i < N - 1) {
            chmin(Rmin, RRight[i+1]);
            chmax(Lmax, LRight[i+1]);
        }
        nowans += max(Rmin - Lmax + 1, 0LL);
        chmax(ans, nowans);
    }
    for(int i = 0; i < N; i++) {
        v[i].second *= -1;
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < N; i++) {
        v[i].second *= -1;
    }
    Rmin[N] = 1e9;
    for(int i = N - 1; i >= 0; i--) {
        Rmin[i] = min(Rmin[i+1], v[i].second);
    }
    set<ll> st;
    st.insert(2e9);
    for(int i = 0; i < N - 1; i++) {
        //cerr << "---" << i << "---" << endl;
        st.insert(v[i].second);
        /*
        for(auto val : st) cerr << val << " ";
        cerr << endl;
        cerr << "----------" << endl;
        */
        auto itr = st.lower_bound(v[i+1].first);
        if(*itr == 2e9) itr--;
        //cerr << *itr << " " << v[i+1].first << endl;
        //cerr << Rmin[i+1] << endl;
        //if(itr != st.begin()) itr--;
        ll nowans = max(*itr - v[i].first + 1, 0LL);
        ll subans = 0;
        subans = Rmin[i+1];
        if(itr != st.begin()) {
            itr--;
            if(itr != st.end()) {
                chmin(subans, *itr);
            }
        }
        //cerr << subans << endl;
        //cerr << nowans << " " << subans << endl;
        subans -= v.back().first;
        subans++;
        chmax(subans, 0LL);
        //cerr << nowans << " " << subans << endl;
        chmax(ans, nowans + subans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10368
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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);
        ABC152_b solver = new ABC152_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC152_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int cyc = 0;
            if (a <= b) {
                cyc = b;
                for (int i = 0; i < cyc; i++) {
                    out.print(a);
                }
            } else {
                cyc = a;
                for (int i = 0; i < cyc; i++) {
                    out.print(b);
                }
            }
            out.println();
        }

    }
}



Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    // true:先頭,false:末尾
    vector<pair<int,char>> v;
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    int turned = 0;
    REP(_,Q) {
        int q;
        cin >> q;
        if(q==1) turned++;
        else {
            int f;
            char c;
            cin >> f >> c;
            bool is_ushiro = (f==2);
            int add = is_ushiro ? -1 : 0;
            v.emplace_back(turned+add, c);
        }
    }
    if (turned%2==1) {
        REP(i,S.size()/2) iter_swap(S.begin()+i,S.end()-1-i);
    }
    for (const auto &it: v) {
        ll place = (turned-it.first);
        bool is_mae = place%2==0;

        if(is_mae) {
            auto beg = S.begin();
            S.insert(beg,it.second);
        } else {
            S.push_back(it.second);
        }
    }
    cout << S << endl;

}


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


Measured memory_bytes: 2928
n, m = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(n)]
vec = [int(input()) for _ in range(m)]
ans = [0]*n
for i, row in enumerate(mat):
    for j in range(m):
        ans[i] += row[j] * vec[j]
[print(ans[i]) for i in range(n)]


Measured memory_bytes: 6016
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    a,b,c,d=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    ans=max(a*c,a*d,b*c,b*d)
    print(ans)
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 16220
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        int n=scanner.nextInt();
        HashMap<Long, Long> map
                = new HashMap<>();
        long sum =0;
        for(int j=0;j<n;j++)
        {
            Long temp=scanner.nextLong();
            if(map.containsKey(temp))
            {
                Long x =map.get(temp);
                x++;
                map.put(temp,x);
            }
            else
            {
                map.put(temp, (long) 1);
            }
            sum+=temp;
        }

        long q= scanner.nextLong();
        for(int j=0;j<q;j++)
        {
            Long b=scanner.nextLong();
            Long c=scanner.nextLong();
            if(map.containsKey(b))
            {
                Long x;
                if(map.containsKey(c))
                {
                    x = map.get(b);
                    sum-=b*map.get(b);
                    Long y=map.get(c);
                    y+=x;
                    sum+=x*c;
                    map.put(c,y);
                }
                else
                {
                    x = map.get(b);
                    sum-=b*map.get(b);
                    map.put(c,x);
                    sum+=c*x;
                }
                map.remove(b);

            }
            System.out.println(sum);
        }
	// write your code here
    }
}


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

using namespace std;

int main(){
        int N, K;
        cin>>N>>K;
        vector <int> p;
        for(int i=0;i<N;i++){
                int pp;cin>>pp;
                p.push_back(pp);
        }
        int res=0;
        sort(p.begin(), p.end());
        for(int i=N-1;i>N-K-1;i--){
                res+=p[i];
        }
        cout<<res<<endl;
        return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b

i=0
rr=[]
for R in s:
    if R=='R':
        rr.append(i)
    i+=1

j=0
gg=[]
for G in s:
    if G=='G':
        gg.append(j)
    j+=1

for rrr in rr:
    for ggg in gg:
        tmp=abs(rrr-ggg)
        if tmp%2==0:
            if max(rrr,ggg)+tmp<n:
                if s[max(rrr,ggg)+tmp]=='B':
                    ans-=1
            if s[(rrr+ggg)//2]=='B':
                ans-=1
            if min(rrr,ggg)-tmp>=0:
                if s[min(rrr,ggg)-tmp]=='B':
                    ans-=1
        else:
            if max(rrr,ggg)+tmp<n:
                if s[max(rrr,ggg)+tmp]=='B':
                    ans-=1
            if min(rrr,ggg)-tmp>=0:
                if s[min(rrr,ggg)-tmp]=='B':
                    ans-=1
print(ans)

Measured memory_bytes: 9276
#include<stdio.h>
#include<string.h>
int main(void)
{
    char s[201];
    char t[101];
    char p[101];
    scanf("%s", s);
    scanf("%s", p);

    strcpy(t, s);
    strcat(s, t);

    if (strstr(s, p) == NULL){
    	printf("No");
    }else{
    	printf("Yes");
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 552
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#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 <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	string s;
	cin >> s;

	if (s[0] == s[1] && s[0] == s[2]) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def spaceinput():
    return list(map(int,input().split(" ")))


M=spaceinput()
P=sorted(spaceinput())
N=spaceinput()
T=sorted(spaceinput())

false=False
k=0
for st in T:
    #print(st,k)
    for kk in range(k,len(P)):
        if st==P[kk]:
            k=kk+1
            break

        #print(P[k])

        if P[kk]>st:
            false=True
            break






if false:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 35428
n=int(input())
li=[0]*4

for i in range(n):
    s=input()
    if s == "AC":
        li[0]+=1
    if s == "WA":
        li[1]+=1
    if s == "TLE":
        li[2]+=1
    if s == "RE":
        li[3]+=1

print("AC","x",li[0])
print("WA","x",li[1])
print("TLE","x",li[2])
print("RE","x",li[3])

Measured memory_bytes: 74740
#include <iostream>
using namespace std;
int main()
{
	char b;
	cin >> b;
	if (b == 'A')
		cout << 'T';
	else if (b == 'T')
		cout << 'A';
	else if (b == 'C')
		cout << 'G';
	else if (b == 'G')
		cout << 'C';	
	return 0;
} 

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

int main(){
    int a,b;
    char op;
    while ((bool) true){
        cin >> a >> op >> b;
        if(op == '+'){
            cout << a+b << endl;
        }
        else if(op == '-'){
            cout << a-b << endl;
        }
        else if(op == '*'){
            cout << a*b << endl;
        }
        else if (op == '/'){
            cout << a/b << endl;
        }
        else{
            break;
        };
    }
    return 0;  
    
}


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();		//勇者の人数
		int a[]= new int[n+1];
		int b[]= new int[n];
		
		for(int i=0;i<n+1;i++) {	//n+1の町にいるモンスター
		    a[i]=sc.nextInt();		//モンスターの数
		}
		
		for(int i=0;i<n;i++) {
		    b[i]=sc.nextInt();		//勇者が倒せる数
		}
		
		long count=0;
		for(int i=0;i<n;i++) {
		    if (b[i]<=a[i]) {
		        count+=b[i];
		    } else {
		        b[i]-=a[i];
		        count+=a[i];
		        
		        int ans= Math.min(a[i+1], b[i]);
		        count+=ans;
		        a[i+1]-=ans;
		    }
		}
		System.out.println(count);
		sc.close();
	}
}


Measured memory_bytes: 50048
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
	string s;
	cin >> s;
	vector<bool> flag(26, 0);
	for (char a : s) {
		flag[a - 'a'] = true;
	}
	for (int i = 0; i < 26; ++i) {
		if (flag[i] == false) {
			char ans = 'a' + i;
			cout << ans << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 998244353ll 
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std;
#define pi (long double)3.14159265358979323846 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 struct sch{
	ll s,e,t;
};
bool sortinrev(const struct sch &a, const struct sch &b) 
{ 
    return (a.s < b.s); 
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll power(ll x,  ll y, ll m); 
ll modInverse(ll a, ll m) 
{ 
    return power(a, m-2, m); 
} 
ll power(ll x,  ll y,  ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 
int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	if(m==1)
	{
		if(k==n-1)
		{
			cout<<1<<endl;
		}
		else
		{
			cout<<0<<endl;
		}
		return 0;
	}
	ll fi = power(m-1,n-1,MOD);
	fi *= m;
	fi %= MOD;
	ll ans=fi;

//	cout<<fi<<endl;
	for(ll i=0;i<k;i++)
	{
		fi *= (n-i-1);
		fi %= MOD;
		fi *= modInverse(m-1,MOD);
		fi %= MOD;
		fi *= modInverse(i+1,MOD);
		fi %= MOD;
		//cout<<fi<<endl;
		ans += fi;
		ans %= MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3588
var input: string = require('fs').readFileSync('/dev/stdin', 'utf8');
var inputLines: string[] = input.trim().split("\n");
var parts = inputLines[0].split(" ");

var count5 = 0;
var count7 = 0;
parts.forEach((part) => {
    var n = parseInt(part);
    if (n == 5) {
        count5 += 1;
    } else if (n == 7) {
        count7 += 1; 
    }
});
console.log(count5 == 2 && count7 == 1 ? "YES" : "NO");

Measured memory_bytes: 7372
#include <cstdio>
#include <utility>
#include <algorithm>

using namespace std;

const int N = 200'009;

pair<int, int> a[N];
int ans[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  sort(a, a + n);
  for (int i = 0; i < n; ++i) {
    if (i >= n / 2) {
      ans[a[i].second] = a[n / 2 - 1].first;
    } else {
      ans[a[i].second] = a[n / 2].first;
    }
  }
  for (int i = 0; i < n; ++i) {
    printf("%d\n", ans[i]);
  }
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807

//子から親を求める演算
auto calc_parent = [](ll x, ll y) { return x+y; };
//親遅延配列を子に伝播する演算
auto calc_lazychild = [](ll &x,ll y) { x+=y/2; };
//遅延配列をノードに反映する演算
auto lazy_to_node = [](ll &x,ll y) { x+=y; };
//遅延配列に値を入れる演算 y-値 l,r-区間index
auto intolazy = [](ll &x,ll y,ll r,ll l) { x+=(r-l)*y; };
//単位元
const ll unit = 0;

struct LazySegTree
{
private:
  ll n;
  vector<ll> node,lazy;
  vector<bool> islazy;

public:
  LazySegTree(vector<ll> v)
  {
    node.resize((1LL << 64 - __builtin_clzll(v.size())) * 2 - 1, unit); 
    lazy.resize((1LL << 64 - __builtin_clzll(v.size())) * 2 - 1, unit); 
    islazy.resize((1LL << 64 - __builtin_clzll(v.size())) * 2 - 1, 0); 

    n = 1LL << 64 - __builtin_clzll(v.size());
    for (ll i = 0; i < v.size(); i++)
      node[i + n - 1] = v[i]; //最下段から構築
    for (ll i = n - 2; i >= 0; i--)
      node[i] = calc_parent(node[2 * i + 1], node[2 * i + 2]);
  }
  
  // k 番目のノードについて遅延評価を行う
  void eval(int k, int l, int r){ 
    // 遅延配列が空でない場合、自ノード及び子ノードへの
    // 値の伝播が起こる
    if (islazy[k]){
      lazy_to_node(node[k],lazy[k]);
      // 最下段かどうかのチェック
      if (r - l > 1){
        calc_lazychild(lazy[2 * k + 1],lazy[k]);
        calc_lazychild(lazy[2 * k + 2],lazy[k]);
        islazy[2 * k + 1] = 1;
        islazy[2 * k + 2] = 1;
      }
      // 伝播が終わったので、自ノードの遅延配列を空にする
      islazy[k] = 0;
      lazy[k] = unit;
    }
  }

  void update(int a, int b, ll x, int k = 0, int l = 0, int r = -1){
    if (r < 0)
      r = n;
    // k 番目のノードに対して遅延評価を行う
    eval(k, l, r);
    // 範囲外なら何もしない
    if (b <= l || r <= a)
      return;
    // 完全に被覆しているならば、遅延配列に値を入れた後に評価
    if (a <= l && r <= b){
      intolazy(lazy[k],x,r,l);
      islazy[k] = 1;
      eval(k, l, r);
    }
    // そうでないならば、子ノードの値を再帰的に計算して、
    // 計算済みの値をもらってくる
    else{
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = calc_parent(node[2 * k + 1] , node[2 * k + 2]);
    }
  }

  // 要求区間 [a, b) 中の要素の最小値を答える k := 自分がいるノードのインデックス 対象区間は [l, r) にあたる
  ll get(ll a, ll b, ll k = 0, ll l = 0, ll r = -1)
  {
    // 最初に呼び出されたときの対象区間は [0, n)
    if (r < 0)
      r = n;
    // 要求区間と対象区間が交わらない -> 適当に返す
    if (r <= a || b <= l)
      return unit;
    // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
    // 関数が呼び出されたら評価！
    eval(k, l, r);
    if (a <= l && r <= b)
      return node[k];
    // 要求区間が対象区間の一部を被覆 -> 子について探索を行う
    // 左側の子を vl ・ 右側の子を vr としている
    // 新しい対象区間は、現在の対象区間を半分に割ったもの
    ll vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
    return calc_parent(vl, vr);
  }
};

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

vector<ll> t(n,0);
LazySegTree s(t);
vector<ll> ans;
rep(i,q){
  ll a  ;
  cin >> a  ;
  if(!a){
    ll b , c , d ;
    cin >> b >> c >> d ;
    s.update(b, c+1, d);
  }
  else {
    ll b ,c;
    cin >> b >>c;
    ans.push_back(s.get(b, c+1));
  }
}

rep(i,ans.size())cout<<ans[i]<<"\n";

return 0;
}



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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (auto &e : s) cin >> e;

  vector<vector<int>> u, d, l, r(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      r[i][j] = s[i][j] == '.';
    }
  }
  u = d = l = r;

  for (int i = 1; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (u[i][j]) u[i][j] += u[i - 1][j];
    }
  }
  for (int i = h - 2; i >= 0; i--) {
    for (int j = 0; j < w; j++) {
      if (d[i][j]) d[i][j] += d[i + 1][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 1; j < w; j++) {
      if (l[i][j]) l[i][j] += l[i][j - 1];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = w - 2; j >= 0; j--) {
      if (r[i][j]) r[i][j] += r[i][j + 1];
    }
  }

  int m = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      m = max(m, u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3);
    }
  }
  cout << m << endl;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, C;
  cin >> N >> C;

  VVI D(C, VI(C));
  cin >> D;

  VVI cnt(3, VI(C));
  REP(y,N) REP(x,N){
	int c;
	cin >> c;
	++cnt[(x+y)%3][c-1];
  }

  int ans = 1e9;
  REP(c1,C) REP(c2,C) REP(c3,C){
	if(c1 == c2 || c2 == c3 || c3 == c1) continue;
	int sum = 0;
	REP(i,C) sum += cnt[0][i] * D[i][c1];
	REP(i,C) sum += cnt[1][i] * D[i][c2];
	REP(i,C) sum += cnt[2][i] * D[i][c3];
	mini(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

s = STR()
t = Counter(s)
print(min(t['0'], t['1']) * 2)

Measured memory_bytes: 61036
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
#include<list>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    double ans = 0;
    int n; cin >> n;
    double k; cin >> k;
    int table[100007]; rep(i, 100007) table[i] = inf;
    int clock = 0;
    while (1) {
        //cout << "clock " << clock << endl;
        for (int j = k + 0.999999999; j <= n; ++j) {
            if (table[j] != inf) break;
            table[j] = clock;
        }
        clock++;
        k /= 2;
        if (k < 0.001) break; //1に引っかかるように
    }
    //rep(i, n + 1) cout << table[i] << " "; cout << endl;
    double div2[100007];
    div2[0] = 1;
    rrep(i, 1, 100008) {
        div2[i] = div2[i - 1] * 0.5;
    }
    rrep(i, 1, n + 1) {
        ans += 1.0 / n * div2[table[i]];
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, Q, W, H, T, X, Y, S;

int main()
{
    cin >> H >> W;
    vector<string> out;
    for (int i = 0; i < H; ++i) {
        string str; cin >> str;
        out.push_back(str);
        out.push_back(str);
    }
    for (auto o : out)
        cout << o << endl;

    return 0;
}

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

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

  ll K; cin >> K;
  for (ll i = 0; i < K; i++) {
    cout << "ACL";
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define iter vector<int>::iterator
#define mod 998244353



int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,k;
    cin>>n>>k;

    int h[n];
    int dp[n];

    for(int i=0;i<n;i++)
    {
    	cin>>h[i];
    }
    dp[0]=0;

    int x,m=1e9;
    for(int i=1;i<n;i++)
    {
    	for(int j=0;j<k;j++)
    	{
    		if(i-k+j>=0)
    		{
    			x=dp[i-k+j]+abs(h[i]-h[i-k+j]);

    			if(m>x)
    				m=x;
    		}
    	}
    	dp[i]=m;
    	m=1e9;
    }

    
    cout<<dp[n-1]<<"\n";
    
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include<iostream>
#include<cmath>
#include<iomanip>

int main()
{
    
    double r;
    std::cin >> r;
    std::cout << std::setprecision(6)<<std::fixed << M_PI * (r * r) << " ";
    std::cout << std::setprecision(6) << std::fixed << 2 * M_PI * r << std::endl;
  
}


Measured memory_bytes: 3248
class PrimeNumber
  def initialize n
    @n = n
    @list = (0...n).map{|i| true}
    @list[0] = false
  end

  def set_list
    n = Math.sqrt(@n).to_i
    n.times do |i|
      next if !@list[i]
      div = i + 1
      (2 * i + 1).step(@n - 1, i + 1) do |j|
        @list[j] = false if !@list[j] || (j + 1) % div == 0
      end
    end
  end

  def prime? n
    false if @n < n
    @list[n]
  end

  def number_of_prime
    @list.count(true)
  end
end


while line = gets do
  n = line.to_i
  prime = PrimeNumber.new(n)
  prime.set_list
  puts prime.number_of_prime
end

Measured memory_bytes: 71064
def dot(A, x):
  return [sum([x[t]*A[s][t] for t in range(13)]) for s in range(13)]

MOD=10**9+7

S=input()
N=len(S)
if N==1:
  if S=='?' or int(S)==5:
    print(1)
  else:
    print(0)
  exit()

if S[0]=='?':
  x=[1]*10+[0]*3
else:
  x=[0]*13
  x[int(S[0])]=1

for i in range(1, N):
  if S[i]=='?':
    tmp=sum(x)
    x=[
      tmp-x[4]-x[8]-x[12],
      tmp-x[3]-x[8]-x[12],
      tmp-x[3]-x[7]-x[12],
      tmp-x[3]-x[7]-x[11],
      tmp-x[2]-x[7]-x[11],
      tmp-x[2]-x[6]-x[11],
      tmp-x[2]-x[6]-x[10],
      tmp-x[1]-x[6]-x[10],
      tmp-x[1]-x[5]-x[10],
      tmp-x[1]-x[5]-x[9],
      tmp-x[0]-x[5]-x[9],
      tmp-x[0]-x[4]-x[9],
      tmp-x[0]-x[4]-x[8]
    ]
  elif S[i]=='0':
    x=[x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9]]
  elif S[i]=='1':
    x=[x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5]]
  elif S[i]=='2':
    x=[x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1]]
  elif S[i]=='3':
    x=[x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10]]
  elif S[i]=='4':
    x=[x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6]]
  elif S[i]=='5':
    x=[x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2]]
  elif S[i]=='6':
    x=[x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11]]
  elif S[i]=='7':
    x=[x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7]]
  elif S[i]=='8':
    x=[x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3]]
  elif S[i]=='9':
    x=[x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12]]
    
  x=[x[j]%MOD for j in range(13)]
    
print(x[5])

Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;
using ll = long long;
// vector<vector<int>> mat(N, vector<int>(M, 0));

void DP_1dim(void)
{
  int N;
  cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }

  vector<int> DP(N + 1,0);

  for (int i = 1; i < N + 1; i++)
  {
    DP[i] = max(DP[i-1],DP[i-1] + vec[i-1]);
  }

  cout<<DP[N];

  return;
}

void DP_2dim(void)
{
  int N,W;
  cin>>N>>W;

  vector<int> value (N,0);
  vector<int> weight (N,0);

  for (int i = 0; i < N; i++)
  {
    cin>>value[i] >> weight[i];
  }

  vector<vector<int> > DP (N+1,vector<int> (W+1,0));

  for (int v = 0; v < N; v++)
  {
    for (int w = 0; w <= W; w++)
    {
      if(w >= weight[v])
      {
        DP[v+1][w] = max(DP[v][w - weight[v]] + value[v],DP[v][w]);//wまでの重さでv番目のものまでを取った時の最大値
      }
      else
      {
        DP[v+1][w] = DP[v][w];
       }
      
    }
    
  }

  // for (int i = 0; i <= N; i++)
  // {
  //   for (int j = 0; j < W; j++)
  //   {
  //     cout<< DP[i][j] << " ";
  //   }
  //   cout<<endl;
    
  // }
  
  cout<<DP[N][W];
  return;
  

}

void solve(void)
{
  std::multiset<int> S;
  int N;
  cin>>N;
  vector<int> v(N,0),pos(N+1,0);

  for (int i = 0; i < N; i++)
  {
    cin>>v[i];
    pos[v[i]] = i +1;
  }

  long long ans = 0;
  
  S.insert(0);
  S.insert(0);
  S.insert(N+1);
  S.insert(N+1);

  for (ll i = N; i >= 1; i--)
  {
    auto it = S.lower_bound(pos[i]);

    ll pos_r = *it;

    it++;

    ll pos_rr = *it;

    it--;
    it--;

    ll pos_l = *it;
    it--;
    ll pos_ll = *it;

    ans += i*(pos_r - pos[i])*(pos_l - pos_ll);
    ans += i*(pos_rr - pos_r)*(pos[i] - pos_l);

    S.insert(pos[i]);
  }
  
  cout<<ans<<endl;
  return;
}
int main(int argc, const char *argv[])
{
  //Practice DP

  solve();
  
  return 0;
}


Measured memory_bytes: 5760