akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

string seq[9] = {"BD","ACE","BF","AEG","BDFH","CEI","DH","GEI","HF"};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  rep(i,1000){
    cin >> s;
    if(s.size() == 1) cout << s << endl;
    rep(j,s.size()-1){
      if(seq[s[j]-'A'].find(s[j+1]) == string::npos) break;
      if(j == s.size()-2) cout << s << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
char s[101],t[101];
int main()
{
	scanf("%s",s);
	scanf("%s",t);
	sort(s,s+strlen(s));
	sort(t,t+strlen(t),greater<char>());
	printf("%s",strcmp(s,t)<0?"Yes":"No");
	return 0;
}

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

long long GCD(long long a, long long b){
  
  if(a % b == 0) return b;
  else return GCD(b, a % b);
}

int main(){
  
  long long N, X, i, j, d, yk;
  cin >> N >> X;
  
  for(i = 0; i < N; i++){
    
    cin >> d;
    d = abs(d - X);
    if(i == 0) yk = d;
    if(d % yk == 0){
      continue;
    }else{
      yk = GCD(d, yk);
    }
  }
  cout << yk << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define lb(x) ((x)&(-(x)))
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 5010
using namespace std;
typedef long long ll;
int n,m,f[2][N<<1];
char s[N];
inline int pw(int a,int b){int r=1;for(;b;b>>=1,a=1ll*a*a%dalao)if(b&1)r=1ll*r*a%dalao;return r;}
inline void upd(int& a,int b){a=a+b>=dalao?a+b-dalao:a+b;}
int main(){
	scanf("%d%s",&n,s+1),m=strlen(s+1);
	f[0][0]=1;
	for(int i=1,z=1;i<=n;i++,z^=1){
		for(int j=0;j<=n+m;j++){
			f[z][j]=f[z^1][j+1];
			if(j)upd(f[z][j],(f[z^1][j-1]<<1)%dalao);
			else upd(f[z][j],f[z^1][j]);
		}
	}
	printf("%lld",1ll*f[n&1][m]*pw(pw(2,m),dalao-2)%dalao);
	return 0;
}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int w,h,n;
int grid[100010] = {0};
int grid2[100010]= {0};
int main(){
	cin >> n >> w >> h;
	//????????¨x,y??§?¨?????????????????????????YesNo??????????????§???k
	REP(i,n){
		int x,y,ww;
		cin >> x >> y >> ww;
		int ux = max(0, x-ww);
		int dx = min(h, x+ww);
		int ly = max(0, y-ww);
		int ry = min(w, y+ww);
		grid[ux]++;
		grid[dx]--;
		grid2[ry]--;
		grid2[ly]++;
	}
	bool flag = true;
	REP(i,w){
		grid[i+1] += grid[i];
		if(grid[i] == 0){
			flag = false;
		}
	}
	if(flag){
		cout << "Yes" << endl;
		return 0;
	}
	REP(i,h){
		grid2[i+1] += grid2[i];
		if(grid2[i] == 0){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1936
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
#define fst first
#define snd second
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
inline int Log2(ll x) {int k; for(k=0; x>0; ++k) x>>=1; return k;} // number of binary digits
template<typename T> inline int count_between(vector<T>& a, T l, T r) {
  return lower_bound(all(a), r) - lower_bound(all(a), l); // [l, r)
}


struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint& operator/=(const mint r) {
    ll a = r.x, b = MOD, u = 1, v = 0;
    while (b) {
      ll t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    x = x * u % MOD;
    if (x < 0) x += MOD;
    return *this;
  }
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// initialization
const int F_MAX = int(2e6)+10;
ll fac[F_MAX], finv[F_MAX], inv[F_MAX];
void binom_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < F_MAX; ++i) {
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

// binom mod MOD
ll binom(int n, int k) {
  if (k < 0 || n < k) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

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

  mint a = mint(A) / (A+B);
  mint b = mint(B) / (A+B);
  mint c = mint(100) / (A+B);

  mint ans = 0;
  rep(i, N) {
    mint x = a.pow(N) * b.pow(i) + a.pow(i) * b.pow(N);
    ans += mint(binom(N-1+i, i)) * c * x * (N+i);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    ll n, d;
    cin >> n >> d;
    int ans = 0;
    rep(i,n){
        ll x, y;
        cin >> x >> y;
        if(d*d >= x*x + y*y){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
import sys

# import bisect
from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, x, y = list(map(int, readline().split()))
    x, y = x - 1, y - 1
    que = deque()
    ans = [0] * n
    loopsize = y - x + 1

    if loopsize % 2 == 1:
        for i in range(1, loopsize // 2 + 1):
            ans[i] = loopsize
    else:
        for i in range(1, loopsize // 2 + 1):
            ans[i] = loopsize
        ans[loopsize // 2] = loopsize // 2

    loopdist = [0] * n
    que.append((0, 0))
    que.append((loopsize - 1, 1))
    visited = [False] * loopsize
    visited[0] = True
    visited[-1] = True

    while que:
        cn, dist = que.popleft()
        loopdist[dist] += 1
        if not cn == 0:
            if not visited[cn - 1]:
                visited[cn - 1] = True
                que.append((cn - 1, dist + 1))
        if not cn == (loopsize - 1):
            if not visited[cn + 1]:
                visited[cn + 1] = True
                que.append((cn + 1, dist + 1))

    left = x
    right = n - y - 1

    for i in range(left):
        for j in range(loopsize // 2 + 1):
            ans[i + 1 + j] += loopdist[j]

    for i in range(1, left):
        ans[i] += left - i

    for i in range(right):
        for j in range(loopsize // 2 + 1):
            ans[i + 1 + j] += loopdist[j]

    if left > 0 and right > 0:
        for i in range(left):
            for j in range(right):
                ans[i + j + 3] += 1


    for i in range(1, right):
        ans[i] += right - i



    for i in range(1,n):
        print(ans[i])

if __name__ == '__main__':
    main()


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

using namespace std;


#define PI 3.14159265
#define int long long

main(){


	int n; cin >> n;

	// cout << 1e18 << endl;


	if(n & 1){
		cout << 0 << endl;
	}else{

		int a = 0, b = 0, base = 5;

		while(base <= n){
			a += (n / base) / 2;
			base *= 5;
		}

		base = 2;

		while(base <= n){
			b += n / base;
			base *= 2;
		}

		cout << min(a, b) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
const int maxn = 100100;
long long fat[maxn];
long long mod = 1000000007;
int main(){
    fat[0] = 1;
    for(int e = 1; e < maxn; e++) fat[e] = fat[e-1]*e%mod;
    long long a, b;
    cin >> a >> b;
    if(abs(a-b) > 1) printf("0\n");
    else if(abs(a-b) == 1){
        cout << (fat[a]*fat[b])%mod << endl;
    } else {
        cout << ((fat[a]*fat[b])%mod)*2%mod << endl;
    }
    return 0;
}


Measured memory_bytes: 1536
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    a,b,k = map(int, input().split())
    ans = []
    if b-a+1 >= 2*k:
        for tmp in range(a, a+k):
            ans.append(tmp)
        for tmp in range(b-k+1,b+1):
            ans.append(tmp)
    else:
        for tmp in range(a, b+1):
            ans.append(tmp)
    ans.sort()
    for tmp in ans:
        print(tmp)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  vector<ll> A(N, 0);
  map<ll, ll> mp;
  map<ll, ll> mp2;
  REP(i, N){
    ll tmp; cin >> tmp;
    A[i] = tmp; mp[tmp]++;
  }
  ll ANS = 0;
  for(auto &i : mp){
    if(i.second > 1){
      ANS += i.second*(i.second-1)/2;
      mp2[i.first] = i.second*(i.second-1)/2;
    }
  }
  REP(i, N){
    ll ans = ANS;
    if(mp2.count(A[i])){
      ans -= mp2[A[i]];
      ans += (mp[A[i]]-1)*(mp[A[i]]-2)/2;
    }
    cout << ans << endl;
  }
}

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

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll t,i,x,j,y,z,k,n;

cin>>x>>y;
z=x*y;
k=__gcd(x,y);
ce(z/k)
}


Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
import string

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

# S = sys.stdin.readline().rstrip()
# print(S[::2])

S = sys.stdin.readline().rstrip()
for c in string.ascii_lowercase:
    if c not in S:
        print(c)
        exit()
print('None')


Measured memory_bytes: 13660
(defun compute(lst)
  (format t "~D~%" (- (reduce #'max lst) (reduce #'min lst)))
  )
(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))
	;(splitat #\a "john mccarthy")
(defun readline (callback)
  (labels ((rec (i)
				(let ((line (read-line nil nil)))
				  (when (not (zerop (length line)))
					(funcall callback line i)
					(rec (1+ i))))))
	(rec 0)))
	;(readline (lambda(line i)))
(defun start()
  (let ((n 0)
        (lst nil))
    (readline (lambda(line i)
                (cond ((zerop i) (setf n (parse-integer line)))
                      (t (compute (mapcar #'parse-integer (splitat #\space line)))))))))
(start)

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

int main()
{

	string textS;
	cin >> textS;

	int textSize = textS.size();

	bool flag  = (textSize % 2 == 0);

	if(flag){
		for (int i = 0; i < textSize/2; i++)
		{
			if(textS[i*2] != 'h' || textS[i*2+1] != 'i'){
				flag = false;
				break;
			}
		}
	}

	cout << (flag ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
class Main {
	public static void main(String[] a) {
		final String nl = System.lineSeparator();
		final StringBuilder sb = new StringBuilder();

		for (int x = 1; x <= 9; x++) {
			for (int y = 1; y <= 9; y++) {
				sb.append(x);
				sb.append("x");
				sb.append(y);
				sb.append("=");
				sb.append(x * y);
				sb.append(nl);
			}
		}

		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 24116
s = list(input())
l = len(s)-1
li = ["+",0]
L = [0]*(l)

from itertools import product
sum1 = 0
for v in product(li,repeat = l):
    a = ""
    for i in range(l):
        if v[i] == "+":
            a += s[i] + (v[i])
        else:
            a +=s[i]
    a +=s[-1]
    sum1 += eval(a)
print(sum1)

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var s string
	var ans int
	fmt.Scan(&s)
	for s != "" {
		if len(s) == 1 {
			s = ""
		} else if s[0] == s[len(s)-1] {
			s = s[1 : len(s)-1]
		} else {
			if s[0] == 'x' {
				s += "x"
				ans++
			} else if s[len(s)-1] == 'x' {
				s = "x" + s
				ans++
			} else {
				ans = -1
				break
			}
		}
	}
	fmt.Println(ans)
}


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

#define PI acos(-1)
#define _fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007
#define mxx 1000000
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;


int tc;

void solve(){

    double a,b,h,m,d,x,hd,md;
    cin>>a>>b>>h>>m;
    hd=h*30+(m/2);
    md=m*6;
    d=abs(hd-md);
    d=min(d,360-d);
    x=(a*a+b*b)-2*a*b*cos((d*PI)/180.0);
    x=sqrt(x);
    cout.precision(12);
    cout<<x<<endl;

}

int main()
{

    _fastIO;

    //cin>>tc; while(tc--)
    solve();

    return 0;
}







Measured memory_bytes: 4132
use proconio::*;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        K: usize,
    }
    let mut ans = 0;
    for i in 1..K + 1 {
        for j in 1..K + 1 {
            for k in 1..K + 1 {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    println!("{}", ans);
}

fn gcd(a: usize, b: usize) -> usize {
    if a < b {
        return gcd(b, a);
    }
    let (mut a, mut b) = (a, b);
    let mut r: usize;
    while a % b != 0 {
        r = a % b;
        a = b;
        b = r;
    }
    b
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main(){
  ll n,r;
  ll ans = 0;
  cin >> n >> r;
  cout << max(r,r + 100 * (10 - n)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	long K;
	cin >> N >> K;

	vector<pair<int, int>> ab(N);
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		ab[i] = make_pair(a, b);
	}

	sort(begin(ab), end(ab));

	long idx = 0;
	for (int i = 0; i < N; i++) {
		int a = ab[i].first, b = ab[i].second;
		if (K <= idx + b) {
			cout << a << endl;
			return 0;
		}

		idx += b;
	}

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
string Asc(string a, int len)
{
    char temp;
    for(int i = 0; i < len; i++){
        for(int j = 0; j < len-1; j++){
            char charA = a[j], charB = a[j+1];
            if(charA > charB){
                temp = charA;
                a[j] = charB;
                a[j+1] = temp;
            }
        }
    }
    return a;
}
string Dsc(string a, int len)
{
    char temp;
    for(int i = 0; i < len; i++){
        for(int j = 0; j < len-1; j++){
            char charA = a[j], charB = a[j+1];
            if(charA < charB){
                temp = charA;
                a[j] = charB;
                a[j+1] = temp;
            }
        }
    }
    return a;
}
int main()
{
    string s,t;
    cin >> s;
    cin >> t;
    int len1 = s.length();
    int len2 = t.length();
    string a = Asc(s, len1);
    string b = Dsc(t, len2);
    if(a < b) cout << "Yes" << "\n"; else cout << "No" << "\n";
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

from collections import defaultdict

def main():
    n = int(input())
    s = input().strip()

    tmp = defaultdict(lambda : 0)
    for state in range(1 << n):
        rs, bs = "", ""
        for i in range(n):
            if (state >> i) & 1:
                rs += s[i]
            else:
                bs += s[i]
        tmp[(rs, bs)] += 1
    
    ans = 0
    for state in range(1 << n):
        rs, bs = "", ""
        for i in range(n):
            if (state >> i) & 1:
                rs += s[-i - 1]
            else:
                bs += s[-i - 1]
        ans += tmp[(rs, bs)]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 170620
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N, M, R;
  cin >> N >> M >> R;
  VEC<int> r(R);
  REP(i, 0, R) {
    cin >> r[i];
    --r[i];
  }
  sort(ALL(r));
  int inf = INT32_MAX / 2;
  MAT<int> g = MATINIT(int, N, N, inf);
  DUMP("HI1");
  REP(i, 0, M) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    g[a][b] = c;
    g[b][a] = c;
  }
  REP(i, 0, N) g[i][i] = 0;
  DUMP("HI2");
  REP(k, 0, N) {
    REP(i, 0, N) {
      REP(j, 0, N) { g[i][j] = min(g[i][j], g[i][k] + g[k][j]); }
    }
  }
  DUMP("HI");
  LL mi = inf;
  do {
    LL sum=0;
    REP(i, 0, R-1) { sum += g[r[i]][r[i+1]]; }
    mi = min(mi, sum);

  } while (next_permutation(ALL(r)));
  cout << mi << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
template<class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }


int main() {
    ll n,m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    ll ans = lcm(n,m);
    map<ll,ll> po;
   
    
    for(int i=1;i<=n;i++){
        int p = (i-1)*(ans/n)+1;
        po[p]=i;
    }

    for(int i=1;i<=m;i++){
        int p = (i-1)*(ans/m)+1;

        if(po[p]!=0){
            int k = po[p]-1;
            if(s[k]!=t[i-1] ){
                cout<<-1<<endl;
                return 0;
            }
        }
    }

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


Measured memory_bytes: 10880
n = int(input())
A = sorted([int(i) for i in input().split()])

alice = []
bob = []

while len(A) > 0:
    a = A.pop()
    alice.append(a)
    if len(A) > 0:
        b = A.pop()
        bob.append(b)
    

print(sum(alice)-sum(bob))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <functional>

template <class T>
struct SegmentTree {
    using Merger = std::function<T(T, T)>;

    int length;
    std::vector<T> dat;
    T unit;
    Merger merge;

    explicit SegmentTree(int n, T unit, Merger merge)
        : length(1), unit(unit), merge(merge) {
        while (length < n) length <<= 1;
        dat.assign(length * 2, unit);
    }

    T query(int ql, int qr) {
        ql = std::max(ql, 0);
        qr = std::min(qr, length);
        ql += length, qr += length;

        T lacc = unit, racc = unit;
        while (ql < qr) {
            if (ql & 1) {
                lacc = merge(lacc, dat[ql]);
                ++ql;
            }
            if (qr & 1) {
                --qr;
                racc = merge(dat[qr], racc);
            }
            ql >>= 1, qr >>= 1;
        }
        return merge(lacc, racc);
    }

    void update(int nidx, T elem) {
        nidx += length;
        dat[nidx] = elem;

        while (nidx > 0) {
            nidx >>= 1;
            T vl = dat[nidx * 2 + 0];
            T vr = dat[nidx * 2 + 1];
            dat[nidx] = merge(vl, vr);
        }
    }
};

using lint = long long;
constexpr lint INF = 1LL << 50;

void solve() {
    int n;
    lint e, t;
    std::cin >> n >> e >> t;

    std::vector<lint> xs(n);
    for (auto& x : xs) {
        std::cin >> x;
        x *= 2;
    }
    xs.push_back(e * 2);

    std::vector<int> ls(n);
    {
        int l = 0;
        for (int i = 0; i < n; ++i) {
            while (xs[i] - xs[l] > t) ++l;
            ls[i] = l;
        }
    }

    SegmentTree<lint>
        near_seg(n + 1, INF,
                 [](auto a, auto b) { return std::min(a, b); }),
        far_seg(n + 1, -INF,
                [](auto a, auto b) { return std::max(a, b); });

    auto update = [&](int i, lint c) {
        near_seg.update(i, c);
        far_seg.update(i, xs[i] - c);
    };

    update(0, 0);
    for (int i = 0; i < n; ++i) {
        lint nc = near_seg.query(ls[i], i + 1) + t;
        lint fc = xs[i] - far_seg.query(0, ls[i]);

        auto c = std::min(nc, fc);
        update(i + 1, c);
    }

    lint ans = e + near_seg.query(n, n + 1);
    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 5488
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

mod = 1000000007

"""
# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    for i in range(100):
        for j in range(100):
            if (i * 4 + j * 7) == N:
                print("Yes")
                exit()
    else:
        print("No")

Measured memory_bytes: 5072
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <string>

#define pb push_back
#define all(c) (c).begin(), (c).end()

using namespace std;

#define N 8
#define BUFSIZE 32
char buf[BUFSIZE];
int d[4] = { 4, -4, 1, -1 };
int pow10[8] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000 };

int main()
{
	queue<int> q;
	map<int, int> m;
	q.push(1234567);
	m[1234567] = 0;
	while (!q.empty()) {
		int t = q.front();
		q.pop();
		if (t == 76543210) break;
		int z;
		int u = t;
		for (z = 0; z < N; ++z) {
			if (u % 10 == 0) break;
			u /= 10;
		}

		for (int i = 0; i < 4; ++i) {
			int k = z + d[i];
			if (k < 0 || k > 7) continue;
			if (z == 3 && k == 4 || z == 4 && k == 3) continue;
			int next = t;
			int d = next / pow10[k] % 10;
			next -= d * pow10[k];
			next += d * pow10[z];
			if (m.find(next) == m.end()) {
				m[next] = m[t] + 1;
				q.push(next);
			}
		}
	}
	while (fgets(buf, BUFSIZE, stdin) != NULL) {
		int ans;
		int v = 0;
		for (int i = 0; i < 15; i += 2)
			v = v * 10 + buf[i] - '0';
//		char* p = strtok(buf, " ");
//		while (p != NULL) { v = v * 10 + *p - '0'; p = strtok(NULL, " "); }
		if (m.find(v) != m.end())
			ans = m[v];
		else {
			queue<int> q2;
			map<int, int> m2;
			q2.push(v);
			m2[v] = 0;
			while (!q2.empty()) {
				int t = q2.front();
				q2.pop();
				if (t == 1234567) { ans = m2[t]; break; }
				int z;
				int u = t;
				for (z = 0; z < N; ++z) {
					if (u % 10 == 0) break;
					u /= 10;
				}

				for (int i = 0; i < 4; ++i) {
					int k = z + d[i];
					if (k < 0 || k > 7) continue;
					if (z == 3 && k == 4 || z == 4 && k == 3) continue;
					int next = t;
					int d = next / pow10[k] % 10;
					next -= d * pow10[k];
					next += d * pow10[z];
					/*
					if (m.find(next) != m.end()) {
						ans = m[next] + m2[t] + 1;
						break;
					}
					*/
					if (m2.find(next) == m2.end()) {
						m2[next] = m2[t] + 1;
						q2.push(next);
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

int main () {

    string S;
    long long K;

    cin >> S >> K;

    int first_number_except_1 = 0;
    int pos = 0;

    for (int i = 0; i < S.size(); i++){
        if (S[i] != '1') {
            first_number_except_1 = (int)S[i] - '0';
            pos = i + 1;
            break;
        }
    }
    if (first_number_except_1 == 0) {
        first_number_except_1 = 1;
    }

    if (first_number_except_1 == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (K < pos) cout << 1 << endl;
    else cout << first_number_except_1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include<vector>
#include<map>
typedef long long ll;

using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<string> ss(n);
	for (int i = 0; i < n; i++) {
		cin >> ss[i];
	}

	int m;
	cin >> m;
	vector<string> ts(m);
	for (int i = 0; i < m; i++) {
		cin >> ts[i];
	}

	std::map<string, int> map_s;
	for (int i = 0; i < n; i++) {
		map_s[ss[i]]+=1;
	}

	std::map<string, int> map_t;
	for (int i = 0; i < m; i++) {
		map_t[ts[i]] += 1;
	}

	int kotae = 0;

	for (auto itr = map_s.begin(); itr != map_s.end(); ++itr) {
		int dammy = 0;
		if (map_t.count(itr->first)) dammy = map_t[itr->first];
		if (itr->second - dammy > 0) kotae 
			= kotae>(itr->second - dammy)? kotae : (itr->second - dammy);
	}
	cout << kotae;
	return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli d[100100];

void func(long long N, long long Q, std::string S, std::vector<long long> l, std::vector<long long> r){

    REP(i,0,N-1){
        if(S[i]=='A' &&S[i+1]=='C'){
            d[i]++;
        }
    }

    REP(i,0,N-1){
        d[i+1]+=d[i];
    }


    REP(i,0,Q){
        cout<<(d[r[i]-1]-d[l[i]-1])<<endl;
    }

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long Q;
    scanf("%lld",&Q);
    std::string S;
    std::cin >> S;
    std::vector<long long> l(Q);
    std::vector<long long> r(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&l[i]);
        scanf("%lld",&r[i]);
        l[i]--,r[i]--;
    }
    func(N, Q, S, std::move(l), std::move(r));
    return 0;
}


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

using namespace std;

const int N = 3*100000 + 1;

const int K = 5000;

int n , k,a[N];

bitset<K> pre[N+1],suf[N+1];


int main(){
	cin >> n >> k;
	for (int i = 1; i <= n; ++i){
		scanf("%d",a+i);
	}
	pre[0][0] = 1;
	for(int i = 1; i <= n;++i){
		pre[i] = (pre[i-1] << a[i]) | pre[i-1];
	}
	suf[n+1][0] = 1;
	for(int i = n; i >= 1;--i){
		suf[i] = (suf[i+1] << a[i]) | (suf[i+1]);
	}

	int ans = 0;
	for(int i = 1; i <= n;++i){
		vector<int> v1,v2;
		for(int j = 0; j < k;++j){
			if(suf[i+1][j])v1.push_back(j);
			if(pre[i-1][j])v2.push_back(j);
		}
		int idx = 1;
		bool imp = false;
		for(int j = v2.size()-1;j>= 0;--j){
			while(idx < v1.size() && v1[idx]+v2[j] < k-a[i])idx++;
			int current = (idx == v1.size()?idx-1:idx);	
			if(v1[current]+v2[j] < k && v1[current]+v2[j]+a[i] >= k){
				imp = true;
			}
		}
		if(imp){
			ans++;
		}
	}
	ans = n-ans;
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 10624
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define sort(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> data(n+1);
	ff(i, 0, n+1) {
		data.at(i) = 1;
	}
	ff(i, 2, n+1) {
		int y = i;
		ff(j, 2, y+1) {
			while (y % j == 0) {
				y /= j;
				data.at(j)++;
			}
		}
	}
	i64 ans = 1;
	ff(i, 0, n+1) {
		ans *= data.at(i);
		ans %= inf;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string.h>
#include<stack>
#include<ctype.h>
using namespace std;
typedef struct LNode
{
    int data;
    struct LNode *next;
} LNode, *LinkList;

typedef struct Binode
{
    char data[4];
    struct Binode *lchild,*rchild;
} Binode,*Bitree;

int main(){
char ch;
cin>>ch;
if(ch>='A'&&ch<='Z')
    printf("A\n");
else printf("a\n");
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    ll n;
    cin >> n;
    cout << (1000 - (n % 1000)) % 1000 << '\n';
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

long long count(string S) {
    ll res = 0;
    FOR(i, 1, S.size()) {
        if (S[i] == S[i - 1]) {
            S[i] = '0';
            res++;
        }
    }
    return res;
}

signed main() {
    string S;
    cin >> S;
    long long K, N = S.size();
    cin >> K;
    bool all_same = true;
    FOR(i, 0, S.size() - 1) {
        all_same &= (S[i] == S[i + 1]);
    }
    if (all_same) {
        cout << N * K / 2 << endl;
        return 0;
    }
    if (K == 1) {
        cout << count(S) << endl;
        return 0;
    }
    if (K == 2) {
        cout << count(S + S) << endl;
        return 0;
    }
    ll cnt3 = count(S + S + S);
    ll diff = count(S + S + S + S) - count(S + S + S);
    cout << diff * (K - 3) + cnt3 << endl;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    int k;
    cin >> n >> k;
    int ans = 0;
    while (n) {
        n /= k;
        ans++;
    }    
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	const int maxn = 1'000'000'1;
	vector<int> pr(maxn, -1), nxt(maxn);
	for(int i = 2; i < maxn; i++){
		if(pr[i] == -1){
			for(int j = i; j < maxn; j += i)
				if(pr[j] == -1)
					pr[j] = i;
		}
	}
	for(int i = 2; i < maxn; i++)
		nxt[i] = i / pr[i];
	int n;
	cin >> n;
	long long sum = 0;
	for(int i = 1; i <= n; i++){
		vector<pair<int,int>> fat;
		int c = i;
		while(c != 1){
			if(fat.empty() || fat.back().first != pr[c]) fat.push_back({pr[c], 1});
			else fat.back().second++;
			c = nxt[c];
		}
		int divs = 1;
		for(auto e : fat){
			divs *= (e.second + 1);
		}
		sum += 1ll * i * divs;
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 81248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll n;
vi a;

int main()
{
    cin >> n;
    a = vi(n);
    REP(i, n)
    {
        cin >> a[i];
    }

    ll ans = INF;
    ll s = 0;
    ll c = 0;
    REP(i, n)
    {
        s += a[i];
        if (i % 2 == 0 and s <= 0)
        {
            c += 1 - s;
            s = 1;
        }
        else if (i % 2 == 1 and s >= 0)
        {
            c += 1 + s;
            s = -1;
        }
    }
    ans = c;
    s = 0;
    c = 0;
    REP(i, n)
    {
        s += a[i];
        if (i % 2 == 0 and s >= 0)
        {
            c += 1 + s;
            s = -1;
        }
        else if (i % 2 == 1 and s <= 0)
        {
            c += 1 - s;
            s = 1;
        }
    }
    ans = min(ans, c);

    OUT(ans);
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int N;
    cin >> N;

    int C;
    cin >> C;

    vector<Vi> cost(C, Vi(C));
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            cin >> cost[i][j];
        }
    }

    vector<Vi> cell(N, Vi(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> cell[i][j];
            --cell[i][j];
        }
    }

    vector<Vi> group(3, Vi(C));
    for (int x = 0; x < N; x++) {
        for (int y = 0; y < N; y++) {
            if ((x + y) % 3 == 0) {
                ++group[0][cell[x][y]];
            }
            else if ((x + y) % 3 == 1) {
                ++group[1][cell[x][y]];
            }
            else {
                ++group[2][cell[x][y]];
            }
        }
    }

    ll ans = L_INF;

    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            for (int k = 0; k < C; k++) {
                if (i == j || j == k || k == i) {
                    continue;
                }
                ll score = 0;
                for (int c = 0; c < C; c++) {
                    score += group[0][c] * cost[c][i];
                }
                for (int c = 0; c < C; c++) {
                    score += group[1][c] * cost[c][j];
                }
                for (int c = 0; c < C; c++) {
                    score += group[2][c] * cost[c][k];
                }
                ans = min(ans, score);
            }
        }
    }

    cout << ans << "\n";

    return 0;
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

const ll mod=1000000007;

char mat[1005][1005];
ll h,w,dp[1005][1005];


int main(){
  cin >> h >> w;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
        cin >> mat[i][j];
        if(mat[i][j]=='#'){
            dp[i+1][j+1]=0;
        }
    }
  }
  dp[1][1]=1;
  for(int i=1;i<=h;++i){
    for(int j=1;j<=w;++j){
       if((i==1 && j==1) || mat[i-1][j-1]=='#'){
          //cout << dp[i][j] << " ";
          continue;
       }
       dp[i][j]=((dp[i-1][j])%mod+(dp[i][j-1])%mod)%mod;
       //cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  cout << dp[h][w];
  return 0;
}

Measured memory_bytes: 9088
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        long[] a = new long[N];
        int count = 0;
        for(int i=0; i<N; i++) {
            a[i] = Long.parseLong(sc.next());
            count += count2(a[i]);
        }
        System.out.println(count);
    }
    static int count2(long a) {
        int count = 0;
        if(a % 2 != 0) {
            return count;
        }else {
            while(true) {
                a /= 2;
                count++;
                if(a % 2 != 0) {
                    return count;
                }
            }
        }
    }
}


Measured memory_bytes: 32424
#E

line = [int(x) for x in input().split()]
reds = [int(x) for x in input().split()]
greens = [int(x) for x in input().split()]
colorless = [int(x) for x in input().split()]

reds.sort(reverse = True)
greens.sort(reverse = True)
colorless.sort(reverse = True)

rI = line[0]-1
gI = line[1]-1

for i in range(0, line[4]):
    if rI == -1 and gI == -1:
        break
    
    elif rI == -1:
        if colorless[i] < greens[gI]:
            break
        else:
            greens[gI] = colorless[i]
            gI = gI - 1
            
    elif gI == -1:
        if colorless[i] < reds[rI]:
            break
        else:
            reds[rI] = colorless[i]
            rI = rI-1
            
    else:
        if colorless[i] < reds[rI] and colorless[i] < greens[gI]:
            break
        else:
            if reds[rI] < greens[gI]:
                reds[rI] = colorless[i]
                rI = rI-1
            else:
                greens[gI] = colorless[i]
                gI = gI - 1

print(sum(reds[:line[0]] ) + sum(greens[:line[1]]))


Measured memory_bytes: 23644
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007 
#define MM 998244353
#define PI 3.14159265 
using namespace std;
 
int main()
{
	long long int n, max, ans = 0; 

	cin >> n;

	long long int a[n];

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

	max = a[0];

	for (long long int i= 0; i< n; i++)
	{
		if (a[i] < max)
		{
			ans = ans + max - a[i];
		}
		else
		{
			max = a[i];
		}
	}	

	cout << ans;

  	return 0;
}

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

using namespace std;

int main()
{
    string s,t,t1;
    cin>>s;
    cin>>t;
    for(int i=0;i<t.length()-1;i++) t1=t1+t[i];
    if(s==t1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
template <class t, class u>
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
void chmax(t& a, u b) {
  if (a < b) a = b;
}
ll f(int x) {
  if (x == -1) return 0;
  if (x == 0) return 0;
  if (x == 1) return 1;
  return x + f(x - 1);
}
int main() {
  string s;
  cin >> s;
  int n = s.size() + 1;
  vector<ll> a(n);
  REP(i, n - 1) {
    if (s[i] == '<') {
      chmax(a[i + 1], a[i] + 1);
    }
  }
  per(i, n - 1) {
    if (s[i] == '>') {
      chmax(a[i], a[i + 1] + 1);
    }
  }
  ll mx = 0;
  REP(i, n) mx += a[i];
  cout << mx << endl;
}

Measured memory_bytes: 4740
#include<stdio.h>

int main(){
  int x=100000;
  int i,n;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    x=x*1.05;
    if(x%1000!=0)
      x=(x/1000+1)*1000;
  }
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{  int a[1000];
   int N;
   while(scanf("%d",&N)==1)
     { for(int i=0;i<N;i++) scanf("%d",&a[i]);
       sort(a,a+N);
       int sum=0;
      // for(int i=0; i<N; i++) cout<<a[i]<<endl;
       for(int i=0;i<N-1;)
        { 
		  if(a[i]!=a[i+1]) 
		  {
		   sum+=(a[i+1]-a[i]);
		   ///cout<<a[i+1]-a[i]<<endl;
		   i++;
	      }
		  else while(a[i]==a[i+1]) i++;
		}
		 printf("%d\n",sum);
	 }
}

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

const int32_t MAX_LEN = 3000;

std::string s, t;
int32_t dp[MAX_LEN + 5][MAX_LEN + 5];
int32_t parent[MAX_LEN + 5][MAX_LEN + 5];

int32_t CalcDp(int32_t ind1, int32_t ind2) {
	if(ind1 == s.size() || ind2 == t.size()) {
		return 0;
	}

	int32_t &memo = dp[ind1][ind2];

	if(memo != -1) {
		return memo;
	}

	if(s[ind1] == t[ind2]) {
		memo = CalcDp(ind1 + 1, ind2 + 1) + 1;
		parent[ind1][ind2] = 2;
	}
	else {
		int32_t aux1 = CalcDp(ind1 + 1, ind2);
		int32_t aux2 = CalcDp(ind1, ind2 + 1);

		if(aux1 >= aux2) {
			memo = aux1;
			parent[ind1][ind2] = 0;
		}
		else {
			memo = aux2;
			parent[ind1][ind2] = 1;
		}
	}

	return memo;
}

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

	std::cin >> s >> t;
	
	memset(dp, -1, sizeof(dp));
	CalcDp(0, 0);

	std::string ans;
	int32_t ind1 = 0, ind2 = 0;
	while(ind1 < s.size() && ind2 < t.size()) {
		if(parent[ind1][ind2] == 2) {
			ans += s[ind1];
			ind1++;
			ind2++;
		}
		else if(parent[ind1][ind2] == 0) {
			ind1++;
		}
		else {
			ind2++;
		}
	}

	std::cout << ans << '\n';
}



Measured memory_bytes: 71040
/************************* B *****************/
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main()
{
	string w;
	cin >> w;
	map<char, int> m;
	for(int i = 0; i < w.length(); i++){
		m[w[i]]++;
	}
	bool check = true;
	for(map<char, int>::iterator it = m.begin(); it != m.end(); it++){
		if(it->second % 2){
			check = false;
			break;
		}		
	}
	if(check == true) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256