akhauriyash/Code-Regression huggingface dataset:
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <set>
#pragma endregion
using namespace std;

#pragma region 定数
#define INF_VAL (2147483647 - 1)
#define INF_VAL_MINUS -INFVAL
#pragma endregion

#pragma region マクロ
// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// for文
#define forn(i, size) for (long long(i) = 0; (i) < (size); (i)++)
#define for0(size) for (long(i) = 0; (i) < (size); (i)++)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length, type_name) sort(array, array + length, std::greater<type_name>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)

// 結果出力系
#define YES                    \
    {                          \
        cout << "YES" << endl; \
        return 0;              \
    }
#define NO                    \
    {                         \
        cout << "NO" << endl; \
        return 0;             \
    }
#define Yes                    \
    {                          \
        cout << "Yes" << endl; \
        return 0;              \
    }
#define No                    \
    {                         \
        cout << "No" << endl; \
        return 0;             \
    }
#pragma endregion

#pragma region Utility
#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion

#pragma region 10進数からN進数(<= 10) へ変換
string convertToN(long n, int base)
{
    string ans = "";
    while (n != 0)
    {
        int temp = n % base; // 1桁取得
        ans = ToString(temp) + ans;
        n /= base;
    }
    return ans;
}
#pragma endregion
#pragma endregion

int main()
{
    // 標準入力から値を取得
    int N, K;
    cin >> N >> K;

    // 入力数がN個の場合
    long H[N];
    int i = 0;
    forn (i, N)
    {
        cin >> H[i];
    }

    // 降順でソート
    SortDESC(H, N, long);

    long long ans = 0;
    for (int i = K; i < N; i++)
    {
        ans += H[i];
    }

    // 結果出力
    printf("%lld\n", ans);
}


Measured memory_bytes: 1792
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

time = 0

def dfs(u, adj, d, f, sumi):
    global time
    sumi.add(u)
    time += 1
    d[u] = time

    for v in adj[u]:
        if v not in sumi:
            dfs(v, adj, d, f, sumi)
            
    time += 1

    f[u] = time


def solve():
    n = int(input())
    adj = [None] * n

    for i in range(n):
        u, k, *vs = [int(j) - 1 for j in input().split()]
        # debug(vs, locals())
        adj[u] = vs

    # debug(adj, locals())
    
    d = [0] * n
    f = [0] * n
    sumi = {0}
    mitan = set(range(1, n))

    dfs(0, adj, d, f, sumi)
    mitan -= sumi
    # debug(mitan, locals())

    
    while mitan:
        u = min(mitan)
        dfs(u, adj, d, f, sumi)
        mitan -= sumi
        # debug(mitan, locals())
        

    for i in range(n):
        print(i + 1, d[i], f[i])

    pass

if __name__ == '__main__':
    solve()

Measured memory_bytes: 7824
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define ll int
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define pll pair<ll,ll>
const ll maxn= 2e5+10;
const ll mod = 5000000  ;
const ll base= 1e7;
void dosth(ll a, ll b , ll c,ll k  )
{
  if (a<b&&b<c)
  {
      cout <<"Yes";
      exit(0);
  }
  if (k==0) return ;
  dosth(a*2,b,c,k-1);
  dosth(a,b*2,c,k-1);
  dosth(a,b,c*2,k-1);
}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*  if (fopen("D_tst.INP","r"))
      {
          freopen("D_tst.INP","r", stdin);
          freopen("D_tst_1.cpp", "w",stdout);
      }*/
      ll a, b, c, k;
       cin>>a>>b>>c>>k;
       dosth(a,b,c,k);
       cout <<"No";


}
/*10 1
56 12 68 23 41 29 97 69 79 76
1 3 5
*/


Measured memory_bytes: 3608
#include<stdio.h>

int main(void)
{
	int i,j,taka,aoki,times;
	int cnt = 0;
	
	scanf("%d %d %d",&taka,&aoki,&times);
	
	for(cnt = 1;cnt <= times; cnt++){
		if (cnt % 2 != 0){
			if (taka % 2 != 0){
				taka = taka--;
			}
			taka = taka / 2;
			aoki = aoki + taka;
		}
		else{
			if(aoki % 2 != 0){
				aoki = aoki--;
			}
			aoki = aoki / 2;
			taka = taka + aoki;
		}
	}
	
	printf("%d %d",taka,aoki);
	
	return 0;
}

Measured memory_bytes: 128
package main

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

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	r, d, x := nextInt(), nextInt(), nextInt()

	for i := 0; i < 10; i++ {
		x = (r * x) - d
		fmt.Println(x)
	}
}


Measured memory_bytes: 640
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
m = s/n
if s%n==0:
    cost = 0
    for i in range(n):
        cost += (a[i]-s//n)**2
else:
    m1 = m//1
    m2 = m//1+1
    cost1 = 0
    cost2 = 0
    for i in range(n):
        cost1 += (a[i]-m1)**2
        cost2 += (a[i]-m2)**2
    cost = min(cost1,cost2)
print(int(cost))

Measured memory_bytes: 38640
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cstdlib>
using namespace std;
int c[27]; string str;
int main() {
	srand((unsigned)time(NULL));
	cout << "?aaaaaaa" << endl;
	while (true) {
		cin >> str;
		if (str[0] != 'a') {
			cout << "!OUT" << endl;
			goto E;
		}
		if (str.size() == 1) { c[26]++; }
		if (str.size() == 2) {
			c[str[1] - 'a']++;
		}
		for (int i = 0; i < 27; i++) {
			if(c[i] >= 2){ 
				cout << "!OUT" << endl;
				goto E;
			}
		}
		char P = str[str.size() - 1];
		string Z = ""; Z += P;
		for (int i = 0; i < 7; i++) {
			int x = (unsigned)(rand()) % 26;
			Z += x + 'a';
		}
		Z += 'a';
		cout << "?" << Z << endl;
	}
E:;
	return 0;
}

Measured memory_bytes: 1260
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<i32> = (0..n).map(|_| read()).collect();
    println!("{}", a.iter().max().unwrap() - a.iter().min().unwrap());
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
function Main(input){
	input = input.split(" ").map(a=>~~a);
  var A = input.shift();
  var B = input.shift();
  var K = input.shift();
  
  var m = Math.min(A,B);
  var cnt = 0;
	for(var i = m; 1 <= i;i--){
  	if(A%i == 0 && B%i == 0){
    	cnt++;
      if(cnt==K)return i;
    }
  }  
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
100 50 4
`);

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(ll i=(n);i<(x);++i)
#define SORT(x) sort(x.begin(),x.end())
using ll = long long;

int main() {
	ll n; cin >> n;
	vector<ll> a(n); rep(i, 0, n) cin >> a[i];

	SORT(a);
	ll ans = 0;
	rep(i, 0, n) {
		ll c = 1;
		while (a[i] == a[i + 1]) {
			i++;
			c++;
		}
		if (a[i] < c) ans += c - a[i];
		else if (a[i] > c) ans += c;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

int pow(int a, int b){
    a%=MOD;
    int res=1;
    while(b>0){
        if(b&1)res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

unsigned int log(unsigned int r, unsigned int n){
    return (n > r-1) ? 1+log(r,n/r) : 0;
}

int no_of_digits(int n){
    return (floor)(log(10,n))+1;
}

signed main() {
   tezz
   
    int n;
    cin >> n;
    map<pair<int,int>, int> mp;
    for(int i=1; i<=n; i++){
        string s = to_string(i);
        mp[{ s[0]-'0' , s[s.length()-1]-'0' }]++;
    }
    int ans=0;
    for(auto it: mp){
        for(auto itt: mp){
            if(it.x.x == itt.x.y && it.x.y == itt.x.x){
                ans += it.y * itt.y;
            }
        }
    }
    cout << ans << endl;
    
    
   return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

class Edge {
public:
  int src, dst, cost;
  Edge(int s, int d, int c)
    : src(s), dst(d), cost(c) {}
  friend bool operator<(const Edge& x, const Edge& y) {
    return x.cost < y.cost;
  }
};

typedef Edge State;

class Graph {
public:
  int N;
  vector<Edge>* V;
  int* visited;
  int* from;
  int time;
  int* time_d;
  int* time_f;

  Graph(int n)
    : N(n), time(0) {
    V = new vector<Edge>[N];
    from = new int[N];
    time_d = new int[N];
    time_f = new int[N];
    visited = new int[N];
    fill(visited, visited+N, 0);
  }
  ~Graph() {
    delete[] V;
    delete[] from;
    delete[] time_d;
    delete[] time_f;
    delete[] visited;
  }

  void add_edge(int src, int dst, int cost = 1) {
    V[src].push_back(Edge(src, dst, cost));
  }

  void dfs(int start) {
    stack<State> S;
    S.push(State(-1, start, 0));
    while (!S.empty()) {
      State s = S.top();
      S.pop();
      if (visited[s.dst] == 0) {
        visited[s.dst] = 1;
        time_d[s.dst] = time++;
        from[s.dst] = s.src;
        S.push(s);
        for (auto x : V[s.dst]) {
          if (visited[x.dst] == 0) {
            S.push(State(s.dst, x.dst, s.cost + x.cost));
          }
        }
      } else if (visited[s.dst] == 1) {
        visited[s.dst] = 2;
        time_f[s.dst] = time++;
      }
    }
  }
};

int main () {
  int n;
  cin >> n;
  Graph graph(n);
  for (auto i = 0; i < graph.N; ++i) {
    int u, k;
    cin >> u >> k;
    --u;
    for (auto j = 0; j < k; ++j) {
      int v;
      cin >> v;
      --v;
      graph.add_edge(u, v);
    }
  }
  for (auto i = 0; i < graph.N; ++i) {
    sort(graph.V[i].begin(), graph.V[i].end());
    reverse(graph.V[i].begin(), graph.V[i].end());
  }
  while (true) {
    bool used = false;
    for (auto i = 0; i < graph.N; ++i) {
      if (graph.visited[i] == 0) {
        graph.dfs(i);
        used = true;
        break;
      }
    }
    if (!used) break;
  }
  for (auto i = 0; i < graph.N; ++i) {
    cout << i+1
         << " " << graph.time_d[i]+1
         << " " << graph.time_f[i]+1 << endl;
  }
}

Measured memory_bytes: 3112
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>

// #include<atcoder/convolution>
// #include<atcoder/dsu>
#include<atcoder/fenwicktree>
// #include<atcoder/internal_bit>
// #include<atcoder/internal_math>
// #include<atcoder/internal_queue>
// #include<atcoder/internal_scc>
// #include<atcoder/internal_type_traits>
// #include<atcoder/lazysegtree>
// #include<atcoder/math>
// #include<atcoder/maxflow>
// #include<atcoder/mincostflow>
// #include<atcoder/modint>
// #include<atcoder/scc>
// #include<atcoder/segtree>
// #include<atcoder/string>
// #include<atcoder/twosat>

using namespace std;
using namespace atcoder;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    return xx*ff;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fastio;

	int n, q; 
	cin>>n>>q;
	int a[n]; 
	forn(i,n) cin>>a[i];
		
	fenwick_tree<ll> f(n);
	forn(i,n) f.add(i, a[i]);

	forn(i,q){
		int c; cin>>c;
		int l, r; cin>>l>>r;
		if(c == 0){
			f.add(l, r);
		}
		else{
			cout<<f.sum(l, r)<<ln;
		}
	}	

	return 0;
}

Measured memory_bytes: 10200
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(){
  int shuffle_num;
  
  while(1){
    string T;
    cin >> T;
    if(T[0] == '-'){
      break;
    }
    
    cin >> shuffle_num;
    int h;
    for(int i=0; i<shuffle_num; i++){
      cin >> h;

      string right = T.substr(0, h);
      string left = T.substr(h, T.size());

      T = left + right;
      
    }
    cout << T << endl;
  }
  
  return(0);

}

Measured memory_bytes: 1212
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll an[200010],bn[200010];
ll ha[200010],hainv[200010],hb[200010],hbinv[200010];

//プラキュー（二分ヒープ）（優先度変更ありバージョン）
int PQhikaku(ll*heap,int i,int j);//jの方が優先度が高いならtrueを返す
void PQchange(ll*heap,ll*heapinv,int n);
void heap_utod(ll*heap,ll*heapinv,int n){
	if(2*n>heap[0])return;
	int rflag=(2*n+1<=heap[0])&&(PQhikaku(heap,2*n,2*n+1));
	if(PQhikaku(heap,n,2*n+rflag)){
		ll temp=heap[2*n+rflag];
		heap[2*n+rflag]=heap[n];
		heap[n]=temp;
		heapinv[heap[n]&0xFFFFFF]=n;
		heapinv[heap[2*n+rflag]&0xFFFFFF]=2*n+rflag;	
		heap_utod(heap,heapinv,2*n+rflag);
	}
}
void heap_dtou(ll*heap,ll*heapinv,int n){
	if(n==1||PQhikaku(heap,n,n/2))return;
	ll temp=heap[n];
	heap[n]=heap[n/2];
	heap[n/2]=temp;
	heapinv[heap[n]&0xFFFFFF]=n;
	heapinv[heap[n/2]&0xFFFFFF]=n/2;
	heap_dtou(heap,heapinv,n/2);
}
ll PQpop(ll*heap,ll*heapinv){
	ll rr=heap[1];
	heapinv[heap[1]&0xFFFFFF]=0;
	heap[1]=heap[heap[0]--];
	heapinv[heap[1]&0xFFFFFF]=1;
	heap_utod(heap,heapinv,1);
	return rr;
}
void PQpush(ll*heap,ll*heapinv,ll n){
	heap[++heap[0]]=n;
	heapinv[heap[heap[0]]&0xFFFFFF]=heap[0];
	heap_dtou(heap,heapinv,heap[0]);
}
//この2つを変える
//*
int PQhikaku(ll*heap,int i,int j){
	if(bit(heap[i],50))return bn[heap[j]&0xFFFFFF]>bn[heap[i]&0xFFFFFF];
	return an[heap[j]&0xFFFFFF]>an[heap[i]&0xFFFFFF];
}
void PQchange(ll*heap,ll*heapinv,int n){
	if(heapinv[n&0xFFFFFF])heap_utod(heap,heapinv,heapinv[n&0xFFFFFF]);
}
//*/


ll a[200010],b[200010];

ll idx[200010];
ll ans[200010];

int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%lld",a+i);
	rep(i,0,n)scanf("%lld",b+i);
	rep(i,0,n)bn[a[i]]++;
	rep(i,0,n)an[b[i]]++;
	
	rep(i,0,n)if(!idx[a[i]])idx[a[i]]=i+1;
	
	rep(i,1,n+1)if(bn[i])PQpush(ha,hainv,i);
	rep(i,1,n+1)if(an[i])PQpush(hb,hbinv,i|1LL<<50);
	
	rep(_,0,n){
		int i1=PQpop(ha,hainv);
		int j=PQpop(hb,hbinv)&0xFFFFFF;
		//printf("t1:%d %d\n",i1,j);
		if(i1==j){
			if(ha[0]==0){
				puts("No");
				return 0;
			}
			int i2=PQpop(ha,hainv);
			//printf("%d\n",i2);
			if(bn[i2]==0){
				puts("No");
				return 0;
			}
			PQpush(ha,hainv,i1);
			i1=i2;
		}
		//printf("t2:%d %d\n",i1,j);
		ans[-1+idx[i1]++]=j;
		an[j]--;
		bn[i1]--;
		PQchange(ha,hainv,j);
		PQchange(hb,hbinv,i1);
		
		if(bn[i1])PQpush(ha,hainv,i1);
		if(an[j])PQpush(hb,hbinv,j|1LL<<50);
		//rep(i,0,n)printf("%lld ",ans[i]);puts("");
		
	}
	puts("Yes");
	rep(i,0,n)printf("%lld ",ans[i]);
}

Measured memory_bytes: 17268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

vector<pair<int,int>> factorize(int n)
{
	vector<pair<int, int>> vp;
	int primes[] = { 2,3,5,7,11,13,17,19,23,29,31,37 };
	for (int i = 0; i < 12; ++i)
	{
		int m = 0;
		while (n%primes[i]==0)
		{
			n = n / primes[i];
			m++;
		}
		if (m > 0)vp.push_back(make_pair(primes[i], m));
	}
	for(auto a :vp)
	{
		std::cout << a.first <<":" << a.second <<"\n";
	}

	return vp;

}


int main()
{
	Iint(n);
	string s1, s2;
	std::cin >> s1 >>s2;
	ll s = 1;
	bool prv = true; int i;
	if (s1[0] == s2[0])
	{
		s *= 3; i = 1;
	}
	else { s *= 6; prv = false; i = 2; }
	for (; i < n; ++i)
	{
		if (s1[i] == s2[i]) { s *= prv ? 2 : 1; prv = true; }
		else { s *= prv ? 2 : 3; i++; prv = false; }
	}
	std::cout << s%
		1000000007		;

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  cin >> n;
  cout << n * (n + 1) / 2 << endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "4 6", "#..#..", ".....#", "....#.", "#.#..." ].parse.expand.solve == 8 );
	assert( [ "8 8", "..#...#.", "....#...", "##......", "..###..#", "...#..#.", "##....#.", "#...#...", "###.#..#" ].parse.expand.solve == 13 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	auto ss = new char[][]( hw[ 0 ], hw[ 1 ] );
	foreach( ref s; ss )
	{
		input.popFront;
		s = input.front.to!( char[] );
	}
	return tuple( ss );
}

auto solve( char[][] ss )
{
	// 横に照らせるマス目をカウント
	auto wss = new long[][]( ss.length, ss[ 0 ].length );
	for( auto y = 0L; y < ss.length; y++ )
	{
		auto c = 0L;
		for( auto x = 0L; x < ss[ 0 ].length; x++ )
		{
			if( ss[ y ][ x ] == '#' )
			{
				wss[ y ][ x - c .. x ] = c;
				c = 0;
			}
			else
			{
				c++;
			}
		}
		wss[ y ][ $ - c .. $ ] = c;
	}
	
	// 縦に照らせるマス目をカウント
	auto hss = new long[][]( ss.length, ss[ 0 ].length );
	for( auto x = 0L; x < ss[ 0 ].length; x++ )
	{
		auto c = 0L;
		for( auto y = 0L; y < ss.length; y++ )
		{
			if( ss[ y ][ x ] == '#' )
			{
				for( auto i = y - c; i < y; i++ ) hss[ i ][ x ] = c;
				c = 0;
			}
			else
			{
				c++;
			}
		}
		for( auto i = wss.length - c; i < wss.length; i++ ) hss[ i ][ x ] = c;
	}
	
	// 縦横を足したときの最大値を判定
	auto ans = 0L;
	for( auto x = 0L; x < ss[ 0 ].length; x++ )
	{
		for( auto y = 0L; y < ss.length; y++ )
		{
			ans = max( ans, wss[ y ][ x ] + hss[ y ][ x ] - 1 );
		}
	}
	return ans;
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
int main(void){
    int n,k;
    cin>>n>>k;
    vector<ll> h(n);
    rep(i,0,n)cin>>h[i];
    sort(h.begin(),h.end());

    ll ans=INF;
    rep(i,0,n-k+1){
        ans=min(ans,h[i+k-1]-h[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1152
from collections import Counter
def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = [0] * n
    ac = Counter(a)
    for i in range(n):
        cnt[i] = ac[i+1]
    for i2 in range(n):
        print(cnt[i2])


if __name__ == '__main__':
    main()

Measured memory_bytes: 35596
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val K = in.nextInt
  val seq = Array(1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51)
  println(seq(K - 1))
}

Measured memory_bytes: 25416
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010000;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;

typedef pair<int, int>P;


int cumW[200020], cumB[200020];
signed main() {
	int N; string S;
	cin >> N >> S;
	m0(cumW), m0(cumB);
	REP(i, N) {
		if (S[i] == '#') {
			cumB[i + 1]++;
		}
		else cumW[i + 1]++;
	}
	REP(i, N) {
		cumW[i + 1] += cumW[i];
		cumB[i + 1] += cumB[i];
	}
	int ans = INF;
	REP(i, N+1) {
		int res = cumB[i] + cumW[N] - cumW[i];
		ans = min(ans, res);
		//pe(i)print(ans);
	}
	print(ans);
}


Measured memory_bytes: 3716
using System;
class C_SumGCD
{
    static void Main(string[] args)
    {
        Int64 Sum = 0;
        int K = Int32.Parse(Console.ReadLine());
        for(int a = 1;a <= K; a++)
        {
            for(int b = 1;b <= K; b++)
            {
                for(int c = 1;c <= K; c++)
                {
                    Sum += C_SumGCD.GCD(a, b, c);
                }
            }
        }
        Console.WriteLine(Sum);
    }
    static int GCD(int a,int b,int c)
    {
        return GCD(GCD(a, b), c);
    }
    static int GCD(int a,int b)
    {
        if (b == 0) return a;
        else return GCD(b, a % b);
    }
}

Measured memory_bytes: 27468
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<climits>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, t; cin >> x >> t;
    cout << max(0, x - t) << endl;
    
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

struct node{
    int key;
    node *next;
    node *prev;
};



node* nil;

void init() {
    nil = (node*)malloc(sizeof(node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key) {
    node* x;
    x = (node*)malloc(sizeof(node));
    x -> key = key;
    x -> next = nil -> next;
    nil -> next -> prev = x;
    nil -> next = x;
    x -> prev = nil;
}

/*node* listSearch(int key) {
    node* x = nil;
    while ( x -> next != nil ) {
        if ( x -> key == key ) return x;
        x = x -> next;
    }
    return nil;
}*/

node* listSearch(int key) {
    node* x = nil -> next;
    while ( x != nil && x -> key != key ) {
        x = x -> next;
    }
    return x;
}

void deleteNode(node* a) {
    if ( a == nil ) {
        return;
    }
    a -> prev -> next = a -> next;
    a -> next -> prev = a -> prev;
    free(a);
}

void deleteFirst() {
    deleteNode(nil -> next);
}

void deleteLast() {
    deleteNode(nil -> prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void printList(){
    node* cur = nil->next;
    int isf = 1;
    while(1){
        if ( cur == nil ) break;
        if ( isf == 0)  printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
    printf("\n");
}

int main() {
    int key;
    int n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for ( i = 0; i < n; i++ ){
        scanf("%s%d", com, &key);
        if ( com[0] == 'i' ) {insert(key); np++; size++;}
        else if ( com[0] == 'd' ) {
            if (strlen(com) > 6){
                if ( com[6] == 'F' ) deleteFirst();
                else if ( com[6] == 'L' ) deleteLast();
            } else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }

    printList();
    return 0;
}


Measured memory_bytes: 34372
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

type SortSlice []int

func (s SortSlice) Len() int {
        return len(s)
}

func (s SortSlice) Swap(i, j int) {
        s[i], s[j] = s[j], s[i]
}

func (s SortSlice) Less(i, j int) bool {
        return s[i] < s[j]
}

func reverseString(str string) string {
        buf := []rune(str)
        for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
                buf[i], buf[j] = buf[j], buf[i]
        }
        return string(buf)
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := readBigLine()

        spl := strSprit(line)

        A := parseInt(spl[0])
        B := parseInt(spl[1])
        K := parseInt(spl[2])

        nums := []int{}

        for i := A; i < A+K; i++ {
                if i > B {
                        break
                }
                nums = append(nums, i)
        }

        for i := B - K + 1; i <= B; i++ {
                if i < A {
                        break
                }
                nums = append(nums, i)
        }

        sort.Sort(sort.IntSlice(nums))

        checker := make(map[int]bool, len(nums))
        for _, v := range nums {
                if !checker[v] {
                        fmt.Println(v)
                        checker[v] = true
                }
        }

}



Measured memory_bytes: 768
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
import logging
import heapq
logging.basicConfig(level=logging.DEBUG)

input = sys.stdin.readline

setrecursionlimit(1000000)

MOD = 10**9+7

def main():
    N=int(input())
    A=[None]+[int(x) for x in input().split()]

    ans=[]
    check=[None]+[0]*N

    for i in reversed(range(1,N+1)):
        # print(i)
        # print(check[i::i])
        if not sum(check[i::i])%2 == A[i]:
            check[i]=1
            ans.append(i)

    # print(A)
    # print(check)
    print(len(ans))
    print(*ans)

main()

Measured memory_bytes: 116012
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#define MAX_N 1000001
#define ll long long
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


using namespace std;

int main(){
	int h, w;
	// string a[9][9];
	cin >> h >> w;
	int count = 0;
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			char s;
			cin >> s;
			if(s == '#') count++;
		}
	}

	if(count == h + w - 1){
		cout << "Possible" << endl;
	} else {
		cout << "Impossible" << endl;
	}


}


Measured memory_bytes: 256
// VU TRUONG AN
#include <bits/stdc++.h>
#define FORX(i,x,y) for(int i = x; i <= y ; ++i)
#define FORN(i,x,y) for(int i = x; i >= y ; --i)
#define reset(x,y) memset(x,y,sizeof(x))
#define bp(i) (1 << i)
#define F first
#define S second
#define maxn 100001
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define bit(p,x) ((x>>p) & 1)
#define Task "ATC"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<db> vdb;
typedef vector<str> vstr;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdb;

const int base = 100003;
const long long MM = 1ll*MOD*MOD;
const int maxc = 2e9;



void Solve(){
    string s,t;
    cin >> s >> t;
    if(t.length() != s.length() + 1){
        cout << "No";
        return;
    }
    for(int i = 0;i < s.length();i++){
        if(s[i] != t[i]){
            cout << "No";
            return;
        }
    }
    cout << "Yes";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    Solve();
}


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

int main() {
    long long n, sum;
    std::cin >> n;
    std::vector<long long> a(n), s(n), f(n-2, -1), g(n-2, -1);
    std::cin >> a[0];
    s[0] = a[0];
    for (long long i = 1; i < n; i++) {
        std::cin >> a[i];
        s[i] = s[i-1] + a[i];
    }
    sum = s[n-1];

    f[0] = 0;
    g[0] = 2;
    for (long long mid = 1; mid < n - 2; mid++) {
        for (long long l = f[mid-1]; l <= mid; l++) {
            if (s[l] * 2 >= s[mid]) {
                if (std::abs(s[l-1] - (s[mid] - s[l-1])) > std::abs(s[l] - (s[mid] - s[l]))) f[mid] = l;
                else f[mid] = l - 1;
                break;
            }
        }
        if (f[mid] == -1 || f[mid] < f[mid-1]) f[mid] = f[mid-1];
        if (f[mid] == mid) f[mid]--; 

        for (long long r = g[mid-1]; r < n; r++) {
            if ((s[r] - s[mid]) * 2 >= s[n-1] - s[mid]) {
                if (std::abs((s[r-1] - s[mid]) - (s[n-1] - s[r-1])) > std::abs((s[r] - s[mid]) - (s[n-1] - s[r]))) g[mid] = r;
                else g[mid] = r - 1;
                break;
            }
        }
        if (g[mid] == -1 || g[mid] < g[mid-1]) g[mid] = g[mid-1];
        if (g[mid] == n - 1) g[mid]--;
    }

    long long ret = -1;

    for (long long mid = 1; mid < n - 2; mid++) {
        auto diff = std::max({s[f[mid]], s[mid] - s[f[mid]], s[g[mid]] - s[mid], s[n-1] - s[g[mid]]}) - std::min({s[f[mid]], s[mid] - s[f[mid]], s[g[mid]] - s[mid], s[n-1] - s[g[mid]]});
        if (diff < ret || ret == -1) {
            ret = diff;
        }
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 6528
import itertools

n,m = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(m)]
num = list(range(1,n+1))
ans = 0
for l in itertools.permutations(num):
    if l[0]!=1:
        continue
    flag = True
    for i in range(len(l)-1):
        if not([l[i],l[i+1]] in edges or [l[i+1],l[i]] in edges):
            flag = False
            break
    if flag:
        # print(l)
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio (false) ;cin.tie(NULL);
#define tc  int t;cin>>t;for(int i=0;i<t;i++)
#define ll long long int
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define um(a,b) unordered_map<a,b>
#define vv(a) vector<a>
#define pp(a,b) pair<a,b>
string find(ll n){
    if(n==0)
     return "";
    else {
        ll rem=n%26;
        if(rem==0)
         return find(n/26-1)+'Z';
        else{
            char ch='A'-1+rem;
            return find(n/26)+ch;}
    }
}
int main() {

     ll a;
     cin>>a;
     string ans=find(a);
     string temp="";
     for(ll i=0;i<ans.length();i++){
        ll j=ans[i]-'A';
        char ch='a'+j;
        temp.pb(ch);
     }
     cout<<temp<<endl;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <limits>
#include <cassert>

#define seq(i, n) for (int i = 0; i < (n); i++)
#define seq2(i, f, t) for (int i = (f); i < (t); i++)
#define rev(i, n) for (int i = (n); i >= 0; i--)
#define rev2(i, f, t) for (int i = (f); i >= (t); i--)
#define all(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;

int solve(int n, int d) {
  int div = n/(2*d+1);
  if(n%(2*d+1)==0){
    return div;
  }
  return div+1;
}

int main() {
  #ifdef TEST
    solve();
  #else
    int n,d;
    cin>>n>>d;
    cout<<solve(n,d)<<endl;
  
  #endif

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define pi 3.1415926535897932384626433832
#define ll long long
using namespace std;
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / __gcd(a, b); }
bool isPrime(int n) {if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false;
return true;}

void lok(){
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll t;
	cin>>t;
	vector<ll> tba(t);
	for(auto &u:tba){
		cin>>u;
	}
	sort(tba.begin(),tba.end(),greater<ll>());
	ll ans=0;
	ans+=tba[0];
	ll te=1;
	ll pa=1;
	while(te<t-2){
		ans+=tba[pa]*2;
		pa++;
		te+=2;
	}
	if(te!=t-1){
		ans+=tba[pa];
	}
	cout<<ans;
	return 0;
}


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

int main()
{
	int N;
	long long K;
	cin >> N >> K;
	priority_queue<long long> que;
	for( int i = 0; i < N; i++ ) {
		long long A;
		cin >> A;
		que.push( A );
	}

	auto f = [&]( double t, priority_queue<long long> q )
	{
		long long k = 0;
		for( int i = 0; i < N; i++ ) {
			long long A = q.top();
			q.pop();
			long long n = ceil( A / t );
			k += n - 1;
		}
		return k;
	};
	double l = 0;
	double r = que.top();
	for( int i = 0; i < 100; i++ ) {
		double m = (l + r) / 2;
		long long k = f( m, que );
		if( k <= K ) r = m;
		else l = m;
	}
	long long ans = ceil( r );

	cout << ans << endl;
}


Measured memory_bytes: 6296
N=int(input())
count=0
def calc(n):
    x=int(n**0.5)+10
    for i in range(2,x):
        count=0
        while n%i==0:
            n=n//i
            count+=1
        if count!=0:
            ans.append([i,count])
for i in range(1,N+1):
    ans=[]
    sum=1
    if i%2==1:
        calc(i)
        for j in range(len(ans)):
            sum*=(ans[j][1]+1)
        if sum==8:
            count+=1
print(count)

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

char *flag;
int head,rear;
int *que;
int factorial[10];

int cal_factorial(int n) {
  if(n == 0) return 1;
  return cal_factorial(n-1)*n;
}

int stotag(char *s) {
  int tag = 0;
  int i;
  for(i = 0; i < 9; i++) {
    int t,j;
    t = 0;
    for(j = 0; j < i; j++) {
      if(s[j] < s[i]) t++;
    }
    tag += factorial[8-i]*(s[i]-'0'-t);
  }
  return tag;
}

char *tagtos(int tag) {
  int i;
  char *s;
  s = (char*)malloc(sizeof(char)*10);
  for(i = 0; i < 9; i++) {
    s[i] = tag%factorial[9-i]/factorial[8-i] + '0';
  }
  s[9] = '\0';
  for(i = 7; i >= 0; i--) {
    int j;
    for(j = 8; j > i; j--) {
      if(s[i] <= s[j]) s[j]++;
    }
  }
  return s;
}


char *move_up(char s[], int x) {
  if(x < 3) return NULL;
  char *s_new;
  s_new = (char*)malloc(sizeof(char)*10);
  strcpy(s_new,s);
  s_new[x] = s[x-3];
  s_new[x-3] = s[x];
  return s_new;
}

char *move_left(char s[], int x) {
  if(x%3 == 0) return NULL;
  char *s_new;
  s_new = (char*)malloc(sizeof(char)*10);
  strcpy(s_new,s);
  s_new[x] = s[x-1];
  s_new[x-1] = s[x];
  return s_new;
}

char *move_right(char s[], int x) {
  if(x%3 == 2) return NULL;
  char *s_new;
  s_new = (char*)malloc(sizeof(char)*10);
  strcpy(s_new,s);
  s_new[x] = s[x+1];
  s_new[x+1] = s[x];
  return s_new;
}

char *move_down(char s[], int x) {
  if(x > 5) return NULL;
  char *s_new;
  s_new = (char*)malloc(sizeof(char)*10);
  strcpy(s_new,s);
  s_new[x] = s[x+3];
  s_new[x+3] = s[x];
  return s_new;
}

int create(char s[], int t) {
  if(strcmp(s,"123456780") == 0) return t;
  int tag = stotag(s);
  if(flag[tag]) return 0;
  flag[tag] = t;
  que[rear] = tag;
  rear++;
  return 0;
}

int check_x(char *s) {
  int i = 0;
  while(s[i] != '0') i++;
  return i;
}

int cal() {
  char *s_right,*s_left,*s_up,*s_down;
  int k,tag;

  tag = que[head];
  char *s = tagtos(tag);
  int x = check_x(s);
  
  if((s_right = move_right(s, x)) != NULL) {
    if((k = create(s_right,flag[tag]+1))) return k;
    free(s_right);
  }
  if((s_left = move_left(s, x)) != NULL) {
     if((k = create(s_left,flag[tag]+1))) return k;
     free(s_left);
  }
  if ((s_up = move_up(s, x)) != NULL) {
    if((k = create(s_up,flag[tag]+1))) return k;
    free(s_up);
  }
  if((s_down = move_down(s, x)) != NULL) {
    if((k = create(s_down,flag[tag]+1))) return k;
    free(s_down);
  }
  free(s);
  head++;
  return 0;
}
  

int solve(char s0[]) {
  int k;
  if((k = create(s0,1))) return k;
  
  while(!(k = cal())) {
    if(head == rear) break;
  }
  return k;
}

int main()
{

  int i,d;
  char s[10];
  for(i = 0; i < 10; i++) factorial[i] = cal_factorial(i);
  flag = (char*)malloc(sizeof(char)*factorial[9]);
  memset(flag , 0, factorial[9]);
  que = (int*)malloc(sizeof(int)*factorial[9]);
  head = 0;
  rear = 0;
  for (i = 0; i < 9; i++) {
    scanf("%d", &d);
    s[i] = d+'0';
  }
  s[9] = '\0';
  printf("%d\n",solve(s)-1);
  
  return 0;
}

Measured memory_bytes: 1684
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main()
{
//    ll t;
//    cin>>t;
//    for(ll q=1;q<=t;q++)
   {
    ll n;
    cin>>n;
    string s;
    cin>>s;
    if(s.length()<=n)
     cout<<s;
     else
     {
         string ans="";
         for(int i=0;i<n;i++)
          ans+=s[i];
          ans+="...";
          cout<<ans;
     }
    // vector<ll> v;
    // for(ll i=0;i<n;i++)
    //  {
    //      ll x;
    //      cin>>x;
    //      v.push_back(x);
    //  } 
    
   }

    return 0;
}


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

#define int long long
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, m, s, t, a[200000], b[200000], c[200000], d[100000], dr[100000], dps[100000], dpt[100000], ans, ngv, nge;
vector<pii> e[100000];
pii sd[100000], td[100000];

void dijkstra(int s, vector<pair<int,int>> g[], int *d, int *dp) {
	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> que;
	fill(d, d+n, linf);
	d[s] = 0;
	dp[s] = 1;
	que.push(make_pair(0,s));
	
	while(!que.empty()) {
		pair<int,int> p = que.top(); que.pop();
		int v = p.second, dis = p.first;
		if (d[v]<dis) continue;
		for (int i = 0; i < g[v].size(); ++i) {
			int to = g[v][i].first, cost = g[v][i].second;
			if (d[to] > d[v] + cost) {
				d[to] = d[v] + cost;
				que.push(make_pair(d[to], to));
				dp[to] = dp[v]%mod;
			} else if (d[to] == d[v] + cost) {
				dp[to] = (dp[to] + dp[v]) %mod;
			}
		}
	}
}

signed main() {
	cin >> n >> m >> s >> t;
	s--, t--;
	rep(i,m) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--, b[i]--;
		e[a[i]].pb({b[i],c[i]});
		e[b[i]].pb({a[i],c[i]});
	}
	// sからの最短距離を全点について求めれば、頂点uからvに最短で行くために辺(v,u)を使っていいかどうかはd[u]==d[v]+cost[v][u]?でわかる
	// sからvへの行き方をdps[v]、vからtへの行き方をdpt[v]とする
	dijkstra(s, e, d, dps);
	dijkstra(t, e, dr, dpt);
	// 2人が途中で出会うようなものも含めた最短路の選び方の組
	ans = dps[t]*dps[t] %mod;
	// tへの距離の半分
	double half = d[t]/2.0;
	rep(i,n) {
		// 2人が頂点上で出会うような最短路の選び方の組
		if (d[i] == half) {
			int tmp = dps[i]*dpt[i]%mod;
			ans = (ans + mod - tmp*tmp%mod) %mod;
		}
		// 2人が辺上で出会うような最短路の選び方の組
		each(it,e[i]) {
			int j = it.fi, co = it.se;
			if (d[i]+co+dr[j] != d[t]) continue;
			if (d[i]<half && d[j]>half) {
				int tmp = dps[i]*dpt[j]%mod;
				ans = (ans + mod - tmp*tmp%mod) %mod;
			}
		}
	}
	
	//cout << ans << " " << ngv << " " << nge << ln;
	cout << ans << ln;
}

Measured memory_bytes: 24532
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=999999999;

int main() {
   string a,b,c;
   cin>>a>>b>>c;
   cout<<(char)(a[0]-'a'+'A')<<(char)(b[0]-'a'+'A')<<(char)(c[0]-'a'+'A')<<endl;
return 0;}

Measured memory_bytes: 256
import sys
import itertools


input = sys.stdin.readline


def main():
    a, b = -1, -1
    count = 0
    for p in itertools.permutations(range(1, N+1)):
        if p == P:
            a = count
        if p == Q:
            b = count
        if a != -1 and b != -1:
            break
        count += 1
    print(abs(a-b))


if __name__ == "__main__":
    N = int(input())
    P = tuple([int(p) for p in input().split()])
    Q = tuple([int(q) for q in input().split()])
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;

Int n, m;
vector<Int> G[300005];
Int s, t;
Int d[300005];

void dfs(Int x) {
    for (Int i = 0; i < (Int)G[x].size(); i++) {
        Int to = G[x][i];
        if (d[x] + 1 < d[to]) {
            d[to] = d[x] + 1;
            dfs(to);
        }
    }
}

int main() {
    cin >> n >> m;
    for (Int i = 0; i < m; i++) {
        Int a, b;
        cin >> a >> b;
        a *= 3;
        b *= 3;
        G[a].emplace_back(b + 1);
        G[a + 1].emplace_back(b + 2);
        G[a + 2].emplace_back(b);
    }
    cin >> s >> t;
    for (Int i = 1; i < (n + 1) * 3; i++) d[i] = INF;
    d[3 * s] = 0;
    queue<Int> q;
    q.push(3 * s);
    while (!q.empty()) {
        Int x = q.front();
        q.pop();
        for (Int i = 0; i < (Int)G[x].size(); i++) {
            Int to = G[x][i];
            if (d[x] + 1 < d[to]) {
                d[to] = d[x] + 1;
                q.push(to);
            }
        }
    }
    dump(d[3 * t] == INF ? -1 : d[3 * t] / 3);
    return 0;
}

Measured memory_bytes: 18944