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

using namespace std;

int main() {
  long long Sqt = 4e5;
  long long N, S;
  cin >> N >> S;

  // b smaller than sqrt(N)
  for (int b = 2; b < Sqt; b++) {
    long long num = N, sum = 0;
    while (num > 0) {
      sum += num % b;
      num /= b;
    }
    if (sum == S) {
      cout << b << '\n';
      return 0;
    }
  }

  // b between sqrtNn) and N 
  long long ans = 5e16;
  for (int x = 1; x < Sqt; x++) { // x = N / b
    long long b = (N - S + x) / x;
    if (b >= 2 && N / b + N % b == S && N / b / b == 0) {
      ans = min(ans, b);
    }
  }

  if (ans == 5e16 && S == N) ans = N + 1;
  if (ans == 5e16) ans = -1;
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int n,q,l,r,ans;
		String str;
		String[] s,stemp;
		int[] list;
		str = bf.readLine();
		stemp = str.split(" ");
		n = Integer.parseInt(stemp[0]);
		q = Integer.parseInt(stemp[1]);
		list = new int[n];
		str = bf.readLine();
		s = str.split("");
		if(s[0].equals("A") && s[1].equals("C")) {
			list[0] = 1;
		}
		for(int i = 1;i < n-1;++i) {
			if(s[i].equals("A") && s[i+1].equals("C")) {
				list[i] = list[i-1] + 1;
			} else {
				list[i] = list[i-1];
			}
		}
		list[n-1] = list[n-2];
		for(int i = 0;i < q;++i) {
			str = bf.readLine();
			stemp = str.split(" ");
			l = Integer.parseInt(stemp[0])-1;
			r = Integer.parseInt(stemp[1])-1;
			if(l == 0) {
				ans = list[r-1];
			} else {
				ans = list[r-1] - list[l-1];
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 48868
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll a[n];
    bool niko=false;
    for(int i=0;i<n;i++){
    	a[i]=(s[i]-'1');
    	if(a[i]==1)niko=true;
    }
    n--;
    bool maki=false;
    for(int i=0;i<=n;i++)maki^=(a[i]&1)&(i==(n&i));
    if(maki){
    	cout << 1<<endl;
    	return 0;
    }
    if(niko){
    	cout << 0 <<endl;
    	return 0;
    }
    for(int i=0;i<=n;i++)a[i]/=2;
    maki=false;
    for(int i=0;i<=n;i++)maki^=(a[i]&1)&(i==(n&i));
    cout << ((maki)?2:0) <<endl;
    return 0;
}


Measured memory_bytes: 9116
n = int(input())
w = list(map(int, input().split()))

sum_w = []
sum = 0
for i in range(n):
    sum += w[i]
    sum_w.append(sum)

diff  = sum
for i in range(n):
    if diff < abs(sum - 2*sum_w[i]):
        break
    else:
        diff = abs(sum - 2*sum_w[i])
print(diff)

Measured memory_bytes: 3064
N = int(input())
a = []
for _ in range(N):
    a.append(int(input()))

num_button = 0
now_light = 0
pushed = set()
while True:
    if now_light in pushed:
        print(-1)
        break

    pushed.add(now_light)
    now_light = a[now_light]-1
    num_button += 1
    if now_light == 1:
        print(num_button)
        break


Measured memory_bytes: 15908
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;
	
ll arr[2][101];
int main()
{
    cin >> N;
    arr[0][0] = 0;
    rep(i, N){
        cin >> arr[0][i+1];
        arr[0][i+1] += arr[0][i];
    }

    arr[1][0] = 0;
    rep(i, N){
        cin >> arr[1][i+1];
        arr[1][i+1] += arr[1][i];
    }
    ll maxv = 0;
    rep(i, N){
        maxv = max(maxv, arr[0][i+1] + arr[1][N] - arr[1][i]);
    }
    cout << maxv;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
typedef long long ll;
typedef pair<int,int> Pii;
const int INF=(1<<30)-1;
const int MAX=310;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int n;
int p[200000];
int main(){
	cin>>n;
	int max=1;
	REP(i,n){
		int t;
		cin>>t;
		p[t-1]=i;
	}
	int co=1;
	FOR(i,1,n){
		if(p[i-1]<p[i]){
			co++;
		}else{
			max=max(max,co);
			co=1;
		}
	}
	max=max(max,co);
	cout<<n-max<<endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
struct DSU{
	int n;
	vector<int> par,siz;
	DSU(int n):n(n){
		par.resize(n);
		siz.resize(n,1);
		for(int i=0;i<n;i++){
			par[i]=i;
		}
	}	
	int find(int x){
		if(par[x]==x){
			return x;
		}
		return par[x]=find(par[x]);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v){
			return;
		}
		if(siz[u]<siz[v]){
			swap(u,v);
		}
		siz[u]+=siz[v];
		par[v]=u;
	}
};
int main(){
	ll n,m,q;cin>>n>>m>>q;
	vector<int> a(q),b(q),c(q);
	DSU uf(n);
	for(int i=0;i<q;i++){
		cin>>a[i]>>b[i]>>c[i];
		if(c[i]==0){
			uf.unite(a[i],b[i]);
		}
	}
	ll s=0;
	for(int i=0;i<n;i++){
		if(uf.find(i)!=i){
			continue;
		}
		s++;
		m-=uf.siz[i]-1;
	}
	set<int> st;
	for(int i=0;i<q;i++){
		if(c[i]==1){
			if(uf.find(a[i])==uf.find(b[i])){
				cout<<"No"<<endl;
				return 0;
			}
			st.insert(uf.find(a[i]));
			st.insert(uf.find(b[i]));
		}
	}
	ll lb=st.size(),ub=s*(s-1LL)/2LL;
	//cout<<lb<<" "<<m<<" "<<ub<<endl;
	if(lb<=m&&m<=ub){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 6912
def gcd(a,b):
  if a>=b:
    if a%b==0:
      return b
    else:
      return gcd(a%b,b)
  else:
    if b%a==0:
      return a
    else:
      return gcd(a,b%a)
  
N=int(input())
HP=[int(i) for i in input().split()]
ans=HP[0]
for i in range(1,N):
  ans=gcd(ans,HP[i])
print(ans)
    

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n,m;
  cin>>n>>m;
  vector<P> v[111111];
  for(int i=0;i<m;i++){
    int l,r,d;
    cin>>l>>r>>d;
    v[l].push_back(P(r,d));
    v[r].push_back(P(l,-d));
  }
  int cos[111111],ans=1;
  fill(cos,cos+n+1,INT_MAX);
  for(int i=1;i<=n;i++){
    if(cos[i]==INT_MAX){
      queue<P> q;
      q.push(P(i,0));
      while(!q.empty()){
	int to=q.front().first;
	int cost=q.front().second;
	q.pop();
	if(cos[to]==INT_MAX){
	  cos[to]=cost;
	  for(int j=0;j<v[to].size();j++){
	    P p=v[to][j];
	    p.second+=cost;
	    q.push(p);
	  }
	}else if(cos[to]!=cost)ans=0;
      }
    }
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 11508
N, M = map(int, input().split())
k = []
lis = []
P = []
for _ in range(M):
    x = list(map(int, input().split()))
    k.append(x[0])
    lis.append(x[1:])
for p in map(int, input().split()):
    P.append(p)
count = 0
for i in range(2**N):
    flag = True
    Switch = [False] * (N+1)
    string = str(bin(i)[2:])
    for index, s in enumerate(string[::-1]):
        if s == '1':
            Switch[index + 1] = True
    for index in range(M):
        total = 0
        for s in lis[index]:
            if Switch[s]:
                total += 1
        if total % 2 != P[index]:
            flag = False
            break
    if flag:
        count += 1
print(count)

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

#define LL long long
#define pii pair<int,int>
using namespace std;
const int inf = 2147483647;
const int mod = 998244353;
const int N = 401;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int add(int x, int y) {x += y; return x >= mod ? x - mod : x;}
int dec(int x, int y) {x -= y; return x < 0 ? x + mod : x;}
int pow_mod(int a, int k) {
	int ans = 1;
	for(; k; k >>= 1, a = (LL)a * a % mod) if(k & 1) ans = (LL)ans * a % mod;
	return ans;
}

int ans, a[N], b[N], f[2][N][N], jc[N], inv[N], bin[N];

int main() {
	int n = read(), S = 0, mx = 0;
	for(int i = 1; i <= n; i++) a[i] = read(), b[i] = read(), S += a[i], mx += b[i] -1;
	jc[0] = 1; for(int i = 1; i <= mx; i++) jc[i] = (LL)jc[i - 1] * i % mod;
	inv[mx] = pow_mod(jc[mx], mod - 2); for(int i = mx; i; i--) inv[i - 1] = (LL)inv[i] * i % mod;
	int s1 = 0, s2 = 0; int iv = pow_mod(S, mod - 2);
	int now = 0;
	f[0][0][0] = mod - 1; for(int i = 1; i <= n; i++) {
		now ^= 1; memset(f[now], 0, sizeof(f[now]));
		int p = (LL)a[i] * iv % mod;
		bin[0] = 1; for(int j = 1; j < b[i]; j++) bin[j] = (LL)bin[j - 1] * p % mod;
		for(int j = 1; j < b[i]; j++) bin[j] = (LL)bin[j] * inv[j] % mod;
		for(int j = s1; j >= 0; j--) for(int k = s2; k >= 0; k--) if(f[now ^ 1][j][k]){
			f[now][j + a[i]][k] = add(f[now][j + a[i]][k], f[now ^ 1][j][k]);
			for(int h = 0; h < b[i]; h++) 
			f[now][j][k + h] = dec(f[now][j][k + h], (LL)f[now ^ 1][j][k] * bin[h] % mod);
		} s1 += a[i], s2 += b[i] - 1;
	} for(int i = 0; i < s1; i++) {
			int C = (LL)i * iv % mod;
			C = pow_mod(dec(1, C), mod - 2);
			for(int j = 0; j <= s2; j++) if(f[now][i][j]) {
			ans = add(ans, (LL)f[now][i][j] * jc[j] % mod * pow_mod(C, j + 1) % mod);
		}
	} put(ans), puts("");
	return 0;
}


Measured memory_bytes: 1536
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	n := nextInt()
	shellSort(n)
}

func insertionSort(A []int, n, g int) ([]int, int) {
	cnt := 0
	for i := g; i < n; i++ {
		v := A[i]
		j := i - g
		for ; j >= 0 && A[j] > v; j -= g {
			A[j+g] = A[j]
			cnt++
		}
		A[j+g] = v
	}
	return A, cnt
}

func shellSort(n int) {
	cnt := 0
	var m int
	A := make([]int, n)
	for i := range A {
		A[i] = nextInt()
	}
	//適度に値に差がつくようなGを定義する
	// シェルソートの間隔の決め方
	// https://programming-place.net/ppp/contents/algorithm/sort/005.html
	G := make([]int, 0)
	for i := 1; i <= n; i = 3*i + 1 {
		G = append(G, i)
	}
	m = len(G)
	for i := len(G) - 1; i >= 0; i-- {
		var tmp int
		A, tmp = insertionSort(A, n, G[i])
		cnt += tmp
	}
	fmt.Println(m)
	sort.Sort(sort.Reverse(sort.IntSlice(G)))
	fmt.Println(strings.Trim(fmt.Sprint(G), "[]"))
	fmt.Println(cnt)
	for _, v := range A {
		fmt.Println(v)
	}
}

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



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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

vector<ll> memo, group;

int main(){ _

	int n; cin >> n;
	vector<vector<ll>> cost(n, vector<ll>(n));
	for(auto& v : cost) for(auto& i : v) cin >> i;

	memo.resize(1<<n, -INF);
	group.resize(1<<n);
	for(int mask=0; mask<(1<<n); mask++) {
		ll ret = 0;
		for(int i=0; i<n; i++) for(int j=i+1; j<n; j++) {
			if((mask & (1 << i)) and (mask & (1 << j))) 
				ret += cost[i][j];
		}
		group[mask] = ret;
	}

	memo[0] = 0;
	for(int mask = 1; mask < (1<<n); mask++) {
		vector<int> in;
		for(int i=0; i<n; i++) if(mask & (1<<i)) in.push_back(i);

		function<ll(int,int)> solve = [&] (int pos, int mmask) {
			if(pos == in.size()) return memo[mask-mmask] + group[mmask];

			return max(solve(pos+1, mmask), solve(pos+1, mmask^(1<<in[pos])));
		};

		memo[mask] = solve(0, mask);
	}

	cout << memo[(1<<n)-1] << endl;

	return 0;
}

Measured memory_bytes: 4272
#include <stdio.h>
int main(){
    int h, w;
    int i = 0;
    int j, k, l, m;
    while(i<1000){
        scanf("%d %d", &h, &w);
        if(w == 0 && h == 0){
            break;
        }else{
            for(j=0; j<w; j++){
                printf("#");
            }
            printf("\n");
            for(k=0; k<h-2; k++){
                printf("#");
                for(l=0; l<w-2; l++){
                    printf(".");
                }
                printf("#\n");
            }
            for(m=0; m<w; m++){
                printf("#");
            }
            printf("\n\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2020
// AOJ 2150 "Matsuzaki Number" (ICPC模擬国内予選 2009 Problem B)
import java.util.Scanner;
import java.util.BitSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
    static BitSet isNotPrime; // 素数でないならtrue
    static ArrayList<Integer> primeList;
    static final int MAX_N = 250000; // 素数表の上限
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        isNotPrime = new BitSet();
        primeList = new ArrayList<Integer>();
        sieve();
        
        while (true) {
            int n = sc.nextInt();
            int p = sc.nextInt();
            if (n == -1) {
                break;
            }
            
            ArrayList<Integer> result = new ArrayList<Integer>();
            List<Integer> tmp;
            int pos = 0;
            while (primeList.get(pos) <= n) {
                pos++;
            }
            tmp = primeList.subList(pos, pos + 100); // nより大きい素数を小さい方から100個とる
            for (int i = 0; i < tmp.size(); i++) {
                for (int j = i; j < tmp.size(); j++) {
                    result.add(tmp.get(i) + tmp.get(j));
                }
            }
            Collections.sort(result);
            System.out.println(result.get(p - 1));
        }
    }
    
    // ここのsieveはふるいにかけると同時に、素数だけのリストを生成する
    public static void sieve() {
        isNotPrime.set(0);
        isNotPrime.set(1);
        for (int i = 2; i < MAX_N; i++) {
            if (!isNotPrime.get(i)) {
                primeList.add(i);
                for (int j = i * 2; j <= MAX_N * 2; j += i) {
                    isNotPrime.set(j);
                }
            }
        }
    }
}

Measured memory_bytes: 99216
#include <iostream>
#define N_MAX 100
#define HN_MAX 201
#define NONE -1
#define TARO 9999
#define HANA 0
using namespace std;

void distribute( int taro[], int hanako[], int n ){
  int hist[ HN_MAX ] = { 0 };
  for( int i = 0; i < n; i++ ){
    int temp;
    cin >> temp;
    hist[ temp ] = TARO;
  }
  int tp = 0;
  int hp = 0;
  for( int i = 1; i <= 2 * n; i++ ){
    switch( hist[ i ] ){
      case TARO:
        taro[ tp++ ] = i;
        break;
      case HANA:
        hanako[ hp++ ] = i;
        break;
    }
  }
}

void out( int *field, int cards[], int outCard, int *counter ){
  *field = cards[ outCard ] ;
  for( int i = outCard; i < ( *counter ) - 1 ; i++ ){
    cards[ i ] = cards[ i + 1 ];
  }
  (*counter)--;
}

int main(){
  while( 1 ){
    int n;
    cin >> n;
    if( !n ){ return 0; }
    int taro[ N_MAX ], hanako[ N_MAX ];
    int tn = n;
    int hn = n;
    int field = NONE;
    distribute( taro, hanako, n );
 
    while( 1 ){
      if( field == NONE ){
        out( &field, taro, 0, &tn );      
      }else{
        bool ok = false;
        for( int i = 0; i < tn; i++ ){
          if( field < taro[ i ] ){
            out( &field, taro, i, &tn );
            ok = true;
            break;
	  }
	}
        if( !ok ){ field = NONE; }
      }
      if( tn == 0 ){ break; }
      if( field == NONE ){
        out( &field, hanako, 0, &hn );      
      }else{
        bool ok = false;
        for( int i = 0; i < hn; i++ ){
          if( field < hanako[ i ] ){
            out( &field, hanako, i, &hn );
            ok = true;
            break;
	  }
	}
        if( !ok ){ field = NONE; }
      }
      if( hn == 0 ){ break; }
    }
    cout << hn << endl;
    cout << tn << endl;
  }
}

Measured memory_bytes: 0
n = int(input())
A = list(map(int, input().split()))

A_csum = [0] * n
Sum = 0
for i in range(n):
    Sum += A[i]
    A_csum[i] = Sum

pat1 = 0
next_sign = 1
now = 0
for i in range(n):
    if (A_csum[i]+now) * next_sign <= 0:
        diff = next_sign-(A_csum[i]+now)
        pat1 += abs(diff)
        now += diff
    else:
        pass
    next_sign *= -1
    
pat2 = 0
next_sign = -1
now = 0
for i in range(n):
    if (A_csum[i]+now) * next_sign <= 0:
        diff = next_sign-(A_csum[i]+now)
        pat2 += abs(diff)
        now += diff
    else:
        pass
    next_sign *= -1

print(min(pat1,pat2))
    


Measured memory_bytes: 85420
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}



// TODO: write
int main() {   
  string s;cin>>s;
  int q;cin>>q;
  
  string tmp = "";
  int cnt = 0;
  rep(i,q){
    int t;cin>>t;
    if(t == 2){
      int f;cin>>f;
      char c;cin>>c;
      if(f == 1){
        if(cnt%2 == 0)tmp += c;
        else s += c;
      }else{
        if(cnt%2 == 1)tmp += c;
        else s += c;
      }
    }else{
      reverse(all(tmp));
      s = tmp+s;
      tmp = "";
      cnt++;
    }
  }

  reverse(all(tmp));
  s = tmp+s;
  if(cnt%2)reverse(all(s));
  print(s);
  return 0;
}



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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    ll cnt = n / k;
    ans += cnt * cnt * cnt;
    if (~k & 1) {
        ll cnt2 = (n + k / 2) / k;
        ans += cnt2 * cnt2 * cnt2;
    }

    cout << ans;
}


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

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

    int val;
    std::vector<int> a = {9};   // <- it enables to use unified calculation to derive a distance.
    for(int i = 0; i < n; ++i){
        std::cin >> val;
        a.push_back(val);
    }

    int i = 1, ans = 0;
    std::vector<int>::iterator preItr = a.begin(), currItr = preItr;
    while(a.end() != currItr){
        currItr = std::find(preItr, a.end(), i++);
        ans += std::distance(preItr, currItr) - 1;  // <- this calculation
        preItr = currItr;
    }

    if(2 == i && ans == a.size() - 1){
        ans = -1;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 1400
s=set()
s.add(1)
x=1001
for i in range(2,1000):
    k=i*i
    while k<x:
        s.add(k)
        k*=i
#print(sorted(s))
l=[i for i in range(1001)]
for i in range(1,1001):
    if i in s:
        l[i]=i
    else:
        l[i]=l[i-1]
print(l[int(input())])

Measured memory_bytes: 9116
#include <iostream>
#include <vector>
#include <map>

using namespace std;

map<string, int> value;
map<string, vector<string> > recip;


int rennkinn(string& obj)
{
	int sum = value[obj];
	
	if( recip.find(obj) != recip.end() ) {

		vector<string>& parts = recip.find(obj)->second;

		int tmp = 0;
		for( auto& p : parts ) {
			tmp += rennkinn(p);
		}

		if( tmp < sum )
			sum = tmp;		
	}

	return sum;
}

int main(int argc, char* argv[])
{
	while(1) {

		int np;
		cin >> np;
		if( np == 0 )
			break;
	
		for( int i = 0; i < np; i++ ) {
			string p;
			cin >> p;
			int v;
			cin >> v;
			value[p] = v;
		}

		int nr;
		cin >> nr;
		for( int i = 0; i < nr; i++ ) {
			string p;
			cin >> p;
			int np;
			cin >> np;
			vector<string> ps;
			for( int j = 0; j < np; j++ ) {
				string p;
				cin >> p;
				ps.push_back(p);
			}
			recip[p] = ps;
		}


		string obj;
		cin >> obj;

		cout << rennkinn(obj) << endl;
		
		value.clear();
		recip.clear();
	}
	

    return 0;
}

Measured memory_bytes: 3188
//********************************************************************//
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fi first 
#define se second 
#define RANGE(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DFOR(i, a, b) for(int i = a; i > b; --i)
#define DEB(x) cout << #x << ": " << x << endl
#define ALL(v) v.begin(), v.end() 
#define SORT(v) sort(ALL(v))
#define DISPV(v) { for(auto x___: v) cout << x___ << " "; cout << endl; }
#define DISPM(m) { for(auto x____: m){ cout << x____.first << ": " << x____.second << endl; } };
#define DISPMV(m) { for(auto x_____: m){ cout << x_____.first << ": " ;DISPV(x_____.second);} };
using LL = long long;
using VI = vector <int>;
using VC = vector <char>;
using VS = vector <string>;
using VL = vector <long long>;
using VVI = vector<VI>;
using VVL = vector <VL>;
using MII = map<int, int>;
using MIVI = map<int, VI>;
using MSS = map<string, string>;
using MLL = map<LL, LL>;
int READ_INT(){int temp;cin>>temp;return temp;}      // read an int
LL READ_LONG(){LL temp;cin>>temp;return temp;}      // read a long long
void mcs(VI &series, int &max_sum){                    // maximum contigous sub sum(kadane)
    int s=0;
    for(auto x: series){
        s += x;
        max_sum = max(max_sum, s);
        if(s < 0)s = 0;
    }
}
template<typename T>
T MAX(T t){ return t;}
template <typename T, typename... Args>
T MAX(T t, Args... args){ return max(t, MAX(args...)); }
const int MOD = int(1e9) + 7;
const int INF = 1e9 + 5;
const double PI = acos(-1.0); //M_PI;
const double EPS = 1e-9;
//********************************************************************//

LL n;
VL sequence;

LL score(LL k){
    LL s = 0;
    for(auto x: sequence)s += abs(k - x);
    return s;
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n;
    RANGE(i,n)sequence.push_back(READ_LONG() - (LL)(i+1));
    SORT(sequence);
    // DISPV(sequence);

    LL l = sequence[0]-1, r = sequence[n-1]+1, m1, m2;
    while(r - l > 2){
        m1 = l + (r-l)/3;
        m2 = r - (r-l)/3;
        LL s1 = score(m1), s2 = score(m2);
        if(s1 < s2)r = m2;
        else if(s1 > s2) l = m1;
        else
            l = m1, r = m2;
    }
    LL ans = min(score(l), min(score(l+1), score(l+2)));
    cout << ans << endl;

    return 0;
}



/* complie flags
-Wall -Wextra -pedantic -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector
*/

Measured memory_bytes: 2420
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    double ans=a[0];
    for(int i=1;i<n;i++){
        ans+=a[i];
        ans/=2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
using namespace std;

int main() {
    string a;
    cin >> a;
    int e = 1000;
    int g = a.size();
    for (int i = 0; i < 26; i++) {
        char f = 'a';
        for (int j = 0; j < i; j++) {
            f += 1;
        }
        int y = 0;
        int v = 0;
        for (int j = 0; j < g; j++) {
            if (a.at(j) != f)y++;
            else y = 0;
            v = max(v, y);
        }
        e = min(e, v);
}
    cout << e << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>

#define INF_LL 9000000000000000000
#define INF 2000000000

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<double, int> PDI;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	string s;
	cin >> s;
	if(s[0] == s[s.size()-1]){
		if(s.size() % 2 == 0){
			cout << "First" << endl;
			return 0;
		}else{
			cout << "Second" << endl;
			return 0;
		}
	}else{
		if(s.size() % 2 == 0){
			cout << "Second" << endl;
			return 0;
		}else{
			cout << "First" << endl;
		}
	}
}


Measured memory_bytes: 512
Z=8,ptr[20],c,d,e,s,i,j;
main(){
#if 1
	for(i=0;i*Z<128;i++)ptr[i]=i*Z;
	for(i=0;i<Z;i++)putchar('+');
	putchar('[');
	for(i=0;i*Z<128;i++)for(putchar('>'),j=0;j<i;j++)putchar('+');
	for(i=0;i*Z<128;i++)putchar('<');
	putchar('-'),putchar(']');
	for(e=-1;~(c=getchar())&&c!='\n';putchar('.')){
		if(s='>',d=c/Z-e,d<0)d=-d,s='<';
		for(i=0;i<d;i++)putchar(s);
		e=c/Z;
		if(s='+',d=c-ptr[c/Z],d<0)d=-d,s='-';
		for(i=0;i<d;i++)putchar(s);
		ptr[c/Z]=c;
	}
#else
	putchar('>');
	for(e=0;~(c=getchar())&&c!='\n';putchar('.')){
		if(s='+',d=c-e,d<0)d=-d,s='-';
		if(d/Z){
			putchar('<');
			for(i=0;i<d/Z;i++)putchar('+');
			putchar('['),putchar('>');
			for(i=0;i<Z;i++)putchar(s);
			putchar('<'),putchar('-'),putchar(']'),putchar('>');
		}
		for(i=0;i<d%Z;i++)putchar(s);
		e=c;
	}
#endif
exit(0);}

Measured memory_bytes: 524
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e9;
const ll MAX = 200005;
//
//

                    vector<ll> vec(MAX);
                int check(ll mid, ll k){
                    ll cuts = 0;
                    for(ll z : vec){
                        cuts += ((z-1)/mid);
                    }
                    return cuts<=k;
                }
                void solve(){
                    ll n,k ;
                    cin>>n>>k;
                    for(int i = 0; i < n; i++)
                        cin>>vec[i];
                    ll lo = 1, hi = INF;
                    while(lo < hi){
                        ll mid = (lo + hi)>>1;
                        if(check(mid, k))
                            hi = mid;
                        else
                            lo = mid+1;
                    }
                    cout<<lo;
                }
                int main(){ 
                        hs;
                        ll t;
                        t=1;
                        // cin>>t;
                        for (int i=1; i<=t; i++){
                                //cout<<"Case #"<<i<<": ";
                                solve();
                         }
        return 0; 
}         
 
 


Measured memory_bytes: 4692
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if(e-a>k) cout<<":(";
  else cout<<"Yay!";
return 0;}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <cstdio>
using namespace std;
typedef long long ll;

int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

int lcm(int a,int b){
    return a*b/gcd(a,b);
}

int main(){
    ll b,c,d,e,k,l,m,n,o=0,p,q,r,x,y,z,max1=0,ans=0,a1,b1;
    string s,t,u;
    ll a[7][7];
    
    cin>>n>>s;
    
    if(n%2==1)cout<<"No"<<endl;
    else {
    for(ll i=0;i<n/2;i++){
        if(s[i]!=s[i+n/2])o++;
       
    }
    if(o==0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}



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

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

	int count = 0;
	for (int i = 0; i < n && n >= 2; i++) //repeat for pairs of evens as long as it's possible to have pairs
	{
		for (int j = i + 1; j < n; j++)
		{
			count++;
		}
	}
	for (int ii = 0; ii < m && m >= 2; ii++) //same for odds
	{
		for (int jj = ii + 1; jj < m; jj++)
		{
			count++;
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

char map[20][21];											//高さ * 幅
int h, w;													//マップの高さ、幅
int px, py, dir = 0;										//自分の座標、方向
int dirx[4] = { 0,0,-1,1 };
int diry[4] = { -1,1,0,0 };
char my[4] = { '^', 'v', '<', '>' };

void act(char *n);
void move(int x);
void shot(int x);
void format(int x, int y);
void view(void);

int main(void) {
	format(20, 20);
	int i, j, k;
	int data;												//繰り返し回数
	int nmax;												//操作列の長さ
	char n[101];											//操作列の格納用
	scanf("%d\n", &data);									//繰り返し回数の取得
	for (k = 0; k < data; k++) {
		scanf("%d %d\n", &h, &w);							//高さと幅の取得
		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				map[i][j] = getchar();
				if (map[i][j] == '^') { px = j, py = i, dir = 0; }
				if (map[i][j] == 'v') { px = j, py = i, dir = 1; }
				if (map[i][j] == '<') { px = j, py = i, dir = 2; }
				if (map[i][j] == '>') { px = j, py = i, dir = 3; }
			}
			getchar();
		}
		scanf("%d\n", &nmax);								//操作列の長さの取得
		if (nmax < 0) { nmax = 0; }
		if (nmax > 100) { nmax = 100; }
		for (i = 0; i < nmax; i++) {						//操作列の取得
			n[i] = getchar();
		}
		n[i] = '\0';
		act(&n[0]);											//行動処理
		view();												//結果の表示
		if (k + 1 != data) { printf("\n"); }
	}
	return 0;
}
void act(char *str) {										//行動処理
	while (*str != '\0') {
		switch (*str) {
		case 'U':
			dir = 0;
			move(dir);
			break;
		case 'D':
			dir = 1;
			move(dir);
			break;
		case 'L':
			dir = 2;
			move(dir);
			break;
		case 'R':
			dir = 3;
			move(dir);
			break;
		case 'S':
			shot(dir);
			break;
		default:
			break;
		}
		str++;
	}
}
void move(int x) {											//移動処理
	int sx = px + dirx[x], sy = py + diry[x], flag = 0;
	if (sx < 0 || sx >= w) { flag = 1; }
	if (sy < 0 || sy >= h) { flag = 1; }
	if (map[sy][sx] == '.' && flag == 0) {
		map[py][px] = '.';									//自分のいた場所を平地へ変更する
		px = sx, py = sy;									//座標を移動する
	}
	map[py][px] = my[dir];
}
void shot(int x) {											//砲弾処理
	int sx = px + dirx[x], sy = py + diry[x] , flag;
	do {													//移動可能な限り繰り返す
		flag = 0;
		if (sx < 0 || sx >= w) { break; }					//幅の範囲外は見ない
		if (sy < 0 || sy >= h) { break; }					//高さの範囲外は見ない
		switch (map[sy][sx]) {
			case '*':										//レンガの壁の場合
				map[sy][sx] = '.';							//平地に変更する
				break;
			case '#':										//鉄の壁の場合
				break;
			default:										//障害物以外の場合
				flag = 1;									//繰り返す
				break;
		}
		sx += dirx[x];
		sy += diry[x];
	} while (flag != 0);
}
void format(int x, int y) {
	int i, j;
	for (i = 0; i < x; i++) {
		for (j = 0; j < y; j++) {
			map[i][j] = '0';
		}
	}
}
void view(void) {
	int i, j;
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			printf("%c", map[i][j]);
		}
		printf("\n");
	}
}



Measured memory_bytes: 2104
#pragma GCC optimize(3)
#pragma GCC optimize(s)
#include <cstdio>
char s[11];
int main()
{
    scanf("%s", s);
    if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

// https://ei1333.github.io/algorithm/cumulative-sum2d.html
template <class T> struct CumulativeSum2D {
    vector<vector<T>> data;

    CumulativeSum2D(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {}

    void add(int x, int y, T z) {
        ++x, ++y;
        if (x >= data.size() || y >= data[0].size())
            return;
        data[x][y] += z;
    }

    void build() {
        FOR(i, 1, data.size()) FOR(j, 1, data.size()) {
            data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
        }
    }

    T query(int sx, int sy, int gx, int gy) {
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }

    void print() {
        for (auto &x : data) {
            for (auto &y : x) {
                cout << y << " ";
            }
            cout << endl;
        }
    }
};

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    char c;
    int n, k, x, y;
    cin >> n >> k;
    CumulativeSum2D<int> s(k * 2, k * 2);
    REP(i, n) {
        cin >> x >> y >> c;
        if (c == 'W') {
            y += k;
        }
        y %= 2 * k;
        if (y >= k) {
            y -= k;
            x += k;
        }
        x %= 2 * k;
        s.add(x, y, 1);
        s.add((x + k) % (2 * k), y + k, 1);
    }
    // 二次元累積和
    s.build();
    // s.print();
    int maxv = 0;
    REP(x, k) REP(y, k) {
        int t = s.query(x, y, x + k, y + k);
        maxv = max({maxv, t, n - t});
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
//#pragma gcc optimize("O3")
//#pragma gcc optimize("unroll-loops")
#ifdef EVAH
    #define _WIN32_WINNT 0x0500
    //#include<windows.h>
#endif
#define openFile(n) ShellExecute(nullptr,"open",n,nullptr,nullptr,SW_SHOWNORMAL);
#define closeP(n) system((string("taskkill /im ")+n+" /f").c_str());
#define closeConsole PostMessage(GetConsoleWindow(), WM_CLOSE, 0, 0);
#define opf "output.txt"
#define ipf "input.txt"
#define mem(n,x) memset(n,x,sizeof(n));
#define sf scanf
#define pf printf
#define ff first
#define ss second
#define pb push_back
#define PII pair<int,int>
#define For(x,n) for(int i=x; i<n; i++)
#define stv v+2*(mid-tl+1)
#define LL long long int
#define N 100001

LL dp[N],cost[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    #ifdef EVAH
        //freopen(ipf,"r",stdin);
        //openFile(ipf);
        //closeConsole;
        //freopen(opf,"w",stdout);
    #endif

    LL n,k;
    cin >> n >> k;
    For(0,n) {
        cin >> cost[i];
        dp[i] = 99999999999999999;
    }
    dp[0] = 0;
    For(1,n) {
        int j = 1;
        while(j<=k && i-j>=0) {
            dp[i] = min(dp[i],abs(cost[i]-cost[i-j])+dp[i-j]);
            j++;
        }
    }
    cout << dp[n-1] << "\n";

    #ifdef EVAH
        //openFile(opf);
        //Sleep(3000);
        //closeP("notepad.exe");
        //closeConsole;
    #endif
}


Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<ll> vel;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int f(int x) {
    if (x % 2 == 0) return x / 2;
    else return 3 * x + 1;
}

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

    int s; cin >> s;
    int inv[1000002];
    inv[s] = 1;
    for(int i = 2; i <= 1000000; i++) {
        s = f(s);
        if(inv[s] != 0) {
            cout << i << endl;
            return 0;
        }
        inv[s] = i;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, dp1[10], dp2[100], dp3[1000];
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> s;
	memset(dp1, 0, sizeof(dp1));
	memset(dp2, 0, sizeof(dp2));
	memset(dp3, 0, sizeof(dp3));
	rep(i, 0, n){
		int si = s[i]-'0';
		
		rep(j, 0, 100){
			if(dp2[j] == 1){
				dp3[j*10+si] = 1;
			}
		}
		rep(j, 0, 10){
			if(dp1[j] == 1){
				dp2[j*10+si] = 1;
			}
		}
		dp1[si] = 1;
	}
	
	
	ll ans = 0;
	rep(j, 0, 1000){
		if(dp3[j] == 1){
			ans++;
		}
	}
	print(ans)
	return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, k, u, v;
string s, t;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n>>m;
	string S[n];
	for (ll i = 0; i < n; ++i)
	{
		cin>>S[i];
	}
	sort(S,S+n);
	for(ll i=0;i<n;i++) cout<<S[i];
		newl;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

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

int main(void){
    int n, m;
    while (cin>>n && n) {
        cin>>m;
        vector<int> tx, ty;
        int a,b,c,d;
        cin >> a >> b;
        for (int i = 1; i < m; i++) {
            cin >> c >> d;
            tx.push_back(c-a);
            ty.push_back(d-b);
            a = c;
            b = d;
        }
        vector<int> rtx, rty;
        for (int i = m-2; i >= 0; i--) {
            rtx.push_back(tx[i]*-1);
            rty.push_back(ty[i]*-1);
        }
        
        
        vector<vector<int> > ax, ay;
        ax.push_back(tx);
        ay.push_back(ty);
        ax.push_back(rtx);
        ay.push_back(rty);
        
        vector<int> ux, uy, rux, ruy;
        // x=-x y=-y
        for (int i = 0; i < tx.size(); i++) {
            ux.push_back(tx[i]*-1);
            uy.push_back(ty[i]*-1);
            rux.push_back(rtx[i]*-1);
            ruy.push_back(rty[i]*-1);
        }
        ax.push_back(ux);
        ay.push_back(uy);
        ax.push_back(rux);
        ay.push_back(ruy);
        ux.clear(); uy.clear(); rux.clear(); ruy.clear();
        
        // x=y y=-x
        for (int i = 0; i < tx.size(); i++) {
            ux.push_back(ty[i]);
            uy.push_back(tx[i]*-1);
            rux.push_back(rty[i]);
            ruy.push_back(rtx[i]*-1);
        }
        ax.push_back(ux);
        ay.push_back(uy);
        ax.push_back(rux);
        ay.push_back(ruy);
        ux.clear(); uy.clear(); rux.clear(); ruy.clear();
        
        // x=-y y=x
        for (int i = 0; i < tx.size(); i++) {
            ux.push_back(ty[i]*-1);
            uy.push_back(tx[i]);
            rux.push_back(rty[i]*-1);
            ruy.push_back(rtx[i]);
        }
        ax.push_back(ux);
        ay.push_back(uy);
        ax.push_back(rux);
        ay.push_back(ruy);
        ux.clear(); uy.clear(); rux.clear(); ruy.clear();
        
        for (int l = 0; l < n; l++) {
            cin >> m;
            cin >> a >> b;
            tx.clear(); ty.clear();
            for (int i = 1; i < m; i++) {
                cin >> c >> d;
                tx.push_back(c-a);
                ty.push_back(d-b);
                a = c;
                b = d;
            }
            for (int i = 0; i < 8; i++) {
                if (tx == ax[i] && ty == ay[i]) {
                    cout << l+1 << endl;
                    break;
                }
            }
        }
        cout << "+++++" << endl;
    }
}

Measured memory_bytes: 3136
n, m, x = map(int, input().split())

books = []

for _ in range(n):
    cost, *power = map(int, input().split())
    books.append((cost, power))


def check(levels, limit):
    for level in levels:
        if level >= limit:
            continue
        else:
            return False

    return True


candidates = []
for pattern in range(2 ** n):
    levels = [0] * m
    result = 0
    for num in range(n):
        if (pattern >> num) & 1:
            cost, powers = books[num]
            result += cost
            for idx in range(m):
                levels[idx] += powers[idx]

    if check(levels, x):
        candidates.append(result)

if not candidates:
    print(-1)
else:
    print(min(candidates))


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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}

void type2(string S){
    
}


int main()
{
    string S;
    ll A,B,M;
    
    cin >> A >> B >> M ;

    ll rei[A],den[B],x[M],y[M],c[M],m_r=1000000,m_d=1000000;

    rep(i,A){
        cin >> rei[i];
        if(rei[i]<m_r) m_r=rei[i];
    }
    rep(i,B){
        cin >> den[i];
        if(den[i]<m_d) m_d=den[i];
    } 
    rep(i,M){
        cin >> x[i] >> y[i] >> c[i];
    }
     

    ll ans=m_r+m_d;

    rep(i,M){
        if(rei[x[i]-1]+den[y[i]-1]-c[i]<ans) ans=rei[x[i]-1]+den[y[i]-1]-c[i];
    }

    cout <<ans<< endl;



 
    return 0;

}

Measured memory_bytes: 4096
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        int[] arr = new int[n + 1];
        for (int i = 1; i < n; i++) {
            for (int j = i + 1; j < n - i * i; j++) {
                for (int k = j + 1; k < n - i * i - j * j; k++) {
                    int ans = ans(i, j, k);
                    if (ans <= n) {
                        arr[ans] = arr[ans] + 6;
                    }
                }
            }
        }

        for (int i = 1; i < n; i++) {
            for (int j = i + 1; j < n - i * i; j++) {
                int ans = ans(i, i, j);
                if (ans <= n) {
                    arr[ans] = arr[ans] + 3;
                }
                ans = ans(i, j, j);
                if (ans <= n) {
                    arr[ans] = arr[ans] + 3;
                }
            }
        }


        for (int i = 1; i < n; i++) {
            int ans = ans(i, i, i);

            if (ans <= n) {
                arr[ans] = arr[ans] + 1;
            }
        }


        for (int i = 1; i <= n; i++) {
            out.println(arr[i]);
        }
        // out.println("Hello World");
        out.flush();
    }

    int ans(int x, int y, int z) {
        return x * x + y * y + z * z + x * y + y * z + z * x;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 37740
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program {
    internal static void Main(string[] args) {
        var inp = ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
        var N = inp[0];
        var M = inp[1];

        var pow = Math.Pow(2, M);
        var ans = (1900 * M) + (100 * (N - M));
        WriteLine(ans * pow);
    }
}

Measured memory_bytes: 11220