akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  vl a(N);
  rep(i, N) cin >> a[i];

  stable_sort(a.begin(), a.end(), greater<ll>());

  if(N == 1){
    cout << a[0] << endl;
    return 0;
  }

  ll ascore = 0, bscore = 0;

  for(int i = 0; i < N; i += 2){
    ascore += a[i];
  }
  for(int i = 1; i < N; i += 2){
    bscore += a[i];
  }

  cout << ascore - bscore << endl;
  
  return 0;
}


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

int V, E;

bool dfs(vector<vector<int>> &G, int u, vector<int> &color){
    color[u] = 1;
    for(auto v: G[u]){
        if(color[v] == 1)
            return true;
        if(color[v] == 2)
            continue;
        if(dfs(G, v, color))
            return true;
    }
    color[u] = 2;
    return false;
}

int main(){
    cin >> V >> E;
    vector<vector<int>> G(V);
    for(int i=0; i<E; i++){
        int s, t; cin >> s >> t;
        G[s].push_back(t);
    }
    
    bool has_cycle = false;
    vector<bool> done(V);
    
    for(int i=0; i<V; i++) if(!done[i]){
        vector<int> color(V, 0);
        has_cycle |= dfs(G, i, color);
        for(int i=0; i<V; i++) if(color[i] == 2)
            done[i] = true;
    }
    cout << has_cycle << endl;
    
    return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

vector<ll> fac(MAX), finv(MAX), inv(MAX), invsum(MAX);

void comInit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(ll i=2; i<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;
	}
	for(ll i=0; i<MAX-1; i++) invsum[i+1] = (invsum[i] + inv[i+1]) % mod;
}


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

int main(){
	int n; cin >> n;
	vl a(n); rep(i,n) cin >> a[i];
	comInit();
	ll f = invsum[n];
	ll ans = 0;
	rep(i,n){
		ans += (f * fac[n] % mod) * a[i] % mod;
		f += (inv[i+2] - inv[n-i] + mod) % mod;
		ans %= mod;
		f %= mod;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 19888
#include<iostream>
#include<string>
#include<regex>

using namespace std;

int main()
{
    long int n;
    long long sum = 0;
    cin >> n;
    for (int i = 0; i <= n; ++i)
    {
        if(i % 3 != 0 && i % 5 != 0){
            sum += i;
        }
    }
    cout << sum << endl;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

const ll mod = 1e9+7;
ll dfs(int K,const vector<vector<ll>>&graph, int now, int from){
  int can_use_color_num;
  if(from == -1){
    can_use_color_num = K-1;//色の残量
  }else{
    can_use_color_num = K-2;//色の残量
  }
  if(K < graph[now].size()){
    return 0;//塗分けできない
  }else{
    ll case_num = 1;
    for(auto e: graph[now]) {//dfs起点の子頂点
      if(e == from) continue;
      case_num*=can_use_color_num;
      can_use_color_num--;
      case_num%=mod;
    }
    for(auto e:graph[now]){//子頂点の子
      if(e == from) continue;
      case_num *= dfs(K,graph,e,now);
      case_num %= mod;
    }
    return case_num;
  }
}

int main(){
  int N,K;cin >> N >> K;
  vector<vector<ll>> graph(N);
  for(int i=0;i<N-1;i++){
    int a,b; cin >> a >> b,a--,b--;
    graph[a].push_back(b);
    graph[b].push_back(a); 
  }
  ll answer = K*dfs(K,graph,0,-1);
  answer%=mod;
  cout << answer << endl;
  return 0;

}

Measured memory_bytes: 11520
# B - String Palindrome

S = input()

ans = 'No'
N = len(S)
left = S[:(N - 1) // 2]
right = S[((N + 3) // 2) - 1:]
if left == right:
    if left == left[::-1] and right == right[::-1]:
        ans = 'Yes'

print(ans)

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

using namespace std;

int main()
{
	string s;
	int n;
	cin >> s >> n;
	if (s.length() == 1) {
		cout << n / 2 << endl;
		return 0;
	}

	vector<pair<char, long long>> p;
	p.emplace_back(make_pair(s[0], 1));
	for (int i = 1; i < s.length(); i++) {
		if (p[p.size() - 1].first != s[i]) {
			p.emplace_back(make_pair(s[i], 1));
		}
		else {
			p[p.size() - 1].second++;
		}
	}

	long long ans = 0;
	if (p.size() == 1) {
		ans = p[0].second * n / 2;
	}
	else if (p[0].first == p[p.size() - 1].first) {
		ans = (p[p.size() - 1].second + p[0].second) / 2 * (n - 1);
		ans += p[0].second / 2 + p[p.size() - 1].second / 2;
		for (int i = 1; i < p.size() - 1; i++) {
			ans += p[i].second / 2 * n;
		}
	}
	else {
		for (int i = 0; i < p.size(); i++) {
			ans += p[i].second / 2 * n;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func Sum(A []int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

const p = 1000000007
const p2 = 500000004

func main() {
  N := NextInt()
  T := make([]map[int]int, N)
  for i := range T {
    T[i] = make(map[int]int)
  }
  E := make([][]int, N - 1)
  for i := range E {
    AB := NextIntVec()
    A, B := AB[0] - 1, AB[1] - 1
    E[i] = []int{A, B}
    T[A][B] = i
    T[B][A] = i
  }
  P := make([]int, N)
  for i := range P {
    if 0 < i { P[i] = -1 }
  }
  Q := make([]int, N)
  pos := 1
  for _, q := range Q {
    for adj, _ := range T[q] {
      if 0 <= P[adj] { continue }
      P[adj] = q
      Q[pos] = adj
      pos++
    }
  }
  ST := make([][]int, N)
  for i := range ST {
    ST[i] = make([]int, 0)
  }
  for i := N - 1; 0 < i; i-- {
    q := Q[i]
    s := Sum(ST[q]) + 1
    ST[P[q]] = append(ST[P[q]], s)
    e := T[q][P[q]]
    if E[e][0] == q {
      E[e][0], E[e][1] = s, N - s
    } else {
      E[e][0], E[e][1] = N - s, s
    }
  }
  B := make([]int, N + 1)
  B[0] = 1
  for i := 0; i < N; i++ {
    B[i + 1] = B[i] * p2 % p
  }
  ans := 0
  cnt := p + 1 - B[N]
  for _, e := range E {
    cnt += (p + 1 - B[e[0]]) * (p + 1 - B[e[1]]) % p
    cnt %= p
  }
  ans = (2 * cnt - N) * p2 % p
  Write(ans)
  Output()
}

Measured memory_bytes: 83584
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	int N;
	cin >> N;
	vector<string> v(N);
	REP(i, N) {cin >> v[i]; sort(ALL(v[i]));}

	vector<vector<int>> alphabet(N, VI('z' + 1, 0));

	string ans = {""};

	REP(i, N)REP(j, v[i].size()) { alphabet[i][(int)v[i][j]]++; }

	vector<int> list('z' + 1, INF);

	FOR(i, 'a', 'z') {REP(j, N) {list[i] = min( list[i], alphabet[j][i] );}}

	FOR(i, 'a', 'z')REP(j, list[i]) {ans += (char)i;}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

n, m, q = map(int, input().split())
t = [ [0] * (n+1) for _ in range(n+1) ]
qq = []
for _ in range(m):
    l, r = map(int, input().split())
    t[l][r] += 1
for _ in range(q):
    tmp = list(map(int, input().split()))
    qq.append(tmp)

s = [ [0] * (n+1) for _ in range(n+1) ]
for i in range(1, n+1):
    tmp = 0
    for j in range(1, n+1):
        tmp += t[i][j]
        s[j][i] = tmp

x = [ [0] * (n+1) for _ in range(n+1) ]
for i in range(1, n+1):
    for j in range(i, n+1):
        tmp = 0
        for k in range(i, j+1):
            tmp += s[j][k]
        x[i][j] = tmp

for qqq in qq:
    print(x[qqq[0]][qqq[1]])

Measured memory_bytes: 70492
#include<bits/stdc++.h>
/**CLICK ss---> ctrl+j**/
#define PI 2.0*acos(0.0)
#define ll              long long int
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define MOD             1000000007
#define mx              123456789
using namespace std;
void solve()
{
    ll n, m, i, j, k, l;
    cin>>n;
    ll a[n+2];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    //sort(a,a+n);
    if (count(a, a + n, 0)) {
    	cout << 0 << "\n";
    	return;
    }
    bool ok=true;
    ll ss=1;
    for(i=0; i<n; i++)
    {
        if(((__int128)ss*a[i])>1000000000000000000)
        {
            cout<<-1<<endl;
            return;
        }
        ss*=a[i];
    }
    cout<<ss<<endl;
}
int main()
{
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4420
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll k;
ll cnt[100001];
vector<int> vec;

int main(void){
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		cnt[a]+=(ll)b;
	}
	ll sum=0;
	for(int i=1;i<=100000;i++){
		sum+=(ll)cnt[i];
		if(sum>=(ll)k){
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int n ;
  cin >> n ;
  vector<int> mochi(n) ;
  int count = 0 ;
  REP(i,n){
    cin >> mochi.at(i) ;
  }
  sort(ALL(mochi)) ;
  
  REP(i,n-1){
    if(mochi.at(i)==mochi.at(i+1)){
      count++ ;
    }
  }
  
  cout << n-count <<endl ;
    

  return 0 ;
}




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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

struct UnionFind{
    vector<int> data;
    //data[i] = -x ... iが根であり、サイズがx
    //data[i] = x ... iの親がx

    //最初は全員根
    UnionFind(int size): data(size,-1){}

    bool union_set(int x, int y){//サイズがx>yになるようにしてから、xにyをつなげる
        x=root(x);
        y=root(y);
        if(x != y){
            if(data[y] < data[x]) swap(x,y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find_set(int x, int y){//ルートが一致するかどうかを返す
        return root(x) == root(y);
    }
    int root(int x){//根を見つける。ついでに深さ2にしちゃう
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

struct Edge{
    int s,t;
    double cost;
    bool operator<(const Edge &o) const{
        return cost < o.cost;
    }
};

struct Graph{
    int n;
    vector<Edge> es;

    double kruskal(){
        sort(ALL(es));

        UnionFind uf(n);
        double min_cost = 0;
        REP(i,es.size()){
            Edge& e = es[i];
            if(!uf.find_set(e.s, e.t)){//辺を追加しても閉路ができなければ採用
                min_cost += e.cost;
                uf.union_set(e.s, e.t);
            }
        }

        return min_cost;
    }
};

int main() {
    while(1){
        int n; cin >> n;
        if (n==0){
            return 0;
        }

        vector<vector<double>> inputs(n, vector<double>(4));
        REP(i,n){
            double x,y,z,r; cin >> x >> y >> z >> r;
            inputs[i] = {x,y,z,r};
        }

        Graph g;
        g.n = n;

        REP(i,n-1){
            FOR(j,i+1,n){
                double l;
                l = sqrt( pow(inputs[i][0]-inputs[j][0], 2)+pow(inputs[i][1]-inputs[j][1], 2)+pow(inputs[i][2]-inputs[j][2], 2));
                if (l <= inputs[i][3]+inputs[j][3]){
                    g.es.push_back({i,j,0.0});
                }else{
                    g.es.push_back({i,j,l-inputs[i][3]-inputs[j][3]});
                }
            }
        }

        cout << fixed << setprecision(3) << g.kruskal() << endl;
    }
}


Measured memory_bytes: 3284
#include <iostream>
#include <algorithm>

using namespace std;

bool palindrome(string s){
    string t=s;
    reverse(t.begin(),t.end());
    return s==t;
}

int main()
{
    string s;
    cin >> s;
    bool ans = true;
    if(!palindrome(s)) ans = false;
    if(!palindrome(s.substr(0,s.size()/2))) ans=false;//半分切り捨て//
    cout << (ans ? "Yes" : "No") << endl;//条件(三項）演算子//
    return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

struct Snuke {
  ll n, S;

  Snuke( ll n, ll S )
  : n(n), S(S)
  {}

  bool operator== ( const Snuke &s ) const {
    return n*s.S == S*s.n;
  }

  bool operator != ( const Snuke &s ) const {
    return n*s.S != S*s.n;
  }

  bool operator> ( const Snuke &s ) const {
    return n*s.S > s.n*S;
  }
};

ll K;

ll f( ll n ) {
  std::ostringstream oss;
  oss << n;
  std::string tmp = oss.str();

  std::string s;
  rep( i, 16-tmp.size() ) 
    s += '0';
  s += tmp;

  ll tsum = 0;
  rep( i, tmp.size() )
    tsum += tmp[i]-'0';

  Snuke mi( n, tsum );
  ll ret = n;

  rep( i, s.size() ) {    
    repi( d, s[i]-'0'+1, 10 ) {
      std::string t = s;

      t[i] = d+'0';
      
      repi( j, i+1, s.size() )
        t[j] = '9';

      ll sum = 0;
      rep( j, s.size() )
        sum += t[j]-'0';

      std::istringstream iss( t );
      ll T;
      iss >> T;
    
      Snuke snuke( T, sum );

      /*
      std::cout << t << std::endl;

      std::cout << P(mi.n, mi.S) << std::endl;
      std::cout << P(snuke.n, snuke.S) << std::endl;
      //*/

      if( mi != snuke && chmin( mi, snuke ) ) {
        ret = T;
      }
    }
  }

  return ret;
}

int main()
{
  std::cin >> K;

  ll n = 1;
  std::cout << n << std::endl;

  rep( i, K-1 ) {
    n = f(n+1);
    std::cout << n << std::endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vecint p(n*n);
  for(auto&&e:p)cin>>e;
  int INF = 1e9;
  vecint dis(n*n, INF);
  auto id = [&] (int i, int j) {
    return i*n + j;
  };
  REP(i,n)REP(j,n) {
    dis[id(i,j)] = min({i, j, n-1-i, n-1-j});
  }
  vector<bool> emp(n*n, false);
  ll ans = 0;
  REP(n2,n*n) {
    int idx = p[n2] - 1;
    ans += dis[idx];
    emp[idx] = true;
    deque<int> q;
    q.push_front(idx);
    while (!q.empty()) {
      auto cidx = q.front();
      auto ii = cidx / n;
      auto jj = cidx % n;
      q.pop_front();
      int di[] = {1, 0, -1, 0};
      int dj[] = {0, 1, 0, -1};
      REP(k,4) {
        int ni = ii + di[k];
        int nj = jj + dj[k];
        if (ni < 0 || nj < 0 || ni >= n || nj >= n) continue;
        int nidx = id(ni, nj);
        int cst = emp[cidx] ? 0 : 1;
        if (dis[nidx] > dis[cidx] + cst) {
          dis[nidx] = dis[cidx] + cst;
          if (cst == 0) {
            q.push_front(nidx);
          } else {
            q.push_back(nidx);
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
	int number;
	char str[10000];
	scanf("%d",&number);
	int temp = number;
	scanf("%s",&str);
	int len = strlen (str);
	for (int i = 0; i < len; i++){
		temp = number;
		if (str[i] + number > 'Z'){
			int temp2 = 'Z' - str[i]+1;
			temp -=temp2;
			str[i]='A';
		}
		str[i] += temp;
	}
	printf("%s\n",str);
	return 0;
}


Measured memory_bytes: 1652
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[]{sc.nextInt(), sc.nextInt()};
        int d = a[0] / a[1], r = a[0] % a[1];
        double f = (double) a[0] / (double) a[1];
        System.out.printf(d + " " + r + " %f\n", f);
    }
}

Measured memory_bytes: 26580
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <complex>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

const double PI = 3.141592653589793;
vector<complex<double>> fft(vector<complex<double>> a, bool inverse = false) {
    int n = a.size();
    int h = 0; // h = log_2(n)
    for (int i = 0; 1 << i < n; i++) h++;

    for (int i = 0; i < n; i++) {
        int j = 0;
        for (int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k);
        if (i < j) swap(a[i], a[j]);
    }

    for (int b = 1; b < n; b *= 2) {
        for (int j = 0; j < b; j++) {
            complex<double> w =
                polar(1.0, (2 * PI) / (2 * b) * j * (inverse ? 1 : -1));
            for (int k = 0; k < n; k += b * 2) {
                complex<double> s = a[j + k];         
                complex<double> t = a[j + k + b] * w;
                a[j + k] = s + t;                   
                a[j + k + b] = s - t;            
            }
        }
    }
    if (inverse)
        for (int i = 0; i < n; i++) a[i] /= n;
    return a;
}

vector<complex<double>> fft(vector<double> a, bool inverse = false) {
    vector<complex<double>> a_complex(a.size());
    for (int i = 0; i < a.size(); i++) a_complex[i] = complex<double>(a[i], 0);
    return fft(a_complex, inverse);
}

vector<double> convolve(vector<double> a, vector<double> b) {
    int s = a.size() + b.size() - 1;
    int t = 1; 
    while (t < s) t *= 2;
    a.resize(t); 
    b.resize(t);
    vector<complex<double>> A = fft(a);
    vector<complex<double>> B = fft(b);
    for (int i = 0; i < t; i++) {
        A[i] *= B[i]; 
    }
    A = fft(A, true); 
    a.resize(s);     
    for (int i = 0; i < s; i++) a[i] = A[i].real(); 
    return a;
}

int main(){
    ll N,M;
    cin >> N >> M;
    vector<double> a(1e5+1,0),b(1e5+1,0);
    a[0] = b[0] = 0;
    rep(i,N){
        int tmp;
        cin >> tmp;
        a[tmp] += 1.0;
    }

    rep(i,1e5+1){ 
        b[i] = a[i];
    }

    vector<double> ans = convolve(a,b);    
    ll Ans = 0;
    
    for(ll j = ans.size(); j > 0; j--){
        ll cnt = (ll)(ans[j]+0.5);
        Ans += j * min(cnt, M);
        M -= cnt;
        if(M <= 0) break;
    }

    cout << Ans << endl;

    return 0;
} 

Measured memory_bytes: 20312
#include <iostream>

using namespace std;

int main()
{
    int no1Index, no1Value = 0, no2Index, no2Value = 0;

	int n, a;
    // pair<int, int> no1(0, 0), no2(0, 0); // <index, value>
    cin >> n;

    for(int i = 0; i < n; ++i) {
        cin >> a;

        if(no1Value < a) {
            no1Index = i;
            no1Value = a;
        }
        else if(no2Value < a) {
            no2Index = i;
            no2Value = a;
        }

        // if(no1.second < a) 
        //     no1 = make_pair(i, a);
        // else if(no2.second < a)
        //     no2 = make_pair(i, a);
    }

    for(int i = 0; i < n; ++i) {
        if(no1Index == i)
            cout << no2Value << '\n';
        else
            cout << no1Value << '\n';

        // if(no1.first == i) 
        //     cout << no2.second << '\n';
        // else
        //     cout << no1.second << '\n';
    }
}

Measured memory_bytes: 1664
import std.stdio;
import std.algorithm;
import std.conv;
import std.numeric;
import std.math;
import std.string;

void main()
{
	auto n = to!int(chomp(readln()));
	auto a1 = n / 100;
	auto a2 = (n / 10) % 10;
	auto a3 = n % 10;
	
	if (a1 == 1) a1 = 9;
	else a1 = 1;
	if (a2 == 1) a2 = 9;
	else a2 = 1;
	if (a3 == 1) a3 = 9;
	else a3 = 1;

	writeln(a1 * 100 + a2 * 10 + a3);
	stdout.flush();
}

Measured memory_bytes: 256
from collections import deque

S = deque(input())
Q = int(input())

inv_flag = False
for _ in range(Q):
    query = list(input().split())
    if int(query[0]) == 1:
        inv_flag = not inv_flag
    else:
        if (int(query[1]) - 1) ^ inv_flag:
            S.append(query[2])
        else:
            S.appendleft(query[2])
if inv_flag:
    print(''.join(reversed(S)))
else:
    print(''.join(S))


Measured memory_bytes: 8564
K = int(input())
A = [1,2,3,4,5,6,7,8,9]

for i in A:
  if K<len(A):
    break
  x = i%10
  for j in range(max(x-1,0),min(x+2,10)):
    A.append(10*i+j)

print(A[K-1])

Measured memory_bytes: 13352
#include <stdio.h>

int main () {
  int h,w;
  int x,y;
  while (1) {
    scanf ("%d %d",&h,&w);
    if (h == 0 && w == 0) break;
    for (y=1;y<=h;y++) {
      for (x=1;x<=w;x++) {
	if ((x+y)%2 == 0) {
	  printf ("#");
	}else{
	  printf (".");
	}
      }
      printf ("\n");
    }
    printf ("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;

int n,times;
char s[MAXN+1];
char ret[MAXN+1];

void run() {
	scanf("%d%d",&n,&times); scanf("%s",s);
	int at=0; bool inv=false;
	while(at!=n&&times>0) {
		char c=s[at]; if(inv) c='A'+(1-(c-'A'));
		--times; if(c=='A') s[at]='A'+(1-(s[at]-'A')); else ++at,inv=!inv;
	}
	int period=n%2==0?n:2*n;
	times%=period;
	if(times>0) {
		at=0;
		while(at!=n&&times>0) {
			char c=s[at]; if(inv) c='A'+(1-(c-'A'));
			--times; if(c=='A') s[at]='A'+(1-(s[at]-'A')); else ++at,inv=!inv;
		}
		assert(at<n);
	}
	REP(i,n) {
		int pos=(at+i)%n;
		char c=s[pos]; if(inv) c='A'+(1-(c-'A'));
		ret[i]=c;
	}
	ret[n]='\0'; printf("%s\n",ret);
}

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


Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

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

	int fe[10][10] = {0};
	rep(i, 1, n + 1) {
		int num = i;
		int end = num % 10;
		while ( num / 10 != 0 ) { num /= 10; }
		int first = num;
		fe[first][end]++;
	}
	int ans = 0;
	rep(f, 0, 10) {
		rep(e, 0, 10) {
			ans += fe[f][e] * fe[e][f];
		}
	}
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main() {

	int keta = 0;
	int input = 0, input2 = 0;
	int a = 0;

	while(scanf("%d %d", &input, &input2) != EOF) {

		a = input + input2;

		if(a == 0) {
			keta = 1;
		}

		while( a != 0 ) {

			a = a / 10;
			keta++;
		}

		printf("%d\n", keta);

		keta = 0;
	}

	return 0;
}

Measured memory_bytes: 1028
n, m = (int(v) for v in input().split())
lamps = [tuple([int(e) for e in input().split()[1:]]) for _ in range(m)]
conds = [int(v) for v in input().split()]

count = 0
for state in range(2**n):
    flag = True
    for cond, lamp in zip(conds, lamps):
        mask = 0
        for sw in lamp:
            mask += 2**(sw-1)
        masked = state & mask
        bit = 0
        for _ in range(n):
            bit += masked % 2
            masked >>= 1
        if (bit + cond) % 2 != 0:
            flag = False
            break
    if flag:
        count += 1
print(count)
            

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

// 素因数分解(first要素がfactで、second要素がその個数)
vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

vector<int> v;

ll num(int n){
    ll ret = 0;
    rep(i, v.size()) ret += (v[i] >= n);
    return ret;
}

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

    map<int, int> t;
    for(int i=1; i<=n; i++){
        auto f = prime_factorize(i);
        rep(j, f.size()){
            t[f[j].first] += f[j].second;
        }
    }

    for(auto p: t) v.push_back(p.second);

    ll case1 = num(4) * (num(4)-1) * (num(2)-2) / 2;
    ll case2 = num(14) * (num(4)-1);
    ll case3 = num(24) * (num(2)-1);
    ll case4 = num(74);
    ll ans = case1 + case2 + case3 + case4;
    cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
r = [False] * n
w = [0] * n
ok = 0
ng = 0
for i in range(m):
  p, s = input().split()
  p = int(p)
  p -= 1
  if s == 'AC':
    if r[p] == False:
      ok += 1
      ng += w[p]
      r[p] = True
  else:
    w[p] += 1
print(ok, ng)

Measured memory_bytes: 77448
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

class UnionFind {
private:
	unsigned size_; 
	std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	//unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	unsigned root(unsigned x)
	{
		while(par[x] != x)
		{
			par[x] = par[par[x]];
			x = par[x];
		}
		return x;
	}
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	string S;
	cin >> N >> S;

	#if 0
	int start_black = -1;
	int total_black = 0; 
	rep(i, N)
	{
		if (S[i] == '#')
		{
			if (start_black < 0)
			{
				start_black = i;
			}
			total_black++;
		}
	}

	int min_ = N - start_black - total_black;
	if (start_black < 0)
	{
		min_--;
	}
	min_ = min(min_, total_black);

	cout << min_ << endl;
	#endif
	vector<pair<int, int> > tmp;
	int total_black=0;
	rep(i, N)
	{
		if (S[i] == '#')
		{
			tmp.pb(make_pair(i, ++total_black));
		}
	}
	int min_ = N+1;
	for(int i = 0; i < tmp.size(); i++)
	{
		int tmp_min_ = N - tmp[i].first - (total_black - tmp[i].second+1) + tmp[i].second - 1;
		
		min_ = min(min_, tmp_min_);
	}
	//min_ = min(min_, N);
	min_ = min(total_black, min_);
	if (tmp.size() == 0)
	{
		min_ = 0;
	}

	cout << min_ << endl;
	return 0;
}


Measured memory_bytes: 2700
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i = 0;i < N;i++) {
        cin>>A[i];
        A[i]--;
    }
    vector<int> idx(N);
    for(int i = 0;i < N;i++) {
        idx[A[i]] = i;
    }
    set<int> s;
    Int ans = 0;
    for(int x = N-1;x >= 0;x--) {
        int i = idx[x];
        Int c = 0;
        
        { //calc c
            s.insert(i);
            vector<Int> L(2,-1);
            vector<Int> R(2,N);
            {
                auto it = s.find(i);
                for(int j = 0;j < 2;j++) {
                    if(it == s.begin())
                        break;
                    --it;
                    L[j] = *it;
                }
            }
            {
                auto it = s.find(i);
                for(int j = 0;j < 2;j++) {
                    it++;
                    if(it == s.end())
                        break;
                    
                    R[j] = *it;
                }
            }

            vector<Int> ls(2);
            ls[0] = i-L[0]; ls[1] = L[0] - L[1];
            vector<Int> rs(2);
            rs[0] = R[0] - i; rs[1] = R[1]-R[0];
            
            c = ls[0]*rs[1] + ls[1]*rs[0];
        }

        ans += c*(x+1);
    }

    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

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

using bint = boost::multiprecision::cpp_int;

constexpr int MOD = 1e9 + 7;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int a,b,c,k;
    cin>>a>>b>>c>>k;
    rep(i,k){
        if(a>=b){
            b*=2;
        }
        else{
            c*=2;
        }
    }
    if(a<b&&b<c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Alchemist
            int N = int.Parse(Console.ReadLine());
            var v = ReadLine();

            v.Sort();
            double ans = v[0];

            for(int i = 1; i < N; i++)
            {
                ans = (ans + v[i]) / 2;
            }

            Console.WriteLine(ans);
        }

        static List<double> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => double.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13396
#include<stdio.h>

int main(){
	int a,b,c;
	int t;
	scanf("%d %d %d", &a,&b,&c);
	if(a>b){
		t=a;
		a=b;
		b=t;
	}
	if(b>c){
		t=b;
		b=c;
		c=t;
	}
	if(a>b){
		t=a;
		a=b;
		b=t;
	}
	printf("%d %d %d\n", a,b,c);
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		long a = 0;
		long b = 0;
		long x = 0;
		long count = 0;
		long reserve = 0;
		Scanner scan = new Scanner(System.in);
		
		a = scan.nextLong();
		b = scan.nextLong();
		x = scan.nextLong();
		
		reserve = b / x;
		count = (a - 1) / x;
		
		if(a == 0) {
			count = -1;
		}
		System.out.println(reserve - count);
	}
}

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

int main(){
  string s,t;
  cin >> s >> t;
  string ans;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if (s<t){
    ans="Yes";
  }
  else{
    ans="No";
  }
  cout << ans << endl;
 }


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

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

    int count = 0;
    for (int i = 0; i < s.length()-2; i++) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#define int long long
using namespace std;
signed main(){
    int n;
    cin>>n;
    int p;
    cin>>p;
    cout<<(n*3+p)/2<<endl;
    return 0;
}


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

using namespace std;

long long maxnum = 3234566667;
vector<long long> ans;

void dfs(long long num, int n, bool check) {
	if (n == 10) {
		if (check) {
			ans.push_back(num / 10);
		}
		return;
	}
	if (!check) {
		for (char i = 0; i <= 9; i++) {
			num += i;
			if (maxnum / pow<long long>(10, 10 - n - 1) < num) {
				return;
			}
			dfs(num * 10, n + 1, i);
			num -= i;
		}
		return;
	}
	for (int i = max<long long>(0, (num % 100) / 10 - 1); i <= min<long long>(9, (num % 100) / 10 + 1); i++) {
		num += i;
		if (maxnum / pow<long long>(10, 10 - n - 1) < num) {
			return;
		}
		dfs(num * 10, n + 1, true);
		num -= i;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	dfs(0, 0, false);
	int k;
	cin >> k;
	sort(begin(ans), end(ans));
	cout << ans[k - 1] << "\n";
}

Measured memory_bytes: 1528
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

Q,H,S,D=gets.chomp.split(' ').map{|n| n.to_i}
N,_=gets.chomp.split(' ').map{|n| n.to_i}
# if(D < S*2 && D < H*4 && D < Q*8)
rem = N
cost = 0
[[2,D,D],[1,S,S*2], [0.5,H,H*4],[0.25,Q,Q*8]].sort{|a,b| a[2] <=> b[2]}.each{|a,c,cn|
	cost += (rem/a).to_i * c
	rem = (rem%a).to_i
}
puts cost





Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    string S, T;
    cin >> S >> T;
    int N = S.size(), M = T.size();
    int res = INF;
    for(int i = 0; i <= N - M; i++) {
        int tmp = 0;
        for(int j = 0; j < M; j++) {
            if(S[i + j] != T[j])
                tmp++;
        }
        res = min(tmp, res);
    }
    cout << res << endl;
}

Measured memory_bytes: 3624
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll n ; cin >>n;
  vector<string> s(n);
  vector<ll> a(5);
  rep(i,n){
    cin >> s[i];
    if(s[i][0]=='M')a[0]++;
    if(s[i][0]=='A')a[1]++;
    if(s[i][0]=='R')a[2]++;
    if(s[i][0]=='C')a[3]++;
    if(s[i][0]=='H')a[4]++;
  }
  ll sum =0;
  
  for (int tmp = 0; tmp < (1 << 5); tmp++) {
    bitset<5> t(tmp);  // 最大20個なので20ビットのビット列として扱う
 
    // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    ll key=0;
    ll sub=1;
    for (int i = 0; i < 5; i++) {
      if (t.test(i)) {
        sub*=a[i];
        key++;
      }
    }
    if (key == 3) {
      sum+=sub;
    }
  }
  cout  <<sum<<endl;
}

Measured memory_bytes: 6432
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1369 

#define x first
#define y second

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	const int MAX = 110000;
	int n, m;
	vector<pair<int,int>> hoge;
	vector<pair<int,int>> in;
	
	cin>>n>>m;
	
	hoge.resize(n);
	in.resize(m);
	
	for(int i = 0; i < m; i++){
		cin>>in[i].x>>in[i].y;
		in[i].y--;
	}
	for(int i = 0; i < n; i++){
		hoge[i].first = i;
		hoge[i].second = i;
	}
	
	// sort(in.begin(), in.end(), greater<pair<int,int>>());
	sort(in.begin(), in.end());
	
	for(int i = 0; i < m; i++){
		int a = hoge[in[i].y].first;
		int b = hoge[in[i].y+1].first;
		int c = hoge[in[i].y].second;
		int d = hoge[in[i].y+1].second;
		
		hoge[in[i].y].first = min(a,b);
		hoge[in[i].y].second = max(c,d);
		
		hoge[in[i].y+1].first = min(a,b);
		hoge[in[i].y+1].second = max(c,d);
	}
	
	for(int i = 0; i < n; i++){
		if(i) cout<<" ";
		cout<<hoge[i].second-hoge[i].first+1;
	}
	
	cout<<endl;
	return 0;
}


Measured memory_bytes: 7568
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define pb      push_back
#define all(v)  v.begin(),v.end()
#define see(x)  cout<<#x<<" : "<<(x)<<endl;
#define ya      cout<<"YES"<<endl;
#define no      cout<<"NO"<<endl;
#define ff      first
#define sc      second
typedef long long ll;
typedef pair<ll,ll> pii;


int main()
{

    string s;
    cin>>s;
    ll ans=0;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R')
        cout<<3<<endl;
    else if(s[0]=='R' && s[1]=='R' || s[1]=='R' && s[2]=='R')
        cout<<2<<endl;
        else if(s[0]=='R' || s[1]=='R' || s[2]=='R')
            cout<<1<<endl;
        else
cout<<ans<<endl;
    return 0;
}


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

int main(){
    int W,H,x,y,r;
    
    cin>>W>>H>>x>>y>>r;
    
    if (x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
        cout<<"Yes"<<endl;
        return 0;
    }else {
        cout<<"No"<<endl;
        return 0;
    }
    
}


Measured memory_bytes: 3088
local n=io.read("n")
local g={}
for i=1,n do
    g[i]={}
end
for i=1,n-1 do
    local x,y=io.read("n","n")
    g[x][y]=true
    g[y][x]=true
end

local bp,wp={},{}
local mod=1000000007
local function solve(cur,frm)
    bp[cur]=1
    wp[cur]=1
    for nxt in pairs(g[cur]) do
        if nxt~=frm then
            solve(nxt,cur)
            wp[cur]=wp[cur]*(wp[nxt]+bp[nxt])%mod
            bp[cur]=bp[cur]*wp[nxt]%mod
        end
    end
    if cur==1 then
        return (bp[cur]+wp[cur])%mod
    end
end
print(solve(1,0))

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

using namespace std;

typedef long long ll;

int main()
{
    int N, R, K;
    cin>>N>>R;
    if(N>=10)
    {
        cout<<R;
    }
    else if(N<10)
    {
        K=R+100*(10-N);
        cout<<K;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 109;
int n, m, x, c[N], a[N][N], p[N], ans = 0x3f3f3f3f;
void dfs(int s, int price) {
    if (s == n + 1) {
        for (int i = 1; i <= m; i++)
            if (p[i] < x)
                return;
        ans = min(ans, price);
        return;
    }
    dfs(s + 1, price);
    for (int i = 1; i <= m; i++)
        p[i] += a[s][i];
    dfs(s + 1, price + c[s]);
    for (int i = 1; i <= m; i++)
        p[i] -= a[s][i];
}
int main() {
    cin >> n >> m >> x;
    for (int i = 1; i <= n; i++) {
        cin >> c[i];
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    }
    dfs(1, 0);
    if (ans > 1e9)
        cout << -1;
    else
        cout << ans;
    return 0;
}

Measured memory_bytes: 3676
N = int(input())
S = str(input())


num2alpha = lambda c: chr(c+64)
#0 ~ 25
alpha2num = lambda c: ord(c) - ord('A')

ans = [0] * len(S)
for i in range(len(S)):
  now = alpha2num(S[i]) + N
  now %= 26
  ans[i] = num2alpha(now + 1)
  
for i in range(len(S)):
  print(ans[i], end = "")

Measured memory_bytes: 9396
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int count=0;
    while(N!=0){
      N/=K;
      count++;
    }    
      System.out.println(count);
  }
}

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

using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;

////////////////////////////////

int main()
{
    int n,m;
    vector<vector<int> > v;
    while(cin >> n >> m,n&&m){
        v.resize(m);
        for(int i=0;i<n;i++){
            int d,t;
            cin >> d >> t;
            v[--d].push_back(t);
        }
        for(auto &a:v)sort(a.begin(),a.end(),greater<int>());
        int res = 0;
        for(auto &a:v)res += a.front();
        cout << res << endl;
        v.clear();
    }
}




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

int main(){
    string s;
    cin >> s;
    int n = s.size()-1;
    if(s.at(n) == 's') cout << s << "es" << endl;
    else cout << s << "s" << endl;

}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long int
#define INF 1000000007

signed main(){
    int a,b,m;
    cin >> a >> b >> m;
    int ai[a];
    int bi[b];
    int a_min = INF;
    int b_min = INF;
    for(int i=0;i<a;i++){
        cin >> ai[i];
        a_min = min(a_min, ai[i]);
    }
    for(int i=0;i<b;i++){
        cin >> bi[i];
        b_min = min(b_min, bi[i]);
    }
    int min_val = a_min + b_min;
    int aj,bj,c;
    for(int i=0;i<m;i++){
        cin >> aj >> bj >> c;
        min_val = min(min_val, ai[aj-1]+bi[bj-1] - c);
    }
    cout << min_val << endl;
}

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

const int INF = 2e9;

int main(){
    int n,x,t;
    cin >> n >> x >> t;
    int ans = (n/x)*t;
    if(n%x != 0) ans += t;
    cout << ans << endl;
}

Measured memory_bytes: 3620