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

using namespace std;

// union by rank
class UnionFindTree { // The range of node number is from 0 to n-1
  public:
    //'rank[x]' is a rank of the union find tree the root of which is x.
    //'parents[x]' is the parent of x
    vector<int> rank, parents;
    // constructor
    UnionFindTree() {}
    UnionFindTree(int n) { // make n trees.
        rank.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) {
            makeTree(i);
        }
    }
    // make a union find tree
    void makeTree(int x) {
        parents[x] = x; // the parent of x is x
        rank[x] = 0;
    }

    // check whether the root of x is the same as that of y
    bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }

    // unite two tree
    void unite(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (rank[x] > rank[y]) {
            parents[y] = x;
        } else {
            parents[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }

    // travel the parents of tree recursivily to find root
    int findRoot(int x) {
        if (x != parents[x]) {
            parents[x] = findRoot(parents[x]); // change the x's parent to the root of tree.
        }
        return parents[x];
    }

    int treeRank(int x) { return rank[findRoot(x)]; }
};

// union by size
class UnionFindTreeBySize {
  public:
    vector<int> size, parents;
    UnionFindTreeBySize() {}
    UnionFindTreeBySize(int n) { // make n trees.
        size.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) {
            makeTree(i);
        }
    }
    void makeTree(int x) {
        parents[x] = x; // the parent of x is x
        size[x] = 1;
    }
    bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }
    void unite(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (size[x] > size[y]) {
            parents[y] = x;
            size[x] += size[y];
        } else {
            parents[x] = y;
            size[y] += size[x];
        }
    }
    int findRoot(int x) {
        if (x != parents[x]) {
            parents[x] = findRoot(parents[x]);
        }
        return parents[x];
    }
    int treeSize(int x) { return size[findRoot(x)]; }
};

int main() {
    int N;            // the number of nodes
    int Q;            // the number of query
    vector<int> P;    // p is a "same" or "unite" command.
    vector<int> A, B; // a and b are nodes.

    cin >> N >> Q;
    UnionFindTreeBySize uft = UnionFindTreeBySize(N); // make trees

    for (int i = 0; i < Q; i++) {
        int p, a, b;
        cin >> p >> a >> b;
        P.push_back(p);
        A.push_back(a);
        B.push_back(b);
    }

    for (int i = 0; i < Q; i++) {

        if (P[i] == 0)
            uft.unite(A[i], B[i]);
        else if (P[i] == 1) {
            if (uft.isSame(A[i], B[i]))
                cout << "1\n";
            else
                cout << "0\n";
        }
    }
    return 0;
}



Measured memory_bytes: 4116
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

X = ii()

lim = 10**3
for a in range((-1)*lim, lim+1):
    for b in range((-1)*lim, lim+1):
        if a**5 -b**5 == X:
            print(a, b)
            exit()

Measured memory_bytes: 9172
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;

const int Max = 10000;
const int Infty = (1 << 21);
const int white = 0, gray = 1, black = 2;

int d[Max], color[Max];
int n;

vector<pair<int, int> > adj[Max];

void dijkstra(int s){
    priority_queue<pair<int, int> > PQ;
    for(int i=0; i<n; i++){
        d[i] = Infty;
        color[i] = white;
    }
    d[s] = 0;
    color[s] = gray;
    PQ.push(make_pair(0, 0)); //(d[u], u) u:be adjacent to s

    while(!PQ.empty()){
        pair<int, int> f = PQ.top();
        PQ.pop();
        int u = f.second;
        color[u] = black;

        if(d[u] < f.first*(-1) ) continue;

        for(int i=0; i<adj[u].size(); i++){
            int v = adj[u][i].first;
            if(color[v] == black) continue;
            if(d[u] + adj[u][i].second < d[v]){
                d[v] = d[u] + adj[u][i].second;
                color[v] = gray;
                PQ.push(make_pair(d[v] * (-1), v));
            }
        }
    }
    for(int i=0; i<n; i++){
        cout << i << " " << ( d[i] == Infty ? -1 : d[i]) << endl;
    }
}

int main(){
    int k, u, v, c;

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra(0);

    return 0;
}


Measured memory_bytes: 8084
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

  switch (n % 10) {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    puts("hon");
    break;

  case 0:
  case 1:
  case 6:
  case 8:
    puts("pon");
    break;

  case 3:
    puts("bon");
  }
}


Measured memory_bytes: 1660
#include <algorithm>
    #include <cstdio>
    #include <iostream>
    #include <cfloat>
    #include <climits>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <queue>
    #include <sstream>
    #include <stack>
    #include <time.h>
    #include <vector>
    #include <complex>
    #include <map>
    #include <set>
    #include <iomanip>
    #include <math.h>
    #include <stdlib.h>
    #include <list>
    #include <utility>
    #include <memory>
    #include <cstring>
    #include <fstream>
    #include <numeric>
    #include <assert.h>
    #include <bitset>
    #include <ios> 
    #include <bits/stdc++.h>
    using namespace std;
    int n,k;
    typedef long long ll;
    ll s[100004],ss[100004];
    int main(){
    	cin>>n>>k;
    	for (int i=1;i<=n;i++){
    		ll x;
    		cin>>x;
    		s[i]=s[i-1]+x;
    		ss[i]=ss[i-1]+max(0ll,x);
    	}
    	ll ans=max(0ll,s[n]);
    	for (int i=k;i<=n;i++){
    		int j=i-k;
    		ans=max(ans,ss[n]-(ss[i]-ss[j])+max(0ll,s[i]-s[j]));
    	}
    	cout<<ans;
    }

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



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

	int turns = 0;
	int sames = 0;
	char buff;
	for (int i = 0; i < n; i++) {
		char buf; cin >> buf;
		if (i == 0);
		else if (buf != buff) turns++;
		else sames++;
		buff = buf;
	}

	for (int i = 0; i < k; i++) {
		if (turns >= 2) {
			turns -= 2;
			sames += 2;
		}
		else if (turns == 1) {
			sames++;
			break;
		}
		else break;
	}

	cout << sames << endl;

	return 0;
}



Measured memory_bytes: 384
N, C = map(int, input().split())
cusum = [[0 for j in range(10**5+1)] for i in range(C+1)]
for i in range(N):
    s, t, c = map(int, input().split())
    cusum[c][s] += 1
    cusum[c][t] += -1
ans = 0
s = 0
for j in range(10**5+1):
    cp = 0
    cm = 0
    for i in range(C+1):
        if cusum[i][j] == 1:
            cp += 1
        elif cusum[i][j] == -1:
            cm += 1
    s += cp
    ans = max(s, ans)
    s -= cm

print(ans)


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

int main(void) {

	int a,b,c;

	scanf("%d%d%d",&a,&b,&c);

	if(a<b&&b<c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back

void solve(){
    int n, x; cin >> n >> x;
    int cnt = 1;
    int sum = 0;
    REP(i, n){
        int l;
        cin >> l;
        sum += l;
        if(sum <= x) cnt++;
    }
    cout << cnt << endl;
}

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

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

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

    int X,t; cin >>X>>t;
    cout << max(0,X-t) << endl;
}


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

int main() {
  int A,B;
  cin >> A>>B;

  if (A >= 13) {
    cout << B << endl;
  }
  else if (A > 5) {
    cout << B/2 << endl;
  }
  else if (A <= 5) {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readline(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readline(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}

signed main(){

    int A, B;
    cin >> A >> B;

    if(A <= 8 && B <= 8){
        cout << "Yay!";
    }else{
        cout << ":(";
    }

    

    return 0;
}

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

int main(){
  int n,sumw,sumh;
  while(1){
    cin>>n;
    if(n==0)break;
    int array[n+1][n+1];
    for(int i=0;i<n;i++){
      sumw=0;
      for(int j=0;j<n;j++){
	cin>>array[i][j];
	sumw+=array[i][j];
      }
      array[i][n]=sumw;
    }
    for(int i=0;i<n+1;i++){
      sumh=0;
      for(int j=0;j<n;j++){
	sumh+=array[j][i];
      }
      array[n][i]=sumh;
    }
    for(int i=0;i<n+1;i++){
      for(int j=0;j<n+1;j++){
	printf("%5d",array[i][j]);
      }
      cout<<endl;
    }
  }
  return 0;
}
    

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

int top, S[1000];

void push(int x){
    S[++top]=x;
}

int pop(){
    top--;
    return S[top+1];
}

int main(){
    int a,b;
    top =0;
    char s[100];
    while( scanf("%s",s) != EOF){
        if (s[0] == '+'){
            a=pop();
            b=pop();
            push(a+b);
        } else if (s[0]== '-'){
          b=pop();
          a=pop();
          push(a-b);  
        } else if (s[0]== '*'){
          a=pop();
          b=pop();
          push(a*b);  
    }     else {
        push(atoi(s));
        }
    }
    
    printf("%d\n", pop() );
    
    return 0;
    
}


Measured memory_bytes: 2724
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int s, t;
  s = a * b;
  t = c * d;

  if (s >= t) {
    cout << s << endl;
  } else {
    cout << t << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::max;
#[allow(unused_imports)]
use std::cmp::min;
#[allow(unused_imports)]
use std::fmt;
#[allow(unused_imports)]
use std::fmt::Debug;
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::str::FromStr;

fn main() {
    let input: Vec<i64> = get_vec_input();
    for i in 0..input.len() {
        if input[i] == 0 {
            println!("{}", i + 1);
            break;
        }
    }
}

#[allow(dead_code)]
fn get_digit(value: i64) -> i64 {
    let mut digit = 0i64;
    let mut value = value;
    while value != 0 {
        value /= 10;
        digit += 1;
    }
    digit
}

#[allow(dead_code)]
fn sum_digit2(value: String) -> u32 {
    return value.chars().fold(0u32, |a, b| a + b.to_digit(10).unwrap());
}

#[allow(dead_code)]
fn sum_digit(value: i64) -> i64 {
    if value < 10 {
        return value;
    }
    return sum_digit(value / 10) + value % 10;
}

#[allow(dead_code)]
fn update_max<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left < right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn update_min<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left > right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn get_vec_input<T>() -> Vec<T>
where
    T: FromStr,
    T::Err: Debug,
{
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");
    let vec: Vec<T> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    vec
}

#[allow(dead_code)]
fn get_tuple_input() -> (u64, f32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c: u64 = iter.next().unwrap().parse().unwrap();
    let n: f32 = iter.next().unwrap().parse().unwrap();
    (c, n)
}

#[allow(dead_code)]
fn get_string_input() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    s.trim().to_string()
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;

int dp[1111];

int main() {
  int n;
  cin >> n;
  P a[n];
  for(int i=0; i<n; i++) cin >> a[i].S >> a[i].F;
  sort(a,a+n);
  fill(dp,dp+n+1,1<<30);
  dp[0]=0;
  for(int i=0; i<n; i++) {
    for(int j=n-1; j>=0; j--) {
      if(dp[j]+a[i].S<=a[i].F) dp[j+1]=min(dp[j+1],dp[j]+a[i].S);
    }
  }
  int ans=0;
  for(int i=0; i<=n; i++) if(dp[i]!=1<<30) ans=i;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3084
#h,w = list(map(int, input().split()))

a = [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]
print(a[int(input())-1])

Measured memory_bytes: 38256
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from collections import deque

MOD = 10**9 + 7
N = int(input())
tree = dict(zip(range(N), [[] for i in range(N)]))
edge_id = {}
c = 0
for i in range(N-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  tree[a].append(b)
  tree[b].append(a)
  edge_id[(a, b)] = c
  edge_id[(b, a)] = c + 1
  c += 2

# 部分木のサイズ
# 頂点v1 -> v2の向きを考えたときに、頂点v2を根とする部分木のサイズを計算する
size = [0] * 2*(N-1)
def calc_size(v1, v2):
  global size
  idx = edge_id[(v1, v2)]
  if size[idx]:
    return size[idx]
  children = tree[v2]
  s = 1
  for child in children:
    if child == v1:
      continue
    s += calc_size(v2, child)
  size[idx] = s
  idx_inv = edge_id[(v2, v1)]
  size[idx_inv] = N - s
  return s

# 階乗、組合せの計算
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
MOD = 10**9+7
for i in range(2, 2*10**5+1):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)

def comb(n, r, mod=MOD):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n-r] % mod

# 頂点iに1を書くときの場合の数
ans = [0] * N
dp = [0] * 2*(N-1)
def calc_dp(v1, v2):
  global dp
  idx = edge_id[(v1, v2)]
  if dp[idx]:
    return dp[idx]
  children = tree[v2]
  s = calc_size(v1, v2)
  res = g1[s-1]
  for child in children:
    if child == v1:
      continue
    res *= calc_dp(v2, child)
    res %= MOD
    _s = calc_size(v2, child)
    res *= g2[_s]
    res %= MOD
  dp[idx] = res
  return res

def calc_ans(i):
  global ans
  global dp
  if ans[i]:
    return ans[i]
  children = tree[i]
  res = g1[N-1]
  for child in children:
    res *= calc_dp(i, child)
    res %= MOD
    _s = calc_size(i, child)
    res *= g2[_s]
    res %= MOD
  ans[i] = res
  return res

# 頂点0に1と記入する場合の数を求める
calc_ans(0)
# そこからはbfsで子に伝搬させていく
# 伝搬の漸化式はnode -> childのとき
# ans[child] = ans[node] * size[(node, child)]/size[(child, node)]
d = deque([[0, -1]])
c = 0
while d:
  node, par = d.popleft()
  c += 1
  children = tree[node]
  for child in children:
    if child == par:
      continue
    s = calc_size(node, child)
    r = s * pow(N-s, MOD-2, MOD) % MOD
    ans[child] = ans[node] * r % MOD
    d.append([child, node])

print(*ans, sep='\n')

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

int main(){
    int t,i,sum=0,sum1=0,min1;
    cin>>t;
    int a[t];
    for(i=0;i<t;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    min1=INT_MAX;
    for(i=0;i<t;i++)
    {
        sum-=a[i];
        sum1+=a[i];
        min1=min(abs(sum-sum1),min1);
    }
    cout<<min1<<endl;
}

Measured memory_bytes: 3600
N, K, Q = map(int, input().split())
A = list(map(int, input().split()))

def find_maximum(y):
  C = [[]]
  for a in A:
    if a < y:
      if len(C[-1]) > 0:
        C.append([])
    else:
      C[-1].append(a)
  cand_x = []
  for Ci in C:
    m = len(Ci)
    if m >= K:
      Ci.sort()
      cand_x += Ci[:m-K+1]
  if len(cand_x) >= Q:
    cand_x.sort()
    return cand_x[Q-1], cand_x[0]
  else:
    return 10**18, 0

ans = 10**18
for a in A:
  x, y = find_maximum(a)
  ans = min(ans, x-y)

print(ans)

Measured memory_bytes: 3316
N, M = map(int, input().split())
student = [tuple(map(int, input().split())) for _ in range(N)]
point = [tuple(map(int, input().split())) for _ in range(M)]

def dist(p, q):
    xp, yp = p
    xq, yq = q
    return abs(xp - xq) + abs(yp - yq)

for i in range(N):
    d = 10 ** 18
    p = -1
    for j in range(M):
        if dist(student[i], point[j]) < d:
            d = dist(student[i], point[j])
            p = j
    print(p + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int n,ans=0;
	cin>>n;
	vector<int>p(n),q(n);
	rep(i,n)cin>>p.at(i);
	rep(i,n)cin>>q.at(i);
	bool pGreaterThanQ = (q<p?true:false);
	while(p!=q){
		next_permutation(all((pGreaterThanQ?q:p)));
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
def get_a(a, b, c):
	q1, mod1 = divmod(a, c)
	q2, mod2 = divmod(b, c)
	if mod1 == 0:
		count = q2 - q1 + 1
	else:
		count = q2 - q1
	return count

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

def main():
	import sys
	input = sys.stdin.readline
	A, B, C, D = map(int, input().split())
	LCM = lcm(C, D)
	notans = get_a(A, B, C) + get_a(A, B, D) - get_a(A, B, LCM)
	sum = B - A + 1
	print(sum - notans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.*;
class Main{
    public static void main(String[] a){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int x = scan.nextInt();
            x += scan.nextInt();
            int digit = 0;
            while(x > 0){
                x /= 10;
                digit++;
            }
            System.out.println(digit);
        }
    }
}


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

int main(void){
    int A, B;
    cin >> A >> B;
    if(A >= 13){
        cout << B << endl;
    }else if(A <= 12 && A >= 6){
        cout << B/2 << endl;
    }else if(A <= 5){
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll A,B, C,D; cin >> A >> B >> C >> D;
    cout << max(A*B,C*D) << endl;
    return 0;
}


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

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    int d1 = abs(a - x);
    int d2 = abs(b - x);

    if (d1 < d2) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }
    
}

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

#define _GLIBCXX_DEBUG
#define chinko long long

using namespace std;

int main()
{
	int n,m;
	cin>>n>>m;
	vector<int> p(n);
	for(int i=0;i<n;i++) p[i]=i;
	
	int ans=0;
	
	bool visited[8][8]={};	
	
	for(int i=0;i<m;++i){
		int a,b;
		cin>>a>>b;
		a--; b--;
		visited[a][b]=visited[b][a]=true;
	}
	
	do{
		bool anko=true;
		for(int i=0;i<n-1;++i){
			if(visited[p[i]][p[i+1]]) continue; 
			anko=false; 
			break;
		}
		if(anko) ++ans;
	}while(next_permutation(p.begin()+1,p.end()));
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int a[200] = { 0 };

	scanf("%d", &n);
	int count = 0;

	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = i; j < n; ++j)
		{
			for (int k = j; k < n; ++k)
			{
				if (a[i] != a[j] && a[k] != a[j] && a[i] != a[k])
				{
					if (a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[k] + a[j] > a[i])
					{
						++count;
					}
				}
			}
		}
	}
	printf("%d\n", count);
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  int A,B;
  cin >> S >> T;
  cin >> A >> B;
  string U;
  cin >> U;
  if(U == S) A--;
  else B--;
  cout << A;
  cout << " ";
  cout << B << endl;
}

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

void Permutation(int pos, int num);

int N;
vector<int> A(8);
vector<int> B(8);

vector<int> P(8);
vector<int> used(10);
vector<vector<int>> P_all;
int a_idx, b_idx;

int main(){

    cin >> N;

    for (int i=0; i<N; i++){
        cin >> A.at(i);
    }
    for (int i=0; i<N; i++){
        cin >> B.at(i);
    }

    /*
    for (int i=0; i<A.size(); i++){
        cout << A.at(i);
    }
    cout << endl;
    for (int i=0; i<B.size(); i++){
        cout << B.at(i);
    }
    cout << endl;
    */

    Permutation(0, N);
    sort(P_all.begin(), P_all.end());

    for (int i=0; i<P_all.size(); i++){
        if (P_all.at(i) == A){
//            cout << "A" << endl;
            a_idx = i;
        }
        if (P_all.at(i) == B){
//            cout << "B" << endl;
            b_idx = i;
        }
    }

    cout << abs(b_idx-a_idx) << endl;
    return 0;
}



void Permutation(int pos, int num){

    if (pos == num){

        /*
        for (int i=0; i<P.size(); i++){
            cout << P.at(i);
        }
        cout << endl;
        */

        P_all.push_back(P);
        return;
    }

    for (int i=1; i<=num; i++){

        if (used.at(i) == 0){
            P.at(pos) = i;
            used.at(i) = true;

            Permutation(pos+1, num);
            used.at(i) = false;
        }
    }
}

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

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    long k = sc.nextLong();
    Long[] a = new Long[n];
    Long[] f = new Long[n];

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    for (int i = 0; i < n; i++) {
      f[i] = sc.nextLong();
    }
    Arrays.sort(a, Comparator.naturalOrder());
    Arrays.sort(f, Comparator.reverseOrder());

    long ng = -1;
    long ok = 1;
    while (!canFinish(ok, n, k, a, f)) ok *= 2;

    while (ok - ng > 1) {
      long mid = (ok + ng) / 2;
      if (canFinish(mid, n, k, a, f)) ok = mid;
      else ng = mid;
    }

    os.println(ok);
  }

  private static boolean canFinish(long time, int n, long k, Long[] a, Long[] f) {

    for (int i = 0; i < n; i++) {
      long c = time / f[i];
      k -= Math.max(a[i] - c, 0);
    }
    return k >= 0;
  }

  private static class Scanner {

    private final InputStream is;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    Scanner(InputStream is) {
      this.is = is;
    }

    private boolean hasNextByte() {
      if (ptr < buflen) {
        return true;
      } else {
        ptr = 0;
        try {
          buflen = is.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (buflen <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte()) return buffer[ptr++];
      else return -1;
    }

    private static boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
      return hasNextByte();
    }

    public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }
}


Measured memory_bytes: 44436
data = input()
data1,data2,data3,data4 = data.split()
data1 = int(data1)
data2 = int(data2)
data3 = int(data3)
data4 = int(data4)


if abs(data1 - data3) <= data4:
    print('Yes')
elif abs(data1 - data2) <= data4 and abs(data2 - data3) <= data4:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n)    for (ll (i) = 0;   (i) < (n); ++(i))
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define EACH(e, v)   for (auto& (e): (v))

#include <boost/multiprecision/cpp_int.hpp>
using bigint = boost::multiprecision::cpp_int;

vector<bool> Eratosthenes(const int n) {
    vector<bool> r(n + 1, true);
    for (int i = 2; i * i <= n; ++i) {
        if (r[i]) {
            for (int j = i * 2; j <= n; j += i) r[j] = false;
        }
    }
    if (r.size() > 2) {
        r[0] = r[1] = false;
    } else if (r.size() > 1) {
        r[0] = false;
    }
    return r;
}

int N;
vector<bigint> A;

ll cubic[2525];
map<bigint, int> mp;

vector<int> prime;
bigint normalize(bigint n) {
    for (auto& p: prime) {
        while (n % cubic[p] == 0) {
            n /= cubic[p];
        }
    }
    return n;
}

signed main() {

    REP(i, 2525) cubic[i] = i * i * i;

    vector<bool> sieve = Eratosthenes(2525);
    REP(i, 2525) if (sieve[i]) prime.emplace_back(i);

    cin >> N;

    int res = 0;
    A.resize(N);
    REP(i, N) cin >> A[i];
    EACH(e, A) {
        bigint norm = normalize(e);
        if (norm == 1) ++res;
        else mp[norm]++;
    }
    if (res > 0) res = 1;
    
    set<bigint> st;
    
    EACH(e, mp) {
        if (st.count(e.first)) continue;
        bigint rev = normalize(e.first * e.first);
        // cout << e.first << ' ' << e.second << ' ' << rev << endl;
        st.emplace(rev);
        res += max(e.second, mp[rev]);
    }

    cout << res << endl;

}


Measured memory_bytes: 29952
// May this submission get accepted
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll n = inp1, k = inp1, x = inp1, y = inp1;

    ll ans = 0;
    REP(i, n) {
        if (i < k) {
            ans += x;
        } else {
            ans += y;
        }
    }
    say(ans);
    
}

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

map<vector<int>, int> memo;
vector<int> op;
int x, y;

using graph = vector<vector<int>>;

int proc(int now, int op) {
    if(op == 0) {
        return now & x;
    } else if(op == 1) {
        return now & y;
    } else if(op == 2) {
        return now | x;
    } else if(op == 3) {
        return now | y;
    } else if(op == 4) {
        return now ^ x;
    } else {
        return now ^ y;
    }
}

int dfs(int v, graph& g, int prev, int now, int turn) {
    if(g.size() == 1) {
        return 0;
    }
    if(g[v].size() == 1 && prev != -1) {
        return now;
    }
    int res = -1;
    for(auto to : g[v]) {
        if(to == prev) {
            continue;
        }
        int t = dfs(to, g, v, proc(now, op[to]), turn^1);
        if(res == -1) {
            res = t;
            continue;
        }
        if(turn == 0) {
            res = max(res, t);
        } else {
            res = min(res, t);
        }
    }
    return res;
}

int main() {
    int N, M;
    cin >> N >> M;
    op.resize(N);
    for(int i=1; i<N; ++i) {
        string o;
        cin >> o;
        char c1 = o[3], c2 = o[4];
        if(c1 == '&') {
            op[i] = o[4] - 'X';
        } else if(c1 == '|') {
            op[i] = 2 + o[4] - 'X';
        } else {
            op[i] = 4 + o[4] - 'X';
        }
    }
    vector<vector<int>> g(N);
    for(int i=0; i<N-1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    for(int i=0; i<M; ++i) {
        cin >> x >> y;
        vector<pair<int, int>> v(8);
        vector<int> v2(8);
        v[0] = make_pair(0, 0);
        v[1] = make_pair(x, 1);
        v[2] = make_pair(y, 2);
        v[3] = make_pair(x|y, 3);
        v[4] = make_pair(x&y, 4);
        v[5] = make_pair(x^y, 5);
        v[6] = make_pair(x^(x&y), 6);
        v[7] = make_pair(y^(x&y), 7);
        auto v3 = v;
        sort(v.begin(), v.end());
        for(int i=0; i<8; ++i) {
            v2[v[i].second] = i;
        }
        int res = -1;
        if(memo.count(v2) == 0) {
            res = dfs(0, g, -1, 0, 0);
            for(auto& p : v) {
                if(p.first == res) {
                    memo[v2] = p.second;
                }
            }
        } else {
            res = v3[memo[v2]].first;
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 18208
#include <iostream>
#include <string> 
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  ll ans=0;
  vector<ll> v(s.size()+1,0);
  vector<ll> u(s.size()+1,0);
  for (int i=0;i < s.size()+1;i++){
    if (s[i]=='<') v.at(i+1)=v.at(i)+1;
  }
  //for (int i=0;i<s.size()+1;i++){
    //cout << v[i] << " ";
  //}
  //printf("\n");
  for (int j=s.size()-1;j >= 0 ;j--){
    if (s[j]=='>') u.at(j)=u.at(j+1)+1;
  }
  //for (int i=0;i<s.size()+1;i++){
    //cout << u[i] << " ";
  //}
  //printf("\n");
  for (int k=0; k < s.size()+1;k++){
     ans+=max(v[k],u[k]);
    //printf("%d\n",ans);
  }
  cout << ans << endl;
  return 0;
}
    
       

Measured memory_bytes: 8708
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll n,m,x;
cin >> n >> m >> x;
ll a[m];
for(ll i=0;i<m;i++){
    cin >> a[i];
}
ll sum[n+1];
ll k=0;
sum[0]=0;
for(ll i=0;i<n;i++){
if(i+1==a[k]){
    sum[i+1]=sum[i]+1;
    k++;
}
else sum[i+1]=sum[i];
}
cout << min(sum[n]-sum[x],sum[x]) << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	var e int
	count := 0

	var sc = bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		if sc.Scan() {
			e, _ = strconv.Atoi(sc.Text())
		}

		if isPrime(e) {
			count++
		}
	}

	fmt.Println(count)
}

func isPrime(e int) bool {
	if e == 2 {
		return true
	}
	l := int(math.Sqrt(float64(e)))

	for i := 2; i <= l; i++ {
		if e%i == 0 {
			return false
		}
	}
	return true
}



Measured memory_bytes: 1248
<?php
fscanf(STDIN,"%d",$n);
$as=explode(' ',trim(fgets(STDIN)));
$bs=explode(' ',trim(fgets(STDIN)));
$cs=explode(' ',trim(fgets(STDIN)));

$sum = 0;
$add = -1;
foreach ($as as $a) {
  $sum += $bs[$a - 1];
  if ($a - 1 == $add) {
    $sum += $cs[$add - 1];
  }
  $add = $a;
}

echo $sum;


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long a[100];
  a[0]=2,a[1]=1;
  for(int i=2;i<=n;i++){
    a[i]=a[i-1]+a[i-2];
  }
  cout<<a[n]<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int n; cin>>n;
    rep(i,1,9+1)
    rep(j,0,9+1){
        if(n==i*1000+i*100+i*10+j){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    rep(i,1,9+1)
    rep(j,0,9+1){
        if(n==i*1000+j*100+j*10+j){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


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


void dfs(vector<vector<pair<int,int> > > &tree,vector<int> &f,int c,int sumw){
	f[c] = sumw;
	//cout <<"current " <<c << " " << sumw <<endl;
	
	for(int i=0;i<tree[c].size();++i){
		pair<int,int> p = tree[c][i];
		int next = p.first;
		int w = p.second;
		//cout << f[next] <<" " <<next << " " << w<<endl;
		if(f[next] == -1){
			dfs(tree,f,next,sumw+w);
		}
	}
	
	
}

int main(){
	int n;
	cin >> n ;
	vector<vector<pair<int,int> > > tree(n+1);
	vector<int> f(n+1,-1);
	
	int u,v,w;
	for(int i=0;i<n-1;++i){
		cin >> u >> v >> w;
		tree[u].push_back( pair<int,int>(v,w));
		tree[v].push_back( pair<int,int>(u,w));
	}
	
	dfs(tree,f,1,0);
	
	for(int i=1;i<=n;++i){
		//cout << " " << f[i] <<endl;
		if(f[i] %2 == 0) cout << 0 <<endl;
		else cout << 1 <<endl;
//		cout << f[i] <<endl;
	}
	
}



Measured memory_bytes: 8192
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

using namespace std;


int main() {
	int m , n;
	cin >> n >> m;
	int a[n];
	int total = 0;
	rep(i, n) {
		cin >> a[i];
		total += a[i];
	}
 	int count = 0;
 	rep(i, n) {
 		if ((double)a[i] < (double) total / ( 4.0 * (double) m)) {
 			continue;
 		}
 		count++;
 	}
 	if (count >= m) {
 		cout << "Yes" << endl;
 	} else {
 		cout << "No" << endl; 		
 	}

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define re cin>>
#define pr cout<<
#define in(x) scanf("%d",&x)
#define inn(x,y) scanf("%d%d",&x,&y)
#define innn(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)


const int N=205;
const int mod=1e9+7;


int n,m;
int grid[N][N];
int dp[N][N][2];

int dfs(int i, int j, int col){
    if(i>n || j>m || i<1|| j<1) return 1e9;
    if(i==n && j==m) {
        if(grid[i][j]) return !col;
        else return 0;
    }
    if(dp[i][j][col]!=-1) return dp[i][j][col];
    if(grid[i][j]) dp[i][j][col]= !col + min(dfs(i+1,j,1),dfs(i,j+1,1));
    else{
        return dp[i][j][col]=min(dfs(i+1,j,0),dfs(i,j+1,0));
    }
    return dp[i][j][col];
}

int main(){
    cin>>n>>m;
    rep1(i,n) rep1(j,m) {
        char c;
        re c;
        grid[i][j]=c=='#';
    }
    rep(i,N) rep(j,N) dp[i][j][0]=dp[i][j][1]=-1;
    cout<<dfs(1,1,0);
    return 0;
}

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

using namespace std;

int main(){
  int A, B;
  cin >> A >> B;
  if(A >= 13) cout << B << endl;
  else if(A >= 6) cout << B / 2 << endl;
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

//--------------------------

int main() {

  int n; cin >> n;
  int j, a = 0, b = 0, cnt = 1;
  bool af = true, bf = true;

  int p[n]; rep(i, n) cin >> p[i];
  int q[n]; rep(i, n) cin >> q[i];
  int s[n]; rep(i, n) s[i] = i+1;

  do {
    for(j = 0; j<n; ++j){
      if(s[j]!=p[j]) af = false;
      if(s[j]!=q[j]) bf = false;
    }
    if(af==true) a = cnt;
    if(bf==true) b = cnt;
    if(a!=0&&b!=0) break;
    ++cnt;
    af = bf = true;
  }while(next_permutation(s, s+n));
  cout << abs(a-b) << endl;

  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++)

int main() {
  string S;
  cin >> S;
  vector<char> c(3);
  rep(i,3) {
    c.at(i) = S.at(i);
  }
  sort(c.begin(), c.end());
  string T = "___";
  rep(i,3) {
    T.at(i) = c.at(i);
  }
  if ( T == "abc" ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <array>

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

    long int n;

    while (std::cin >> n, n) {
        long int age;
        std::array<long int, 13> arr{{}};

        while (n--) {
            std::cin >> age;
            ++arr[age / 10];
        }
        std::cout << arr[0] << '\n'
                  << arr[1] << '\n'
                  << arr[2] << '\n'
                  << arr[3] << '\n'
                  << arr[4] << '\n'
                  << arr[5] << '\n'
                  << arr[6] + arr[7] + arr[8]
                   + arr[9] + arr[10] + arr[11]
                   + arr [12] << '\n';
    }

    return 0;
}

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

int main() {
	int n; cin >> n;
	vector<pair<int, int>> v(n);
	for (auto& x : v) { cin >> x.first >> x.second; }
	int cnt = 0;
	for (auto& x : v) {
		if (x.first != x.second) { cnt = 0; }
		if (x.first == x.second) { cnt++; }
		if (cnt == 3) { cout << "Yes" << endl; return 0; }
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
using namespace std;
const int MAX =1e5+9;
int main(){
	int n ;
	string s;
	cin>>n;
	cin>>s;
	int pre[n+1] , suf[n+1];
	memset(pre, 0, sizeof(pre));
	memset(suf, 0, sizeof(suf));
	if(s[0]=='#')
		pre[0]=1;
	if(s[n-1]=='.')
		suf[n-1]=1;
	for(int i=1;i<n;i++){
		pre[i]=pre[i-1];
		if(s[i]=='#')
			pre[i]+=1;
	}
	for(int i=n-2;i>=0;i--){
		suf[i]=suf[i+1];
		if(s[i]=='.')
			suf[i]+=1;
	}
	int mn=INT_MAX;
	for(int i=0;i<n;i++){
		mn=min(mn , pre[i]+suf[i+1]);
	}
	if(s[0]=='#')
		mn=min(mn, suf[0]);
	cout<<mn;
	
}

Measured memory_bytes: 2180
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
unsigned long long nCrModPFermat(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    unsigned long long fac[n + 1]; 
    fac[0] = 1; 
    for (int i = 1; i <= n; i++) 
        fac[i] = (fac[i - 1] * i) % p; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 
int main()
{
    fio;
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        if(n==1)
        {
            cout<<0<<endl;
            continue;
        }
        /*
        ll res=power(10,n-2,(int)1e9+7);
        ll res1=((n%mod)*((n-1)%mod))%mod;
        ll res2=nCrModPFermat(n,2,(int)1e9+7);
        res=((res%mod)*(res2%mod)*2)%mod;
        */
        ll res=power(10,n,(int)1e9+7);
        ll res1=power(8,n,(int)1e9+7);
        ll res2=power(9,n,(int)1e9+7);
        res2=(res2*2)%mod;
        res=(res-res2+mod)%mod;
        res=(res%mod + res1%mod)%mod;
        cout<<res<<endl;
    }
}

Measured memory_bytes: 3636
package main

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

func solve() {
	n := getInt()
	s := getRunes()

	for i := range s {
		r := s[i] + rune(n)
		if r > 'Z' {
			s[i] = r - 'Z' + 'A' - 1
		} else {
			s[i] = r
		}
	}

	ans := string(s)
	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

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

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int main(){
	int n, m;
	int x[100010], diff[100010];
	cin >> n >> m;
	for(int i=0; i<m; i++) {
		cin >> x[i];
	}

	sort(x, x+m);
	for(int i=0; i<m-1; i++)
	{
		diff[i] = abs(x[i+1] - x[i]);
	}	

	sort(diff, diff+m-1);
	int sum = 0;
	for(int i=0; i<m-n; i++){
		sum += diff[i];
	}
	
	cout << sum;
	
	return 0;
}


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


def main():
    n = int(input())
    d, x = map(int, input().split())
    a = [int(input()) for _ in range(n)]
    choco = [1 for _ in range(100 + 1)]
    ans = x

    for i in range(n):
        ans += sum(choco[:d:a[i]])

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060