akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

template<typename T>
T minT(T a, T b) {
	if (a < b) return a;
	else return b;
}

template<typename T>
T maxT(T a, T b) {
	if (a > b) return a;
	else return b;
}

template<typename T>
T absT(T a) {
	if (a < 0) a *= -1;
	return a;
}

template<typename T>
T powT(T a, T x) {
	T res = 1;
	while (x > 0) {
		if (x & 1) res = res*a;
		a = a*a;
		x >>= 1;
	}
	return res;
}

ll StoLL(string str) {
	ll ret = 0, ini = 0;
	if (str[0] == '-') ini = 1;
	repi(i, ini, str.length()) {
		ret *= 10;
		ret += (ll)(str[i] - '0');
	}
	if (ini) ret *= -1;
	return ret;
}

///////////////////////////////////////////////////////////////////////////////////////

ll fill9(ll n, ll d) {
	repi(i, 0, d) {
		n /= 10;
	}
	repi(i, 0, d) {
		n *= 10;
		n += 9;
	}
	return n;
}

ll calcDSum(ll x) {
	ll ret = 0;
	while (x > 0) {
		ret += (x % 10);
		x /= 10;
	}
	return ret;
}

ll calcNAns(ll x) {
	ll ret = x, retS = calcDSum(x);

	ll t = x, d = 0;
	while (t > 0) {
		d++;
		t /= 10;
	}

	repi(i, 1, d + 1) {
		ll temp = fill9(x, i), tempS = calcDSum(temp);
		if (ret*tempS > temp*retS) {
			ret = temp, retS = tempS;
		}
	}
	return ret;
}

int main() {
	ll ans = 0, K;
	cin >> K;
	repi(i, 0, K) {
		ans = calcNAns(ans + 1);
		wrln(ans);
	}
	return 0;
}


Measured memory_bytes: 256
#![allow(unused)]

//
// Based on EbTech's Scanner https://stackoverflow.com/q/56449027
//
struct Scanner<'a, R: std::io::BufRead> {
    reader: R,
    buf: String,
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a, R: std::io::BufRead> Scanner<'a, R> {
    fn new(reader: R) -> Self {
        Self { reader, buf: String::new(), iter: "".split_whitespace() }
    }

    fn get_str(&mut self) -> &str {
        if let Some(t) = self.iter.next() {
            return t;
        }
        self.buf.clear();
        self.reader.read_line(&mut self.buf).expect("I/O error");
        self.iter = unsafe { std::mem::transmute(self.buf.split_whitespace()) };
        self.get_str()
    }

    fn get<T: std::str::FromStr>(&mut self) -> T {
        self.get_str().parse().ok().expect("Parse error")
    }
}

fn main() {
    let stdin = std::io::stdin();
    solve(Scanner::new(stdin.lock()));
}

fn solve<R: std::io::BufRead>(mut sc: Scanner<R>) {
    let n = sc.get();
    let k = sc.get();
    let owners: Vec<Vec<usize>> = (0..k).map(|_| {
        let d = sc.get();
        (0..d).map(|_| sc.get()).collect()
    }).collect();

    let mut have = vec![false; n];
    
    for i in 0..k {
        for &a in &owners[i] {
            have[a - 1] = true;
        }
    }

    println!("{}", have.iter().filter(|&&x| !x).count());
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    long long n;
    string s;
    cin >> n;
    while (n)
    {
        n--;
        s += char('a' + n%26);
        n/=26;
    }
    reverse(s.begin(), s.end());
    cout << s;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
long long n,pre,ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		if(x>pre)pre=x;else ans+=pre-x;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main(){
    cout << fixed << setprecision(10);
    while(true){
        double x,h;
        cin >> x >> h;
        if(x == 0 and h == 0) break;
        cout << 2*sqrt(h*h+(x*x)/4)*x + x*x << endl;
    }
    return 0;
}

Measured memory_bytes: 1276
fun main(args: Array<String>) {
    abc146b()
}

private fun cap(value: Long, cap: Long): Long {
    return if (value > cap) value - cap else value
}


fun abc146b() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val answer = s.map { it + n }.map { if (it > 'Z') it - 26 else it }.joinToString("")

    println(answer)
}


Measured memory_bytes: 33652
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

double x[3], y[3];
double len(double x1, double y1, double x2, double y2)
{
    double L = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    return pow(L, 0.5);
}
double calc(double a, double b, double c)
{
    double s = (a + b + c) / 2.0, S = s * (s - a) * (s - b) * (s - c);
    S = pow(S, 0.5);
    return S / s;
}

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

    rep(i, 3) cin >> x[i] >> y[i];
    double a = len(x[0], y[0], x[1], y[1]);
    double b = len(x[0], y[0], x[2], y[2]);
    double c = len(x[1], y[1], x[2], y[2]);
    double r = calc(a, b, c);
    double ans = max({a, b, c}) / (2.0 + max({a, b, c}) / r);
    cout << setprecision(20) << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;
const int mod=1e9+7;
int a[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	int sum=0;
	for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
    int cnt=0;
    double max1=1.0/(4*m)*sum;
    //cout<<max1<<'\n';
    for(int i=1;i<=n;i++)
    {
        if(a[i]>=max1)
            cnt++;
    }
    if(cnt>=m)
    {
        cout<<"Yes"<<'\n';
    }
    else
        cout<<"No"<<'\n';






}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + 7;

#define inc(i, x, y) for (int i = x; i <= y; ++i)
#define dec(i, x, y) for (int i = x; i >= y; --i)
#define gc getchar

bool chkmin(int &x, int y) { return x > y ? x = y, 1 : 0; }
bool chkmax(int &x, int y) { return x < y ? x = y, 1 : 0; }

int rd() {
	int ret = 0; bool fl = 0; char ch = 0;
	while (!isdigit(ch)) fl |= (ch == '-'), ch = gc();
	while (isdigit(ch)) ret = (ret << 1) + (ret << 3) + (ch ^ 48), ch = gc();
	return fl ? -ret : ret;
}

vector<int> e[N];
bool vis[N], g[N];

void dfs(int u) {
    vis[u] = 1;
    inc(i, 0 ,(signed)e[u].size() - 1) {
        int v = e[u][i];
        if (vis[v]) continue;
        dfs(v);
    }
}

int a[N], b[N], l[N], h[N];

int main() {
	int n = rd(), cnt = 0;
	inc(i, 1, n) a[i] = rd(), l[i] = a[i], a[0] ^= a[i];
	inc(i, 1, n) b[i] = rd(), h[i] = b[i], b[0] ^= b[i];
	l[0] = a[0], h[0] = b[0];
	sort(l, l + n + 1), sort(h, h + n + 1);
	inc(i, 0, n) if (l[i] != h[i]) return puts("-1"), 0;
	int z = unique(l, l + n + 1) - l, p = unique(h, h + n + 1) - h;
	inc(i, 0, n) {
		a[i] = lower_bound(l, l + z, a[i]) - l;
		b[i] = lower_bound(h, h + p, b[i]) - h;
	}
	g[a[0]] = g[b[0]] = 1;
	e[a[0]].push_back(b[0]);
	inc(i, 1, n) {
		if (a[i] == b[i]) continue;
		cnt++; 
		g[a[i]] = g[b[i]] = 1;
		e[a[i]].push_back(b[i]);
	}
	inc(i, 0, n) {
		if (g[i] && (vis[i] == 0)) 
			dfs(i), cnt++;
	}
	printf("%d\n", max(cnt - 1, 0));
}

Measured memory_bytes: 45440
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll n;
  cin >> n;
  ll res = 0;
  for(ll x=1;x<=n;x++){
    if(x*x>n)break;
    res += x*x;
    ll y_high=n/x;
    res += 2*x*(y_high*(y_high+1)/2-x*(x+1)/2);
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

void solve()
{
	long double a,b,h,m;
	cin>>a>>b>>h>>m;
	long double mang = m*6.0;
	long double hang = h*30.0 + m/2.0;
	long double ans = sqrt(a*a + b*b - 2.0*a*b*cos((hang-mang)*3.14159265359/180.0));
	cout << fixed << setprecision(16) << ans << "\n";
}

int main()
{
	fastIO;
	int t=1;
	// cin>>t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 4168
#include<stdio.h>
int n,m,map[20][20],mark[20],sum;
void dfs(int x)
{
	int i,j=0;
	for(i=1;i<=n;i++)
	{
		if(mark[i]==1)
		j++;
	}
	if(j==n)
	{
		sum++;
		return;
	}
	for(i=1;i<=n;i++)
	{
		if(!mark[i]&&map[x][i]==1)
		{
			mark[i]=1;
			dfs(i);
			mark[i]=0;
		}
	}
	return;
}
int main(void)
{
	int a,b,i,j,k;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(map,0,sizeof(map));
		memset(mark,0,sizeof(mark));
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		map[a][b]=map[b][a]=1;
	}
	mark[1]=1;
	sum=0;
	for(i=2;i<=n;i++)
	{
		if(!mark[i]&&map[1][i]==1)
		{
			mark[i]=1;
			dfs(i);
			mark[i]=0;
		}
	}
	printf("%d\n",sum);
	}
	return 0;
}

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

int main() {
	int N, K; cin >> N >> K;
	int h[100010], dp[100010];
	for(int i=0; i<N; ++i) cin >> h[i];
	dp[0]=0;
	for(int i=1; i<N; ++i){
	    dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
	    for(int j=2; j<=min(i, K); ++j){
	        dp[i]=min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
	    }
	}
	cout << dp[N-1] << endl;
	return 0;
}


Measured memory_bytes: 1024
class UnionFind:
    __slots__ = ["forest"]

    def __init__(self, forest: list):
        self.forest = forest

    def get_root(self, x: int) -> int:
        if self.forest[x] < 0:
            return x
        else:
            self.forest[x] = self.get_root(self.forest[x])
            return self.forest[x]

    def unite(self, x, y) -> None:
        root_x, root_y = self.get_root(x), self.get_root(y)
        if root_x != root_y:
            bigroot, smallroot = \
                (root_x, root_y) if self.forest[root_x] < self.forest[root_y]\
                else (root_y, root_x)
            self.forest[bigroot] += self.forest[smallroot]
            self.forest[smallroot] = bigroot

n, q = map(int, input().split())
uf = UnionFind([-1 for _ in [None]*n])
for _ in [None]*q:
    c, x, y = map(int, input().split())
    if c == 0:
        uf.unite(x, y)
    else:
        print(1 if uf.get_root(x) == uf.get_root(y) else 0)

Measured memory_bytes: 8460
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 200007

std::vector<ll> g[hell];
ll b, w;

void dfs(ll v, ll c, ll p = -1) {
	w += c == 0;
	b += c == 1;

	for (auto zx : g[v]) {
		if (zx != p) {
			dfs(zx, c ^ 1, v);
		}
	}
}

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t, i, x, j, y, 	z, k, n;
	cin >> n;

	if (n % 1000 == 0)	ce(0)
		else ce(1000 - (n % 1000))
		}



Measured memory_bytes: 8352
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(long[]);

    long[] BS;
    BS.length = N + 1;

    foreach (i, a; AS) {
        BS[i+1] = BS[i] + a;
    }

    long[long] memo;
    foreach (b; BS) {
        if (b in memo) {
            ++memo[b];
        } else {
            memo[b] = 1;
        }
    }
    long r;
    foreach (_, n; memo) {
        r += n * (n-1) / 2;
    }
    writeln(r);
}

Measured memory_bytes: 29828
#include <stdio.h>
#include <math.h>

int main(void)
{
	double a,b,c,s,l,h;
	double pi=3.141592653589;

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

	s = a*b*sin(c*pi/180)/2;

	l = a+b+sqrt(a*a+b*b-2*a*b*cos(c*pi/180));

	h = s*2/a;

	printf("%f\n%f\n%f\n",s,l,h);

	return 0;
}

Measured memory_bytes: 648
input_ = input()
operators = input_.split(' ')

stack = []

def operate(b, a, op):
    return {
        '+': a+b,
        '-': a-b,
        '*': a*b,
    }.get(op)

for op in operators:
    if op in ('+','-','*'):
        stack.append(operate(stack.pop(), stack.pop(), op))
    else:
        stack.append(int(op))

print(stack.pop())
        

Measured memory_bytes: 7740
#include<cstdio>
#include<string>
#include<queue>
using namespace std;

int main(){
  priority_queue<int> p;
  int x;
  char com[20];
  while(1){
    scanf("%s", com);
    
    if(com[2]=='s'){
      scanf("%d", &x);
      p.push(x);
    }
    else if(com[2]=='t'){
      printf("%d\n",p.top());
      p.pop();
    }
    else if(com[2]=='d') break;
  }
      
  return 0;
}


Measured memory_bytes: 6520
#include <stdio.h>
int main(void){
    int N, M, C;
    scanf("%d %d %d", &N, &M, &C);
    int B[M];
    int A[N][M];
    int sum[N];
    for (int i = 0; i < M; i++){
        scanf("%d", &B[i]);
    }
    int ans = 0;
    for (int i = 0; i < N; i++){
        sum[i] = 0;
        for (int j = 0; j < M; j++){
            scanf("%d", &A[i][j]);
            sum[i] += A[i][j] * B[j]; 
        }
        if(sum[i] + C > 0){
            ans += 1;
        }
    }
    printf("%d\n", ans);
    return 0; 
}

Measured memory_bytes: 128
X, Y, Z, K = map(int, input().split())
*A, = sorted(map(int, input().split()), reverse=True)
*B, = sorted(map(int, input().split()), reverse=True)
*C, = sorted(map(int, input().split()), reverse=True)
AB = [A[x] + B[y] for y in range(Y) for x in range(X)]
AB.sort(reverse=True)
AB = AB[:K]
XY = len(AB)
ABC = [AB[xy] + C[z] for z in range(Z) for xy in range(XY)]
ABC.sort(reverse=True)
for k in range(K):
    print(ABC[k])


Measured memory_bytes: 161608
#include <iostream>

#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

using std::max;

int
main()
{
  int N;
  cin >> N;
  int count = 0;
  int value = 1;
  for (int n = 1; n <= N; n++)
  {
    int new_count = 0;
    int nn = n;
    while (nn % 2 == 0)
    {
      nn /= 2;
      new_count++;
    }
    if (count < new_count)
    {
      count = new_count;
      value = n;
    }
  }
  cout << value << endl;
  return 0;
}


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

int main(){
    using namespace std;
    unsigned long N, M;
    cin >> N >> M;
    unsigned long ans;
    cin >> ans;
    ans >>= 1;
    unsigned long k = __builtin_ffsl(ans);
    for(unsigned long i{1}, a; i < N; ++i){
        cin >> a;
        a /= 2;
        if(k != __builtin_ffsl(a))return 0 & puts("0");
        (ans /= __gcd(a, ans)) *= a;
        if(ans > M)return 0 & puts("0");
    }
    cout << M / ans - M / (2 * ans) << endl;
    return 0;
}

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

int main() {
    int n, m, sum = 0;
    cin >> n >> m;
    vector<int> arr(n);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
        sum += arr[i];
    }
    sort(begin(arr), end(arr));
    reverse(begin(arr), end(arr));
    int ratio = ceil((double)sum / 4.0 / (double)m);
    bool ans = true;
    for(int i = 0; i < m; i++) {
        if(arr[i] < ratio) {
            ans = false;
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(n);
    vector<int> a(n),b(n),c(n);
    vector<ll> btoa(n),ctob(n),bsum(n+1,0);
    in(a,b,c);
    sort(all(a));
    sort(all(b));
    sort(all(c));
    for(int i=0;i<n;i++){
        btoa[i]=(ll)(lower_bound(all(a),b[i])-a.begin());
        ctob[i]=(ll)(lower_bound(all(b),c[i])-b.begin());
    }
    for(int i=1;i<n+1;i++){
        bsum[i]=bsum[i-1]+btoa[i-1];
    }
    //debug(bsum);
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=(ll)bsum[ctob[i]];
    }
    out(ans);
}

Measured memory_bytes: 6716
#include<iostream>
using namespace std;
#include<vector>
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
vector<int> a(0);
int main(){
  int N, count=0;
  cin >> N;
  rep(i,0,N){
    int temp, prev;
    cin >> temp;
    if(temp != i + 1) count++;
    prev = temp;
    //cout << count << endl;
  }
  if(count <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll=long long;
using namespace std;
//const int INF = 7+(1e+9);
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 / GCD(x, y) * y;
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
vector<vector<char>> vec(12,vector<char>(12));

int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
int dfs(int y,int x){
    vec[y][x]='5';
    for(int i=0;i<4;i++){
        if(x+dx[i]<12&&x+dx[i]>=0&&y+dy[i]<12&&y+dy[i]>=0&&vec[dy[i]+y][dx[i]+x]=='1'){
            dfs(y+dy[i],x+dx[i]);
        }
    }
    return 0;
}
int main(){
    int n,m;
    
    while(cin>>n>>m){
    vector<vector<int>> vec(m,vector<int>(3));
    for(int i=0;i<m;i++){
        int a,b,w;
        cin>>a>>b>>w;
        vec[i][0]=w;
        vec[i][1]=a;
        vec[i][2]=b;
    }
    sort(vec.begin(),vec.end());
    UnionFind tree(n);
    int sum=0;
    for(int i=0;i<m;i++){
        if(!tree.same(vec[i][1],vec[i][2])){
            tree.unite(vec[i][2],vec[i][1]);
            sum += vec[i][0];
        }
    }
    if(sum==0)break;
    cout<<sum<<endl;
    }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define lp(i, x, n) for (int i = x; i < (int)n; ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll long long

int n, m;
pair<int, int> p[51], p2[51];

ll dst(int x, int y, int x1, int y1) {
        return (abs(x - x1) + abs(y - y1));
}
int main() {
        cin >> n>> m;
        lp (i, 0, n) { cin >> p[i].first>> p[i].second; }
        lp (i, 0, m) { cin >> p2[i].first>> p2[i].second; }
        for (int i = 0; i < n; i++) {
                ll mn = 1e12, ind = 0;
                for (int j = 0; j < m; j++) {
                        ll ds = dst(p[i].first, p[i].second, p2[j].first, p2[j].second);
                        if (ds < mn) {
                                mn = ds;
                                ind = j + 1;
                        }
                }
                cout << ind <<endl;
        }
        return 0;
}


Measured memory_bytes: 256
n = int(input())
a,b = map(int,input().split())
p = list(map(int,input().split()))
cnt1 = 0
cnt2 = 0
cnt3 = 0
for i in range(n):
    if p[i]<=a:
        cnt1 += 1
    elif p[i]<=b:
        cnt2 += 1
    else:
        cnt3 += 1
print(min(cnt1,cnt2,cnt3))

Measured memory_bytes: 3064
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iterator>
#include <numeric>
#include <functional>
#include <climits>



using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<string, int> psi;

int main(int argc, char *argv[]){
  size_t n;
  int q;
  cin >> n >> q;
  queue<psi> qu;
  for (size_t i = 0; i < n; i++) {
    string buf;
    int bufi;
    cin >> buf >> bufi;
    qu.push(psi(buf, bufi));
  }
  int now = 0;
  while(qu.size() > 0){
    psi buf = qu.front(); qu.pop();
    if(buf.second <= q){
      now += buf.second;
      cout << buf.first << " " << now << endl;
    } else{
      now += q;
      qu.push(psi(buf.first, buf.second-q));
    }
  }

  return 0;
}

Measured memory_bytes: 4412
from collections import deque
from itertools import chain, combinations
import json
import numpy as np


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

    l = all((a % 5 == 0 or a % 3 == 0) for a in A if a % 2 == 0)

    print('APPROVED' if l else 'DENIED')


if __name__ == "__main__":
    main()


Measured memory_bytes: 21100
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Sun Dec  9 21:32:52 2018
//
package main

import "fmt"

func main() {
	var S, T string
	fmt.Scan(&S, &T)

	if S == T {
		fmt.Println("Yes")
		return
	}

	for i := 1; i < len(S); i++ {
		if S[i:len(S)]+S[0:i] == T {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
	return
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}

int main() {

	ll n, k;
	cin >> n;

	vector<ll> a(n);
	ll tot = 0;
	rep(i, n) {
		cin >> a[i];
		tot += a[i];
	}

	sort(a.begin(), a.end(), greater<>());

	ll i = 0, ans = 1;

	while (a[i] <= (tot - a[i]) * 2) {
		tot -= a[i];
		ans++;
		i++;
	}

	cout << ans;

	return 0;
}


ll gcd(ll a, ll b) {
	if (a % b == 0)return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

Measured memory_bytes: 8792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
using static CS_Contest.Utils;

namespace CS_Contest {
	using Li = List<int>;
	using LLi = List<List<int>>;
	class Program {
        static void Main(string[] args) {
			new Calc().Solve();
			return;
        }

		private class Calc {
			public void Solve() {
				int N = ReadInt();
				Li s = new Li();
				REP(N, x => s.Add(ReadInt()));
				long sum = s.Sum();

				if (sum % 10 == 0) {

					if (s.Any(x => x % 10 != 0)) {
						var f = s.Where(x=>x%10!=0).Min();
						(sum - f).WL();
					}
					else {
						0.WL();
					}
				}
				else {
					sum.WL();
				}
				return;
			}
		}
    }

	
	
    public static class Utils {
		public static int INF = (int)(1e9);
        public static void WL(this object obj) => WriteLine(obj);
        public static void WL(this string obj) => WriteLine(obj);
        public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL());
		public static int ReadInt() => int.Parse(ReadLine());
		public static List<int> ReadInt(char s) => ReadLine().Split(s).Select(int.Parse).ToList();
		public static long ReadLong() => long.Parse(ReadLine());
		public static List<long> ReadLong(char s) => ReadLine().Split(s).Select(long.Parse).ToList();
		public static void REP(int n,Action<int> act) {
			for (int i = 0; i < n; i++) {
				act(i);
			}
		}
		public static void RREP(int n,Action<int> act) {
			for (int i = n-1; i >=0; i--) {
				act(i);
			}
		}
		public static void REP(long n, Action<int> act) => REP((int)n, act);
		public static void RREP(long n, Action<int> act) => RREP((int)n, act);

		public static void Yes() => "Yes".WL();
		public static void No() => "No".WL();

		public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1);

		public class Tree {
			public LLi Graph;
			public Tree(int nodes) {
				Graph = new LLi();
				REP(nodes, x => {
					Graph.Add(new Li());
				});
			}
			public void Add(int x,int y) {
				Graph[x].Add(y);
				Graph[y].Add(x);
			}
		}
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 100;
const int MAX = 1e9 + 1;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int main() {
    int i, j;
    int n;
    map<int, int> mp;
    cin >> n;
    for (i = 0; i < n; ++i) {
        int t;
        cin >> t;
        ++mp[t];
    }
    vector<int> k, v;
    for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
        if (it->second > 1) {
            k.push_back(it->first);
            v.push_back(it->second);
        }
    }
    if (k.size() == 0) {
        cout << 0 << endl;
        return 0;
    }
    if (k.size() == 1) {
        if (v[0] < 4) {
            cout << 0 << endl;
        }
        else {
            cout << (ll)k[0] * (ll)k[0] << endl;
        }
        return 0;
    }
    ll ans = (ll)k[k.size() - 1] * (ll)k[k.size() - 2];
    ll t = -1;
    for (i = k.size() - 1; i >= 0; --i) {
        if (v[i] >= 4) {
            t = k[i];
            break;
        }
    }
    if (t != -1)
        cout << max(ans, t * t) << endl;
    else
        cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

std::vector<long long> all{};

void rec(long long val, bool three, bool five, bool seven, int num) {
    if (val > 1000000000 or val > num) {
        return;
    }
    if (three and five and seven) {
        all.emplace_back(val);
    }
    rec(val * 10 + 3, true, five, seven, num);
    rec(val * 10 + 5, three, true, seven, num);
    rec(val * 10 + 7, three, five, true, num);
}

int main()
{
    int N;
    std::cin >> N;
    rec(0, false, false, false, N);
    std::cout << all.size() << std::endl;
    return 0;
}

Measured memory_bytes: 640
#include <cstdint>
#include <iostream>
#include <string>

int main()
{
    int64_t n,k;
    std::cin >> n >> k;
    auto md = n % k;
    n = md;
    do {
        auto tmp = std::abs(n - k);
        if (tmp < n) {
            n = tmp;
        }
        else {
            break;
        }

    }while(true);
    std::cout << n << std::endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
#include <set>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

//MODを考慮して累乗を計算
ll mpow(ll x, ll n, ll mod) { //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % mod;
		x = x * x % mod;
		n = n >> 1;
	}
	return ans % mod;;
}

//10進数を2進数に変換_20個の要素を持つ配列
vector<int> Convert10to2(ll n) {
	vector<int> ans(20);
	rep(i, 20) {
		ans[i] = n % 2;
		n -= n % 2;
		n /= 2;
	}
	return ans;
}



int main() {
	int n;
	cin >> n;
	string x;
	cin >> x;

	REVERSE(x);

	int s = 0;
	rep(i, n) {
		if (x[i] == '1')s++;
	}
	int s1 = s + 1;
	int s2 = s - 1;
	int flg = 1;
	if (s2 == 0)flg = 0;

	vector<int> a1(n), a2(n);
	rep(i, n) {
		a1[i] = mpow(2, i, s1);
		if (flg)a2[i] = mpow(2, i, s2);
	}

	vector<int> f(200005);
	rep(i, 200005) {
		if (i == 0) {
			f[0] = 0;
			continue;
		}
		if (i == 1) {
			f[1] = 1;
			continue;
		}
		auto z = Convert10to2(i);
		int sum = 0;
		rep(j, z.size()) {
			sum += z[j];
		}
		f[i] = f[i % sum] + 1;
	}

	int sum1 = 0, sum2 = 0;
	rep(i, n) {
		if (x[i] == '0') continue;
		sum1 += a1[i];
		sum1 = sum1 % s1;
		if (flg) sum2 += a2[i];
		if (flg) sum2 = sum2 % s2;
	}

	rrep(i, n) {
		if (x[i] == '0') {
			int ans = sum1;
			ans += a1[i];
			ans = ans % s1;
			cout << f[ans] + 1 << endl;
		}
		else {
			if (flg) {
				int ans = sum2;
				ans -= a2[i];
				if (ans <= 0) {
					ans += s2;
				}
				ans = ans % s2;
				cout << f[ans] + 1 << endl;
			}
			else {
				cout << 0 << endl;
			}
		}
	}
}








Measured memory_bytes: 6088
N,M=map(int,input().split())
s=[list(map(int,input().split()))[1:] for m in range(M)]
p=list(map(int,input().split()))
count=0
for i in range(1<<N):
    for m in range(M):
        switch=0
        for j in range(N):
            if (i>>j)&1 and j+1 in s[m]:
                switch+=1
        if switch%2!=p[m]:
            break
    else:
        count+=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

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

    long double a, b;
    while (cin >> a >> b)
    {
        cout << (long double)a / 3.305785 * b << endl;
    }
    return 0;
}


Measured memory_bytes: 3304
n = int(input());
a = input().split(" ");
x = int(a[0]);
y = 0;
for i in range(1,n) :
	y += int(a[i]);

ans = abs(x - y);
for i in range(1,n-1) :
	x += int(a[i]);
	y -= int(a[i]);
	if abs(x - y) < ans :
		ans = abs(x - y);
print(ans);

Measured memory_bytes: 19068
n = int(input())
x = list(map(int, input().split()))
mid = sum(x)//n
mid2 = mid + 1
ans = 0
ans2 = 0
for i in range(n):
    ans += (x[i] - mid) ** 2
    ans2 += (x[i] - mid2) ** 2
print(min(ans, ans2))

Measured memory_bytes: 3060
H, W = map(int, input().split())
art = []
ansflag = 1
for i in range(H):
    art.append(input())
for i in range(H):
    for j in range(W):
        if art[i][j] == "#":
            flag = 0
            for a in [1, -1]:
                try:
                    if art[i][j+a] == "#":
                        flag = 1
                except IndexError:
                    pass
                try:
                    if art[i+a][j] == "#":
                        flag = 1
                except IndexError:
                    pass
            if flag == 0:
                ansflag = 0
if ansflag == 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }




void solve(){
    ll a,b;
    cin>>a>>b;
    if(a<=b){
        rep(i,b) cout<<a;
        cout<<endl;
    }
    else{
        rep(i,a) cout<<b;
        cout<<endl;
    }
    

}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    
     

    solve(); 


    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	ll K; cin >> K;
	vi A(N);
	REP(i,N) {
		cin >> A[i];
		--A[i];
	}

	int h = 1;
	while (((ll)1 << h) <= K) ++h;
	vvi parents(h, vi(N));
	REP(i,N) {
		parents[0][i] = A[i];
	}
	REP(i,h-1) {
		REP(j,N) {
			parents[i+1][j] = parents[i][parents[i][j]];
		}
	}
	int current = 0;
	REP(i,h) {
		if (K & ((ll)1 << i)) {
			current = parents[i][current];
		}
	}
	cout << current + 1 << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 51708
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <math.h>
#include <map>
#include <numeric>
#include <stack>
#include <queue>
#include <functional>
#include <stdio.h>
#include <queue>
#define ll long long
#define pl pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define vvvb vector<vector<vector<bool> > >
#define rep(i,a) for(ll i = 0;i<a;++i)
#define rep1(i,a) for(ll i = 1;i<a;++i)
#define rrep(i,a) for(ll i = a;i>=0;--i)
#define mod 1000000007
#define inf 10010010010
using namespace std;

//O(logB)
ll mpow(ll a, ll b, ll m){
	if (!b) return 1 % m;
	if (b == 1) return a % m;
	if (b % 2) return (a*mpow(a, b - 1, m)) % m;
	else return mpow((a*a) % m, b / 2, m) % m;
}

int main(){
    ll h,w; cin>>h>>w;
    //0:siro 1:kuro
    vvl gameMap(h,vl(w,0));
    rep(i,h) rep(j,w) {
        char c; cin>>c;
        if(c == '.') gameMap[i][j] = 0;
        else gameMap[i][j] = 1;
    }
    queue<pair<ll,ll> > q;
    q.push(make_pair(0,0));
    vvl mindist(h,vl(w,inf));
    vvb table(h,vb(w,false));
    table[0][0] = true;
    if(gameMap[0][0] == 1){
        mindist[0][0] = 1;
    }else{
        mindist[0][0] = 0;
    }
    while(!q.empty()){
        pair<ll,ll> now = q.front();
        q.pop();
        
        ll i = now.first;
        ll j = now.second;
        
        ll canddist = inf;
        if(i > 0){
            if(gameMap[i][j] == 1){
                if(gameMap[i][j] == gameMap[i-1][j]){
                    canddist = min(canddist,mindist[i-1][j]);
                }
                else{
                    canddist = min(canddist,mindist[i-1][j]+1);
                }
            }
            else{
                canddist = min(canddist,mindist[i-1][j]);
            }
        }
        if(j > 0){
            if(gameMap[i][j] == 1){
                if(gameMap[i][j] == gameMap[i][j-1]){
                    canddist = min(canddist,mindist[i][j-1]);
                }
                else{
                    canddist = min(canddist,mindist[i][j-1]+1);
                }
            }
            else{
                canddist = min(canddist,mindist[i][j-1]);
            }
        }
        mindist[i][j] = min(mindist[i][j],canddist);
        if(i<h-1 && !table[i+1][j]){
            q.push(make_pair(i+1,j));
            table[i+1][j] = true;
        }
        if(j < w-1 && !table[i][j+1]){
            q.push(make_pair(i,j+1));
            table[i][j+1] = true;
        }
    }
    cout<<mindist[h-1][w-1]<<endl;
	return 0;
}


Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

//50142488

fn main() {
    let n: i32 = read();
    let k: i32 = read();
    let vec: Vec<i32> = (0..n).map(|_| read()).collect();

    let mut min: i32 = <i32>::max_value();

    if n == k {
        let left: usize = 0;
        let right: usize = (n-1) as usize;
        let from_left = vec[left].abs() + (vec[right] - vec[left]).abs();
        let from_right = vec[right].abs() + (vec[left] - vec[right]).abs();

        let each_min = cmp::min(from_left, from_right);
        min = cmp::min(each_min, min);
    } else {
        for i in 0..n-k+1 {
            let left: usize = i as usize;
            let right: usize = (i + k - 1) as usize;
            let from_left = vec[left].abs() + (vec[right] - vec[left]).abs();
            let from_right = vec[right].abs() + (vec[right] - vec[left]).abs();

            let each_min = cmp::min(from_left, from_right);
            min = cmp::min(each_min, min);
        }
    }
    println!("{}", min);
}

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

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 4352
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    a, b, c = gets.chomp.split.map(&:to_i)

    if a == b
      puts c
    elsif a == c
      puts b
    else
      puts a
    end
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2172
#include <iostream>

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

    int ret = 1;
    for (;;) {
        const int tmp = ret * 2;
        if (tmp > N) {
            break;
        } else {
            ret = tmp;
        }
    }

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


Measured memory_bytes: 256
N=int(input())
W=list(map(int,input().split()))
sam=0
j=0
X=sum(W[i] for i in range(N))
while sam<=X/2:
	sam=sam+W[j]
	j=j+1
print(min((sam*2-X),(X-sam*2+W[j-1]*2)))

Measured memory_bytes: 3064
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	int n;
	string s;

	cin >> n >> s;
	//bool flag = false;
	int cnt = 0;
	for (int i = 0; i < s.length() - 2; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' &&s[i + 2] == 'C') {
	//		flag = true;
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
H,W,K = map(int,input().split())

c = []
ans = 0

for i in range(H):

    tmp =list(input())
    c.append(tmp)

for i in range(2**H):

    for j in range(2**W):

        now = 0
        for x in range(H):
            for y in range(W):

                if 2**x & i > 0 and 2**y & j > 0:
                    if c[x][y] == "#":
                        now += 1

        if now == K:
            ans += 1

print (ans)


Measured memory_bytes: 9184