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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string ans;
  rep(i, 3) {
    string s; std::cin >> s;
    ans += s[0] + 'A' - 'a';
  }
  std::cout  << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>

#define SIZE 100005

using namespace std;

struct room {
	vector<int> edge;
	int visited = -1;
	int sign = 0;
};


int main(void) {

	int n, m;
	room r[SIZE];
	cin >> n >> m;
	queue<int> q;


	int a, b;
	while (m--) {
		cin >> a >> b;
		r[a].edge.push_back(b);
		r[b].edge.push_back(a);
	}

	q.push(1);
	r[1].visited = 0;
	int x;

	while (!q.empty()) {
		x = q.front();
		q.pop();
		for (int i : r[x].edge) {
			if (r[i].visited == -1) {
				r[i].visited = r[x].visited + 1;
				r[i].sign = x;
				q.push(i);
			}
		}
	}

	for (int i = 2; i <= n; i++) {
		if (r[i].visited == -1) {
			cout << "No" << endl;
			return 0;
		}

	}
	cout << "Yes" << endl;

	for (int i = 2; i <= n; i++) {
		cout << r[i].sign << endl;
	}

	return 0;
}

Measured memory_bytes: 10928
#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    ll k, a, b;
    cin >> k >> a >> b;

    if (b-a <= 2){
        cout << k + 1 << endl;
        return 0;
    }

    ll biscuit = 1;

    k = k - a + 1;

    ll ans = a;
    ans += (b-a) * (k / 2); 
    if (k%2 == 1) ans++;

    cout << ans << endl;


}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

constexpr int MOD = 100000;

bool solve() {
    int n, m, s;
    std::cin >> n >> m >> s;
    if (n == 0) return false;
    n *= n;

    auto dp = vec(n + 1, vec(s + 1, 0));
    dp[0][0] = 1;
    for (int x = 1; x <= m; ++x) {
        for (int i = n - 1; i >= 0; --i) {
            for (int y = 0; y + x <= s; ++y) {
                dp[i + 1][y + x] += dp[i][y];
                if (dp[i + 1][y + x] >= MOD) dp[i + 1][y + x] -= MOD;
            }
        }
    }

    std::cout << dp[n][s] << "\n";

    return true;
}

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

    while (solve()) {}

    return 0;
}



Measured memory_bytes: 3364
from sys import stdin
import math
import numpy as np
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = [int(x) for x in stdin.readline().rstrip().split()]
x = []
for i in range(5):
  x.append(int(stdin.readline().rstrip().split()[0]))

x10 = [(int((i-1)/10)+1)*10 for i in x]
y = np.array([j-i for i, j in zip(x10,x)])
mini = np.min(y)
print(sum(x10)+mini)

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

int main(){
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i=0 ; i<n ; i++){
    for (int j=0 ; j<d ; j++)
      cin >> x.at(i).at(j);
  }
  
  int d2, ans = 0;
  double d1;
  for (int i=0 ; i<n-1 ; i++){
    for (int j=i+1 ; j<n ; j++){
      d2 = 0;
      for (int k=0 ; k<d ; k++){
        d2 += (x.at(i).at(k)-x.at(j).at(k))*(x.at(i).at(k)-x.at(j).at(k));
      }
      d1 = sqrt(d2);
      if (d1 == floor(d1))
        ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3616
io = STDIN
n=io.gets.to_i
a=io.gets.split.map(&:to_i)
aa=[0]+a+[0]
base=0
aa.each_cons(2) do |x,y|
  base+=(y-x).abs
end

aa.each_cons(3) do |x,y,z|
  if x<=y && y<=z ||
    x>=y && y>=z
    puts base
  elsif x<=y && y>=z
    if x<=z
      puts base - (y-z)*2
    else
      puts base - (y-x)*2
    end
  else
    if x<=z
      puts base - (x-y)*2
    else
      puts base - (z-y)*2
    end
  end
end


Measured memory_bytes: 12556
#include<iostream>

using namespace std;
#define int long long

signed main(){

   int X;
   cin>> X;

   int s=0;
   for(int i=1; ; i++){
      if(s+i>=X){
         cout<< i<< endl;
         return 0;
      }else{
         s+=i;
      }
   }

   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <climits>

void solve(int& N, std::vector<int>& A, std::vector<int>& Acp)
{
    for(int i = 0; i < N; i++)
    {
        if(A[i] != Acp[0]) std::cout << Acp[0] << std::endl;
        else std::cout << Acp[1] << std::endl;
    }
}

int main()
{
    int N; std::cin >> N;
    std::vector<int> A(N, 0), Acp(N, 0);

    for(int i = 0; i < N; i++) std::cin >> A[i];

    std::copy(A.begin(), A.end(), Acp.begin());
    std::sort(Acp.begin(), Acp.end(), std::greater<int>());
    
    solve(N, A, Acp);

    return 0;
}

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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define debp(a) cerr << #a << " => " <<"("<<a.fs<<", "<<a.sc<<") " << en;
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debpa(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int32_t main() { fastio;
	int n; cin >> n;
	double res = 1;
	bool is = false;
	int arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		res = res * arr[i];
		if (res > 1e18) {
			is = true;
		}
		if (arr[i] == 0) {
			is = false;
			cout << 0 << endl;
			exit(0);
		}
	}
	if (is) cout << -1 << endl;
	else {
		int ans = 1;
		for (int i = 0; i < n; i++) {
			ans = ans * arr[i];
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 4420
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#define INF 1e17
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P; 

class datas{
public:
	ll a,b;
	datas(ll aa,ll bb){
		a=aa;
		b=bb;
	}
	bool operator<(const datas &d1)const {
		return d1.b<b;
	}
};

int n,segn;
ll x[31],y[31],d;
vector<P> data[2];

void dfs(int v,ll ax,ll ay){
	if(v==(n+1)/2){
		data[0].push_back(P(ax,ay));
	}else{
		dfs(v+1,ax,ay);
		dfs(v+1,ax+x[v],ay-y[v]);
		dfs(v+1,ax-x[v],ay+y[v]);
	}
}

void dfs2(int v,ll ax,ll ay){
	if(v==n){
		data[1].push_back(P(ax,ay));
	}else{
		dfs2(v+1,ax,ay);
		dfs2(v+1,ax+x[v],ay-y[v]);
		dfs2(v+1,ax-x[v],ay+y[v]);
	}
}
int main(void){
	scanf("%d %lld",&n,&d);
	for(int i=0;i<n;i++){
		scanf("%lld %lld",&x[i],&y[i]);
	}
	dfs(0,0,0);
	sort(data[0].begin(),data[0].end());
	data[0].erase(unique(data[0].begin(),data[0].end()),data[0].end());
	dfs2((n+1)/2,0,0);
	sort(data[1].begin(),data[1].end());
	data[1].erase(unique(data[1].begin(),data[1].end()),data[1].end());
	int l=data[1].size()-1,r=data[1].size()-1;
	ll res=0;
	multiset<datas> s;
	for(int i=0;i<data[0].size();i++){
		while(-data[0][i].first-d<=data[1][l].first && l>=0){
			s.insert(datas(data[1][l].first,data[1][l].second));
			l--;
		}
		while(-data[0][i].first+d<data[1][r].first && r>l){
			multiset<datas>::iterator it=s.find(datas(data[1][r].first,data[1][r].second));
			s.erase(it);
			r--;
		}
		if(s.size()>0){
			multiset<datas>::iterator it=s.begin();
			datas kkk=*it;
			res=max(res,kkk.b+data[0][i].second);
		}
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 593036
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let m: usize = it.next().unwrap().parse().unwrap();
    let k: usize = it.next().unwrap().parse().unwrap();
    let d: Vec<usize> = (0..m).map(|_| it.next().unwrap().parse::<usize>().unwrap()- 1).collect();
    let mut v = vec![vec![0; k]; n];
    for i in 0..n {
        for j in 0..k {
            v[i][j] = it.next().unwrap().parse::<usize>().unwrap() - 1;
        }
    }
    let mut g = vec![vec![]; 1 << m];
    for i in 1..(1 << m) {
        for j in 0..k {
            let mut bit = 0;
            for l in 0..m {
                if (i >> l) & 1 == 0 {
                    continue;
                }
                let next = v[d[l]][j];
                if let Some(v) = d.iter().position(|d| *d == next) {
                    bit |= 1 << v;
                }
            }
            if bit != i {
                g[bit].push(i);
            }
        }
    }
    let mut dp = vec![1_000_000; 1 << m];
    dp[0] = 0;
    let mut q = std::collections::VecDeque::new();
    q.push_back(0);
    while let Some(v) = q.pop_front() {
        for &u in &g[v] {
            if dp[u] > dp[v] + 1 {
                dp[u] = dp[v] + 1;
                q.push_back(u);
            }
        }
    }
    println!("{}", dp[(1 << m) - 1]);
}

fn main() {
    run();
}



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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, Y;
    cin >> N >> Y;
    Y /= 1000;

    bool f = false;
    REP(a,0,Y/10+1) {
        REP(b,0,Y/5+1) {
            ll c = N - a - b;
            if(c >= 0 && 10*a+5*b+c == Y) {
                PS(a); PS(b); PR(c);
                f = true;
                break;
            }
        }
        if(f) break;
    }
    if(!f) PR("-1 -1 -1");

    return 0;
}

/*

10a + 5b + c = Y
c = N - a - b

*/

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

int n, m;
vector<int> x, dist;

ll solve() {
  if (n >= m) {
    return 0;
  } else {
    int i;
    ll ans = 0;

    sort(x.begin(), x.end());

    dist.resize(m - 1);
    for (i = 0; i < m - 1; i++) {
      dist[i] = x[i + 1] - x[i];
    }

    sort(dist.begin(), dist.end());

    for (i = 0; i < m - n; i++) {
      ans += dist[i];
    }
    return ans;
  }
}

int main() {
  int i;

  cin >> n >> m;

  x.resize(m);
  for (i = 0; i < m; i++) {
    cin >> x[i];
  }

  cout << solve() << "\n";
  return 0;
}

Measured memory_bytes: 1024
#n = int(input())
#s = input()
#n, k= map(int,input().split())
#da = list(map(int,input().split()))
class UnionFind:
    def __init__(self, n):
        self.size = n
        self.par = [i for i in range(n)]
        self.rank = [0]*n
        self.size = [1]*n
    def root(self, x):
        if self.par[x] != x:
            self.par[x] = self.root(self.par[x])
        return self.par[x]
    def unite(self, x, y):
        if self.root(x) == self.root(y):
            return
        if self.rank[x] > self.rank[y]:
            self.size[self.root(x)] += self.size[self.root(y)]
            self.par[self.root(y)] = self.root(x)
        else:
            self.size[self.root(y)] += self.size[self.root(x)]
            self.par[self.root(x)] = self.root(y)
        if self.rank[x] == self.rank[y]:
            self.rank[y]+=1
    def check(self, x, y):
        return self.root(x) == self.root(y)
    def sizeCheck(self, x):
        return self.size[self.root(x)]

n,m,k = map(int,input().split())
uf = UnionFind(n)
ans = [0]*n
for i in range(m):
    a,b = map(int,input().split())
    a-=1
    b-=1
    uf.unite(a,b)
    ans[a]-=1
    ans[b]-=1
co = [0]*n
for i in range(n):
    ans[i] += uf.sizeCheck(i)-1
for i in  range(k):
    c,d = map(int,input().split())
    if uf.check(c-1,d-1):
        ans[c-1]-=1
        ans[d-1]-=1
for i in range(n):
    if i == n-1:
        print(ans[i])
    else:
        print(ans[i],end=' ')

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

// ref. https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#5-%E4%BA%8C%E9%A0%85%E4%BF%82%E6%95%B0-ncr
const int MAX = 200001;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// a^n mod を計算する
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
      if (n & 1) res = res * a % MOD;
      a = a * a % MOD;
      n >>= 1;
  }
  return res;
}

int main(){
  long long N, M, K;
  cin >> N >> M >> K;
  COMinit();
  long long ans = 0;
  for(long long k = 0; k<=K; k++){
    long long tmp = COM(N-1, k);
    tmp *= M;
    tmp %= MOD;
    tmp *= modpow(M-1, N-k-1);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8328
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>      // setprecision
using namespace std;

int main() {
    cout << setiosflags(ios::fixed) << setprecision(6);
    int N, T, L, B;
    while (cin >> N >> T >> L >> B, N) {
        vector<bool> lose(N, false), back(N, false);
        for (int i = 0; i < L; i++) {
            int t; cin >> t; lose[t] = true;
        }
        for (int i = 0; i < B; i++) {
            int t; cin >> t; back[t] = true;
        }

        // dp[turn][pos] := probability
        vector<vector<double> > dp(T + 2, vector<double>(N + 1, 0));
        dp[0][0] = 1.0;
        for (int turn = 0; turn < T; turn++) {
            for (int pos = 0; pos < N; pos++) {
                for (int dice = 1; dice <= 6; dice++) {
                    int npos = pos + dice;
                    int nturn = turn + 1;
                    if (npos > N) npos = N - (npos - N);
                    if (lose[npos]) nturn += 1;
                    if (back[npos]) npos = 0;
                    dp[nturn][npos] += dp[turn][pos] / 6;
                }
            }
        }

        double ans = 0;
        for (int i = 0; i <= T; i++) {
            ans += dp[i][N];
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3292
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const ll mod = LLONG_MAX;
ll f(ll b, ll n) {
    if (n < b) {
        return n;
    }
    return f(b, n / b) + n % b;
}
 
int main() {
    ll n, s;
    cin >> n >> s;
    if (n == s) {
        cout << n + 1 << endl;
        return 0;
    }
    
    for (ll b = 2; b * b <= n; b++) {
        if (f(b, n) == s) {
            cout << b << endl;
            return 0;
        }
    }
    
    ll ans = 1e12;
    for (ll p = 1; p * p <= n; p++) {
        ll b = (n - s) / p + 1;
        if (b >= 2 && f(b, n) == s) {
            ans = min(ans, b);
        }
    }
    if (ans == 1e12) {
        ans = -1;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pii;

int main() {
  int N;
  cin >> N;
  vector<bool> dp(N + 1, false);
  dp[0] = true;
  for (int i = 100; i <= N; i++) {
    for (int j = 0; j <= 5; j++) {
      if (i - 100 - j >= 0 && dp[i - 100 - j]) {
        dp[i] = true;
      }
    }
  }
  if (dp[N]) {
    cout << "1" << endl;
  } else {
    cout << "0" << endl;
  }
  return 0;
}


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


void solve(){

}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int arr[n];
    long long int sum=0, temp=0, p, ans=INT_MAX;
    for(int i=0; i<n; ++i){
        cin >> arr[i];
        sum += arr[i];
    }
    p = sum/n;
    //cout << "p is: " << p << "\n";
    for(int i=0; i<2; ++i){
            temp = 0;
            for(int j=0; j<n; ++j){
                temp += (arr[j] - p- i)*(arr[j] - p- i);
            }
        ans = min(ans, temp);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  double n,ans;
  cin>>n;
  if((int)n==1){
    ans=n;
  }
  else {
    if((int)n%2==0){
    ans=n/2;
  }
  else if((int)n%2!=0){
    ans=(n+1)/2;
  }
  }
  cout<<ans/n<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;
//const ll INF = (ll)1e18 + 1;


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

  double ans = 0;
  int n;
  for (double i = 1; i <= N; ++i){
    if (i >= K) n = 0;
    else n = ceil(log(K / i) / log(2.0));
    ans += 1 / (N * pow(2, n));
  }
  printf("%.9f\n", ans);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int **mat;

int main(){
  int n, u, k;
  int *v;
  int i, j;

  scanf("%d",&n);

  mat = (int **)malloc(n * sizeof(int *));
   
  for(i=0; i<n; i++){
    mat[i] = (int *)malloc(n * sizeof(int));
    for(j=0; j<n; j++)
      mat[i][j] = 0;
  }

  for(i=0; i<n; i++){
    scanf("%d%d",&u ,&k);

    v = (int *)malloc(k * sizeof(int));

    for(j=0; j<k; j++){
      scanf("%d",&v[j]);
      mat[u-1][v[j]-1] = 1;
    }

    free(v);
  }

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      printf("%d",mat[i][j]);

      if(j<n-1)
	printf(" ");
    }
    printf("\n");
  }

  for(i=0; i<n; i++)
    free(mat[i]);
  free(mat);
  
  return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define ll long long
//#define For(i,a,b) for(register long long i=a;i<=b;i++)
using namespace std;
const int maxn=2e5+10;
char s[maxn];
ll ans,n;
int c[30];
signed main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	ans=n*(n-1)/2;
	for(int i=1;i<=n;++i) c[s[i]-'a']++;
	for(int i=0;i<26;++i){
		ans-=1ll*c[i]*(c[i]-1)/2;
	}
	ans++;
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
#include <stdio.h>

#define CLASS_MAX 	(9)
#define LEN_MAX 	(15)
#define PM_RATE		(200)
#define AM_RATE		(300)


typedef struct {
	char class_name[LEN_MAX + 1];
	int in_total;
	int result;
} DATA;

int main(void)
{
	DATA sf[CLASS_MAX];
	int in_am, in_pm;
	int i;
	
	for (i = 0; i < CLASS_MAX; i++){
		scanf("%s %d %d", sf[i].class_name, &in_pm, &in_am);
		sf[i].in_total = in_pm + in_am;
		sf[i].result = (in_pm * PM_RATE) + (in_am * AM_RATE);
	}
	
	for (i = 0; i < CLASS_MAX; i++){
		printf("%s %d %d\n", sf[i].class_name, sf[i].in_total, sf[i].result);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main(void){
   int r, g ,b;
   cin >> r >> g >> b;
   
   int k;
   cin >> k;
   
   while (r >= g){
       g *= 2;
       k--;
   }
   
   while (g >= b){
       b *= 2;
       k--;
   }
   
   if (k >= 0) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 3620
def main():
  import sys
  b=sys.stdin.buffer
  input=b.readline
  n=int(input())
  d=[0]*n+[1<<c-97for c in input()[:n]]
  for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
  r=[]
  add=r.append
  input()
  for q,a,b in zip(*[iter(b.read().split())]*3):
    i,s=int(a)+n-1,0
    if q<b'2':
      d[i]=1<<b[0]-97
      while i:
        i>>=1
        d[i]=d[i+i]|d[i-~i]
      continue
    j=int(b)+n
    while i<j:
      if i&1:
        s|=d[i]
        i+=1
      if j&1:
        j-=1
        s|=d[j]
      i>>=1
      j>>=1
    add(bin(s).count('1'))
  print(' '.join(map(str,r)))
main()

Measured memory_bytes: 44708
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long N, std::string S){
  rep(i,S.size()){
    ll idx = int(S[i]-'A');
    (idx += N) %= 26;
    S[i] = char('A'+idx);
  }
  cout << S << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long N;
  scanf("%lld",&N);
  std::string S;
  std::cin >> S;
  solve(N, S);
  return 0;
}


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

#define int long long

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

int Q,H,S,D,N;

signed main() {
    cin >> Q>>H>>S>>D>>N;
    H=min(H,2*Q);
    S=min(S,2*H);
    D=min(D,2*S);
    int ans=N/2*D+N%2*S;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535;
#define MOD 1000000007;


int main(void) {
	string a, b;
	cin >> a >> b;
	for (int i = 0; i < 3; i++) {
		if (a[i] != b[2-i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int a[maxn];
int cnt[maxn];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int first = (a+d-1)/d;
	int second = (c+b-1)/b;
	cout << (first>=second?"Yes":"No") << "\n";
}


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

int main(){
  string N;
  cin >> N;
  int sum = 0;
  
  for (int i=0;i<N.size();i++){
    sum += N[i] - '0';
  }
  if (stoi(N) % sum == 0){
    cout << "Yes" << endl;
  } else cout << "No" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def eratosthenes_sieve(n):
    """ 素数列挙(エラトステネスの篩) """

    table = [0] * (n + 1)
    prime_list = []
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
    return prime_list

X = INT()

primes = sorted(eratosthenes_sieve(2 * 10**5))

for prime in primes:
    if prime >= X:
        print(prime)
        exit()


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

using namespace std;

int main()
{
    double w, h , x, y;
    cin>>w>>h>>x>>y;

    cout<<fixed<<setprecision(15)<<(0.5*w*h)<<' ';

    if(x*2==w && y*2==h)  cout<<1;
    else cout<<0;

    return 0;
}


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

using namespace std;

int main()
{
    long long n;
    cin >> n;
    long long res=n;
    for(long long i=1;i*i<=n;i++)
    {
        if((n%i)!=0) continue;
        res=min(res,i+n/i-2);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))

d={}
for i in range(2**n):
    c=0
    for j in range(n):
        if (i>>j)&1:
            c+=a[j]
    d[c]=1

for i in range(q):
    if m[i] in d:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5644
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {
	static Scanner sc = new Scanner(System.in);
	
	public static void main (String [] args){
		ArrayList <Integer> list = new ArrayList<Integer>();
//		String [][] boad = new String[4][4];
		int a = Integer.parseInt(sc.next());
		int total = 0;
		String answer;		
		for(int i = 0;i<a;i++){
			list.add(Integer.parseInt(sc.next()));
		}
		
		Collections.sort(list);
		for(int i = 0;i<a-1;i++){
			total += list.get(i);
		}
		if(list.get(a-1)<total){
			answer = "Yes";
		}else{
			answer = "No";
		}
		
		
		System.out.println(answer);
		System.out.flush();
		sc.close();

	}
}

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

N, Q = map(int, input().split())

F = [0 for i in range(N)]
T = [[]for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [X[i] for i in range(N)]
for i in range(N):
    F[i] = 1
    for j in range(len(T[i])):
        if F[T[i][j]] == 1:
            continue
        ans[T[i][j]] += ans[i]

for i in range(N):
    print(ans[i], end =" ")


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

 
int main(){
  
 int n; cin >> n;
 map<string,int> m;
 for (int i = 0; i < n; ++i)
 { string k; cin >> k;
  sort(k.begin(), k.end());
   m[k]++;
 }
 long long int cnt = 0;
 
 
//n*n-1/2;
 for(auto it=m.begin(); it!= m.end(); it++){
 long long  int z = it->second;
  cnt+= (z*(z-1))/2;
  
  
 }
 
 cout <<  cnt ;




}

Measured memory_bytes: 11136
L = int(input())
B = bin(L)
N = len(B)-2

print(N,2*N+B.count("1")-3)

for i in range(1,N):
    print(i,i+1,0)
    print(i,i+1,2**(i-1))
    if int(B[N+2-i]):
        print(i,N,L-2**(i-1))
        L -= 2**(i-1)

Measured memory_bytes: 3060
n=int(input())
A=list(map(int,input().split()))
count=0
for i in range(n):
    min=i
    for j in range(i,n):
        if A[j]<A[min]:
            min=j
    if min!=i:
        A[i],A[min]=A[min],A[i]
        count+=1
for i in range(n-1):
    print(A[i],end=" ")
print(A[n-1])
print(count)


Measured memory_bytes: 5608
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=3000005;

int n,a,b,ans[N];

int main()
{
	scanf("%d%d%d",&n,&a,&b);
	if (a==1)
	{
		if (b!=n) {puts("-1");return 0;}
		for (int i=n;i>=1;i--) printf("%d ",i);
		return 0;
	}
	if (a>n||b>n) {puts("-1");return 0;}
	int tot=0,now=b;
	for (int i=b;i>=1;i--) ans[++tot]=i;
	if (n-b<a-1) {puts("-1");return 0;}
	int x=(n-b)/(a-1),y=(n-b)%(a-1);
	if (x+(y>0)>b) {puts("-1");return 0;}
	for (int i=1;i<=y;i++)
	{
		for (int j=now+x+1;j>now;j--) ans[++tot]=j;
		now+=x+1;
	}
	for (int i=1;i<=a-1-y;i++)
	{
		for (int j=now+x;j>now;j--) ans[++tot]=j;
		now+=x;
	}
	for (int i=1;i<=n;i++) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int n,l;
char c[100];
int p[100];

bool input(){
    scanf("%d%d",&n,&l);
    REP(i,n){
        cin >> c[i] >> p[i];
        p[i] *= 2;
    }
    return n != 0;
}

void solve(){
    int t = 0;int down = 0;int e[1000],maxi;
    while(down < n){
        fill(e,e+1000,0);
        maxi = -1;
        REP(i,n){
            if(p[i] == -1)
                continue;
            if(c[i] == 'R')
                p[i]++;
            else
                p[i]--;
            if(p[i] == 0 || p[i] == l * 2){
                if(p[i] == 0 || (p[i] == l * 2 && maxi == -1))
                    maxi = i;
                p[i] = -1;
                down++;
                continue;
            }
            e[p[i]]++;
        }
        REP(i,l*2 + 2){
            if(e[i] == 2){
                vector<int> a;
                REP(j,n){
                    if(p[j] == i)
                        a.pb(j);
                }
                if(i % 2 == 0){
                    char ex = c[a[0]];
                    c[a[0]] = c[a[1]];
                    c[a[1]] = ex;
                }
            }
        }
        t++;
    }
    printf("%d %d\n",t/2,maxi+1);
}

int main(){
    while(input()){
        solve();
    }
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
struct node
{
    int a,b;
}a[N];
int cmp(node a,node b)
{
    return a.b<b.b;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i].a>>a[i].b;
    sort(a+1,a+n+1,cmp);
    int t=0;
    for(int i=1;i<=n;i++)
    {

        t=t+a[i].a;
        //cout<<"t= "<< t<<endl;
        if(t>a[i].b)
        {
            printf("No\n");
            return 0;
        }

    }
    printf("Yes\n");
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 1792
use std::io::prelude::*;

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

fn main() {
    let n: i64 = input();
    println!("{}", n / 3);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007

//  ---------------------Template---------------------------
using namespace std;
typedef long long int ll;

void InputSetup()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
}
//  ---------------------Template---------------------------

void solve()
{
	int n; cin >> n;
	int b[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> b[i];
	}
	bool flag = 0;
	int a[n];
	for (int i = 0; i < n and !flag; ++i)
	{
		for (int j = n-1-i; j >= 0; --j)
		{
			flag = 1;
			if (b[j] == j+1)
			{
				a[n-1-i] = b[j];
				for (int k = j; k < n-1-i; ++k)
					b[k] = b[k+1];
				flag = 0;
				break;
			}
		}
	}
	if (flag)
	{
		cout << -1;
		return;
	}
	for (int i = 0; i < n; ++i)
	{
		cout << a[i] << ' ';
	}

}

int main(void)
{
	auto start = chrono::high_resolution_clock::now();

	InputSetup();
	solve();

	auto finish = chrono::high_resolution_clock::now();
	cerr << "Time elapsed: " << (chrono::duration<long double>(finish-start)).count() << "s\n";
}

Measured memory_bytes: 256
import math
import numpy as np
X, N = map(int,input().split())
ans = False
if not N == 0:
  p = list(map(int,input().split()))
else:
  print(X)
  ans = True
if not ans:
  for i in range(101):
    if not (X- i in p):
      print(X-i)
      break
    elif not (X + i in p):
      print(X+i)
      break


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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repk(i,n,k) for(int i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int h1,h2;
    int m1,m2;
    int k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    
    int ans = (h2 - h1-1) * 60 + (m2+60-m1) - k;
    print(ans);

    return 0;
}

Measured memory_bytes: 3648
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        //out.print("AMan");
        int n = sc.nextInt(), k=sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int dp[] = new int[n];
        Arrays.fill(dp, (int) 1e9 + 7);
        dp[0] = 0;
        for (int i = 0; i < n; i++) {
            for(int j=1;j<=k;j++) {
                if(i+j<n) dp[i+j] = Math.min(dp[i+j], dp[i] + Math.abs(a[i+j] - a[i]));
            }
            // if (i + 1 < n)
            //     dp[i + 1] = Math.min(dp[i + 1], dp[i] + Math.abs(a[i + 1] - a[i]));
            // if (i + 2 < n)
            //     dp[i + 2] = Math.min(dp[i + 2], dp[i] + Math.abs(a[i + 2] - a[i]));
        }
        out.println(dp[n - 1]);

        out.flush();
        out.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

Measured memory_bytes: 34992
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
m=0

for y in range(H):
  for x in range(W):
    if S[y][x]=="#":
      continue
    D=[[400]*W for i in range(H)]
    D[y][x]=0
    q=[]
    q.append([x,y])
    while len(q)>0:
      c=list(q.pop(0))
      for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:
        if c[1]+dy<0 or c[1]+dy>=H:
          continue
        if c[0]+dx<0 or c[0]+dx>=W:
          continue
        if S[c[1]+dy][c[0]+dx]==".":
          if D[c[1]+dy][c[0]+dx]>D[c[1]][c[0]]+1:
            D[c[1]+dy][c[0]+dx]=D[c[1]][c[0]]+1
            q.append([c[0]+dx,c[1]+dy])
    A=[[D[y][x] if D[y][x]!=400 else -1 for x in range(W)] for y in range(H)]
    for i in range(H):
      m=max(m,max(A[i]))
print(m)

Measured memory_bytes: 3444
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ff first 
#define ss second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define testcase(t) int t;cin>>t;while(t--)
#define mp(x,y) make_pair(x,y)
#define in(x) insert(x)
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define PI 3.14159265358979323846
#define SP(x) setprecision(x)
#define reflex ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define M 1000000007
#define sz(a) (int)a.size()
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(x) x.resize(distance(x.begin(), unique(all(x))))
#define mem(arr,val) memset(arr,val,sizeof(arr)) //For "0" and "-1"                  
#define inp0(a,n) rep(i,0,n-1) cin>>a[i];
#define inp1(a,n) rep(i,1,n) cin>>a[i]; 
#define prll(x) printf("%lld",x)
#define nth_ele(v,n) nth_element(v.begin(), v.begin()+n ,v.end())//O(N)
#define DEBUG(x) cerr << (#x) << ": " << (x) << endl
#define DEBUGV(x) for(auto IT:x) cout<<IT<<" "; cout<<endl;
#define minheap priority_queue <int, vector<int>, greater<int>>
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll gcd(ll n1, ll n2){if(n2!=0) return gcd(n2, n1%n2);else return n1;}
ll powerM(ll a,ll b){if(b==0) return 1;  if(b==1) return a%M; ll x=powerM(a,b/2)%M; if(b&1){return ((((a%M)*(x%M))%M)*(x%M))%M;}return ((x%M)*(x%M))%M;}
ll power(ll a,ll b){if(b==0) return 1;  if(b==1) return a; ll x=power(a,b/2); if(b&1){return ((((a)*(x)))*(x));}return ((x)*(x));}
 
const ll INF=1e18; 
const int SIZE = 100006;

int main(){
	int a[32]={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};
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;	
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
const int qq = 1005;
const int N = 1e9 - 500;
int num[qq];

int main(){
	int n; scanf("%d", &n);
	if(n < 1200){
        printf("ABC\n");
	}else{
        printf("ARC\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const long long INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int N;
ll h[110000];
ll dp[110000];

int main() {
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }

  for (int i = 0; i < 110000; i++) dp[i] = INF;
  dp[0] = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= K; j++) {
      chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }
  cout << dp[N - 1] << endl;
}

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

bool dfs(int k, int r, int cnt) {
    bool res = false;
    if (cnt == 0) {
        if (r == 0 && k >= 0)
            return 1;
        else
            return 0;
    }
    for (int i = k; i >= 0; i--) {
        if (r - cnt * i >= 0) res |= dfs(k - i, r - cnt * i, cnt - 1);
        if (res == true) break;
    }
    return res;
}

int main() {
    int x;
    cin >> x;
    int k = x / 100, r = x % 100;
    cout << (int)dfs(k, r, 5) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt();
                        int[] A = new int[N];
                        for (int i = 0; i < N; i++) {
                                A[i] = sc.nextInt();
                        }

                        int x = A[N - 1];
                        int i = -1;
                        for (int j = 0; j < N - 1; j++) {
                                if (A[j] <= x) {
                                        i++;
                                        int tmp = A[i];
                                        A[i] = A[j];
                                        A[j] = tmp;
                                }
                        }
                        int tmp = A[i + 1];
                        A[i + 1] = A[N - 1];
                        A[N - 1] = tmp;
                        for (int k = 0; k < N; k++) {
                                if (k == i + 1) {
                                        System.out.print("["+A[k]+"]");
                                } else {
                                        System.out.print(A[k]);
                                }
                                if (k == N - 1) {
                                        System.out.print("\n");
                                } else {
                                        System.out.print(" ");
                                }
                        }
                }
        }
}

Measured memory_bytes: 68828
#include <iostream>
#include <string>

using namespace std;

class Dice{
private:
  int D1;
  int D2;
  int D3;
  int D4;
  int D5;
  int D6;

public:
  Dice(int d1,int d2,int d3,int d4,int d5,int d6){
  D1=d1;
  D2=d2;
  D2=d2;
  D3=d3;
  D4=d4;
  D5=d5;
  D6=d6;
  }

  void roll(char dire){
  int dd1=D1;
  int dd2=D2;
  int dd3=D3;
  int dd4=D4;
  int dd5=D5;
  int dd6=D6;
  
  if(dire=='E')
    {
    D1=dd4;
    D3=dd1;
    D4=dd6;
    D6=dd3;
    }
  if(dire=='N')
  {
    D1=dd2;
    D2=dd6;
    D5=dd1;
    D6=dd5;
  }
  if(dire=='S')
  {
    D1=dd5;
    D5=dd6;
    D6=dd2;
    D2=dd1;
  }
  if(dire=='W')
  {
    D1=dd3;
    D3=dd6;
    D6=dd4;
    D4=dd1;
  }
  
  }
  
  int ue(){
  return D1;
  }
  
  int light(int up,int mae){
    int i;
    int j;
    int k;
      for(i=0;i<4;i++)
      {
      roll('E');
     for(j=0;j<4;j++)
     {
      roll('S');
     for(k=0;k<4;k++)
     {
        roll('E');
        
        if(up==D1 && mae==D2)
          return D3;
     }
     }
    }
  }

  int check1(){
    return D1;
  }
  int check2(){
    return D2;
  }
  int check3(){
    return D3;
  }
  int check4(){
    return D4;
  }
  int check5(){
    return D5;
  }
  int check6(){
    return D6;
  }


};

int main()
{
  int di1[6]={};
  int di2[6]={};
  int i;
  int j;
  int k;
  int l;
  
  for(i=0;i<6;i++)
    cin >> di1[i];
    
  for(i=0;i<6;i++)
    cin >> di2[i];
    
  Dice dice1(di1[0],di1[1],di1[2],di1[3],di1[4],di1[5]);
  Dice dice2(di2[0],di2[1],di2[2],di2[3],di2[4],di2[5]);
  
  for(i=0;i<4;i++)
  {
    dice2.roll('E');
    for(j=0;j<4;j++)
    {
      dice1.roll('S');
      
      for(k=0;k<4;k++)
      {
         dice1.roll('E');
         for(l=0;l<4;l++)
         {
          dice1.roll('S');
          if(dice1.check1()==dice2.check1() &&dice1.check2()==dice2.check2() &&dice1.check3()==dice2.check3()&&dice1.check4()==dice2.check4()&&dice1.check5()==dice2.check5() &&dice1.check6()==dice2.check6() )
              {
                cout <<"Yes\n";
                goto Exit;
              }
         }
         
      }
    }
  }
  

    cout << "No\n";
  
  Exit:;
}

Measured memory_bytes: 1128
from collections import defaultdict


def main():
    n = int(input())
    S = input()
    '''
    r_inds = []
    g_inds = []
    b_inds = []
    for i in range(len(S)):
        if S[i] == "R":
            r_inds.append(i)
        elif S[i] == "G":
            g_inds.append(i)
        else:
            b_inds.append(i)

    total_comb = len(r_inds)*len(g_inds)*len(b_inds)
    ded = 0
    for i in r_inds:
        for j in g_inds:
            s_ind = min(i, j)
            b_ind = max(i, j)
            diff = b_ind - s_ind
            bigger_ind = b_ind + diff
            smaller_ind = s_ind - diff
            if bigger_ind < len(S) and bigger_ind in b_inds:
                ded += 1
            if smaller_ind >= 0 and smaller_ind in b_inds:
                ded += 1
            if diff % 2 == 0:
                mid_diff = diff // 2
                mid_ind = s_ind + mid_diff
                if mid_ind in b_inds:
                    ded += 1
    print(total_comb - ded)
    '''
    color_num = defaultdict(int)
    num_subst = 0

    for i in range(len(S) - 1):
        color_num[S[i]] += 1 
        for j in range(i + 1, len(S)):
            if S[i] != S[j]:
                diff = j - i
                idx = j + diff
                if idx < len(S) and S[idx] != S[i] and S[idx] != S[j]:
                    num_subst += 1
    color_num[S[len(S) - 1]] += 1 
    total_num_comb = color_num["R"] * color_num["G"] * color_num["B"]
    print(total_num_comb - num_subst)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9448