akhauriyash/Code-Regression huggingface dataset:
//Aizu - ALDS1_5_C
#include <bits/stdc++.h>

using namespace std;

const double pi = acos(-1);

void koch(int n, pair<double, double> p1, pair<double, double> p2)
{
    if (n == 0) return;

    double th = pi * 60.0 / 180.0;
    pair<double, double> s, u, t;

    s.first = (2.0 * p1.first + p2.first) / 3.0;
    s.second = (2.0 * p1.second + p2.second) / 3.0;

    t.first = (p1.first + 2.0 * p2.first) / 3.0;
    t.second = (p1.second + 2.0 * p2.second) / 3.0;

    u.first = cos(th) * (t.first - s.first) - sin(th) * (t.second - s.second) + s.first;
    u.second = sin(th) * (t.first - s.first) + cos(th) * (t.second - s.second) + s.second;

    koch(n - 1, p1, s);
    printf("%.8lf %.8lf\n", s.first, s.second);
    koch(n - 1, s, u);
    printf("%.8lf %.8lf\n", u.first, u.second);
    koch(n - 1, u, t);
    printf("%.8lf %.8lf\n", t.first, t.second);
    koch(n - 1, t, p2);
}

int main()
{
    int n;
    cin >> n;
    printf("%.8lf %.8lf\n", 0.0, 0.0);
    koch(n, make_pair(0.0, 0.0), make_pair(100.0, 0.0));
    printf("%.8lf %.8lf\n", 100.0, 0.0);
    return 0;
}


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

string s, t;
int len = 4;
long long i, ans, A, B;

bool flg = true;

int calc(long long k, long long A, long long B, char c){
    // printf("k = %lld, A = %lld, B = %lld\n", k, A, B);
    // kは何個目の隙間かを表す
    // 隙間に+を入れるか入れないかで深さ優先探索
    if(k>0) t[k-1]=c;
    if(k == 3){
      // ans += A+B;
      if(A==7){
        printf("%d%c%d%c%d%c%d=%lld\n", s[0]-48,t[0],s[1]-48,t[1],s[2]-48,t[2],s[3]-48, A);
        exit(0);
      }
    }
    else{
      calc(k+1, A+B, s[k+2]-48, '+');
      calc(k+1, A-B, s[k+2]-48, '-');
    }
}

int main(){
  cin>>s;
  calc(0, s[0]-48, s[1]-48, 'a');
  // calc(0, 0, s[0]-48);
  // printf("%lld\n", ans);

}


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

using namespace std;

#define MAX 1100000

int main()
{
    int N, X;
    
    bool prime[MAX];
    fill(prime, prime + MAX, 1);
    prime[0] = prime[1] = 0;

    for (int i = 2; i < MAX; i++) {
        if (prime[i]) {
            for (int j = i * 2; j < MAX; j += i) {
                prime[j] = 0;
            }
        }
    }
    
    while (cin >> N >> X, N) {
        vector<int> a(N);
        for (int i = 0; i < N; i++) {
            cin >> a[i];
        }
        
        bool dp[MAX] = {};
        dp[0] = 1;

        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= X-a[i]; j++) {
                if (dp[j]) {
                    dp[j+a[i]] = 1;
                }
            }
        }
        
        int res = -1;
        for (int i = X; i >= 0; i--) {
            if (prime[i] && dp[i]) {
                res = i;
                break;
            }
        }
        if (res == -1) {
            cout << "NA" << endl;
        } else {
            cout << res << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5152
//In the Name of ̲A̲l̲l̲a̲h̲
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define sz size()
#define ll long long

using namespace std;

int n, t[5];
double dp[351][351][351];

main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        t[a]++;
    }
    for (int k = 0; k <= n; k++)
    {
        for (int j = 0; j <= n; j++)
        {
            for (int i = 0; i <= n; i++)
            {
                if (!i && !j && !k)
                    continue;
                if (i > 0)
                    dp[i][j][k] += i*dp[i-1][j][k];
                if (j > 0)
                    dp[i][j][k] += j*dp[i+1][j-1][k];
                if (k > 0)
                    dp[i][j][k] += k*dp[i][j+1][k-1];
                dp[i][j][k] += n;
                dp[i][j][k] /= (i+j+k);
            }
        }
    }
    cout << setprecision(15)<< dp[t[1]][t[2]][t[3]];
}

/*𝐻𝒶𝒹𝒾*/


Measured memory_bytes: 290816
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct LCA {
  int N, logN; // logN-1 == floor(lg(N-1))
  vector<vector<int>> G;
  vector<int> depth;
  // vから根の方向に2^k回登ったときのノード parent[k][v]
  vector<vector<int>> parent;

  LCA(int size) : N(size), G(size), depth(size) {
    logN = 0;
    for(int x = 1; x < N; x *= 2) logN++;
    logN = 21;
    parent.assign(logN, vector<int>(N));
  }

  // どちらが根であってもOK
  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }

  void dfs(int v, int par, int dep) {
    depth[v] = dep;
    parent[0][v] = par;
    for(int next : G[v]) {
      if(next != par) dfs(next, v, dep + 1);
    }
  }

  void init(int root) {
    dfs(root, -1, 0);
    for(int k = 1; k < logN; k++) {
      for(int v = 0; v < N; v++) {
        if(parent[k - 1][v] == -1) parent[k][v] = -1;
        else parent[k][v] = parent[k - 1][parent[k - 1][v]];
      }
    }
  }

  int lca(int u, int v) {
    if(depth[u] > depth[v]) swap(u, v); // vのほうが深くなる
    // uとvの深さが同じになるまでvを根の方向に移動する
    for(int k = 0; k < logN; k++) {
      if(((depth[v] - depth[u]) >> k) & 1) {
        v = parent[k][v];
      }
    }
    if(u == v) return u;
    for(int k = logN - 1; k >= 0; k--) {
      if(parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};

int main() {
  ios::sync_with_stdio(false);
  int N; cin >> N;
  LCA lca(N);
  for(int u = 0; u < N; u++) {
    int k; cin >> k;
    while(k--) {
      int v; cin >> v;
      lca.add_edge(u, v);
    }
  }
  lca.init(0);
  int Q; cin >> Q;
  while(Q--) {
    int u, v; cin >> u >> v;
    cout << lca.lca(u, v) << endl;
  }
}

Measured memory_bytes: 17668
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;
 
class Data{
public:
  string mName;
  int mC,mV,mD,mL;
  Data(string _n,int _c,int _v,int _d,int _l){
    mName = _n;
    mC = _c;
    mV = _v;
    mD = _d;
    mL = _l;
  }
};
 
int dp[301][3];
 
int main(){
  int N,M;
 
  string line;
  stringstream ss;
  while(getline(cin,line)){
    ss << line;
    ss >> N >> M;
    ss.clear();
 
    vector<Data> idols;
    for(int i=0;i<N;i++){
             
      getline(cin,line);
      string name = line;
 
      getline(cin,line);
      ss << line;
 
      int C,V,D,L;
      ss >> C >> V >> D >> L;
      ss.clear();
 
      idols.push_back(Data(name,C,V,D,L));
    }
 
 
    memset(dp,0,sizeof(dp));
 
    for(int i=0;i<=M;i++){
      for(int j=0;j<idols.size();j++){
	for(int k=0;k<=M;k++){
	  if(i-idols[j].mC*k < 0) break;
	  dp[i][0] = max(dp[i-idols[j].mC*k][0] + idols[j].mV*k,dp[i][0]);
	  dp[i][1] = max(dp[i-idols[j].mC*k][1] + idols[j].mD*k,dp[i][1]);
	  dp[i][2] = max(dp[i-idols[j].mC*k][2] + idols[j].mL*k,dp[i][2]);
	}
      }
    }
 
    int maxv = 0;
    for(int i=0;i<=M;i++){
      for(int j=0;j<3;j++){
	maxv = max(dp[i][j],maxv);
      }
    }
    printf("%d\n",maxv);
 
  }
}

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

int main() {
  // 入力整数
  double a = 0;
  double b = 0;
  
  // 整数を入力
  cin >> a >> b;
  
  // 平均値を計算
  double avg = (a + b) / 2;
  
  // 切り上げをするため、0.5を足す
  int answer = avg + 0.5;
  
  // 答え
  cout << answer << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Numerics;

namespace ABC176
{
    class Program
    {
        static void Main(string[] args)
        {
            b();
        }

        public static void b()
        {
            string n = Console.ReadLine();
            //long g = long.Parse(n);
            long sum = 0;
            for(int i = 0; i < n.Length; i++)
            {
                char c = n[i];
                int x = Convert.ToInt32(new string(c, 1));
                sum += x;
               // Console.WriteLine(sum);
            }
            //Console.WriteLine(sum);
            if(sum % 9 == 0)
            { Console.WriteLine("Yes"); }
            else
            { Console.WriteLine("No"); }
        }
    }
}


Measured memory_bytes: 32976
#define PL 1.05

#include<stdio.h>

int main(void){
	int i, n, debt = 100000;

	scanf("%d", &n);
	if (n > 100) {
		printf("Error!\n\a");
		return 0;
	}

	for (i = 0; i < n;i++) {
		debt = debt * PL;
		if (debt%1000 != 0) {
			debt = debt - (debt%1000) + 1000;
		}
	}

	printf("%d\n", debt);
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 10*9+7

int main(){
  int n; cin >> n;
  vector<int>ans(n,0);
  for(int i=0;i<n-1;i++){
    int a; cin >> a;
    a--;
    ans[a]++;
  }
  for(auto v:ans) cout<< v <<endl;
}


Measured memory_bytes: 4032
import numpy as np

H, W = map(int, input().split())
input_map = np.array([input() for i in range(H)])

mine_map = np.array([[0 if j == "." else "#" for j in i] for i in input_map])

for y in range(H):
	for x in range(W):
		if mine_map[y][x] == "#":
			pass
		else:	
			y_lower = 0 if y-1<0 else y-1
			y_upper = H if y+2>H else y+2
			x_lower = 0 if x-1<0 else x-1
			x_upper = W if x+2>W else x+2

			mine_map[y][x] = np.sum(mine_map[y_lower:y_upper, x_lower:x_upper] == "#")

		print(mine_map[y][x], end = "")
	print("")

Measured memory_bytes: 12896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	int ans=0;
	int m=0;
	rep(i,0,n){
		int a; cin>>a;
		chmax(m,a);
		ans+=a;
	}
	cout<<ans-(m/2)<<endl;
	
	return 0;
}

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

#define ll long long 
using namespace std;


int main(){
    ll a,b;
    ll c;
    cin >> a >> b;
    c = abs(a - b);
    // cout << c;
    if(c % 2 == 0){
        c = c / 2;
        if(a+c == b-c){
            cout << a + c << endl;
        }else{
            cout << a - c << endl;
        }
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

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

int main() {
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    cout << (bool)(m1 != m2) << endl;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
ans = 0
if N >= M//2:
    ans = M//2
else:
    for i in range(max(0,M//2-N-10), max(0, M//2-N+10)):
        ans = max(ans,min(N+i//2,(M-i)//2))
print(ans)

Measured memory_bytes: 3060
program main
  implicit none
  integer i,p(20),N,ans,a,b
  read(*, *) N
  read(*, *) (p(i), i = 1,N)
  ans = 0
  do i= 2,N-1
    a = p(i)-p(i-1)
    b = p(i)-p(i+1)
    if(a*b<0) then
      ans = ans +1
    end if
  end do


  write(*, *) ans
end program main


Measured memory_bytes: 640
from collections import deque
import bisect
n=int(input())
sft=deque()
x=deque([3,5,7])
while x:
    a=x.popleft()
    if 100<=a<=777:
        sft.append(a)
    else:
        x.append(a*10+3)
        x.append(a*10+5)
        x.append(a*10+7)
ans=[]
for i in range(3**11):
    a=sft.popleft()
    ans.append(a)
    sft.append(a*10+3)
    sft.append(a*10+5)
    sft.append(a*10+7)
count=0
for i in ans:
    if n<i:
        print(count)
        break
    else:
        ss=str(i)
        if "3" in ss and "5" in ss and "7" in ss:
            count+=1

Measured memory_bytes: 38240
#include <stdio.h>

int main(void)
{
	char a,b;
	
	scanf("%c%c%*c", &a, &b);

	if(a == '9' || b == '9') {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	
	return 0;
}


Measured memory_bytes: 128
def ope(f):
    if f:
        return "+"
    return "-"

flag = False
A, B, C, D = map(int, list(input()))
for a in [1, 0]:
    for b in [1, 0]:
        for c in [1, 0]:
            for d in [1, 0]:
                result = eval("{} {} {} {} {} {} {}".format(A, ope(a), B, ope(b), C, ope(c), D))
                if result == 7:
                    print("{}{}{}{}{}{}{}=7".format(A, ope(a), B, ope(b), C, ope(c), D))
                    flag = True
                    break
            if flag:
                break
        if flag:
            break
    if flag:
        break


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main(){
    double x1, x2, y1, y2, distance;
    cin >> x1 >> y1 >> x2 >> y2;

    distance = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));

    cout << fixed;
    cout << setprecision(6) << distance << endl;

    return 0;
}



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

using namespace std;
#define ll long long
#define db long double
#define f(i,l,u) for(ll i=l;i<u;i++)
ll k;
ll val;
ll bs(ll left,ll right,ll a[],ll n)
{
    
    ll cost=0;
    ll mid=(left+right)/2;
  //  cout<<"left = "<<left<<" right= "<<right<<endl;
//    cout<<"mid = "<<mid<<endl;
    f(i,0,n)
    {
        cost+=a[i]/mid;
        if(a[i]%mid==0)
        cost--;
    }
  //  cout<<"cost= "<<cost<<endl<<endl;
    if(left==right)
    {
    //    cout<<"cost= "<<cost<<endl;
    return mid;
    
    }
    
    else if(cost<=k)
    return bs(left,mid,a,n);
    else
    return bs(mid+1,right,a,n);
}

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

    cin>>k;
    ll a[n];
    f(i,0,n)
    {
        cin>>a[i];    }
    
    sort(a,a+n);
    ll val=bs(1,a[n-1],a,n);
    cout<<val<<endl;
    
    return 0;
}

Measured memory_bytes: 5128
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int MAXN = (1 << 18) + 5;
const LL MOD = 998244353;
const LL INV2 = (MOD + 1) >> 1;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, len;
LL p[MAXN], psum, a[MAXN];

inline LL ksm(LL x, LL k) {
	LL ret = 1;
	while (k) {
		if (k & 1) ret = ret * x % MOD;
		x = x * x % MOD;
		k >>= 1;
	}
	return ret;
}

void FWT(LL *a) {
	for (int i=1;i<len;i<<=1) {
		int p = i << 1;
		for (int j=0;j<len;j+=p) {
			for (int k=0;k<i;++k) {
				LL x = a[j+k], y = a[j+k+i];
				a[j+k] = (x + y) % MOD;
				a[j+k+i] = (x - y + MOD) % MOD;
			}
		}
	}
}

void IFWT(LL *a) {
	for (int i=1;i<len;i<<=1) {
		int p = i << 1;
		for (int j=0;j<len;j+=p) {
			for (int k=0;k<i;++k) {
				LL x = a[j+k], y = a[j+k+i];
				a[j+k] = (x + y) * INV2 % MOD;
				a[j+k+i] = (x - y + MOD) * INV2 % MOD;
			}
		}
	}
}

void init() {
	read(n); len = 1 << n;
	for (int i=0;i<len;++i) {
		read(p[i]);
		psum += p[i];
	}
	psum = ksm(psum, MOD - 2);
	for (int i=0;i<len;++i) {
		p[i] = p[i] * psum % MOD;
		a[i] = MOD - 1;
	}
	p[0] = (p[0] - 1 + MOD) % MOD;
	a[0] = len - 1;
}

void solve() {
	FWT(a); FWT(p);
	for (int i=0;i<len;++i) {
		a[i] = a[i] * ksm(p[i], MOD - 2) % MOD;
	}
	IFWT(a);
	for (int i=0;i<len;++i) {
		printf("%lld\n", (a[i] - a[0] + MOD) % MOD);
	}
}

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


Measured memory_bytes: 6912
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String S = in.next();
		
		int divNum = S.length() % 2;  
		
		int cnt = 0;
		for (int i = 0, j = S.length(); i < S.length() / 2; ++i, --j) {
			if (!S.substring(i, i+1).equals(S.substring(j -1, j))) {
				cnt++;
			}
		}
		
		int ans = cnt;
		System.out.println(ans);
	}

}


Measured memory_bytes: 24020
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let w = 8 * std::mem::size_of::<usize>();
    let mut dp: Vec<usize> = vec![0; 2000 * n / w + 2];
    dp[0] = 1;
    let mut sum = 0;
    for a in a {
        let q = a / w;
        let r = a % w;
        if r == 0 {
            for i in (0..(sum / w + 1)).rev() {
                dp[i + q] |= dp[i];
            }
        } else {
            for i in (0..(sum / w + 1)).rev() {
                let v = dp[i];
                dp[i + q + 1] |= v >> (w - r);
                dp[i + q] |= v << r;
            }
        }
        sum += a;
    }
    let mut ans = (sum + 1) / 2;
    while ((dp[ans / w] >> (ans % w)) & 1) == 0 {
        ans += 1;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

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, m;
  cin >> n >> m;
  UnionFind tree(n);
  rep(i, m) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    tree.unite(x, y);
  }
  set<int> s;
  rep(i, n) s.insert(tree.root(i));
  cout << s.size() << endl;
}

Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>

using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
int a[1234];
//std::ios::sync_with_stdio(0); std::cin.tie(0);
int main() {
	int n, k;
	cin >> n >> k;
	int i;
	for (i = 0; i < n; ++i)cin >> a[i];
	sort(a, a + n);
	int ans = 0;
	for (i = 0; i < k; ++i)ans += a[i];
	cout << ans << endl;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;

const int N = 1e5 + 10;

int n, a[N], val[N], s[N];

int bit[N * 2 + 10];

void modify(int x) {
	x += n + 2;
	for( ; x <= 2 * n + 10; x += x & -x) ++ bit[x];
}

int query(int x) {
	x += n + 2;
	int res = 0;
	for( ; x ; x -= x & -x) res += bit[x];
	return res;
}

int check(int val) {
	// puts("go 1");
	for(int i = 0 ; i <= 2 * n + 10 ; ++ i) bit[i] = 0;
	for(int i = 1 ; i <= n ; ++ i) {
		if(a[i] <= val) s[i] = 1;
		else s[i] = -1;
		s[i] += s[i - 1];
	}
	long long res = 0, len = 1ll * n * (n + 1) / 2;
	modify(0);
	for(int i = 1 ; i <= n ; ++ i) {
		res += query(s[i] - 1);
		modify(s[i]);
	}
	return res >= len / 2 + 1;
}

int main() {
	scanf("%d", &n);
	for(int i = 1 ; i <= n ; ++ i) {
		scanf("%d", &a[i]);
		val[i] = a[i];
	}
	sort(val + 1, val + 1 + n);
	int k = unique(val + 1, val + 1 + n) - val - 1;
	int l = 1, r = k, ans = 0;
	while(l <= r) {
		int mid = (l + r) >> 1;
		if(check(val[mid])) {
			ans = val[mid];
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 2176
#include <iostream>
using namespace std;
using ll = long long;
int main() {
    ll n,m;
    cin >> n >> m;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        ans *= (m - i);
        ans %= 1000000007;
    }
    ll p = 1;
    ll q = 0;
    for (int i = 0; i < n; i++) {
        int qq = q;
        q = (qq+p) * (n - i - 1);
        p *= (m - n);
        p += qq * (m - n + 1);
        p %= 1000000007;
        q %= 1000000007;
    }
    cout << ans*p%1000000007 << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int fld[111][111];

signed main(){
    int A,B;
    cin>>A>>B;

    rep(i,50)rep(j,100)fld[i][j]=0,fld[99-i][j]=1;

    A--;B--;

    for(int i=0;i<50;i+=2){
        for(int j=0;j<50;j+=2){
            if(B){
                fld[i][j]^=1;
                B--;
            }
            if(A){
                fld[99-i][j]^=1;
                A--;
            }
        }
    }

    cout<<100<<" "<<100<<endl;
    rep(i,100){
        rep(j,100){
            if(fld[i][j])cout<<"#";
            else cout<<".";
        }cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
/*

Author : AllKilled
Date   : 201911166

Contest: AtCoder Beginner Contest 145.
Problem: Task B.
Result :

*/
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

const LL MAXN = 1e6+7;

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



int main()
{
    int n, i, j, res = 0;
    string s;
    cin >> n >> s;
    if(n & 1) return cout << "No", 0;
    for(i = 0, j = n / 2; j < n; ++i, ++j){
        if(s[i] != s[j]) break;
    }
    cout << (j == n ? "Yes" : "No");
    return 0;
}


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

int w,h;
char maps[51][51];
bool closed[51][51];
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};

char check(int i,int j)
{
  // cout<<i<<" "<<j<<endl;
  if(i<0 || i>=h || j<0 || j>=w)
    return 'X';
  if(maps[i][j]!='.')
    return maps[i][j];
  if(closed[i][j])
    return 'X';
  closed[i][j]=true;
  char tmp='X';
  for(int xx=0;xx<4;xx++)
    {
      char tt=check(i+dx[xx],j+dy[xx]);
      if(tmp=='X' || tmp==tt)
	tmp=tt;
      else if(tt!='X')
	{
	  tmp='Z';
	  break;
	}
    }
  //maps[i][j]=tmp;
  //  cout<<i<<" "<<j<<" "<<tmp<<endl;
  return tmp;
}

int main()
{
  for(;cin>>w>>h,w;)
    {
      int ans[2]={0,0};
      for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	  {
	    cin>>maps[i][j];
	    if(maps[i][j]=='B')
	      ans[0]--;
	    if(maps[i][j]=='W')
	      ans[1]--;
	  }

      for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	  {
	    memset(closed,false,sizeof(closed));
	    maps[i][j]=check(i,j);
	    char tmp=maps[i][j];
	    if(tmp=='B')
	      ans[0]++;
	    if(tmp=='W')
	      ans[1]++;
	  }
      /*
      for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	  {
	    cout<<	    maps[i][j];
	    if(j==w-1)
	      cout<<endl;
	  }
      */
      cout<<ans[0]<<" "<<ans[1]<<endl;
    }
}

Measured memory_bytes: 1276
def resolve():
    D = int(input())
    C = list(map(int, input().split()))
    S = [list(map(int, input().split())) for _ in range(D)]
    T = [int(input()) for _ in range(D)]
    last = [0 for _ in range(26)]
    score = 0
    for i, t in enumerate(T):
        score += S[i][t-1]
        last[t-1] = i+1
        for j in range(26):
            score -= C[j]*(i+1-last[j])
        print(score)



if __name__ == '__main__':
    resolve()

Measured memory_bytes: 9336
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll ans;
vector<vector<ll> > vv;

ll dfs(ll a, ll p, ll h){
  if(vv[a].sz==1&&p!=-1){
    return 1;
  }
  ll ret = 0;
  rep(i,0,vv[a].sz){
    if(vv[a][i]==p)continue;
    ret += dfs(vv[a][i],a,h+1);
  }
  if(ret==1){
  	if(vv[a].sz==2){
  		return 1;
  	}
  	else{
  		return 0;
  	}
  }
  else if(ret>1){
  	ans += ret-1;
  	return 0;
  }
  return 0;
}

int main() {
	ans = 0;
	ll n;
	cin>>n;
	if(n==2){
		cout << 1 << endl;
		return 0;
	}
	vector<vector<ll> > vv_(n,vector<ll>());
	vv = vv_;
	rep(i,0,n-1){
		ll a,b;
		cin>>a>>b;
		vv[a].pb(b);
		vv[b].pb(a);
	}
	rep(i,0,n){
		if(vv[i].sz>2){
			dfs(i,-1,0);
			break;
		}
	}
	cout << max(1LL,ans) << endl;
	return 0;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	vector<ll> p(a), q(b), r(c);
	REP(i,a) cin >> p[i];
	REP(i,b) cin >> q[i];
	REP(i,c) cin >> r[i];
	sort(ALL(p), greater<ll>());
	sort(ALL(q), greater<ll>());
	sort(ALL(r), greater<ll>());

	vector<ll> xy(x+y);
	ll ans = 0;
	REP(i,x){
		xy[i] = p[i];
		ans += p[i];
	}
	REP(i,y){
		xy[i + x] = q[i];
		ans += q[i];
	}
	sort(ALL(xy));
	int xyc = 0;
	int rc = 0;
	while(xy[xyc]<r[rc]){
		ans += (r[rc]-xy[xyc]);
		xyc++, rc++;
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 3968
//Decayed Bridges

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int>par;
    UnionFind(int n){par=vector<int>(n,-1);}
    int root(int x){
        if(par[x]<0)return x;
        return par[x]=root(par[x]);
    }
    bool unite(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y)return false;
        if(par[x]>par[y])swap(x, y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }
    bool same(int x,int y){return root(x)==root(y);}
    int size(int x){return -par[root(x)];}
};

signed main (){
    int n,m;cin>>n>>m;
    vector<P>in(m);
    vector<int>out;
    rep(i,0,m)cin>>in[i].first>>in[i].second;
    reverse(range(in));
    UnionFind uf(n);
    int f=n*(n-1)/2;
    rep(i,0,m){
        out.pb(f);
        int a=in[i].first-1,b=in[i].second-1;
        int o=uf.size(a)*uf.size(b);
        if(!uf.unite(a,b))continue;
        f-=o;
        if(f<0)f=0;
        uf.unite(a,b);
    }
    reverse(range(out));
    for(auto i:out)cout<<i<<nnn;
    return 0;
}

Measured memory_bytes: 6620
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	vector<lli> x(n),y(n);
	REP(i,0,n)cin>>x[i]>>y[i];
	vector<lli> per(n);
	REP(i,0,n)per[i]=i;

	double sum = 0;
	lli cnt=0;

	do{
		double sX=x[per[0]];
		double sY=y[per[0]];

		REP(i,1,n){
			double dX = abs(sX-x[per[i]]);
			double dY = abs(sY-y[per[i]]);
			sum += sqrt(dX*dX + dY*dY);
		}
		cnt++;

	}while(next_permutation(per.begin(),per.end()));

	cout<<setprecision(15);
	cout<<sum/(double)cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int x;
    scanf("%d", &x);
    if(x>=0 && x<=1)
    {
    if(x== 0)
    {
        printf("1\n");
    }
    else if(x==1)
    {

        printf("0\n");
    }
    }

    return 0;
    }


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

int main() {
  string s;
  cin>>s;
  int ans = 700;
  if (s[0] == 'o') {
    ans += 100;
  }
  if (s[1] == 'o') {
    ans += 100;
  }
  if (s[2] == 'o') {
    ans += 100;
  }
  cout<<ans<<endl;

}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int z;
	cin>>z;
	int a,s;
	
	
	int ans=0;
	
	for(int q=1;q<=z;q++)
	{
		cin>>a>>s;
		ans+=(s-a+1);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 234567;
int X[MAXN];
LL pre_sum[MAXN], suf_sum[MAXN];

int main() {
    int L, N;
    scanf("%d %d", &L, &N);
    for (int i = 1; i <= N; i++) scanf("%d", &X[i]);
    for (int i = 1; i <= N; i++) pre_sum[i] = pre_sum[i - 1] + X[i];
    for (int i = 1; i <= N; i++) suf_sum[i] = suf_sum[i - 1] + (L - X[N - i + 1]);
    LL ans = 0;
    for (int f = 0; f <= N; f++) {
        int b = N - f;
        if (f == 0) {
           ans = max(ans, (LL)(L - X[1]));
           continue;
        }
        if (f == N) {
           ans = max(ans, (LL)X[N]);
           continue;
        }
        int can = min(f, b);
        LL ans1 = 0, ans2 = 0;
        LL sum = 2 * (pre_sum[f] - pre_sum[f - can] + suf_sum[b] - suf_sum[b - can]);
        //last = b, last = f
        if (f >= b) {
           ans1 = sum - X[f];
           if (f > b) ans1 += 2 * X[f - can];
           ans2 = sum - (L - X[f + 1]);
        } else {
           ans1 = sum - X[f];
           ans2 = sum + 2 * (L - X[f + 1 + can]) - (L - X[f + 1]);
        }
        ans = max(ans, max(ans1, ans2));
    }
    printf("%lld\n", ans);
    return 0;
}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

int w, h;
int a[51][51];
int dx[]{1,-1,0,0,1,-1,1,-1};
int dy[]{0,0,1,-1,1,-1,-1,1};

void dfs(int x, int y) {
    a[x][y] = 0;
    rep(i, 8) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(nx>=0&&nx<h&&ny>=0&&ny<w&&a[nx][ny]==1) {
            dfs(nx, ny);
        }
    }
}

int main()
{
    while(cin>>w>>h, w) {
        rep(i,h) rep(j,w) a[i][j] = 0;

        rep(i,h) {
            rep(j,w) {
                cin >> a[i][j];
            }
        }

        int ans = 0;
        rep(i,h) {
            rep(j, w) {
                if(a[i][j]==1) {
                    dfs(i,j);
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v) {
  if (reachablefrom1[v]) return;
  reachablefrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}
void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

int main() {
  int m=in(), d=in();
  int ans = 0;
  rep (i, d+1) {
    int d1 = i % 10;
    int d10 = i / 10;
    if (d1 < 2 || d10 < 2) continue;
    if (m >= d1*d10) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
const long long INF = 1LL << 60;

// --------write my code!!!!!----------//

int main(){
    double A,B; cin >> A >> B;
    cout << A/B << endl;
}


Measured memory_bytes: 256
// ABC054 B - Template Matching
'use strict'

function Main(input) {
    const tmp = input.trim().split('\n');
    const NM = tmp[0].split(' ');
    const N = Number(NM[0])
    const M = Number(NM[1])
    const AB = tmp.splice(1);
    const A = AB.slice(0, N);
    const B = AB.slice(-M);
    // console.log(N, M, A, B);

    const joinB = B.join('');
    for (let y = 0; y < (N - M + 1); y++) {
        for (let x = 0; x < (N - M + 1); x++) {
            if (A[y][x] === joinB[0]) {
                // joinAを作る
                let joinA = '';
                for (let i = 0; i < M; i++) {
                    joinA += A[y + i].slice(x, x + M)
                }
                // joinAとjoinBが同じならYes
                if (joinA === joinB) {
                    console.log('Yes');
                    return;
                }
            }
        }
    }
    console.log('No');
    return;

}


Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,max_c=map(int,readline().split())
    d=[list(map(int,readline().split())) for _ in range(max_c)]
    c=[list(map(lambda x:int(x)-1,readline().split())) for _ in range(n)]

    #前処理
    color_table=[[0]*max_c for _ in range(3)]
    for color in range(max_c):
        for i in range(n):
            for j in range(n):
                color_table[(i+j+2)%3][color]+=d[c[i][j]][color]

    #全探索
    ans=float("inf")
    for i in range(max_c):
        for j in range(max_c):
            for k in range(max_c):
                if i==j or j==k or k==i:
                    continue
                ans=min(ans,color_table[0][i]+color_table[1][j]+color_table[2][k])

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 43868
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;
const int N_MAX = 200;
const int R_MAX = 8;
const int M_MAX = (N_MAX * (N_MAX - 1)) / 2 + 1;
const int INF = INT_MAX / 3;
int N;
int M;
int R;
int r[R_MAX];
int C[M_MAX][M_MAX];
int mi = INF;
void dfs (int p, int sum, bool visited[R_MAX]) {
    bool end = true;
    for (int i = 0; i < R; i++) {
        if (!visited[i]) end = false;
    }
    if (end) {
        mi = min(mi, sum);
        return ;
    }
    for (int i = 0; i < R; i++) {
        if (!visited[i]) {
            visited[i] = true;
            dfs(r[i], sum + C[p][r[i]], visited);
            visited[i] = false;
        }
    }
}

int main (void) {
    bool visited[R_MAX];

    cin >> N >> M >> R;
    for (int i = 0; i < R; i++) {
        int ri;
        cin >> ri;
        ri--;
        r[i] = ri;
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            C[i][j] = INF;
        }
    }
    for (int i = 0; i < M; i++) {
        int a;
        int b;
        cin >> a >> b;
        a--;
        b--;
        cin >> C[a][b];
        C[b][a] = C[a][b];
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
            }
        }
    }

    for (int i = 0; i < R; i++) visited[i] = false;

    for (int i = 0; i < R; i++) {
        visited[i] = true;
        dfs(r[i], 0, visited);
        visited[i] = false;
    }

    cout << mi << endl;

    return 0;
}

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

typedef int Val;
typedef pair<Val,int> Res;
#define val first
#define idx second

Res readExpr(string &s, int idx);
Res readTerm(string &s, int idx);
Res readFctr(string &s, int idx);

Res readExpr(string &s, int idx){
  Res r = readTerm(s, idx);
  while (s[r.idx]=='+'){
    Res r2 = readTerm(s, r.idx+1);
    r.val += r2.val;
    r.idx = r2.idx;
  }
  return r;
}
Res readTerm(string &s, int idx){
  Res r = readFctr(s, idx);
  while (s[r.idx]=='*'){
    Res r2 = readFctr(s, r.idx+1);
    r.val *= r2.val;
    r.idx = r2.idx;
  }
  return r;
}
Res readFctr(string &s, int idx){
  return Res(s[idx]-'0',idx+1);
}
Val LtoR(string &s){
  Val v;
  v = s[0]-'0';
  for (int i=1; i<s.size(); i+=2){
    if (s[i]=='+') v += s[i+1]-'0';
    else v *= s[i+1]-'0';
  }
  return v;
}

int main(void){
  string ex;
  int r,mul,ltr;
  string buf="IMLU";
  
  cin >> ex >> r;
  mul = readExpr(ex,0).val;
  ltr = LtoR(ex);
  cout << buf[(mul==r)+(ltr==r)*2] << endl;
  return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include<string>
using namespace std;
int main(){
   int N;
   cin>>N;
   int W[N];
   int min=200;
   int ABS;
   int sum1=0;
   int sum2=0;
   for(int i=0; i<N; i++){
       cin>>W[i];
       sum1=sum1+W[i];
       
   }
   for(int j=0; j<N; j++){
       cin>>W[j];
       sum2=sum2+W[j];
       sum1=sum1-W[j];
       ABS=abs(sum2-sum1);
       if(ABS<min){
           min=ABS;
           
       }
       
       
   }
   cout<<min;
}




Measured memory_bytes: 764
#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 main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, ans=1;
    cin>>N;
    
    for(ll i=2;i*i<=N;i++) ans=i;
    cout1(ans*ans)
}

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

int N;
int a[1000006];

int x[1000006];

int c[4];

long long int p[2000006];

long long int MOD = 1000000007;

long long int POW(long long int a, long long int k) {
	if (k == 0) { return 1; }
	if (k == 1) { return a;}

	if (k % 2 == 1) { return (POW(a, k - 1)*a) % MOD; }
	long long int tmp;
	tmp = POW(a, k / 2);

	return (tmp*tmp) % MOD;
}

long long int INV(long long int K) {
	return POW(K, MOD - 2);
}

int C(int n, int m) {
	bool y = (n== (n | (n - m)));
	return y;
}

string s;
int main(void) {

	cin >> N;
	cin >> s;
	for (int i = 1; i <= N; i++) {
		x[i-1] = s[i - 1] - '0'-1;
	}

	for (int i = 1; i <= N; i++) {
		c[x[i-1]]++;
	}

	int ans = 0;

	if (c[1] == 0) {
		long long int num = 0;
		for (int i = 0; i <= N - 1; i++) {
			if (x[i] == 2) { num += C(N - 1, i); num %= 2; }
		}
		if (num == 1) { ans = 2; }
		else { ans = 0; }
	}
	else {
		int num = 0;
		for (int i = 0; i <= N - 1; i++) {
			//cout <<x[i]<<"  "<< C(N - 1, i) << endl;
			if (x[i] == 1) {
				num += C(N - 1, i);   num %= 2;
			}
		}
		if (num == 1) { ans = 1; }
		else { ans = 0; }
	}

	cout << ans << endl;
	

	return 0;
}

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

lint calc(lint l, lint h, lint m, lint val){
    lint res = (h - l) * (h - l - 1LL) / 2LL;
    res -= (m - l) * (m - l - 1LL) / 2LL;
    res -= (h - m) * (h - m - 1LL) / 2LL;
    res *= val;
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<lint> a(n), rev(n + 1);
    rep(i, n){
        cin >> a[i];
        rev[a[i]] = i + 1;
    }
    lint ans = 0;
    set<lint> st;
    st.insert(0);
    st.insert(n + 1);
    REP(i, 1, n + 1){
        auto it1 = st.upper_bound(rev[i]);
        auto it2 = it1--;
        ans += calc(*it1, *it2, rev[i], i);
        st.insert(rev[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
x,y=map(str, input().split())
x=x.replace('A','1').replace('B','2').replace('C','3').replace('D','4').replace('E','5').replace('F','6')
y=y.replace('A','1').replace('B','2').replace('C','3').replace('D','4').replace('E','5').replace('F','6')

if x>y:
    print('>')
elif x==y:
    print('=')
else:
    print('<')

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a,b,c,d,n;
int main(){
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&n);
	b=min(b,a*2);
	c=min(c,b*2);
	d=min(d,c*2);
	cout<<1ll*(n/2)*d+(n%2)*c<<endl;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())

if a >= b:
    if a >= c:
        if b >= c:
            print(c, b, a)
        else:
            print(b, c, a)
    else:
        print(b, a, c)
else:
    if b >= c:
        print(a, c, b)
    else:
        print(a, b, c)
        


Measured memory_bytes: 5596