akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>
#include <set>

using namespace std;


int main() {

    set<string> s;

    int N;
    cin >> N;

    vector<string> ws;

    for (int i = 0; i < N; i++) {
        string w;
        cin >> w;
        ws.push_back(w);
    }

    char end = ws[0].back();
    s.insert(ws[0]);

    bool ok = true;

    for (int i = 1; i < N; i++) {

        string w = ws[i];

        if (s.find(w) != s.end()) {
            ok = false;
            break;
        }

        char first = w[0];
        if (end == first) {
            s.insert(w);
            end = w.back();
            continue;
        } else {
            ok = false;
            break;
        }
    }

    if (ok) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }


    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
	int N, M;
	cin >> N >> M;
	vector<P> v(N);
	for (int i = 0; i < N; ++i) {
		ll a, b;
		cin >> a >> b;
		v[i] = P(a, b);
	}
	sort(v.begin(), v.end());

	ll cost = 0;
	ll cnt = 0;
	for (int i = 0; i < N; ++i) {
		ll a = v[i].first;
		ll b = v[i].second;

		if (cnt + b <= M) {
			cost += (a * b);
			cnt += b;
		} else {
			cost += ((M - cnt) * a);
			break;
		}
	}

	cout << cost << endl;

	return 0;
}


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

int main() {
    int ans = 0;
    int N;
    cin >> N;
    vector<int> L(N), ab(N * (N - 1) / 2);
    for(size_t i = 0; i < N; i++) {
        cin >> L[i];
    }
    sort(L.begin(), L.end());
    int c = 0;
    for(size_t i = 0; i < N; i++) {
        for(size_t j = i + 1; j < N; j++) {
            ab[c] = L[i] + L[j];
            c++;
        }
    }

    sort(ab.begin(), ab.end());
    for(size_t i = 2; i < N; i++) {
        auto it = upper_bound(ab.begin(), ab.end(), L[i]);
        int index = it - ab.begin();
        int num = i * (i - 1) / 2;
        ans += num - index;
    }

    cout << ans << endl;
}

Measured memory_bytes: 8064
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>

using namespace std;

class Union_find{
 public:
  vector<int> Parent;

  Union_find(int N){
   Parent=vector<int>(N+1,-1);
  }

  int root(int A){
   if(Parent[A]< 0)return A;
   return  Parent[A]=root(Parent[A]);
  }

  int size(int A){
   return - Parent[root(A)];
  }
  
  bool connect(int A,int B){
   A=root(A);
   B=root(B);
   if(A==B)return false; 

 //  cout<<"c"<<endl;
   if(size(A)<size(B))swap(A,B);
   Parent[A]+=Parent[B]; 
   Parent[B]=A;
   return true; 
  }
};

int main(void){
 int N,M;

 cin>>N>>M;
 vector<int> A(M);
 vector<int> B(M);
 vector<long long int>ans(M);

 for(int i=0; i<M;i++)cin>>A[i]>>B[i];
 Union_find Uni(N);  
 ans[M-1]=(long long int)N*(N-1)/2;

 for(int i=M-1; i>=1; i--){
  ans[i-1]=ans[i];
  //cout<<"b"<<endl;
  if(Uni.root(A[i])!=Uni.root(B[i])){
   ans[i-1]-=(long long int)Uni.size(A[i])*Uni.size(B[i]);
   Uni.connect(A[i],B[i]);
  }
 }
 for(int i=0; i<M; i++)cout<<ans[i]<<endl;
 return 0;
}

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

int main (){
  double long a,b,h,m;
  cin>>a>>b>>h>>m;
  double long pi = 3.141592653589793;
  double long big,small;
  big = 30*h + m/2;
  small = 6*m;
  double long c = abs(big-small);
  double long ans = a*a + b*b - 2*a*b*cos((c*pi)/180);
  cout << fixed << setprecision(20) << sqrt(ans) << endl;
}

Measured memory_bytes: 4168
#include<stdio.h>
# define N 200000
int MB(int , int);
int main(){
  int i,n,hako[N];
  int max,min;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&hako[i]);
      }
  max=-1000000000;
  min = hako[0];
  for(i=1;i<n;i++){
    if(max <=hako[i]-min) max =hako[i]-min;
    if(min>hako[i]) min=hako[i];
    }
  printf("%d\n",max);
  
  return 0;
}



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

int main()
{
  int N;
  cin >> N;
  
  vector<int> L(N);
  for(int i = 0; i < N; i++) cin >> L.at(i);
  
  int total = 0;
  
  if(N < 3) cout << "0" << endl;
  else
  {
    for(int i = 0; i < N - 2; i++)
    {
      for(int j = i + 1; j < N - 1; j++)
      {
        for(int k = j + 1; k < N; k++)
        {
          if(L.at(i) == L.at(j) || L.at(j) == L.at(k) || L.at(k) == L.at(i))
          {
            continue;
          }
          if(L.at(i) + L.at(j) > L.at(k) && L.at(i) + L.at(k) > L.at(j) && L.at(j) + L.at(k) > L.at(i))
          {
            total++;
          }
        }
      }
    }
    cout << total << endl;
  }
}

Measured memory_bytes: 3600
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    string s = inp1;
    ll n = s.size();

    ll ans = 0;
    REP(i, n/2) {
        ans += s[i] != s[n-i-1];
    }
    say(ans);
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll  = long long;
template <typename T> inline T In() { T t; cin >> t; return t;}

using AB = pair<int, int>;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N = In<int>();
    vector<AB> vec(N);
    for(int i = 0; i < N; i++) {
        vec[i] = make_pair<int,int>(In<int>(), In<int>());
    }

    sort(vec.begin(), vec.end(), [](const AB &ab1, const AB &ab2) { 
        return ab1.second < ab2.second; });
    ll time = 0;
    for(const auto &ab: vec) {
        time += ab.first;
        if(time > ab.second) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

using namespace std;

int main() {
  int N, Y;
  cin >> N >> Y;

  int x = -1;
  int y = -1;
  int z = -1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N - i; j++) {
      int k = N - (i + j);

      if (i + j + k == N && 10000 * i + 5000 * j + 1000 * k == Y) {
        x = i;
        y = j;
        z = k;

        break;
      }
    }

    if (x != -1) {
      break;
    }
  }

  string answer = to_string(x) + " " + to_string(y) + " " + to_string(z);

  cout << answer << endl;
}


Measured memory_bytes: 256
h,w=map(int,raw_input().split())
c=[raw_input() for _ in xrange(h)]
ans=[""]*(2*h)
i=0
j=0
while i<2*h:
    ans[i]+=c[j]
    ans[i+1]+=c[j]
    i+=2
    j+=1
for i in xrange(2*h):
    print(ans[i])

Measured memory_bytes: 2692
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
typedef long long int ll;
#define INF 2<<30
int N;

class DP{
public:
	int cost, s;
	
	DP(){}
	DP(int cc, int ss){
		cost = cc;s=ss;
	}
	
	bool operator< (const DP &opp) const {
		return cost>opp.cost;
	}
};

int dest[100010]={0};
int com[100010]={0};
int visit[100010]={0};

int setDest(int s){
	if(dest[s]) return dest[s];
	dest[s] = -1;
	if(com[s]) return dest[s] = setDest(s + com[s]);
	else return dest[s] = s;
}

main(){
	int i,j;
	cin >> N;
	for(i=1;i<=N;i++) cin >> com[i];
	for(i=1;i<=N;i++) setDest(i);
	priority_queue<DP> dp;
	DP S;
	dp.push(DP(0, 1));
	visit[1] = 1;
	while(!dp.empty()){
		S = dp.top();
		dp.pop();
		if(S.s == N) break;
		for(i=1;i<=6;i++){
			DP T=S;
			if(T.s+i > N || dest[T.s+i] < 0) continue;
			T.s = dest[T.s+i];
			T.cost ++;
			if(visit[T.s]) continue;
			visit[T.s] = 1;
			dp.push(T);
		}
	}
	cout << S.cost << endl;
	return 0;
}

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

vector<int> bfs(const vector<vector<int>>& g, int s) {
  vector<int> d(g.size(), 1e9);
  d[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int i = q.front();
    q.pop();
    for (auto j : g[i]) {
      if (d[i] + 1 < d[j]) {
        d[j] = d[i] + 1;
        q.push(j);
      }
    }
  }
  return d;
}

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  vector<vector<int>> g(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);
  }

  auto du = bfs(g, u);
  auto dv = bfs(g, v);
  int r = 0;
  for (int i = 0; i < n; i++) {
    if (du[i] > dv[i]) continue;
    r = max(r, dv[i] - 1);
  }
  cout << r << endl;
}


Measured memory_bytes: 6656
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

divisor :: Int -> (Int,Int)
divisor n = sub (floor (sqrt $ fromIntegral n))
  where
    sub i | i < 1  = error " ??? "
          | n `mod` i == 0 = (i, n `div` i)
          | otherwise = sub (i-1)

main :: IO ()
main = do
  s <- readLn :: IO Int
  let n = (ceiling (sqrt $ fromIntegral s))
      (x,y) = divisor $ (n^2) - s
  if n^2 == s then putStrLn $ "0 0 0 " ++ (show n) ++ " "  ++ (show n) ++ " 0"
    else putStrLn $ "0 0 " ++ (show x) ++ " " ++ (show n) ++ " " ++ (show n) ++ " " ++ (show y)


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

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

    vector<int> cnt(N+1, 0);
    vector<int> ans;
    for(int n=N; n>=1; n--){
        if(cnt[n]%2 == a[n]) continue;
        ans.push_back(n);
        for(int i=1; i*i<=n; i++){
            if(n%i != 0) continue;
            cnt[i]++;
            if(i != n/i) cnt[n/i]++;
        }
    }

    cout << ans.size() << endl;
    for(int a: ans){
        cout << a << " ";
    }cout << endl;
}


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

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

  vector<int> ans(S.size());
  int cnt = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'L') {
      ans.at(i) += cnt / 2;
      ans.at(i - 1) += (cnt + 1) / 2;
      cnt = 0;
    } else
      cnt++;
  }

  reverse(S.begin(), S.end());
  reverse(ans.begin(), ans.end());

  cnt = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'R') {
      ans.at(i) += cnt / 2;
      ans.at(i - 1) += (cnt + 1) / 2;
      cnt = 0;
    } else
      cnt++;
  }

  reverse(ans.begin(), ans.end());

  for (int i = 0; i < S.size(); i++) {
    if (i != S.size() - 1)
      cout << ans.at(i) << ' ';
    else
      cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 1024
import copy

n = int(input())
if n == 1:
    print(1)
    exit()

l_2 = 0
l_1 = 2
l_0 = 1
for i in range(2, n+1):
    l_2 = copy.deepcopy(l_1)
    l_1 = copy.deepcopy(l_0)
    l_0 = l_1 + l_2
print(l_0)

Measured memory_bytes: 9296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18;
int n,p[5003],len;
int K;
ll C[5002],ans=-INF,ret[5002];
void dfs(int x,int w){
	if(x==w)return;
	++len;
	ret[len]=ret[len-1]+C[p[x]];
	dfs(p[x],w);
}
int main(){
	cin>>n>>K;
	for(int i=1;i<=n;i++)cin>>p[i];
	for(int i=1;i<=n;i++)cin>>C[i],ans=max(ans,C[i]);
	for(int i=1;i<=n;i++){
		ret[1]=C[p[i]];
		len=1;
		dfs(p[i],i);
		for(int j=1;j<=min(len,K);j++)ans=max(ans,ret[j]);
		if(K>len&&ret[len]>0){
			ll pr=K/len,ps=K%len,res=pr*ret[len];
			for(int j=0;j<=ps;j++)ans=max(ans,res+ret[j]);
			for(int j=0;j<=len;j++)ans=max(ans,res-ret[len]+ret[j]);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3728
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod//i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n-r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD


@mt
def slv(N, M, K):
    mod = 10**9+7
    C = Combination(N*M, mod)
    b = C(N*M-2, K-2)
    ans = 0
    m = M**2
    for d in range(1, N):
        ans += (N-d) * b * d * m
        ans %= mod
    m = N**2
    for d in range(1, M):
        ans += (M-d) * b * d * m
        ans %= mod



    return ans



def main():
    N, M, K = read_int_n()
    print(slv(N, M, K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 80876
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    string A,B,C,D;
    string S,T;
int main(){
    cin>>A>>B;
REP(i,stoi(A))C+="00";
    if(B!="100"){cout<<B+C;}
else {cout<<stoi(B+C)+stoi("1"+C);}
    return 0;

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int i=1, j, a[101]={0}, count[101]={0}, max=0;

	while(scanf("%d", &a[i]) != EOF)
		i++;

	for(i=1; i<=100; i++){
		for(j=1; j<=100; j++){
			if(a[j] == i)
				count[i]++;
		}
	}

	for(i=1; i<=100; i++){
		if(max < count[i])
			max = count[i];
	}

	for(i=0; i<=100; i++){
		if(count[i] == max)
			printf("%d\n", i);
	}
	return 0;

}

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

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

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn abs(x: i32) -> i32 {
    if x >= 0 {
        x
    } else {
        -x
    }
}

fn main() {
    let n = read::<i32>();
    let w = read_vec::<i32>();
    let mut min = 100000;

    for t in 0..n {
        let mut s1 = 0;
        let mut s2 = 0;
        for i in 0..t {
            s1 += w[i as usize];
        }
        for j in t..n {
            s2 += w[j as usize]
        }
        let sub = abs(s1 - s2);
        if sub < min {
            min = sub;
        }
    }
    println!("{}", min);
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int a[100];
int cells[100][100]; // r * c

int N, C;
vector<vector<ll>> D(30, vector<ll>(30, 0));
vector<vector<ll>> cnt(3, vector<ll>(30, 0));

ll calc(int index, int to) {
  ll ans = 0;
  rep0(i, C) {
    ans += cnt[index][i] * D[i][to];
  }
  return ans;
}

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

  rep0(i, C) rep0(j, C) cin >> D[i][j];

  rep0(i, N) rep0(j, N) {
    ll temp; cin >> temp;
    cnt[(i + j) % 3][temp - 1]++;
  }

  ll ans = 1e18;
  rep0(i, C) rep0(j, C) rep0(k, C) {
    if (i == j || j == k || k == i) continue;
    ll temp = 0;
    temp += calc(0, i);
    temp += calc(1, j);
    temp += calc(2, k);
    ans = min(ans, temp);
  }

  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;

  if (K%2 == 0 && N >= K/2){
    long long ans = 0, t = 0;
    for (int i = K / 2; i <= N; i += K){
      t++;
    }
    ans = t * t * t;
    t = 0;
    for (int i = K; i <= N; i += K){
      t++;
    }
    ans += t * t * t;

    printf("%llu\n", ans);
  }else{
    long long ans = 0, t = 0;
    for (int i = K; i <= N; i += K){
      t++;
    }
    ans += t * t * t;
    printf("%llu\n", ans);
  }
}


Measured memory_bytes: 3760
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=20,Mod=1e9+7;
int n,m,a[N],fac[1<<N],fai[1<<N],S[1<<N],f[N][1<<N],inv[1<<N];
void add(int &x,int y){x+=y;if(x>=Mod)x-=Mod;}
int C(int n,int m){
	if(n<0 || m<0 || n<m)return 0;
	return 1ll*fac[n]*fai[m]%Mod*fai[n-m]%Mod;
}
int cmp(int a,int b){return a>b;}
int main(){
	n=gi();m=gi();
	for(int i=1;i<=m;i++)a[i]=gi();
	sort(a+1,a+m+1,cmp);
	int all=1<<n;fac[0]=fai[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=all;i++)fac[i]=1ll*fac[i-1]*i%Mod;
	for(int i=2;i<=all;i++)inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
	for(int i=1;i<=all;i++)fai[i]=1ll*fai[i-1]*inv[i]%Mod;
	for(int i=1;i<=all;i++)S[i]=S[i-(i&(-i))]+1;
	f[0][0]=1;
	for(int i=1;i<=m;i++)
		for(int s=0;s<all;s++)
			if(f[i-1][s]){
				add(f[i][s],f[i-1][s]);
				for(int j=0;j<n;j++)
					if(!(s&(1<<j)))
						add(f[i][s|(1<<j)],1ll*f[i-1][s]*fac[1<<j]%Mod*C(all-a[i]-s,(1<<j)-1)%Mod);
			}
	ll ans=0;
	for(int s=0;s<all;s++){
		if(S[s]&1)ans=(ans-1ll*f[m][s]*fac[all-s-1]%Mod+Mod)%Mod;
		else ans=(ans+1ll*f[m][s]*fac[all-s-1]%Mod)%Mod;
	}
	printf("%lld\n",1ll*ans*all%Mod);
	return 0;
}


Measured memory_bytes: 41472
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll n,k;
bool check(ll mid){
  ll sum=mid;
  ll num=mid;
  ll cnt=1;
  while(num>0&&cnt<n){
    cnt++;
    sum+=num/2;
    num/=2;
  }
  // cout<<sum<<endl;
  if(sum<=k)return true;
  else return false;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>k;
  ll le=1,ri=k+1;
  while(ri-le>1){
    ll mid=(le+ri)/2;
    if(check(mid)){
      le=mid;
    }else ri=mid;
  }
  cout<<le<<endl;
  return 0;
}



Measured memory_bytes: 3180
N, M = map(int, input().split())
ken = [[] for _ in range(N)]
for i in range(1, M + 1):
    p, y = map(int, input().split())
    ken[p - 1].append((y, i))
ans = [0] * M
for k, li in enumerate(ken, 1):
    for i, (_, p) in enumerate(sorted(li), 1):
        ans[p - 1] = str(k).zfill(6) + str(i).zfill(6)
for x in ans:
    print(x)

Measured memory_bytes: 35920
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a,c,j;
    int b[105];
    int s[505];
    int i=0;
    while(cin>>n && n){
        n++;
        for(j=0;j<n;j++){
            cin>>b[j];
        }
        c=b[1]-b[0];
        for(j=1;j<n-1;j++){
            if(c!=b[j+1]-b[j]){
                if(j==1){
                    c=b[4]-b[3];
                    a=b[1]-b[0];
                    if(c!=a){
                        if(c==b[2]-b[0]){
                            j=0;
                        }else{
                            j=-1;
                        }
                    }
                }
                if(j==2){
                    if(b[2]-b[0]==b[4]-b[3]){
                        j=0;
                    }
                }
                j++;
                break;
            }
        }
        s[i]=b[j];
        i++;
    }
    for(j=0;j<i;j++){
        cout<<s[j]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3092
import java.io.*;

class Main {
	public static void main(String[] args) {
		BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
		try {
			int n;
			String str;
			double[] xi = new double[ 100+1 ];
			double[] yi = new double[ 100+1 ];
			double[] absxy = new double[ 100+1 ];
			int i;
			double Dxy = 0, max = 0;
			
			n = Integer.parseInt( kb.readLine() );
			i = 0;
			for( String nums: kb.readLine().split( " ", 0 ) ) {
				xi[i++] = Double.parseDouble( nums );
			}
			i = 0;
			for( String nums: kb.readLine().split( " ", 0 ) ) {
				yi[i++] = Double.parseDouble( nums );
			}
			Dxy = 0;
			for( i=0; i<n; i++ ) {
				absxy[i] = Math.abs( xi[i]-yi[i] );
				if( max < absxy[i] ) {
					max = absxy[i];
				}
				Dxy += absxy[i];
			}
			System.out.print( Dxy + "\n" );

			Dxy = 0;
			for( i=0; i<n; i++ ) {
				Dxy += Math.pow( absxy[i], 2 );
			}
			System.out.print( Math.sqrt( Dxy ) + "\n" );
			
			Dxy = 0;
			for( i=0; i<n; i++ ) {
				Dxy += Math.pow( absxy[i], 3 );
			}			
			System.out.print( Math.cbrt( Dxy ) + "\n" );
			
			System.out.print( max + "\n" );

		} catch( IOException e ) {
			System.err.println( e );
		}
	}
}

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

using namespace std;

const int V = 100005;
vector<int> to[V * 2];
bool visited[V * 2];

vector<int> cnt;
void dfs(int v)
{
	//cout << "dfs(" << v << ")" << endl;
	if (visited[v])
	{
		//cout << v << " is visited(in dfs)." << endl;
		return;
	}
	visited[v] = true;
	cnt[v / V]++;
	for (int u : to[v])
		dfs(u);
}

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

	for (int i = 0; i < n; ++i)
	{
		int x, y;
		cin >> x >> y;
		y += V;
		to[x].push_back(y);
		to[y].push_back(x);
	}

	long long ans = 0;
	for (int i = 0; i < V * 2; ++i)
	{
		if (visited[i])
		{
			//cout << i << " is visited at first." << endl;
			//cout << i << ":" << cnt[0] << " " << cnt[1] << endl;
			continue;
		}
		cnt = vector<int>(2);
		dfs(i);
		ans += (long long)cnt[0] * cnt[1];
		//cout << i << ":" << cnt[0] << " " << cnt[1] << endl;
	}
	ans -= n;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 10240
#include <stdio.h>

int main()
{
	int array[10];
	int i;
	int first=0, second=0, third=0;

	for(i=0;i<10;i++)
	{
		scanf("%d", &array[i]);

		if(array[i]>first)
		{
			third = second;
			second = first;
			first = array[i];
		}
		else if(array[i]<first &&array[i]>=second)
		{
			third = second;
			second = array[i];
		}
		else if(array[i]<second && array[i]>=third)
		{
			third = array[i];
		}
	}
	printf("%d\n", first);
	printf("%d\n", second);
	printf("%d\n", third);

	return 0;
}

Measured memory_bytes: 600
//
// Created by 中野誠大 on 2019-02-10.
//

#include<iostream>

#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;


int main() {
    string s;
    int n;
    cin >> s;
    n = s.size() -2;
    cout << s.at(0) << n << s.at(n+1)<<endl;

    return 0;

}

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

public class Main {


    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	int[] data=new int[3];

    	for(int i=0;i<3;i++) {
    		data[i]=sc.nextInt();
    	}

    	int K=sc.nextInt();
    	Arrays.sort(data);

    	for(int i=0;i<K;i++) {
    		data[2]*=2;
    	}

    	int sum=0;

    	for(int i=0;i<3;i++) {
    		sum+=data[i];
    	}

    	System.out.println(sum);



    }

}







Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int rmq[maxn][20];
int dis[maxn];
vector<int> mp[maxn];
int n;
void dfs(int u,int pre)
{
	dis[u]=dis[pre]+1;
	if(pre)rmq[u][0]=pre;
	else rmq[u][0]=u;
	for(int i=1;i<20;++i)
		if(u==1)rmq[u][i]=u;
		else rmq[u][i]=rmq[rmq[u][i-1]][i-1];
	sort(mp[u].begin(),mp[u].end());
	for(int v:mp[u])
		dfs(v,u);
}
queue<int> q;
vector<int> path;
void bfs(int u)
{
	q.push(u);
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		for(int v:mp[u])
		{
			path.push_back(v);
			q.push(v);
		}
	}
}
int getlca(int u,int v)
{
	if(dis[u]<dis[v])swap(u,v);
	for(int i=19;i>=0;--i)
		if(dis[rmq[u][i]]>=dis[v])u=rmq[u][i];
	if(u==v)return u;
	for(int i=19;i>=0;--i)
		if(rmq[u][i]!=rmq[v][i])
			u=rmq[u][i],v=rmq[v][i];
	return rmq[u][0];
}
int main()
{
	int p,u;
	scanf("%d",&n);
	for(int i=2;i<=n;++i)
	{
		scanf("%d",&p);
		mp[p].push_back(i);
	}
	dfs(1,0);
	bfs(1);
	u=1;
	long long res=0;
	for(int v:path)
	{
		res+=dis[u]+dis[v]-dis[getlca(u,v)]*2;
		u=v;
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 23384
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 1000005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897
#define db double
#define noop
#define flu fflush(stdout)
#define imp {cout<<"NO\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}

bool compare(pll a, pll b) {
    if(a.se<b.se) return true;
    // if(a.se==b.se && a.fi<b.fi) return true;
    return false;
}

int main() {

    get(n);
    vector<pll> A(n);
    rep(i,n) {
        get2(a,b);
        A[i] = {a-b, a+b};
    }

    sort(ALL(A), compare);
    ll i = 0, count = 1;

    rep2(j,1,n) {
        if(A[j].fi>=A[i].se) {
            i = j;
            count++;
        }
    }
    // while(i<n) {
    //     count++;
    //     ll last = A[i].se;
    //     i++;
    //     while(i<n && A[i].fi<=last)
    //         i++;
    // }


    printf("%lld\n", count);
    
    return 0;  
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int input[10];
    
    for(int i = 0; i < 10; i++){
        cin >> input[i];
    }
    
    sort(input, input+10, greater<int>());
    
    for(int n = 0; n < 3; n++){
        cout << input[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
import sys

def is_ok(a_lst, b_lst, c):
    if len(a_lst) != len(b_lst):
        print(a_lst)
        print(b_lst)
        raise 'aaaaaaaaa'

    s = sum([ a * b for a, b in zip(a_lst, b_lst)]) + c
    return s > 0

def main():
    line = sys.stdin.readline()
    lst = line.split()
    n = int(lst[0])
    m = int(lst[1])
    c = int(lst[2])

    line = sys.stdin.readline()
    b_lst = [ int(s) for s in line.split()]

    ans = 0

    for i in range(n):
        line = sys.stdin.readline()
        a_lst = [ int(s) for s in line.split()]

        if is_ok(a_lst, b_lst, c):
            ans += 1

    print(ans)

    return 0

if __name__ == '__main__':
    sys.exit(main())


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

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n";
#define print(a) for(auto &x : a) cout << x << " "; cout << "\n";

const int inf = 1e18 + 5;
const int N = 2e5 + 50;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int l = 0, r = n - 1;
    int ans = 0;
    bool flag = 0;
    while(l < r)
    {
        while(s[l] == 'R') 
        {
            l++;
            if(l >= r)
            {
                flag = 1;
                break;
            }
        }
        if(flag) break;
        while(s[r] == 'W') 
        {
            r--;
            if(l >= r)
            {
                flag = 1;
                break;
            }
        }
        if(flag) break;
        if(s[l] == 'W' && s[r] == 'R') 
        {
            swap(s[l], s[r]);
            l++, r--;
            ans++;
        }
    }
    cout << ans << endl;
}

int32_t main()
{
    DESYNC
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            string strDice = Console.ReadLine();
            string strOrder = Console.ReadLine();
            Dice insD = new Dice(strDice, strOrder);
            int intTop = insD.GetTop();

            //出力
            Console.WriteLine(intTop); 
            
        }
        
    }
    
    class Dice{
        
        private string strDice;
        private string strOrder;
        private int[] dice;
        
        public Dice(string strDice, string strOrder){
            this.strDice = strDice;
            this.strOrder = strOrder;
            SetDice();
        }
        
        private void SetDice(){
        
            string[] strDiceArray = strDice.Split(' ');
            this.dice = new int[6];
            for(int index = 0; index < 6; index++){
                dice[index] = int.Parse(strDiceArray[index]);
            }
            char[] chOrder = strOrder.ToCharArray();
            for(int order = 0; order < chOrder.Length; order++){
                Roll(chOrder[order]);
            }
            
        }
        
        private void Roll(char chDirection){
            if(chDirection == 'N'){
                int intTemp = dice[0];
                dice[0] = dice[1];
                dice[1] = dice[5];
                dice[5] = dice[4];
                dice[4] = intTemp;
            }else if(chDirection == 'W'){
                int intTemp = dice[0];
                dice[0] = dice[2];
                dice[2] = dice[5];
                dice[5] = dice[3];
                dice[3] = intTemp;
            }else if(chDirection == 'E'){
                int intTemp = dice[0];
                dice[0] = dice[3];
                dice[3] = dice[5];
                dice[5] = dice[2];
                dice[2] = intTemp;
            }else{
                int intTemp = dice[0];
                dice[0] = dice[4];
                dice[4] = dice[5];
                dice[5] = dice[1];
                dice[1] = intTemp;
            }
        }
        
        public int GetTop(){
            return dice[0];
        }
        

        
        
    }

}



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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vector<vector<int>>ve(n);
  for(int i=0;i<n-1;i++){
    int a,b;cin>>a>>b;
    ve[--a].pb(--b);
    ve[b].pb(a);
  }
  int used[n+100]={};
  used[0]=1;used[n-1]=2;
  queue<int>fe,su;
  fe.push(0);
  su.push(n-1);
  int cnt=0;
  while(!fe.empty()||!su.empty()){
    if(cnt%2==0){
      vector<int>point;
      while(!fe.empty()){
	int now=fe.front();
	fe.pop();
	for(int i=0;i<ve[now].size();i++){
	  if(used[ve[now][i]]==0){
	    used[ve[now][i]]=1;
	    point.pb(ve[now][i]);
	  }
	}
      }
      for(int i=0;i<point.size();i++)fe.push(point[i]);
      cnt++;
    }else{
      vector<int>point;
      while(!su.empty()){
	int now=su.front();
	su.pop();
	for(int i=0;i<ve[now].size();i++){
	  if(used[ve[now][i]]==0){
	    used[ve[now][i]]=2;
	    point.pb(ve[now][i]);
	  }
	}
      }
      for(int i=0;i<point.size();i++)su.push(point[i]);
      cnt++;
    }
  }
  int fenec=0,snuke=0;
  for(int i=0;i<n;i++)
    if(used[i]==1)fenec++;
    else snuke++;
  if(fenec>snuke)cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
  return 0;
}


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

int main(int argc, char *argv[])
{
    int m, t, p, r, mk, tk, pk, jk, score, team, prev_pnt, prev_pnl;
    while (cin >> m >> t >> p >> r, m) {
        vector<int> ans(t + 1, 0);
        vector<int> penalty(t + 1, 0);
        vector<vector<int> > wrong(t + 1, vector<int>(p + 1, 0));
        for (int i = 0; i < r; ++i) {
            cin >> mk >> tk >> pk >> jk;
            if (jk != 0) {
                wrong[tk][pk]++;
            } else {
                ans[tk]++;
                penalty[tk] += 20 * wrong[tk][pk] + mk;
            }
        }
        prev_pnt = prev_pnl = -1;
        for (int i = 0; i < t; ++i) {
            score = -1;
            for (int j = 1; j <= t; ++j) {
                if (score < ans[j]) {
                    score = ans[j];
                    team = j;
                } else if (score == ans[j]) {
                    team = (penalty[team] < penalty[j]) ? team : j;
                }
            }
            if (i != 0 && prev_pnt == ans[team] && prev_pnl == penalty[team])
                cout << "=";
            else if (i != 0)
                cout << ",";
            cout << team;
            prev_pnt = ans[team];
            prev_pnl = penalty[team];
            ans[team] = -2;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
#include <string.h>

void reverse(char *);

int main(void)
{
    char str[21];

    scanf("%s", str);
    reverse(str);
    puts(str);

    return 0;
}

void reverse(char *str)
{
    int i, j;
    char ch;
    for (i = 0, j = strlen(str) - 1; i < j; i++, j--) {
        ch = str[i];
        str[i] = str[j];
        str[j] = ch;
    }
}


Measured memory_bytes: 1980
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;
 
char str0[105];
char str1[105];
char str2[105];
 
int main(int argc, char* argv[])
{    
    int n;
    scanf("%d%s%s%s", &n, str0, str1, str2);
    int i;
    int cnt=0;
    for(i=0; i<n; i++) {
        if(str0[i]==str1[i] && str1[i]==str2[i]) {
            ;
        }
        else if(str0[i]==str1[i] || str1[i]==str2[i] || str2[i]==str0[i]) {
            cnt++;
        }
        else {
            cnt+=2;
        }
    }
    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
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())
vector<int>ans;
int main(){
	int n; cin>>n;
	for(int i=1;;i++){
	    if(i%2==0||i%3==0||i%5==0) ans.pb(i);
	    if(ans.size()==n) break;
	}
	ll sum = 0;
	for(int i=0;i<n;i++) sum += ans[i];
	int t = 0;
	if(sum%30 != 0 || (ans[ans.size()-1]%2!=0&&ans[ans.size()-1]%3!=0&&ans[ans.size()-1]%5!=0) || (ans[ans.size()-2]%2!=0&&ans[ans.size()-2]%3!=0&&ans[ans.size()-2]%5!=0)){
	    int zan = 120-sum%30;
	    for(int i=0;i<=zan;i++){
            int x = ans[ans.size()-2]+i;
            int y = ans[ans.size()-1]+zan-i;
            if(x%2==0||x%3==0||x%5==0){
                if(y%2==0||y%3==0||y%5==0){
                    ans[ans.size()-2]+=i;
                    ans[ans.size()-1]+=zan-i;
                    goto tugi;
                }
            }
	    }
	}tugi:;
	SORT(ans);
	for(int i=1;i<n;i++) assert(ans[i-1]!=ans[i]);
	sum = 0;
	for(int i=0;i<n;i++) sum += ans[i];
	for(int i=0;i<n;i++) assert(__gcd(sum,(ll)ans[i])>1);
	assert(ans[n-1]<=30000);
	for(int i=0;i<n;i++) printf("%d ",ans[i]);
	puts("");
}

Measured memory_bytes: 512
import collections
N = int(input())


def prime_factorize(n):
    assert n > 0
    res = []
    while n % 2 == 0:
        res.append(2)
        n //= 2
    m = 3
    while m ** 2 <= n:
        if n % m == 0:
            res.append(m)
            n //= m
        else:
            m += 2
    if n != 1:
        res.append(n)
    return res


ans = 0
for i in range(1, N+1, 2):
    d = collections.Counter(prime_factorize(i))
    tmp = 1
    for v in d.values():
        tmp *= (1 + v)
    if tmp == 8:
        ans += 1
print(ans)



Measured memory_bytes: 38384
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

std::vector<int> topological_sort(std::vector<std::vector<int>> edges,
								  std::vector<int> indegrees) {
	int n = edges.size();
	std::vector<int> sorted;
	std::vector<bool> is_used(n, false);
	std::queue<int> q;
	for(int i = 0; i < n; i++) {
		if(indegrees[i] == 0) {
			q.push(i);
		}
	}

	while(!q.empty()) {
		int node = q.front();
		q.pop();
		sorted.push_back(node);
		is_used[node] = true;
		for(int& e : edges[node]) {
			indegrees[e]--;
			if(!is_used[e] && indegrees[e] == 0) {
				q.push(e);
			}
		}
	}
	return sorted;
}

int main() {
	int n, m;
	cin >> n >> m;
	VI2D edges(n);
	VI indegrees(n, 0);
	REP(i, m) {
		int x, y;
		cin >> x >> y;
		edges[x - 1].push_back(y - 1);
		indegrees[y - 1]++;
	}
	int result = 0;
	VI sorted = topological_sort(edges, indegrees);
	VI dp(n, 0);
	REP(i, n) {
		EACH(e, edges[sorted[i]]) {
			dp[e] = max(dp[e], dp[sorted[i]] + 1);
			chmax(result, dp[e]);
		}
	}
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 15540
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    LL k, a, b;
    cin >> k >> a >> b;
    if (a > b || k - 1 < a || b - a <= 1) {
        cout << k + 1 << endl;
        return 0;
    }

    cout << a + ((k - a + 1) / 2 * (b - a)) + (k - a + 1) % 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
	while (1) {
		long long n, a[110], k, ans, r, l;
		ans = 0;
		cin >> n;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		cin >> k;
		r = n-1;
		l = 0;
		while (r - l >= 0) {
			ans++;
			long long m = (l + r) / 2;
			if (a[m] == k) {
				break;
			}
			else if (a[m] > k) {
				r = m - 1;
			}
			else if (a[m] < k) {
				l = m + 1;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include<stdio.h>
int main(void)
{
    int A1,A2,A3;
  
    scanf("%d%d%d",&A1,&A2,&A3);
  
    if(A1+A2+A3>=22) printf("bust\n");
    else printf("win\n");
  
    return 0;
}

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

using namespace std;

#define int long long
#define double long double
#define sz(x) ((int) (x).size())

signed main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0);

    map<pair<int, int>, int> counts;

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        double x;
        cin >> x;
        int two = 0, five = 0;
        for (int it = 0; it < 10; ++it) {
            x *= 10;
            --two; --five;
        }
        int y = roundl(x);
        while (y % 2 == 0) {
            y /= 2;
            ++two;
        }
        while (y % 5 == 0) {
            y /= 5;
            ++five;
        }
        ++counts[{two, five}];
    }
    
    int ans = 0;
    for (auto [p1, c1]: counts) {
        for (auto [p2, c2]: counts) {
            if (p1.first + p2.first < 0 || p1.second + p2.second < 0) continue;
            if (p1 > p2) continue;
            if (p1 == p2) {
                ans += c1 * (c1 - 1) / 2;
            } else {
                ans += c1 * c2;
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3780
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int c[51000];
int bit[51000];
int getsum(int a,int b){
	if(a)return getsum(0,b)-getsum(0,a-1);
	int ret=0;
	for(;b>=0;b=(b&(b+1))-1)ret+=bit[b];
	return ret;
}
void add(int a,int b){
	for(;a<51000;a|=a+1)bit[a]+=b;
}
int sum[51000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<b;i++)scanf("%d",c+i);
		for(int i=0;i<b;i++)sum[i+1]=sum[i]+c[i];
		int L=0;
		int R=a;
		while(L+1<R){
			int M=(L+R)/2;
			for(int i=0;i<=b+1;i++)bit[i]=0;
			add(0,1);
			add(1,-1);
			for(int i=0;i<b;i++){
				if(!getsum(0,i))continue;
				if(sum[b]-sum[i]+b-i-1<=a){
			//		printf("%d %d\n",M,i);
					add(b,1);break;
				}
				int l=i;
				int r=b;
				while(l+1<r){
					int m=(l+r)/2;
					if(M*(m-i-1)>=a-(sum[m]-sum[i]))r=m;
					else l=m;
				}
				int v1=r;
			//	if(v1-i-1>a-(sum[v1]-sum[i]))continue;
				l=i-1;
				r=b;
				while(l+1<r){
					int m=(l+r)/2;
					if(m-i-1>a-(sum[m]-sum[i]))r=m;
					else l=m;
				}
				int v2=l;
			//	printf("%d %d %d %d\n",M,i,v1,v2);
				if(v1<=v2){
					add(v1,1);
					add(v2+1,-1);
				}
			}
			if(getsum(0,b))R=M;
			else L=M;
		}
		printf("%d\n",R);
	}
}

Measured memory_bytes: 1604