akhauriyash/Code-Regression huggingface dataset:
/*
	Divisors
	last verified	: 2020/09/15, AtCoder
		problem			: https://atcoder.jp/contests/abc142/tasks/abc142_d
		submission		: https://atcoder.jp/contests/abc142/submissions/16753557
*/
#include <iostream>
#include <vector>

std::vector<long long> common_divisors(long long a, long long b) {
	if (a > b) std::swap(a, b);
	std::vector<long long> ret(0), st(0);
	for (int i = 1; i <= a / i; i++) {
		if (a % i == 0) {
			if (b % i == 0) ret.push_back(i);
			if (b % (a / i) == 0 && i < a / i) st.push_back(a / i);
		}
	}
	while (st.size()) {
		ret.push_back(st.back());
		st.pop_back();
	}
	return ret;
}

bool is_prime(long long n) {
	if (n < 2) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (int i = 3; i <= n / i; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

int main() {
	long long a, b;
	std::cin >> a >> b;
	std::vector<long long> v = common_divisors(a, b);
	long long ans = 1;
	for (auto i : v) {
		if (is_prime(i)) ans++;
	}
	std::cout << ans << '\n';

	return 0;
}

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

vector<vector <int>> c;
vector<int> p, h, sib;
vector<bool> t;

int pre(int id) {
	if (h[id] == 0 && p[id] != -1)
		return pre(p[id]);
	else if (h[id] != 0 && c[id][0] != -1 && t[c[id][0]] == 0) {
		t[c[id][0]] = 1; 
		return c[id][0];
	}
	else if (h[id] != 0 && c[id][1] != -1 && t[c[id][1]] == 0) {
		t[c[id][1]] = 1;
		return c[id][1];
	}
	else if (p[id] != -1)
		return pre(p[id]);
	else
		return -1;
}

int in(int id) {
	if (h[id] == 0 && p[id] != -1) {
		if (t[p[id]] == 0) {
			t[p[id]] = 1;
			return p[id];
		}
		else
			return in(p[id]);
	}
	else if (h[id] != 0 && c[id][0] != -1 && t[c[id][0]] == 0) {
		if (h[c[id][0]] == 0 || c[c[id][0]][0] == -1) {
			t[c[id][0]] = 1;
			return c[id][0];
		}
		else
			return in(c[id][0]);
	}
	else if (h[id] != 0 && c[id][1] != -1 && t[c[id][1]] == 0) {
		if (h[c[id][1]] == 0 || c[c[id][1]][0] == -1) {
			t[c[id][1]] = 1;
			return c[id][1];
		}
		else
			return in(c[id][1]);
	}
	else if (p[id] != -1) {
		if (t[p[id]] == 0) {
			t[p[id]] = 1;
			return p[id];
		}
		else
			return in(p[id]);
	}
	else
		return -1;
}

int post(int id) {
	if (h[id] == 0 && p[id] != -1) {
		if (c[p[id]][1] == id) {
			t[p[id]] = 1;
			return p[id];
		}
		else if (sib[id] != -1 && h[sib[id]] == 0) {
			t[sib[id]] = 1;
			return sib[id];
		}
		else if (sib[id] != -1)
			return post(sib[id]);
		else if (p[id] != -1) {
			t[p[id]] = 1;
			return p[id];
		}
		else
			return -1;
	}
	else if (h[id] != 0 && c[id][0] != -1 && t[c[id][0]] == 0) {
		if (h[c[id][0]] == 0) {
			t[c[id][0]] = 1;
			return c[id][0];
		}
		else if (c[id][0] != -1)
			return post(c[id][0]);
		else
			return -1;			
	}
	else if (c[id][1] != -1 && t[c[id][1]] == 0) {
		if (h[c[id][1]] == 0) {
			t[c[id][1]] = 1;
			return c[id][1];
		}
		else if (c[id][1] != -1)
			return post(c[id][1]);
		else
			return -1;
	}
	else if (sib[id] != -1 && t[sib[id]] == 0) {
		if (h[sib[id]] == 0) {
			t[sib[id]] = 1;
			return sib[id];
		}
		else if (sib[id] != -1)
			return post(sib[id]);
		else
			return -1;
	}
	else if(p[id] != -1) {
		t[p[id]] = 1;
		return p[id];
	}
	else
		return -1;
}

int main()
{
	int n = 0, id = 0;

	cin >> n;

	c.resize(n);
	p.assign(n, -1);
	h.assign(n, -1);
	sib.assign(n, -1);

	for (int i = 0; i < n; i++) {
		int l = 0, r = 0;
		cin >> id >> l >> r;
		c[id].push_back(l);
		c[id].push_back(r);

		if (l != -1) {
			p[l] = id;
			sib[l] = r;
		}
		if (r != -1) {
			p[r] = id;
			sib[r] = l;
		}
		if (l == -1 && r == -1)
			h[id] = 0;
	}

	cout << "Preorder" << endl;

	int k = 0, r = 0;
	t.assign(n, 0);

	for (int i = 0; i < n; i++) {
		if (p[i] == -1) {
			r = i;
			break;
		}
	}

	k = r;

	while (k != -1) {
		cout << " " << k;
		k = pre(k);
	}

	cout << endl << "Inorder" << endl;

	t.assign(n, 0);

	if (c[r][0] == -1) {
		k = r;
		t[r] = 1;
	}
	else
		k = in(r);

	while (k != -1) {
		cout << " " << k;
		k = in(k);
	}
	

	cout << endl << "Postorder" << endl;

	t.assign(n, 0);
	k = post(r);

	if (k == -1)
		cout << " " << r;
	else {
		while (k != -1) {
			cout << " " << k;
			k = post(k);
		}
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 3168
#include<stdio.h>
int p[61],q[61];
long long t[61];
int main(int argc, char const *argv[]){
	long long a,b,c,d;
	int i;
	scanf("%lld",&a);
	scanf("%lld",&b);
	if(a==b){
		printf("1\n");
		return 0;
	}
	t[0]=1;
	for(i=1;i<61;i++){
		t[i]=t[i-1]*2;
	}
	c=a;
	d=b;
	i=1;
	while(c>0){
		p[i]=c%2;
		c/=2;
		i++;
	}
	p[0]=i-1;
	i=1;
	while(d>0){
		q[i]=d%2;
		d/=2;
		i++;
	}
	q[0]=i-1;
	if(p[0]==q[0]){
		while(p[p[0]]==q[p[0]]){
			p[0]--;
			q[0]--;
		}
		while(p[0]>0 && p[p[0]]==0){
			p[0]--;
		}
		a=0;
		b=0;
		for(i=0;i<p[0];i++){
			a+=t[i]*p[i+1];
		}
		for(i=0;i<q[0];i++){
			b+=t[i]*q[i+1];
		}
	}
	c=t[q[0]-1];
	d=b-c;
	i=0;
	while(d>=t[i]){i++;}
	d=t[i]-1;
	if(d>=a) printf("%lld\n",2*c-a);
	else printf("%lld\n",2*c-2*a+d+1);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<string.h>
#include<cstdlib>
#include<algorithm>
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%I64d",&x)
#define pi(x) printf("%d",&x)
#define pl(x) printf("%I64d",&x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
using namespace std;
int n;
int a[100100],b[100100],c[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++)
		cin>>c[i];
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	long long res=0;
	int numa=0,numc=0;
	c[n+1]=2e9;
	for(int i=1;i<=n;i++){
		while(a[numa]<b[i]&&numa<=n) numa++;
		while(c[numc]<=b[i]&&numc<=n) numc++;
		res+=(long long)(numa-1)*(long long)(n-numc+1);
	}
	cout<<res<<endl;
	return 0;
}


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

using namespace std;

vector< vector<long long> > dp(2, vector<long long>(2005, -1));
vector<long long> v;
long long n, z, w;

long long get_ans(int player, int left)
{
    if(dp[player][left] != -1) return dp[player][left];
    long long other=w;
    if(left+1<=n) other=v[left];
    if(player==0)
    {
        long long best=-1;
        for(int take=1; take<=left; take++)
        {
            if(take==left)
            {
                best=max(best, abs(v[0]-other));
            }
            else
            {
                best=max(best, get_ans(1-player, left-take));
            }
        }
        return dp[player][left]=best;
    }
    else
    {
        long long best=1e18;
        for(int take=1; take<=left; take++)
        {
            if(take==left)
            {
                best=min(best, abs(v[0]-other));
            }
            else
            {
                best=min(best, get_ans(1-player, left-take));
            }
        }
        return dp[player][left]=best;
    }
}

int main()
{
    scanf("%lld %lld %lld", &n, &z, &w);
    v.assign(n, -1);
    for(int i=0; i<n; i++)
    {
        scanf("%lld", &v[i]);
    }
    reverse(v.begin(), v.end());
    printf("%lld\n", get_ans(0, n));
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 998244353;
constexpr int inf = 3e18;

int mod_pow(int x,int y,int m=mod){
	int res=1;
	while(y>0){
		if(y&1)(res*=x)%=m;
		(x*=x)%=m;
		y>>=1;
	}
	return res;
}
vector<int>perm,inv;
void init_perm(){
	int x=1e6+1;perm.resize(x);inv.resize(x);
	perm[0]=1;
	REP(i,x+1)perm[i]=perm[i-1]*i%mod;
	inv[x]=mod_pow(perm[x],mod-2);
	for(int i=x-1;i>=0;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
}
int nCk(int x,int y){
	if(x<y)return 0;
	return perm[x]*inv[x-y]%mod*inv[y]%mod;
}
int K,N;
int dp[2005][2005];
signed main(){
	init_perm();
	cin>>K>>N;
	REP(i,K+1)dp[0][i]=dp[1][i]=1;
	REP(i,N){
		REP(j,K+1){
			(dp[i][j+1]+=dp[i][j])%=mod;
			(dp[i+1][j]+=dp[i][j])%=mod;
		}
	}
	REP(i,K+1)(dp[N][i+1]+=dp[N][i])%=mod;
	for(int i=2;i<=2*K;i++){
		int mn=max(1ll,i-K),mx=i/2;
		int ans=0;
		rep(j,mx-mn+2){
			if(2*j>N)break;
			if(j%2==0)(ans+=nCk(mx-mn+1,j)*dp[N-2*j][K]%mod)%=mod;
			else (ans-=nCk(mx-mn+1,j)*dp[N-2*j][K]%mod-mod)%=mod;
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 50340
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], cnt, n;
bool vis[maxn];
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) 
	{
		scanf("%d", &a[i]); 
		if(a[i] == i) vis[i] = 1;
	}
	for(int i = 1; i <= n; ++i)
	{
		if(!vis[i]) continue;
		int r = i;
		while(r <= n && vis[r]) ++r;
		cnt += (r - i + 1) / 2;
		i = r - 1;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}
void yes_no(bool f) {
  if (f)
    printf("yes\n");
  else
    printf("no\n");
}

template <typename T>
void deb1(T x) {
  cout << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  string s;
  cin >> s;
  map<char, int> mp;
  rep(i, size(s)) mp[s[i]]++;
  bool f = true;
  for (auto i : mp)
    if (i.se > 1) f = false;
  yes_no(f);
}
int main(void) { solve(); }

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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ll n,a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    ll m=min({a,b,c,d,e});
    ll ans=5+(n-1)/m;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>

#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))

using namespace std;

const long long INF = (1LL << 31) - 1;
const long long sqrtN = 512;

struct SqrtDecomposition {
  long long N, K;
  vector<long long> data;
  vector<long long> bucketMin;
  SqrtDecomposition(long long n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, INF);
    bucketMin.assign(K, INF);
  }
  void update(long long x, long long y) {
    long long k = x / sqrtN;
    long long minVal = data[x] = y;
    for (long long i = k * sqrtN; i < (k + 1) * sqrtN; ++i) {
      minVal = min(minVal, data[i]);
    }
    bucketMin[k] = minVal;
  }
  // [x, y)
  long long find(long long x, long long y) {
    long long minVal = INF;
    for (long long k = 0; k < K; ++k) {
      long long l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= x || y <= l)
        continue;
      if (x <= l && r <= y) {
        minVal = min(minVal, bucketMin[k]);
      } else {
        for (long long i = max(x, l); i < min(y, r); ++i) {
          minVal = min(minVal, data[i]);
        }
      }
    }
    return minVal;
  }
};

int main() {
    long long n,q,que,x,y;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> q;
    SqrtDecomposition qq(n);
    rep(i,q) {
        cin >> que;
        if(que) {
            cin >> x >> y;
            cout << qq.find(x,y+1) << endl;
        } else {
            cin >> x >> y;
            qq.update(x,y);
        }
    }
    return 0;
}


Measured memory_bytes: 3596
n,a=map(int,input().split())
m=list(map(lambda x:int(x)-a,input().split()))
x=max(abs(max(m)),abs(min(m)))*n
dp=[[0for _ in range(2*x+1)]for i in range(n)]
dp[0][0+x]+=1
dp[0][m[0]+x]+=1
for i in range(1,n):
  y=m[i]
  for j in range(2*x+1):
    if 0<=j+y and j+y<2*x+1:
      dp[i][j+y]+=dp[i-1][j]
    dp[i][j]+=dp[i-1][j]
  #print(y,dp[i])
print(max(0,dp[n-1][0+x]-1))

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N;
  cin >> N;
  vector<int> T(N), A(N);
  REP(i, N) cin >> T[i];
  REP(i, N) cin >> A[i];
  vector<int> tmin(N), tmax(N);
  REP(i, N) {
    if (i == 0 || (0 < i && T[i - 1] < T[i])) {
      tmin[i] = T[i];
      tmax[i] = T[i];
    } else {
      tmin[i] = 1;
      tmax[i] = T[i];
    }
  }
  vector<int> amin(N), amax(N);
  RREP(i, N) {
    if (i == N - 1 || (i < N - 1 && A[i + 1] < A[i])) {
      amin[i] = A[i];
      amax[i] = A[i];
    } else {
      amin[i] = 1;
      amax[i] = A[i];
    }
  }
  ll ans = 1;
  REP(i, N) {
    int mn = max(tmin[i], amin[i]);
    int mx = min(tmax[i], amax[i]);
    ans *= max(0ll, 1ll * (mx - mn + 1));
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int n, m;
long res;

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

	res = 1;
	for (int i = 0; i < m; ++i)
		res *= 2;

	res *= (1900 * m + 100 * (n - m));

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
t = input()
n = len(t)
s_list = list(t)
for i in range(len(s_list)-1):
    if s_list[i] == '?':
        if s_list[i+1] == 'D' and s_list[i-1] == 'D':
            s_list[i] = 'P'
        elif s_list[i+1] == 'D' and s_list[i-1] == 'P':
            s_list[i] = 'D'
        elif s_list[i+1] == 'P' and s_list[i-1] == 'P':
            s_list[i] = 'D'
        elif s_list[i+1] == '?' and s_list[i-1] == 'D':
            s_list[i] = 'P'
        elif s_list[i+1] == '?' and s_list[i-1] == 'P':
            s_list[i] = 'D'
        else:
            s_list[i] = 'D'
if s_list[-1] == "?":
    s_list[-1] = 'D'


t = ''.join(s_list)
print(t)

Measured memory_bytes: 10756
class Node:
    def __init__(self, num, left, right):
        self.value = num
        self.left = left
        self.right = right

EmptyTree = None

def make_node(num, left, right):
    return Node(num, left, right)

def value(tree):
    return tree.value

def left(tree):
    return tree.left

def right(tree):
    return tree.right

def is_empty(tree):
    return tree == EmptyTree

def make_leaf(num):
    return make_node(num, EmptyTree, EmptyTree)

# ????????¢?´¢??¨??¨??????????????????tree???x?????????????????°????????¨?????????
def add_node(tree, x):
    if is_empty(tree):
        return make_leaf(x)
    elif x < value(tree):
        return make_node(value(tree), add_node(left(tree), x), right(tree))
    else:
        return make_node(value(tree), left(tree), add_node(right(tree), x) )

def make_binary_search_tree(a):
    tree = EmptyTree
    # ????????????????????¶:
    # ????????????i???????????£?????¨????????¨????¬????????????????????????§??????
    # a?????????i???????????§???????´????????????¢?´¢??¨tree????????????????????????
    for num in a:
        tree = add_node(tree, num)
    return tree

def inorder(tree):
    if is_empty(tree):
        return []
    return inorder(left(tree)) + [value(tree)] + inorder(right(tree))

def preorder(tree):
    if is_empty(tree):
        return []
    return [value(tree)] + preorder(left(tree)) + preorder(right(tree))

def postorder(tree):
    if is_empty(tree):
        return []
    return postorder(left(tree)) + postorder(right(tree)) + [value(tree)]

# ?????????????????¨????§??????¨???????????¨?????????????¨???????????????????
def calc(tree):
    if is_empty(right(tree)) or is_empty(left(tree)):
        return value(tree)

    if value(tree) == "+":
        return calc(right(tree)) + calc(left(tree))
    elif value(tree) == "-":
        return calc(right(tree)) - calc(left(tree))
    elif value(tree) == "*":
        return calc(right(tree)) * calc(left(tree))
    elif value(tree) == "/":
        return calc(right(tree)) / calc(left(tree))

def recover(preorder, inorder):
    # preorder??????????????????root
    # root???inorder??????????????¢???
    # inorder??????root????¢??????????
    # ?????????????????????Node??????????????£???????????????????????£?????????
    if len(inorder) == 0:
        return EmptyTree
    root_val = preorder[0]
    idx = inorder.index(root_val)
    left = inorder[:idx]
    right = inorder[idx+1:]
    return make_node(root_val, recover(preorder[1:], left),  recover(preorder[1+len(left):],right) )

n = input()
pre = list(map(int, input().split()))
ino = list(map(int, input().split()))
t = recover(pre, ino)
t = map(str, postorder(t))
print(' '.join(t))

Measured memory_bytes: 7872
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep (i, n) cin >> a[i];
  vector<pair<int, int>> apair(n);
  rep (i, n) apair[i] = {a[i], i + 1};
  sort(all(apair));
  rep (i, n) cout << (i == 0 ? "" : " ") << apair[i].second;
  cout << endl;
  return 0;
}

Measured memory_bytes: 2048
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		if(a > b){
			for(int i = 0;i < a;i++){
				System.out.print(b);
			}
		} else {
			for(int i = 0;i < b;i++){
				System.out.print(a);
			}
		}
		System.out.println("");
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21200
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
  int N;
  cin >> N;
  if(N%10 == 3) cout << "bon" << endl;
  else if(N%10 == 0 ||N%10 == 1 ||N%10 == 6 ||N%10 == 8) cout << "pon" << endl;
  else{
    cout << "hon" << endl;
  }
}



Measured memory_bytes: 3632
import itertools
n=int(input())
P=tuple((map(int,input().split())))
Q=tuple((map(int,input().split())))
L=[]

for i in range(n):
    L.append(i+1)
    
M=list(itertools.permutations(L))


print(abs(M.index(P)-M.index(Q)))


Measured memory_bytes: 13804
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	string s, t;
	cin >> s >> t;
	
	cout << t + s << endl;
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  a--;
  b--;
  char g[100][100];
  for (int i=0; i<50; i++) for (int j=0; j<100; j++) g[i][j] = '#';
  for (int i=50; i<100; i++) for (int j=0; j<100; j++) g[i][j] = '.';
  for (int i=0; i<49; i+=2) {
    if (a==0) break;
    for (int j=0; j<100; j+=2) {
      if (a==0) break;
      g[i][j] = '.';
      a--;
    }
  }
  for (int i=51; i<100; i+=2) {
    if (b==0) break;
    for (int j=0; j<100; j+=2) {
      if (b==0) break;
      g[i][j] = '#';
      b--;
    }
  }
  printf("100 100\n");
  for (int i=0; i<100; i++) {
    for (int j=0; j<100; j++) printf("%c", g[i][j]);
    printf("\n");
  }
  return 0;
}


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

int gcd(int a,int b){
    int tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }

    tmp = a % b;

    while(tmp!=0){
        a = b;
        b = tmp;
        tmp = a % b;
    }
    return b;
}


int main(){
    int N,tmp=0;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    for(int i=0;i<N;++i) cin >> A[i],B[i]=A[i];

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

    int j = B[1]+1,cnt=0;
    while(cnt<N-1){
        --j;
        cnt = 0;
        for(int i=0;i<N;++i){
            if(A[i]%j==0) ++cnt;
        }
    }

    cout << j << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=100005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
inline void read(int &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,k,c[N];
ll a=1,b;

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&c[i]);
	for(int i=1;i<=n;i++)
		if(c[i]&1) a=b=a+b; else a*=2,b*=2;
	if(k) printf("%lld\n",b); else printf("%lld\n",a);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    REP(i, h) {
        REP(j, w) {
            if (i < b ^ j < a) {
                cout << "1";
            } else {
                cout << "0";
            }
        }
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 1280
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define lu unsigned long long int
#define pi pair<ll, ll>
#define pll pair<ll, ll>
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define vll ve<ll>
#define vpl ve<pll>
#define lr(n) for(ll i = 0; i < n; i++)
#define ltr(i, l, r) for (ll i = l; i <= r; i++)
#define rtl(i, l, r) for (ll i = r; i >= l; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define be begin
#define sz(a) (ll)(a.size())
#define con continue
#define ret return
#define endl "\n"
const ll INF = 1e18;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

// ll gcd(ll a, ll b){
// 	return b == 0 ? a : gcd(b, a % b);
// }

// ll mod = 1e9+7;

// ll mult(ll x, ll y){
//     ll rem=1;
//     while(y){
//         if(y&1){
//             rem=(rem*x)%mod;
//         }
//         x=(x*x)%mod;
//         y>>=1;
//     }
//     return rem;
// }


void solve(ll T){
	ll a, b, c, d;
	cin>>a>>b>>c>>d;
	cout << max(b*d, max(a*c, max(a*d, b*c))) << "\n";
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// std::cout << std::unitbuf;
	ll T=1;
	// cin>>T;
	for(ll t=1;t<=T;t++){
		solve(t);
	}
	return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>

int main(void){
    int x,y;
    scanf("%d %d",&x,&y);
    
    int tmp;
    if(x<y){
        tmp=x;
        x=y;
        y=tmp;
    }
    
    while(x%y!=0){
        tmp=y;
        y=x%y;
        x=tmp;
    }
    
    printf("%d\n",y);
    
}



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

int main() {
  int n; cin >> n;
  vector<vector<int> > v(n, vector<int>(3, 0));
  vector<vector<int> > r(n+1, vector<int>(3, 0));
  for (int i=0; i<n; i++) {
    for (int j=0; j<3; j++) {
      cin >> v[i][j];
    }
  }

  for (int i=0; i<n; i++) {
    for (int j=0; j<3; j++) {
      for (int k=0; k<3; k++) {
        if (j == k) continue;
        r[i+1][k] = max(r[i+1][k], r[i][j] + v[i][k]);
      }
    }
  }

  cout << max(r[n][0], max(r[n][1], r[n][2]))	<< endl;
  return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <random>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, x[3], l[10];

lli rec(lli i, lli a, lli b, lli c) {
  if (i==n) {
    if (a==0 || b==0 || c==0) return 1e9;
    return abs(a-x[0]) + abs(b-x[1]) + abs(c-x[2]);
  }
  lli r = l[i];
  lli res = 1e9;
  res = min(res, (a==0 ? 0 : 10) + rec(i+1, a+r, b, c));
  res = min(res, (b==0 ? 0 : 10) + rec(i+1, a, b+r, c));
  res = min(res, (c==0 ? 0 : 10) + rec(i+1, a, b, c+r));
  res = min(res, rec(i+1, a, b, c));
  return res;
}

int main() {
  cin >> n; read_n(x, 3); read_n(l, n);
  lli ans = rec(0, 0, 0, 0);
  cout << ans << '\n';
  return 0;
}


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

namespace AtCoder
{
    class Abc168C
    {
        public static void Main()
        {
            var abhm = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var a = abhm[0];
            var b = abhm[1];
            var h = abhm[2];
            var m = abhm[3];

            double mm = m / 60.0;
            double hh = (h + mm) / 12;

            Console.WriteLine(Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos((hh - mm) * 2 * Math.PI)));
        }
    }
}


Measured memory_bytes: 28688
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int vis[10000010],pri[1000010],cntp;
void init(){
	int i,j,k;vis[1]=1;
	for(i=2;i<=10000005;i++){
		if(!vis[i]) pri[++cntp]=i;
		for(j=1;j<=cntp;j++){
			k=i*pri[j];if(k>=10000005) break;
			vis[k]=1;
			if(i%pri[j]==0) break;
		}
	}
}
struct graph{//DINIC大法好！网络流应该比匈牙利快吧...... 
	int first[1010],dep[1010],cur[1010],cnte;
	struct edge{
		int to,next,w;
	}a[100010];
	graph(){
		memset(first,-1,sizeof(first));cnte=-1;
	}
	inline void add(int u,int v,int w){
//		cout<<"addedge "<<u<<' '<<v<<' '<<w<<'\n';
		a[++cnte]=(edge){v,first[u],w};first[u]=cnte;
		a[++cnte]=(edge){u,first[v],0};first[v]=cnte;
	}
	bool bfs(int s,int t){
		int q[1010],head=0,tail=1,i,u,v;
		for(i=s;i<=t;i++) dep[i]=-1,cur[i]=first[i];
		dep[s]=0;q[0]=s;
		while(head<tail){
			u=q[head++];
			for(i=first[u];~i;i=a[i].next){
				v=a[i].to;if(~dep[v]||!a[i].w) continue;
				dep[v]=dep[u]+1;q[tail++]=v;
			}
		}
		return ~dep[t];
	}
	int dfs(int u,int t,int lim){
		if(u==t||!lim) return lim;
		int i,v,f,flow=0;
		for(i=cur[u];~i;i=a[i].next){
			v=a[i].to;cur[u]=i;
			if(dep[v]==dep[u]+1&&(f=dfs(v,t,min(lim,a[i].w)))){
				a[i].w-=f;a[i^1].w+=f;
				flow+=f;lim-=f;
				if(!lim) return flow; 
			}
		}
		return flow;
	}
	int dinic(int s,int t){
		int re=0;
		while(bfs(s,t)) re+=dfs(s,t,1e9);
		return re;
	}
}G;
int n,x[110],one[210],cnt,l[210],cntl,r[210],cntr;
int main(){
	init();int i,j,match;
	n=read();
	for(i=1;i<=n;i++) x[i]=read();
	for(i=1;i<=n;i=j+1){
		j=i;
		while((x[j+1]==x[j]+1)&&j<n) j++;
		one[++cnt]=x[i];one[++cnt]=x[j]+1;
	}
	for(i=1;i<=cnt;i++){
		if(one[i]%2) l[++cntl]=one[i];
		else r[++cntr]=one[i];
	}
	for(i=1;i<=cntl;i++) G.add(0,i,1);
	for(i=1;i<=cntr;i++) G.add(i+cntl,cntl+cntr+1,1);
	for(i=1;i<=cntl;i++){
		for(j=1;j<=cntr;j++){
//			cout<<"do "<<i<<' '<<j<<' '<<l[i]<<' '<<r[j]<<'\n';
			if(!vis[abs(l[i]-r[j])]) G.add(i,cntl+j,1);
		}
	}
	match=G.dinic(0,cntl+cntr+1);
	printf("%d\n",match+((cntl-match)/2+(cntr-match)/2)*2+((cntl-match)%2)*3);
}

Measured memory_bytes: 43392
func readIntPair() -> (Int, Int) {
    let line = readLine()!.split(separator: " ").map({Int($0)!})
    return (line[0], line[1])
}

let (A, V) = readIntPair()
let (B, W) = readIntPair()
let T = Int(readLine()!)!

print(((V - W) * T < max(A, B) - min(A, B)) ? "NO" : "YES")


Measured memory_bytes: 8292
#!/usr/bin/env python3


def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    A.sort()
    B.sort()
    if N % 2 == 1:
        print(B[(N-1)//2] - A[(N-1)//2] + 1)
    else:
        print(B[N//2]-A[N//2] +B[N//2-1]-A[N//2-1] + 1)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 25504
N, K = map(int,input().split())
S = input()
group_size = 1
count = 0
for i in range(0,N):
  if i>0 and S[i] == S[i-1]:
    count += 1
  elif i >0 and S[i] != S[i-1]:
    group_size += 1
for i in range(K):
  if group_size > 2:
    count +=2
    group_size -=2
  elif group_size == 2:
    count += 1
    group_size -=1
  else:
    break
print(count)

  



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

int main() {
  
  string S;
  cin >> S;

  if (S == "SUN") {
    cout << 7 << endl;
  }
  if (S == "MON") {
    cout << 6 << endl;
  }
  if (S == "TUE") {
    cout << 5 << endl;
  }
  if (S == "WED") {
    cout << 4 << endl;
  }
  if (S == "THU") {
    cout << 3 << endl;
  }
  if (S == "FRI") {
    cout << 2 << endl;
  }
  if (S == "SAT") {
    cout << 1 << endl;
  }
  
return 0;
}

Measured memory_bytes: 3568
# -*- coding: utf-8 -*-
from math import factorial

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

def ncr(n, r):
    return factorial(n) // (factorial(r) * factorial(n - r)) 

for i in range(1, K+1):
    if i <= N-K+1:
        print(ncr(K-1, i-1) * ncr(N-K+1, i) % (10**9 + 7))
    else:
        print(0)

Measured memory_bytes: 3316
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int H, W, N;
	cin >> H >> W >> N;

	int k = max(H, W);

	co((N + k - 1) / k);


	Would you please return 0;
}

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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

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

const double pi = 3.1415926;

int main(void) {
    double r;
    cin>>r;

    cout<<2*r*pi<<endl;

    return 0;
}




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

ll inf=1ll<<60,mod=1000000007;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int h,w,i,j,k,a[50][50],b[9][2],s=0;
	cin>>h>>w;
	vector<string> g(h);
	for (i=0;i<h;i++){
		cin>>g[i];
	}
	for (i=0;i<h;i++){
		for (j=0;j<g[i].size();j++){
			b[0][0]=i-1;b[0][1]=j-1;
			b[1][0]=i-1;b[1][1]=j;
			b[2][0]=i-1;b[2][1]=j+1;
			b[3][0]=i;b[3][1]=j-1;
			b[4][0]=i;b[4][1]=j+1;
			b[5][0]=i+1;b[5][1]=j-1;
			b[6][0]=i+1;b[6][1]=j;
			b[7][0]=i+1;b[7][1]=j+1;
			for (k=0;k<8;k++){
				if (b[k][0]>=0&&b[k][1]>=0&&b[k][0]<h&&b[k][1]<w){
					if (g[b[k][0]][b[k][1]]=='#'){
						s++;
					}
				}
			}
			a[i][j]=s;
			s=0;
		}
	}
	for (i=0;i<h;i++){
		for (j=0;j<w;j++){
			if (g[i][j]=='#'){
				cout<<"#";
			}
			else {
				cout<<a[i][j];
			}
		}
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
X, K, D = map(int, input().split())
ans = 0
if X == 0:
    if K % 2 != 0:
        ans = D
elif X > 0:
    a = int(X/D)
    if K > a:
        diff = K - a
        X_temp = X - a * D
        if abs(X_temp - D) < X_temp:
            if (diff - 1) % 2 == 0:
                ans = abs(X_temp - D)
            else:
                ans = X_temp
        else:
            if diff % 2 == 0:
                ans = X_temp
            else:
                ans = abs(X_temp - D)
    else:
        ans = X - K * D
else:
    a = int(abs(X)/D)
    if K > a:
        diff = K - a
        X_temp = X + a * D
        if abs(X_temp + D) < abs(X_temp):
            if (diff - 1) % 2 == 0:
                ans = abs(X_temp + D)
            else:
                ans = abs(X_temp)
        else:
            if diff % 2 == 0:
                ans = abs(X_temp)
            else:
                ans = abs(X_temp + D)
    else:
        ans = abs(X + K * D)
print(ans)

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

#define pb push_back
#define ll long long
#define MAXN 100005

using namespace std;

const int H = 1 << 17;
int mod;
vector<int> graph[MAXN];
int down[MAXN], up[MAXN];

int add(int a, int b) {

    a += b;
    if(a >= mod)
        a -= mod;
    return a;
}

int mul(int a, int b) {

    return ((ll)a * b) % mod;
}

int get(vector<int> bit, int x) {

    int ans = 1;
    for(int i = x; i > 0; i -= i & -i)
        ans = mul(ans, bit[i]);
    return ans;
}

void upd(vector<int> &bit, int x, int y) {

    for(int i = x; i <= bit.size(); i += i & -i)
        bit[i] = mul(bit[i], y);
}

void make_down(int u, int p) {

    down[u] = 1;
    for(int v: graph[u]) {
        if(v != p) {
            make_down(v, u);
            down[u] = mul(down[u], add(1, down[v]));
        }
    }
}

void make_up(int u, int p) {

    int n = graph[u].size();
    if(p != -1)
        n--;

    vector<int> arr(n);
    vector<int> pre(n);
    vector<int> suf(n);
    int br = 0;
    for(int v: graph[u])
        if(v != p)
            arr[br++] = v;

    for(int i = 0; i < n; i++) {
        int j = n - i - 1;
        pre[i] = add(1, down[arr[i]]);
        suf[j] = add(1, down[arr[j]]);
        if(i) {
            pre[i] = mul(pre[i], pre[i - 1]);
            suf[j] = mul(suf[j], suf[j + 1]);
        }
    }

    for(int i = 0; i < n; i++) {
        if(!i && i == n - 1)
            up[arr[i]] = add(1, up[u]);
        else if(!i)
            up[arr[i]] = add(1, mul(up[u], suf[i + 1]));
        else if(i == n - 1)
            up[arr[i]] = add(1, mul(up[u], pre[i - 1]));
        else
            up[arr[i]] = add(1, mul(up[u], mul(pre[i - 1], suf[i + 1])));
        make_up(arr[i], u);
    }
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n >> mod;
    for(int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;

        graph[u].pb(v);
        graph[v].pb(u);
    }

    make_down(0, -1);
    up[0] = 1;
    make_up(0, -1);

    for(int i = 0; i < n; i++)
        cout << mul(down[i], up[i]) << endl;
    return 0;
}


Measured memory_bytes: 23276
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
 
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}

void solve(){
    int n;
    string s;
    cin >> n >> s;
    s = '#'+s;
    vector<int>pre(n+5);
    FOR(i,1,n+1)if(s[i] == 'R')pre[i] = pre[i-1]+1;
    else pre[i] = pre[i-1];
    int ans = inf;
    FOR(i,0,n+1){
        int rc = pre[i],wc = i-rc,tot = 0;
        if(wc == 0)tot = pre[n]-rc;
        else {
            int orc = pre[n]-rc;
            int canswap = min(orc,wc);
            wc -= canswap;
            tot += canswap;
            orc -= canswap;
            tot += wc+orc;
        }
        ans = min(ans,tot);
    }
    cout << ans << "\n";
}
 
signed main()
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...

Measured memory_bytes: 5048
#include<stdio.h>
int main()
{
  int i,j,x;
  int n[24];
  double t[24];
  double max=999;
  int maxn=0;
  for(i=0;i<24;i++)
    scanf("%d%lf",&n[i],&t[i]);
 
  for(i=0;i<3;i++)
    {
      for(x=0;x<2;x++)
	{
	  max=999;
	  maxn=0;
	  for(j=0;j<8;j++)
	    {
	      if(max>t[i*8+j])
		{
		  max=t[i*8+j];
		maxn=i*8+j;
		}
	    }
	  printf("%d %.2f\n",n[maxn],max);
	  t[maxn]=999;
	}
    }
  for(x=0;x<2;x++)
    {
      max=999;
      for(i=0;i<24;i++)
	{
	  if(max>t[i])
	    {
	      max=t[i];
	      maxn=i;
	    }
	}
      printf("%d %.2f\n",n[maxn],max);
      t[maxn]=999;
    }
  
return 0;
}

Measured memory_bytes: 652
// Ryo Kamoi

#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

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

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

int INF = 1000000000;

int n;
string s;
int main(){
    int r = 0;
    cin >> n;
    cin >> s;
    REP(i, n) {
        if (s[i] == 'R') r++;
    }

    if (n-r < r) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

vector<int> A, B, C;
vector<ll> D;
int N, M, Q;


ll eval(vector<int> a){
  ll score = 0;
  // for(int s : a){
  //   cout << s << " ";
  // }
  for(int i =0;  i<Q;  i++){
    if(a.at(B.at(i)-1) - a.at(A.at(i)-1) == C.at(i)){
      score += D.at(i);
    }
  }
  // cout << score << endl;

  return score;
}



ll fun(vector<int> a, int n, int last){
  if(n == 0){
    // cout << "eval";
    return eval(a);
  }
  ll score = 0;

  // cout <<  n << "test" << endl;

  for(int i = last; i<=M;i++){
    a.push_back(i);
    score = max(score, fun(a, n-1, i));
    a.pop_back();
  }

  return score;
}


int main(){

  cin >> N >> M >> Q;

  A = vector<int>(Q);
  B = vector<int>(Q);
  C = vector<int>(Q);
  D = vector<ll>(Q);

  for(int i = 0; i<Q; i++){
    cin >> A.at(i)  >> B.at(i) >> C.at(i) >> D.at(i);
  }
  
  vector<int>a;
  cout << fun(a, N, 1) << endl;

}




Measured memory_bytes: 3640