akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main(){
	
	long double Ax, Ay, Bx, By;
	long double a;
	
	
	cin >> Ax >> Ay >> Bx >> By;
	
	a = (Bx - Ax) * (Bx - Ax) + (By - Ay) * (By - Ay);
	
	printf("%lf\n",sqrt(a)) ;
	
	return 0;
}

Measured memory_bytes: 1236
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a <= c && c <= b) {
            System.out.println("Yes");
        } else if (b <= c && c <= a) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


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

int main() {
  int A,B,C,K;
  cin >> A >> B >> C;
  cin >> K;
  for(int i = 0;i < K;i++) {
    if(max(A,max(B,C)) == A) {
      A = A * 2;
    }
    if(max(A,max(B,C)) == B) {
      B = B * 2;
    }
    if(max(A,max(B,C)) == C) {
      C = C * 2;
    }
  }
  cout << A + B + C << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long k=sc.nextLong();
		long[] a=new long[n];
		long[] sum=new long[n+1];
		HashMap<Long,Integer> map=new HashMap<>();
		for(int i=0; i<n; i++){
			a[i]=sc.nextLong();
			sum[i+1]=(sum[i]+a[i]-1+k)%k;
		}
		long ans=0;
		int j=0;
		for(int i=0; i<=n; i++){
			if(i-j==k){
				map.put(sum[j],map.get(sum[j])-1);
				j++;
			}
			if(map.containsKey(sum[i])){
				ans+=map.get(sum[i]);
				map.put(sum[i],map.get(sum[i])+1);
			}else{
				map.put(sum[i],1);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 95624
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,X,Y,x,y;
  cin >> N >> M >> X >> Y;
  int Z = X;
  for (int i = 0; i < N; i++){
    cin >> x;
    Z = max(Z,x);
  }
  Z++;
  bool res = true;
  if (Y < Z) res = false;
  for (int i = 0; i < M; i++){
    cin >> y;
    if (y < Z) res = false;
  }
  cout << (res ? "No War" : "War");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int k = scan.nextInt();

        int m = 1;

        for (int i = 0; i < n; i++){
            if (A(m) <= B(m, k)){
                m = A(m);
            }
            else {
                m = B(m, k);
            }
        }

        System.out.println(m);
    }

    /**
     * Double the value
     * @param n
     * @return
     */
    public static int A (int n){
        return n * 2;
    }

    /**
     * N + k
     * @param n
     * @return
     */
    public static int B(int n, int k){
        return n + k;
    }

}


Measured memory_bytes: 22996
#include<iostream>
#include<string>
#include<iomanip>
#include<stdio.h>
#include<sstream>
#include<cmath>
#include<typeinfo>
#include<cstdlib>

using namespace std;

int main(void){
	int N;
	long a[110];
	int ans = 0;
	cin >> N;
	for(int i =0; i < N; i++){
		cin >> a[i];
	}

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

Measured memory_bytes: 256
N = int(input())
a_list = list(map(int, input().split()))

sort_a_list = sorted(a_list, reverse=True)

alice = 0
bob = 0

for i, a in enumerate(sort_a_list):
    if i % 2 == 0:
        alice += a
    else:
        bob += a

print(alice - bob)

Measured memory_bytes: 38256
#include<stdio.h>
int main() {
	int x[100] , y[100] ,X,Y, n, m, i;
	scanf("%d %d %d %d", &n, &m, &X,&Y);
	int max = X, min = Y;
	for (i = 0; i < n; i++){
		scanf("%d", &x[i]);
		if(max < x[i])  max = x[i];
	}
	for (i = 0; i < m; i++) {
		scanf("%d", &y[i]);
		if (min > y[i])  min = y[i];
	}
  max < min ? printf("No War"):printf("War") ;
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int B[30];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M,C;
    cin>>N>>M>>C;
    
    rep(i,M) cin>>B[i];
    
    int cnt=0;
    rep(i,N){
        int sum=C;
        rep(j,M){
            int A;
            cin>>A;
            sum += A*B[j];
        }
        if(sum>0) cnt++;
    }
    
    cout1(cnt)
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};

ll a,b,n;
ll func(ll x){
  ll j = x/b,i = (a*x);
  ll k = i/b,l = j*a;
  return k-l;
}

int main(){

  
  cin >> a >> b >> n;
  ll left = 0,right = min(n,b);
  while(right - left > 1){
    ll l = (right*2+left)/3,r = (right+left*2)/3;
    if(func(l) >= func(r))left = l;
    else right = r;
  }
  ll l = func(left),r = func(right);
  cout << max({0ll,l,r,func(n)}) << endl;




  

  return 0;
}


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

using namespace std;
typedef long long ll;
#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++)
const ll INF=1000000000000000;

vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}

int main(){
	ll N,M; cin>>N>>M;
	vector<ll> div=divisor(M);
	sort(div.bg,div.ed);
	//rep(i,div.sz) cout<<div[i]<<endl;
	for(int i=div.sz-1;i>=0;i--){
		if(div[i]*N<=M){
			cout<<div[i];
			return 0;
		}
	}
}

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

int dw[] = {-1,1,0,0};
int dh[] = {0,0,-1,1};
int H,W,Ch,Dh,Cw,Dw,pre_cost;
vector<vector<char>> S;
vector<vector<int>> costs;
queue<P> que;
queue<P> vis;

void StepA(int h,int w){
    S[h][w] = '#';
    FOR(i,0,4){
        
        int tmp_h = h + dh[i];
        int tmp_w = w + dw[i];
        if(tmp_h < 0 || tmp_w < 0 || tmp_h > H-1 || tmp_w > W-1) continue;
        if(S[tmp_h][tmp_w] == '.'){
            vis.push(P(tmp_h,tmp_w));
            costs[tmp_h][tmp_w] = pre_cost;
            StepA(tmp_h,tmp_w);
        }
    }
}

int main(void){
    cin >> H >> W;
    cin >> Ch >> Cw;
    cin >> Dh >> Dw;
    Ch--;Cw--;Dh--;Dw--;
    S = vector<vector<char>>(H, vector<char>(W));
    costs.assign(H,vector<int>(W,-1));
    REP(i,H){
        REP(j,W){
            cin >> S[i][j];
            if(S[i][j] == '#') costs[i][j] = 999;
        }
    }

    que.push(P(Ch,Cw));
    pre_cost = 0;
    //costs[Ch][Cw] = pre_cost;

    while(!que.empty() || !vis.empty()){
        //StepA
        while(!que.empty()){
            P tmp = que.front();
            que.pop();
            vis.push(tmp);
            costs[tmp.first][tmp.second] = pre_cost;
            StepA(tmp.first,tmp.second);
        }
        //StepB
        while(!vis.empty()){
            P tmp = vis.front();
            vis.pop();
            for(int i = -2;i <= 2;i++){
                for(int j = -2;j <= 2;j++){
                    int tmp_h = tmp.first + i;
                    int tmp_w = tmp.second + j;
                    if(tmp_h < 0 || tmp_w < 0 || tmp_h > H-1 || tmp_w > W-1) continue;
                    if(S[tmp_h][tmp_w] == '.'){
                        que.push(P(tmp_h,tmp_w));
                    }
                }
            } 
        }
        pre_cost++;
    }

    cout << costs[Dh][Dw] << endl;
    return 0;
}

Measured memory_bytes: 9112
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int counter;
	int max = 0;
	int ans = 1;
	bool flag = false;
	int d = 0;
	for (int i = 1; i <= n; i++) {
		d = i;
		while (true) {
			if (d % 2 != 0) {
				if (max < counter) {
					max = counter;
					ans = i;
				}
				flag = true;
				counter = 0;
				break;
			}
			else {
				d /= 2;
				counter++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
s,t = 2.times.map{gets.chomp}

if s == t
  puts 'Yes'
  exit
end

s.size.times do |i|
  last = s.size-2
  s = s[-1] + s[0..last]
  if s == t
    puts 'Yes'
    exit
  end
end

puts 'No'

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

using namespace std;

int main()
{
  int max,min,dif,t,count,word_size,end;
  int c_a,point,i,j;
  string p = "0";

  while(1){
    string v;
    vector<int> vec;
    i = 0;
    end = 0;
    word_size = 0;

    cin>>v>>count;

    if(v == "0" && count == 0){
      break;
      }

    for(char e : v){
      word_size++;
    }

    c_a = count - word_size;

    for(int q = 0;q < c_a;++q){
      v = p+v;
    }

    point = atoi(v.c_str());

    vec.push_back(point);

    while(1){
      i++;
      sort(v.begin(),v.end());
      min = atoi(v.c_str());

      reverse(v.begin(),v.end());
      max = atoi(v.c_str());

      dif = max - min;

      j = 0;

      for(int e : vec){
        if(dif == e){
          end = 1;
          break;
        }
        j++;
      }

      if(end == 1){
        cout<<j<<" "<<dif<<" "<<i-j<<endl;
        break;
      }
      vec.push_back(dif);
      v = to_string(dif);
      word_size = 0;

      for(char e : v){
        word_size++;
      }
      c_a = count - word_size;

      for(int q = 0;q < c_a;++q){
        v = p+v;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

ll ans = 0;

void gcd(ll a, ll b){
    ll c = a%b, d = a/b;
    ans += 3*d*b;
    if(c != 0) gcd(b, c);
}

int main(){
    ll N, X;
    cin >> N >> X;
    gcd(X, N-X);
    cout << ans << endl;
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define SUBL freopen("/home/ajinkya/Desktop/input.txt","r",stdin); freopen("/home/ajinkya/Desktop/output.txt","w",stdout); 
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;




int main()
{
    fastio 
    // SUBL
  	int n, d;
  	cin >> n >> d;
  	int a[n+1][d+1];
  	FI(i,1,n) FI(j,1,d) cin >> a[i][j];
  	int ans=0;
  	FI(i,1,n)
  	{
  		FI(j,i+1,n)
  		{
  			int temp=0;
  			FI(k,1,d)
  			{
  				temp += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
  			}
  			// double k = sqrt(temp);
  			// cout << sqrt(temp);
  			if((int)sqrt(temp)==sqrt(temp)) ans++;
  		}
  	}
  	cout << ans;
    return 0;
}         	

Measured memory_bytes: 256
li = list(map(int,input().split()))
k=int(input())

cnt=0
while li[0]>=li[1]:
  li[1]*=2
  cnt+=1

while li[1]>=li[2]:
  li[2]=2*li[2]
  cnt+=1 

if cnt<=k:
  print("Yes")
elif cnt>k:
  print("No")

Measured memory_bytes: 9112
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

#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)


int main()
{
    int A,B,C,X,cnt;
    cin >> A >> B >> C >> X;
    X /= 50;
    cnt = 0;
    REP(i,A+1) {
        REP(j,B+1) {
            REP(k,C+1) {
                if (10*i+2*j+k == X) {
                    ++cnt;
                    break;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
vector<int>g[50];
map<pair<int,int>, int> mp;
vector<int> cal(int n, const int u, const int v){
    vector<int> pre(n);
    queue<int>q;
    q.push(u);
    vector<int>used(n);
    while(q.size()){
        int s = q.front();
        used[s]=1;
        q.pop();
        for(auto x:g[s]){
            if(used[x])continue;
            q.push(x);
            pre[x] = s;
        }
    }
    vector<int>res(n-1);
    int now = v;
    while(now!=u){
        res[mp[{now,pre[now]}]]=1;
        now = pre[now];
    }
    return res;
}
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
        mp[{a,b}] = mp[{b,a}] = i;
    }
    int m;
    cin >> m;
    vector<vector<int>> st(m);
    rep(i,m){
        int u, v;
        cin >> u >> v;
        st[i] = cal(n, u - 1, v - 1);
    }
    vector<ll> dp(1<<m);
    vector<vector<int>> dp2(1<<m,vector<int>(n-1));
    rep(i,1<<m){
        if(i){
            rep(j,m){
                if(i>>j&1){
                    dp2[i] = st[j];
                    rep(k,n-1)dp2[i][k]|=dp2[i-(1<<j)][k];
                    break;
                }
            }
        }
        int cnt = 0;
        rep(j,n-1)cnt+=dp2[i][j];
        dp[i] = 1LL<<(n - 1 - cnt);
    }
    ll ans = 0;
    for(int i = 0; i < 1 << m; i++){
        int f = __builtin_popcount(i);
        if(f%2)ans -= dp[i];
        else ans += dp[i];
    }
    cout << ans << endl;
}


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

int main(void){
    long long N;cin>>N;
    long long H[N];cin>>H[0];
    for(long long i=1;i<N;i++){
        cin>>H[i];
    }
    for(long long i=N-1;i>=1;i--){
        if(H[i-1]>H[i]){
            if(H[i-1]-H[i]>=2){
                cout<<"No"<<endl;
                return 0;
            }
            else{
                H[i-1]--;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n)
    cin >> a[i];
  sort(a.begin(),a.end());
  double ans = a[0];
  rep2(i,1,n)
    ans = (ans+a[i])/2;
  cout << fixed << setprecision(10);
  cout << ans << endl;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    [n, t] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    ts <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    print $ n * t - sum (map (\x -> max (t - x) 0) $ zipWith subtract ts (tail ts))


Measured memory_bytes: 4988
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define STRING_SIZE 15

int main()
{
	char inputS[STRING_SIZE], inputT[STRING_SIZE], inputU[STRING_SIZE];
	int redBallsNumber, blueBallsNumber;

	scanf("%s""%s", &inputS, &inputT);
	scanf("%d""%d", &redBallsNumber, &blueBallsNumber);
	scanf("%s", &inputU);

	if (strcmp(inputU, inputS) == 0)
	{
		redBallsNumber--;
	}
	else if (strcmp(inputU, inputT) == 0)
	{
		blueBallsNumber--;
	}

	printf("%d"" ""%d \n", redBallsNumber, blueBallsNumber);

	return 0;
}


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

void furui(int m, vector<bool>&prime){
	for(int i=2; i<=m; i++){
		if(!prime.at(i)) continue;
		for(int j=i*2; j<=m; j+=i){
			prime.at(j) = 0;
		}
	}
}
int main() {
	vector<bool> prime(int(1e5)+1,1);
	prime.at(0)=0;
	prime.at(1)=0;
	furui((int)1e5,prime);
	int q; cin >> q;
	vector<int> like(int(1e5)+1); 
	for(int i=3; i<=int(1e5); i+=2){
		like.at(i) = like.at(i-2);
		if(prime.at(i)&&prime.at((i+1)/2)) like.at(i)++;
	}
	for(int i=0; i<q; i++){
		int l,r; cin >>l>>r;
		if(l>1)cout << like.at(r)-like.at(l-2)<<endl;
		else cout << like.at(r) << endl;
	}
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FOR(x, z, y) for(int x = (z); y; x++)
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; FOR(cnt, 0, getline(stream,res,sp_word))
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
typedef long long ll;
using namespace std;

int main(){
  string ab;
  getline(cin,ab);

  if(ab[0] == ab[2]) puts("H");
  else puts("D");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

const int MOD = 1000000007;

int a[25][25];
long dp[(1 << 23)];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	dp[0] = 1;
	for (int i = 1; i < (1 << n); i++) {
		int num = __builtin_popcount(i);
		for (int j = 0; j < n; j++) {
			int t = 1 << j;
			if (i & t) {
				dp[i] += dp[i ^ t] * a[num - 1][j];
				dp[i] %= MOD;
			}
		}
	}
	cout << dp[(1 << n) - 1] << endl;
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;	cin>>s;
	int k;	cin>>k;
	for(int i=0;i<s.size();i++){
		if(i==s.size()-1){
			k%=26;
			s[i]='a'+(s[i]-'a'+k)%26;
			k=0;
		}
		else{
			if(s[i]=='a')	continue;
			int adis=(int)('z'-s[i])+1;
			if(adis<=k){
				s[i]='a';
				k-=adis;
			}
		}
		if(k==0)	break;
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 640
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    V vec(n);
    rep(i, n) cin >> vec[i];
    ll Max = 0;
    ll Min = 1e18;
    rep(i, n)
    {
        chmax(Max, vec[i]);
        chmin(Min, vec[i]);
    }
    if (Max - Min > 1)
    {
        cout << "No" << endl;
        return 0;
    }
    ll MinCount = 0;
    ll MaxCount = 0;
    rep(i, n)
    {
        if (vec[i] == Min)
        {
            MinCount++;
        }
        else
        {
            MaxCount++;
        }
    }
    if (Max == Min)
    {
        if (n >= Max * 2 || Max == n - 1)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        if (MaxCount>=2*(Max-MinCount)&&MinCount<Max)
        {
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 1024
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

#define POSSIBLE cout<<"POSSIBLE"<<endl; return 0;
#define IMPOSSIBLE cout<<"IMPOSSIBLE"<<endl; return 0;

LL mod=1000000007LL;
//         
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    if((abs(a-b)<=d&&abs(b-c)<=d)||(abs(a-c)<=d)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}


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

//int func(int i, int *h, map<int,int>* memo);

int main(){
    int N = 0,K = 0;
    cin>>N;
//    cout << N << endl;
    cin>>K;
//    cout << K << endl;
    int h[N];
    for(int i = 0; i < N; ++i){
        cin >> h[i];
//        cout <<"("<<i<<")"<< h[i];
    }
//    cout <<endl;
//    map<int,int> memo;
    //int ans = func(N-1,h,memo);
    
    int memo[N];
    memo[0] = 0;
//    cout << "(0)"<< memo[0];
    if(N < K) {
        cout <<abs(h[N-1] - h[0]);
        return 0;
    }
    for(int i = 1; i < K; ++i){
        memo[i] = abs(h[i] - h[0]);
//        cout << "("<<i <<")"<< memo[i];
    }
    vector<int> A(K);
    for(int j = K; j < N; ++j){
        for(int k = 1; k <= K; ++k){
            A[k-1]= memo[j-k] + abs(h[j] - h[j-k]);
        }
        sort(A.begin(),A.end());
        memo[j] = A[0];
//        cout <<"("<< j <<")"<< A[0];
    }
//    cout << endl;
    int ans = memo[N-1];
    cout << ans << endl;
    return 0;
}

//int func(int i,int *h,map<int,int>* memo){
////    初期値の部分
//    if(i==0) return 0;
//    else if(i==1) return abs(h[1]-h[0]);
////    ２択の部分
//    auto it = memo->find(i-1);
//    int a = 0;
//    if(it != memo->end()){
//        a = it->second;
//    }else{
//        a = func(i-1,h,memo) + abs(h[i] - h[i-1]);
//    }
//    int b = 0;
//    auto it2 = memo->find(i-2);
//    if(it2 != memo->end()){
//        b = it2->second;
//    }else{
//        b = func(i-2,h,memo) + abs(h[i] - h[i-2]);
//    }
//    memo->insert(i,min(a,b));
//    return min(a,b);
//}




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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define LL long long
#define ULL unsigned long long


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    string a, b;
    cin >> a >> b;

    int n = sz(a), m = sz(b);
    if(n > m){
        cout << "GREATER" << endl;
        return 0;
    }
    else if(n < m){
        cout << "LESS" << endl;
        return 0;
    }
    else
    {
        REP(i, 0, n)
        {
            if(a[i] > b[i]){
                cout << "GREATER" << endl;
                return 0;
            }
            else if(a[i] < b[i]){
                cout << "LESS" << endl;
                return 0;
            }
        }
    }

    cout << "EQUAL" << endl;

	return 0;
}

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

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

    ll n;
    cin >> n;
    ll arr[n];
    bool check=true;

    for (ll i=0;i<=n-1;i++)
    {
        cin >> arr[i];
        if (arr[i]==0)
        {
            check=false;
        }
    }

    if (check==false)
    {
        cout << "0" << endl;
        return 0;
    }

    ll big=1000000000000000000;
    ll ans=1;
    for (ll i=0;i<=n-1;i++)
    {
        ll a=ceil(big/ans);
        if (arr[i]>a)
        {
            ans=-1;
            break;
        }
        if (ans>big)
        {
            ans=-1;
            break;
        }

        ans=ans*arr[i];
    }

    if (ans>big)
    {
        ans=-1;
    }

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

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n, x, t; cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;
    return 0;
}


Measured memory_bytes: 3664
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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

int a,b;
string s,t,u;

int main(){
    cin>>s>>t>>a>>b>>u;
    if(s==u)a--;
    else b--;
    cout<<a<<" "<<b<<endl;
}
    
    

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

void solve()
{
    vector<pair<int,pair<int,int>>>v;
    rep(i,1,200)rep(j,i+1,200){
        v.push_back({i*i+j*j,{i,j}});
    }
    sort(v.begin(),v.end());
    int i,j;
    while(cin>>i>>j && i!=0){
        auto res=find(v.begin(),v.end(),make_pair(i*i+j*j,make_pair(i,j)));res++;
        cout<<res->second.first<<" "<<res->second.second<<endl;;
    }
}

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



Measured memory_bytes: 3276
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
ll L;
string s;
int cnt[100005];
set<ll>S[100005];

ll ans(ll v){
	ll ret = 1;
	while(v%2 == 0){ ret *= 2LL; v /= 2; }
	return ret;
}
int main(){
	cin >> n >> L;
	rep(i,n){
		cin >> s;
		int sz = s.size();
		cnt[sz]++;
		ll hs[2]={};
		ll v[2]={1,1};
		rep(j,sz){
		    if(s[j] == '0') hs[0] += v[0]; hs[0] %= mod;
		    if(s[j] == '0') hs[1] += v[1]; hs[1] %= mod;
		    S[j+1].insert(hs[0]*mod+hs[1]);
		    v[0] = v[0] * 37LL % mod;
		    v[1] = v[1] * 41LL % mod;
		}
	}
	ll flag = 0;
	for(int i=1;i<=100000;i++){
	    //長さiのprefixの種類？
	    //if(S[i].size()) cout << i << " " << S[i].size() << endl;
		if(S[i].size()%2 == 1) flag ^= ans(L+1-i);
	}
	cout<<(flag?"Alice":"Bob")<<endl;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int n; scanf("%d", &n);

	i64 ans = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			for(int k = 1; k <= n; k++) {
				ans += std::gcd(std::gcd(i, j), k);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3768
L = [s for s in input()]
if not 'R' in L:
  print(0)
elif not 'S' in L:
  print(3)
elif L[1] == 'S':
  if 'R' in L :
    print(1)
elif L[0] == 'S':
  if L[2] =='S':
    print(1)
  else:
    print(2)
else:
  print(2)
  

Measured memory_bytes: 8972
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    double[] p = new double[N];
    for (int i = 0; i < N; i++)
      p[i] = sc.nextDouble();
    sc.close();

    double[][] dp = new double[N][N + 1];
    dp[0][0] = 1d - p[0];
    dp[0][1] = p[0];
    for (int i = 0; i < N - 1; i++) {
      for (int j = 0; j < i + 2; j++) {
        dp[i + 1][j] += dp[i][j] * (1d - p[i + 1]);
        dp[i + 1][j + 1] += dp[i][j] * p[i + 1];
      }
    }

    double ans = 0;
    for (int i = (N + 1) / 2; i < N + 1; i++) ans += dp[N - 1][i];
    System.out.println(ans);
  }
}

Measured memory_bytes: 121796
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 99940000
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define sp ' '
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
ll power(ll x,ll y){
    ll ret=1;
    while(y>0){
        if(y&1)
            ret=(ret*x);
        y/=2;
        x=(x*x);
    }
    return ret;
}
string rot(string s){
	string ret="";
	ll i;
	for(i=1;s[i];i++){
		ret+=s[i];
	}
	ret+=s[0];
	return ret;
}
ll power(ll x,ll y,ll p)
{
	ll ret=1;
	while(y>0)
	{
		if(y&1)
			ret=(ret*x)%p;
		y/=2;
		x=(x*x)%p;
	}
	return ret%p;
}
void solve(){
	ll n,i,ans;
	ll arr[5];
	sfl(i,0,5){
		cin>>arr[i];
		if(arr[i]==0){
			ans=i+1;
		}
	}
	cout<<ans<<endl;
}	
int main(){
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
}	


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

int main() {
	string sa;
	cin >> sa;
	int n = 0, s = 0, e = 0, w = 0;
	for (int i = 0; i < sa.size(); i++) {
		if (sa[i] == 'N')n++;
		else if (sa[i] == 'E')e++;
		else if (sa[i] == 'S')s++;
		else w++;
	}
	if ((n&&!s)||(!n&&s)||(e&&!w)||(!e&&w))cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>

int main(int argc, char const *argv[]) {
    long long N;std::cin >> N;
    int sqrt_N;
    sqrt_N= std::sqrt(N);
    while (true) {
        if (N%sqrt_N==0) {
            std::cout << std::to_string(N/sqrt_N).length() << '\n';
            break;
        }
        sqrt_N-=1;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    
    public static void main(String args[]) {
        int h = 0, w = 0;
        boolean[][] flag = null;
        try (Scanner scanner = new Scanner(System.in)) {
            h = scanner.nextInt();
            w = scanner.nextInt();
            
            flag = new boolean[h][w];
            for(int i = 0; i < h; i++) {
                String str = scanner.next();
                for(int j = 0; j < w; j++) {
                    if(str.charAt(j) == '.')
                        flag[i][j] = true;
                }
            }
            
        }
        
        // for(boolean [] b : flag)
        //     System.out.println(Arrays.toString(b));
        
        int[][] dp = new int[h][w];
        if(flag[0][0])
            dp[0][0] = 1;
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                if(i == 0 && j ==0)
                    continue;
                if(flag[i][j]) {
                    dp[i][j] = ((i-1>=0?dp[i-1][j]:0) + (j-1>=0?dp[i][j - 1]:0))%(1000*1000*1000 + 7);
                }
            }
        }
        
        // for(int [] b : dp)
        //     System.out.println(Arrays.toString(b));
        
        System.out.println(dp[h-1][w-1]);
        
    }
}

Measured memory_bytes: 35268
s = input()
a = int(s[:2])
b = int(s[2:])

if 0<a<13:
    if 0<b<13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 0<b<13:
        print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 9084
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

int sx, sy, x, y;

void init()
{
	cin >> sx >> sy >> x >> y;
}

int main()
{
	init();

	ostringstream oss;

	REP(_i, y - sy)
		oss << 'U';
	REP(_i, x - sx)
		oss << 'R';
	REP(_i, y - sy)
		oss << 'D';
	REP(_i, x - sx)
		oss << 'L';

	oss << 'L';
	REP(_i, y - sy + 1)
		oss << 'U';
	REP(_i, x - sx + 1)
		oss << 'R';
	oss << 'D';

	oss << 'R';
	REP(_i, y - sy + 1)
		oss << 'D';
	REP(_i, x - sx + 1)
		oss << 'L';
	oss << 'U';


	cout << oss.str() << endl;
}


Measured memory_bytes: 256
N=int(input())
hairetsu=[[0 for i in range(N)] for j in range(2)]
hairetsu[0]=list(map(int,input().split()))
hairetsu[1]=list(map(int,input().split()))
goukei=0
ans=0


for i in range(N):
    goukei=0
    for j in range(N):
        if j<=i:
            goukei+=hairetsu[0][j]
        if j>=i:
            goukei+=hairetsu[1][j]
        if goukei>ans:
            ans=goukei
            
print(ans)



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

using ll=long long;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    ll v1=*max_element(a.begin(),a.end());
    ll v2=0;
    
    for(int i=0;i<n;i++){
        if(abs(v2*2-v1)>abs(a[i]*2-v1)){
            v2=a[i];
        }
    }
    
    cout<<v1<<" "<<v2<<endl;
    return 0;
}

Measured memory_bytes: 1024
from itertools import permutations

N,C = map(int,input().split())
D = list(list(map(int,input().split())) for _ in range(C))
c = list(list(map(int,input().split())) for _ in range(N))

rem = [[] for _ in range(3)]
for i in range(N):
    for j in range(N):
        rem[(i+j+2)%3].append(c[i][j])

cost = [[] for _ in range(3)]

for i in range(3):
    for s in range(C):
        tmp = 0
        for t in rem[i]:
            tmp += D[t-1][s]
        cost[i].append((tmp,s+1))

for i in cost:
    i.sort()
    i = i[:3]

ans = 1e10
for i in cost[0]:
    for j in cost[1]:
        for h in cost[2]:
            if i[1] != j[1] and j[1] != h[1] and h[1] != i[1]:
                ans = min(ans,i[0]+j[0]+h[0])
print(ans)

Measured memory_bytes: 13628
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string s, t;
int s_len, t_len;
vector<int> v[26];
long long ans; 

void binary_search(int letter)
{
  int pos = ans % s_len;
  int l = 0, r = v[letter].size(), mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (pos > v[letter][mid]) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  ans += v[letter][l] - pos + 1;
}

int main()
{
  cin >> s >> t;
  
  s_len = s.length();
  t_len = t.length();
  
  s += s;
  
  for (int i = 0; i < s_len * 2; i++) {
    v[s[i]-'a'].push_back(i);
  }
  
  for (int i = 0; i < t_len; i++) {
    if (v[t[i]-'a'].empty()) {
      cout << -1 << endl;
      return 0;
    }
    binary_search(t[i]-'a');
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1788
#include<stdio.h>
#include<stdlib.h>

int n;
int *N;

void maxHeapify(int i){
  int l, r, largest, a;

  l = 2 * i;
  r = 2 * i + 1;

  if(l <= n && N[l] > N[i]) largest = l;

  else largest = i;

  if(r <= n && N[r] > N[largest]) largest = r;

  if(largest != i){
    a = N[i];
    N[i] = N[largest];
    N[largest] = a;
    maxHeapify(largest);
  }
}

void buildMaxHeap(){
  int i;

  for(i = n / 2; i >= 1; i--) maxHeapify(i);
}

int main(){
  int i;

  scanf("%d", &n);

  N = (int *)malloc(sizeof(int) * (n + 1));

  for(i = 1; i <= n; i++) scanf("%d", &N[i]);

  buildMaxHeap();

  for(i = 1; i <= n; i++) printf(" %d", N[i]);

  printf("\n");

  return 0;
}

Measured memory_bytes: 2556
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            int A = int.Parse (str[0]);
            int B = int.Parse (str[1]);
            int C = int.Parse (str[2]);
            int X = int.Parse (str[3]);
            int Y = int.Parse (str[4]);

            long ans = 10000000000;
            long cost = 0;
            for (int i = (Max (X, Y)) * 2; i >= 0; i -= 2)
            {
                cost = A * Max (0, X - i / 2) + B * Max (0, Y - i / 2) + C * i;
                ans = Min (ans, cost);
            }

            Console.WriteLine (ans);
        }
    }

    class MyLibrary
    {
        public static int GCD (int a, int b)
        {
            if (a % b == 0) return b;
            return GCD (b, a % b);
        }
    }
}

Measured memory_bytes: 27436
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n, x;
	cin >> n >> x;
	int m[n];
	int min=1000;
	for(int i=0; i<n; i++){
		cin >> m[i];
		x-=m[i];
		if(m[i]<=min) min=m[i];
	}
	cout << n+x/min << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 *
 * @author Milo
 */
class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    static FastReader in = new FastReader();
    public static void main(String[] args) {
        int t = 1; //in.nextInt();
        while (t-- > 0)
            solve();
    }
 
    public static void solve() {
        
        int r = in.nextInt();
        System.out.println((2 * r * Math.PI));
                
    }
 
    public static int max(int a, int b) {
        return a > b ? a : b;
    }
 
    public static int min(int a, int b) {
        return a < b ? a : b;
    }
 
    public static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, (a % b));
    }
}


Measured memory_bytes: 33256
#include <bits/stdc++.h>
using namespace std; 
#define int long long int 

signed main() {
	int n, w ; cin >> n >> w ; 
	std::vector<int> dp(w+1,0) ; 
	for (int i = 0; i < n; ++i ) {
		int val, weight ; cin >> weight >> val ; 
		for (int j = w; j >= weight; --j) {
			dp[j] = max(dp[j], dp[j-weight]+val) ; 
		}
	}
	int ans = 0 ; 
	for (int i = 0; i <= w; ++i) {
		ans = max(ans, dp[i]) ; 
	}
	cout << ans << endl ; 
	return 0 ; 
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static boolean[] check = new boolean[10];
	static int n;
	static int s;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			Arrays.fill(check,false);
			n = sc.nextInt();
			s = sc.nextInt();
			if(n==0 && s==0)break;
			int ans = dfs(0,0,-1);
			System.out.println(ans);
		}
	}
	
	static int dfs(int pos, int sum, int max){
		if(sum == s && pos==n)return 1;
		if(sum > s)return 0;
		if(pos > n)return 0;
		
		int ret = 0;
		for(int i=max+1; i<10; i++){
			if(!check[i]){
				check[i]=true;
				ret += dfs(pos+1,sum+i,i);
				check[i]=false;
			}
		}
		return ret;
	}
}

Measured memory_bytes: 18304
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int ca=0,cb=0;
  for(int i=0;i<=2;i++){
  		if(s[i]=='A')
          ca+=1;
    	else
          cb+=1;
  }
  if(ca==0 || cb==0)
    cout<<"No";
  else
    cout<<"Yes";
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def selectionSort(A, N):
    count = 0
        
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if minj != i:
            count += 1

        A[i], A[minj] = A[minj], A[i]

    return A, count

if __name__ == '__main__':

    N = int(input())
    A = [int(a) for a in input().split(" ")]

    A, count = selectionSort(A, N)
    print(" ".join(map(str, A)))
    print(count)



Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int k;
int g[222][222];
int main(){
    cin>>k;
    LL ans = 0;
    for(int i = 1;i <= k; i++){
        for(int j = 1;j <= k; j++)g[i][j] = __gcd(i, j);
    }
    for(int a = 1;a <= k; a++){
        for(int b = 1;b <= k; b++){
            for(int c = 1;c <= k; c++){
                ans += g[g[a][b]][c];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(void){
        long i,nt,na,K;
        cin >> nt >> na >> K;
        nt -= K;
        if(nt<0){
                na += nt;
        }
        if(nt<0){nt = 0;}
        if(na<0){na = 0;}
        cout << nt << " " << na << endl;
        return 0;
}

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

int main() {
	int N, A, B, ans = 0; cin >> N >> A >> B;
	for( int a = 0; a < 10; a++ )
	for( int b = 0; b < 10; b++ )
	for( int c = 0; c < 10; c++ )
	for( int d = 0; d < 10; d++ ){
		int x = a + b + c + d;
		if( 1000*a + 100*b + 10*c + d > N )goto end;
		if(A <= x && x <= B )ans += 1000*a + 100*b + 10*c + d;
	}
	if( A >= 1 && N == 10000 ) ans += 10000;
	end:;
	
	cout << ans << endl;
}

Measured memory_bytes: 256