akhauriyash/Code-Regression huggingface dataset:
N,M,K=map(int, input().split())

MOD=998244353

ans=0
temp2=1
#temp4=(M-1)**(N-1)%MOD

def getInvs(n, MOD):
  invs = [1] * (n+1)
  for x in range(2, n+1):
    invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
  return invs

invs = getInvs(max(N+3,M-1), MOD)

Vec=[0]*N
#inv=1
#for i in range(MOD-2):
#  inv*=M-1
#  inv%=MOD

'''
for i in range(K+1):
  if i == 0:
    temp1=M
    temp1*=(M-1)**(N-1)%MOD
    temp1%=MOD
    ans+=temp1*temp2%MOD
    #print(cmb)
  else:
    temp1*=invs[M-1]%MOD
    temp2*=(N-i)*invs[i]
    temp2%=MOD
    ans+=temp1*temp2%MOD
    cmb=cmb*(N-i-1)*i*invs[i]%MOD
    #print(cmb)
'''
for i in range(N):
  if i == 0:
    temp1=M
    Vec[N-i-1]=temp1
  else:
    temp1*=(M-1)*(N-i)
    temp1*=invs[i]
    temp1%=MOD
    Vec[N-i-1]=temp1


ans=sum(Vec[:K+1])

print(ans%MOD)


Measured memory_bytes: 26100
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n; cin >> n;
    int cnt = -1;

    int tmp = 1;

    rep(i,7){
        tmp *= 2;
        cnt++;
        if(tmp > n) break;
    }

    int ans =1;

    rep(i,cnt) ans*=2;

    cout << ans << endl;
}

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

#define DIV 1000000007

long long mypow(long long k, long long n) {
	long long temp = 1;

	k = k % DIV;
	while (n) {
		if (n % 2) temp = temp * k % DIV;
		k = k * k % DIV;
		n = n / 2;
	}
	return temp % DIV;
}

long long cmb(long long n, long long r) {
	long long x = 1, y = 1, y_inv;
	long long min;

	if (n - r > r) min = r;
	else min = n - r;
	for (long long i = 0; i < min; i++) {
		x = x * (n - i) % DIV;
		y = y * (i + 1) % DIV;
	}
	y_inv = mypow(y, DIV - 2);
	return x * y_inv % DIV;
}

int main(void) {
	long long n, a, b;
	long long ans ;

	scanf("%lld %lld %lld", &n, &a, &b);
	ans = mypow(2, n) - 1;
	//printf("%lld\n", ans);

	ans = (ans - cmb(n, a));
	if (ans < 0)ans = (ans + DIV);
	//printf("%lld\n", ans);

	ans = (ans - cmb(n, b)) ;
	if (ans < 0)ans = (ans + DIV);
	//printf("cmb(n,b)=%lld\n", cmb(n, b));

	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		
		int W,H,x,y,r;
		
		Scanner sc = new Scanner(System.in);
		
		W = sc.nextInt();
		H = sc.nextInt();
		x = sc.nextInt();
		y = sc.nextInt();
		r = sc.nextInt();
		
		if(x + r > W || x - r < 0){
			System.out.println("No");
		}
		else if(y + r > H || y - r < 0){
			System.out.println("No");
		}
		else if(x > W || y > H){
			System.out.println("No");
		}
		else{
			System.out.println("Yes");
		}


	}

}

Measured memory_bytes: 26396
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>

using namespace std;
int n,m;
int d[101][2];
int inf = 1111111111;
vector<pair<int,int> > g[101][2];
void dijkstra(int s){
  priority_queue<pair<pair<int,int>,int>,vector<pair<pair<int,int>,int> >,greater<pair<pair<int,int>,int> > >que;
  fill((int *)d,(int *)d+101*2,inf);
  d[s][0] = 0;
  que.push(make_pair(make_pair(0,s),0));

  while(!que.empty()){
    pair<pair<int,int>,int> p = que.top();que.pop();
    int v = (p.first).second;
    for(int i = 0;i<g[v][0].size();i++){
      pair<int,int> e = g[v][0][i];
      if(d[e.first][p.second] > d[v][p.second] + e.second){
	d[e.first][p.second] = d[v][p.second] + e.second;
	que.push(make_pair(make_pair(d[e.first][p.second],e.first),p.second));
      }
    }
      //?????¶???
      //e.second???0
    for(int i = 0;p.second != 1 && i<g[v][1].size();i++){
      pair<int,int> e = g[v][1][i];
      if(e.second == 0 && p.second != 1 && d[e.first][p.second+1] > d[v][p.second] + e.second){
	d[e.first][p.second+1] = d[v][p.second] + e.second;
	que.push(make_pair(make_pair(d[e.first][p.second+1],e.first),p.second+1));
    
      
      }
    }
    
  }

}
int main(){
  while(cin>>n>>m){
    if(n==0&&m==0)
      break;
    for(int i = 0;i<n;i++)
      for(int j = 0;j<2;j++)
	g[i][j].clear();
    for(int i = 0;i<m;i++){
      int a,b,c;
      cin>>a>>b>>c;
      a--;b--;
      g[a][0].push_back(make_pair(b,c));
      g[b][0].push_back(make_pair(a,c));
    }
    for(int i = 0;i<n;i++){
      for(int j = 0,e=g[i][0].size();j<e;j++){
	pair<int,int> tmp = g[i][0][j];
	for(int k = 0;k<g[tmp.first][0].size();k++){
	  pair<int,int>t = g[tmp.first][0][k];
	  if(t.second==0)
	    continue;
	  g[i][1].push_back(make_pair(t.first,0));
	}
      }
    }
    dijkstra(0);
    int ans = min(d[n-1][0],d[n-1][1]);
    /*
    for(int i = 0;i<n;i++){
      for(int j = 0;j<2;j++){
	cout<<d[i][j]<<" ";
      }
      cout<<endl;
    }
    */
    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N; cin >> N;
    vector<int> P(N),Q(N),R(N);
    for (int i=0;i<N;i++) cin >> P[i];
    for (int i=0;i<N;i++) cin >> Q[i];
    for (int i=0;i<N;i++) R[i] = i+1;
    int p,q;
    int cnt = 0;
    do
    {
        if (P==R) p = cnt;
        if (Q==R) q = cnt;
        cnt++; 
    } while (next_permutation(R.begin(),R.end()));
    cout << abs(p-q) << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List

main=do
    a<-getLine
    b<-getLine
    putStrLn $ cmp a b
cmp a b
    | length a < length b = "LESS"
    | length a > length b = "GREATER"
    | a < b = "LESS"
    | a > b = "GREATER"
    | True = "EQUAL"

Measured memory_bytes: 380
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
#include <bitset>
#include <queue>
using namespace std;

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007


signed main(){

	int N, x;
	cin >> N >> x;
	bool hanten = false;
	if (x > N){
		hanten = true;
		x = 2*N - x;
	}
	if (x == 1){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;

	int a[223456] = { 0 };
	a[N] = x;
	a[N - 1] = 1;
	for (int i = N + 1; i <= 2*N-1; i++){
		a[i] = i;
	}
	for (int i = 1; i <= N - 2; i++){
		if (i + 1 < x) a[i] = i + 1;
		else a[i] = i + 2;
	}

	if (hanten){
		for (int i = 1; i <= 2*N-1; i++)
			a[i] = 2*N - a[i];
	}
	for (int i = 1; i <= 2*N-1; i++)
		cout << a[i] << endl;


	return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long int ll;
#define MOD (1000000007);
#define INF (2e9)



int main(void){
	int n;
	cin>>n;
	int *a=new int[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	int memo=a[0];
	int count=1;
	for(int i=1;i<n;i++){
		if(memo!=a[i]){
			count++;
			memo=a[i];
		}
	}
	cout<<(count+1)/2*2-1<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())

#define dbn cerr << "\n"
#define dbg(x) cerr << #x << " : " << (x) << " "
#define dbs(x) cerr << (x) << " "

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

template <class T>
void debug(T a, T b) {
    cerr << "[";
    for (T i = a; i != b; ++i) {
        if (i != a) cerr << ", ";
        cerr << *i;
    }
    cerr << "]\n";
}

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

    int n, x;
    cin >> n >> x;

    if (n == 1) {
        cout << "Yes\n";
        cout << 1 << "\n";
        return 0;
    }

    if (n == 2) {
        if (x == 2) {
            cout << "Yes\n";
            cout << "1\n2\n3\n";
        } else {
            cout << "No\n";
        }
        return 0;
    }

    if (x == 1 or x == 2 * n - 1) {
        cout << "No\n";
        return 0;
    }

    vi mark(2 * n, false);
    deque <int> q;
    if (x == 2 * n - 2) {
        q.pb(x - 1);
        q.pb(x);
        q.pb(x + 1);
        q.pb(x - 2);
        for (int y = x - 2; y <= x + 1; ++y) {
            mark[y] = true;
        }
    } else {
        q.pb(x + 1);
        q.pb(x);
        q.pb(x - 1);
        q.pb(x + 2);
        for (int y = x - 1; y <= x + 2; ++y) {
            mark[y] = true;
        }
    }

    forn (i, 1, 2 * n) {
        if (!mark[i]) {
            if (sz(q) & 1) {
                q.push_front(i);
            } else {
                q.pb(i);
            }
        }
    }
    assert(sz(q) == 2 * n - 1);
    cout << "Yes\n";
    rep (i, sz(q)) {
        cout << q[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)

int main() {
  ll n; cin >> n;
  vector<ll> A(n);
  rep(i,n) cin >> A[i];
  
  sort(A.rbegin(),A.rend());
  ll ans = A[0];
  
  if(n%2==0){
    for(ll i=1; i<n/2; i++){
      ans += A[i]*2;
    }
  }
  if(n%2==1){
    for(ll i=1; i<n/2; i++){
      ans += A[i]*2;
    }
    ans += A[n/2];
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4820
def main():
  s=str(input())
  l=len(s)
  ans=0
  
  for i in range(2**(l-1)):
    j=bin(i)[::-1]
    t=s
    c=1
    for k in j:
      if k=="1":
        ans+=int(t[-c:])
        t=t[:-c]
        c=1
      else:
        c+=1
    else:
      ans+=int(t)
    
  print(ans)
  
  
if __name__=="__main__":
  main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{ 
    cool;
    int n,i,cnt=0;
    cin>>n;
    int a[n+1];
    for(i=1;i<=n;i++)
    {
    	cin>>a[i];
    	if(i!=a[i])
    	cnt++;
	}
	if(cnt==0||cnt==2)
	cout<<"YES";
	else
	cout<<"NO";
	return 0;
}

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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    sort(A.rbegin(), A.rend());
    ll ans = 0;
    for ( int i = 1; i < N; i++ ) {
        ans += A[i/2];
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		System.out.println(strArr[1] + strArr[0]);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


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

using namespace std;

int n, m;

int main() {
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            string s;
            cin >> s;
            if(s[0] == 's' && s[1] == 'n' && s[2] == 'u' && s[3] == 'k' && s[4] == 'e') {
                cout << (char)('A' + j - 1) << i << "\n";
            }
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << (a + b) / 2 + (a + b) % 2;
}


Measured memory_bytes: 256
# coding=utf-8
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for coin500 in range(A + 1):
 for coin100 in range(B + 1):
  for coin50 in range(C + 1):
   if coin50 * 50 + coin100 * 100 + coin500 * 500 == X:
    cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include<iostream>
#include <algorithm>
#include<stdio.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include<vector>

using namespace std;
#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define Fs first
#define Sc second
#define endl "\n"
#define MOD 1000000007
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long int lli;

int main()
{
    int n,m;
    cin>>n>>m;
    int pen[n];
    bool ac[n];
    for(int i=0;i<n;++i)
    {
        ac[i]=false;
        pen[i]=0;
    }
    int p;
    string s;
    for(int i=0;i<m;++i)
    {
        cin>>p>>s;
        p=p-1;
        if(!ac[p])
        {
            if(s=="AC")
                ac[p]=true;
            else
                pen[p]++;
        }
    }
    int sum=0,cnt=0;
    for(int i=0;i<n;++i)
    {
        if(ac[i])
        {
            cnt++;
            sum+=pen[i];
        }
    }
    cout<<cnt<<" "<<sum<<endl;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int main(){
    int n, m;
    cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2<< endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define	REP(i,n) for(int i = 0;	i < (int)(n); i++)
typedef	long long ll;

int main() {
  int K, X;
  cin>>K>>X;
  int left = X-(K-1);
  int right = X+(K-1);
  for(int i = left; i <= right;	i++) cout << " " << i;
  cout << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <climits>

void testprint(std::vector<long long> & input)
{
    int size = input.size();
    for(int i = 0; i < size ; i ++)
    {
        std::cout<<input[i]<<std::endl;
    }
}

long long min_search(std::vector<long long> & input)
{
    int size = input.size();

    long long min = LLONG_MAX;

    for(int i = 0 ; i < size ; i ++)
    {
        if(input[i] <= min)
        {
            min = input[i];
        }
    }

    return min;
}

int main(void)
{

int N;
int sub;
std::cin>> N ;

if( N <= 111)
{
    std::cout<<"111"<<std::endl;
}
else if (N <= 222)
{
    std::cout << "222" << std::endl;
}
else if (N <= 333)
{
    std::cout << "333" << std::endl;
}
else if (N <= 444)
{
    std::cout << "444" << std::endl;
}
else if (N <= 555)
{
    std::cout << "555" << std::endl;
}
else if (N <= 666)
{
    std::cout << "666" << std::endl;
}
else if (N <= 777)
{
    std::cout << "777" << std::endl;
}
else if (N <= 888)
{
    std::cout << "888" << std::endl;
}

else if (N <= 999)
{
    std::cout << "999" << std::endl;
}

return 0;
}

Measured memory_bytes: 256
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <iostream>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
int main() {
    ll n,k;
    cin >> n >> k;
    ll a[n + 1];
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll firstvisit[n + 1];
    for (int i = 1; i <= n; i++) {
        firstvisit[i] = -1;
    }
    firstvisit[1] = 0;
    ll i = a[1];
    ll count = 1;
    while(firstvisit[i] < 0) {
        firstvisit[i] = count;
        i = a[i];
        count++;
    }
    ll cycle = count - firstvisit[i];
    if (k <= firstvisit[i]) {
        ;
    }
    else {
        k = (k - firstvisit[i]) % cycle + firstvisit[i];
    }
    int j = 1;
    for (int i = 1; i <= k; i++) {
        j = a[j];
    }
    cout << j;
    return 0;
}

Measured memory_bytes: 6760
n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]

xh.sort()

ends = [None] * n
start = 0
# loop = 0
d2 = 2 * d
for base in range(n):
    while True:
        if start >= n:
            break

        x = xh[start][0]
        # loop += 1
        if x > xh[base][0] + d2:
            # start -= 1 # in range
            break
        start += 1
    # for start, (x, _) in enumerate(xh[start:], start):
    #     loop += 1
    #     if x > xh[base][0] + 2 * d:
    #         # start -= 1 # in range
    #         break
    # else:
    #     start = n
    ends[base] = start
#     print(start)
# print(ends)
# print(loop, "loop")

cnt = [0] * (n + 1)

hist = 0
ans = 0
for i, end in enumerate(ends):
    hist += cnt[i]
    atk = (max(0, xh[i][1] - hist * a) + a - 1) // a
    # print(atk, "atk", hist, end=" ")
    ans += atk
    hist += atk

    cnt[i] += atk
    cnt[end] -= atk
    # print(":", cnt)

print(ans)
# print(cnt)
#
# import functools
# import operator
# print(functools.reduce(operator.add, cnt[:-1]), ans)


Measured memory_bytes: 86744
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        for( int i = 1; i <= 9; i++ ) {
            for( int j = 1; j <= 9; j++ ) {
                System.out.println( String.format("%dx%d=%d", i, j , i * j) );
            }
        }
    }
}



Measured memory_bytes: 24712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define MM 1e9

int A1,A2;
char S[4];

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

void input() {
    cin >> S[0];
    A1 = ctoi(S[0]) *10;
    cin >> S[1];
    A1 += ctoi(S[1]);
    cin >> S[2];
    A2 = ctoi(S[2]) *10;
    cin >> S[3];
    A2 += ctoi(S[3]);
}

bool check(int aa, int low, int high) {
    if ( low <= aa && aa <= high) return true;
    else return false;
}

void solve(){
    bool A1_YY,A1_MM,A2_YY,A2_MM;
    A1_YY = check(A1,0,99);
    A1_MM = check(A1,1,12);
    A2_YY = check(A2,0,99);
    A2_MM = check(A2,1,12);

    if (A1_YY && A1_MM && A2_YY && A2_MM) cout << "AMBIGUOUS" << endl;
    else if (A1_YY && A2_MM) cout << "YYMM" << endl;
    else if (A1_MM && A2_YY) cout << "MMYY" << endl;
    else cout << "NA" << endl;

}


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

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node x, int k){
  while(x != NIL && k != x->key){
    if(k < x->key) x = x->left;
    else x = x->right;
  }
  return x;

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;
  }

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
    else if(strcmp(com,"print")){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 20496
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
t = 1900 * M + 100 * (N - M)
r = 1 - (1/2) ** M
ans = t * ((1/2) ** M) * (1/(1 - r) ** 2)
print(int(ans)) 

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;

long long pow_mod(long long x, long long n){
    long long ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

int main(){
    long long n,a,b;
    cin >> n >> a >> b;
    long long ans = pow_mod(2,n);
    ans += mod-1;
    ans %= mod;
    long long x=1;
    for(int i=1; i<=a; i++){
        x *= n+1-i;
        x %= mod;
        x *= pow_mod(i,mod-2);
        x %= mod;
    }
    ans += mod-x;
    ans %= mod;
    for(int i=a+1; i<=b; i++){
        x *= n+1-i;
        x %= mod;
        x *= pow_mod(i,mod-2);
        x %= mod;
    }
    ans += mod-x;
    ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import math
n = int(input())
t = 0
x = 0
y = 0
txy = []
for i in range(n):
    ti, xi, yi = list(map(int, input().split()))
    txy.append((ti, xi, yi))

for ti, xi, yi in txy:
    if abs(xi - x) + abs(yi - y) > abs(ti - t):
        print("No")
        exit()
    elif (abs(xi - x) + abs(yi - y) - abs(ti - t)) % 2 != 0:
        print("No")
        exit()
    else:
        t = ti
        x = xi
        y = yi
print("Yes")


Measured memory_bytes: 22580
#include <iostream>
#include <utility>
#include <cstdio>
#include <cmath>
#include <climits>
using namespace std;

//---- Print a Frame
int main(){
    int H,W;
    while(1){
        scanf("%d %d", &H, &W);
        if(H==0 && W==0){break;}
        for(int i=0; i<H; i++){
            if(i==0 || i==H-1){
                for(int j=0; j<W; j++){
                    printf("#");
                }
            }
            else{
                for(int j=0; j<W; j++){
                    if(j==0 || j==W-1){
                        printf("#");
                    }
                    else{
                        printf(".");
                    }
                }
            }
            
            printf("\n");
        }
        printf("\n");
    }
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N , a , b , c , d;
  cin >> N ;
 
a = N/1000;
b = (N%1000)/100;
c = (N%100)/10;
d = N%10;

  if ((a==b && b==c)||(b==c && c==d) ){
    cout <<"Yes" << endl;
    }else {
    cout << "No" << endl;
    }
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define ll long long
#define re return
#define mp map<int,int>
using namespace std;
int main() {
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	if(w/2==x&&h/2==y)
		cout<<fixed<<setprecision(6)<<w*h/2<<" 1";
	else cout<<fixed<<setprecision(6)<<w*h/2<<" 0";
	re 0;
}


Measured memory_bytes: 256
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]


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

kb = format(K, 'b')[::-1]
l = len(kb)

ab = [""]*(N)
for i in range(N):
    ab[i] = format(A[i], 'b').zfill(l)[::-1]

res = 0
for i in reversed(range(l)):
    cnt = 0
    for e in ab:
        if e[i] == '0':
            cnt += 1

    if cnt > N // 2 and res + 2 ** i <= K:
        res += 2 ** i


ans = 0
for e in A:
    ans += res ^ e
print(ans)


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

int main()
{
	const long long int z = 1e18;
	long long int n,ans=1;
	cin >> n ;
	vector<long long int> a(n);
	for (long long int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == 0)
		{
			cout << "0";
			return 0;
		}
	}
	for (long long int i = 0; i < n; i++)
	{
		if (a[i] > z/ans)
		{
			cout << "-1";
			return 0;
		}
		ans *= a[i];
	}
	cout << ans;
}

Measured memory_bytes: 4044
def di(cost,start,goal,numV,ii):
  d = [float("inf")]*numV
  used = [False]*numV
  d[start] = 0
  while True:
    v = -1
    for i in range(numV):
      if (not used[i]) and (v ==-1 or d[i]<d[v]):
        v = i
    if v == -1:
      break 
    used[v] = True
    for i in range(numV):
      d[i] =min(d[i],d[v]+cost[v][i])
  
  for i in range(len(goal)):
    shortest_matrix[ii][i] = d[goal[i]]
  return

      
n,m,r = map(int,input().split())
li_r = list(map(int,input().split()))
for i in range(len(li_r)):
  li_r[i] = li_r[i]-1

matrix = [[float("inf")]*n for i in range(n)]
shortest_matrix=[[0]*r for i in range(r)]

for i in range(m):
  a,b,c = map(int,input().split())
  matrix[a-1][b-1]=c
  matrix[b-1][a-1]=c
  
#tree = [[] for i in range(n)]

#for i in range(m):
#  a,b,c = map(int,input().split())
#  tree[a-1].append([b-1,c])
#  tree[b-1].append([a-1,c])

for iii in range(len(li_r)):  
  di(matrix,li_r[iii],li_r,n,iii)

import itertools 
base = [i for i in range(len(li_r))]
li =[]
for i in itertools.permutations(base):
   li.append(i)

ans = float("inf")
for chiten in li:
  tmp_ans = 0
  for j in range(1,len(chiten)):
    tmp_ans = tmp_ans +shortest_matrix[chiten[j]][chiten[j-1]]
  ans = min(ans,tmp_ans)
print(ans)


Measured memory_bytes: 8948
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val k = sc.nextInt()
    println(problem097c(s, k))
}

fun problem097c(s: String, k: Int): String {
    val set = mutableSetOf<String>()
    fun subStringGenerator(current: String, index: Int) {
        set.add(current)
        if (index == s.length - 1) return
        if (current.length > k) return
        if (current.length == 1) {
            subStringGenerator(s[index + 1].toString(), index + 1)
        }
        subStringGenerator(current + s[index + 1], index + 1)
    }
    subStringGenerator(s[0].toString(), 0)
    return set.sorted()[k - 1]
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 


int	F(int H, vector<int> &C, vector<vector<int>> &A) {
	if (C.at(H)>=0)
		return C.at(H);
	int S=INF;
	for (int i=0; i<A.size(); i++)
		if (H<=A.at(i).at(0))
			S=min(S, A.at(i).at(1));
		else 
			S=min(S, A.at(i).at(1)+F(H-A.at(i).at(0), C, A));
	C.at(H)=S;
	return S;
}

int	main() {
	int H, N;
	cin >>H >>N;
	vector<vector<int>> A(N, vector<int> (2, 0));
	vector<int> C(H+1, -1);
	for (int i=0; i<N; i++)
		cin >>A.at(i).at(0) >>A.at(i).at(1);
	cout <<F(H, C, A) <<endl;
	return 0;
}



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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int count = 0;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <=B; j++) {
      int d = X - i * 500 - j * 100;
      if (d >= 0 && d <= C * 50) {
        count += 1;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var N = +o.getValue(0);
    var Ai = o.getArray(1);

    var sorted = Ai.sort(function (a, b) {
        return b - a;
    })

    var score = 0;
    for (let i = 0; i < N; i++) {
        var diff = i === 0 ? -1 : 0 - i % 2;
        var b = Math.ceil(i / 2);
        var index = i - (i - b - diff);
        if (sorted[index]) score += sorted[index];
    }

    return score;
}

Measured memory_bytes: 54240
def comb(n,k,p):
  from math import factorial
  if n<0 or k<0 or n<k:return 0
  if n==0 and k==0:return 1
  a=factorial(n)%p
  b=factorial(k)%p
  c=factorial(n-k)%p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  if b==0:
    return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return (d*d)%p
  else:
    return (a*power_func(a,b-1,p))%p
n,m=map(int,input().split())
mod=10**9+7
d=[]
for i in range(2,int(m**0.5)+1):
  if m%i==0:
    cnt=0
    while m%i==0:
      m//=i
      cnt+=1
    d.append(cnt)
if m>1:
  d.append(1)
ans=1
for k in d:
  ans=(ans*comb(k+n-1,k,mod))%mod
print(ans)

Measured memory_bytes: 112860
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>
using namespace std; 

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int r;
    cin>>r;
    cout<<r*r*3<<endl;
	
    return 0;
}

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

INF = float('inf')
dp = [INF for j in range(2**n)]

dp[0] = 0

for i in range(m):
    a, b = map(int, input().split())
    c = map(int, input().split())

    k = 0
    for ci in c:
        ci -= 1
        k |= (1 << ci)
    for j in range(2**n):
        l = k | j
        dp[l] = min(dp[l], dp[j] + a)

if dp[2**n-1] == INF:
    print(-1)
else:
    print(dp[2**n-1])


Measured memory_bytes: 48860
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}

vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
	fact.resize(n + 5);
	factinv.resize(n + 5);
	inv.resize(n + 5);
	fact.at(0) = fact.at(1) = 1;
	factinv.at(0) = factinv.at(1) = 1;
	inv.at(1) = 1;
	for (ll i = 2; i < n + 5; i++) {
		fact.at(i) = (fact.at(i - 1) * i) % mod;
		inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
		factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
	}

}
ll nCk(ll n, ll k) {
	return (fact.at(n) * ((factinv.at(k) * factinv.at(n - k)) % mod)) % mod;
}
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	rep(i, N) {
		cin >> A.at(i);
	}
	sort(A.begin(), A.end());
	prenCkModp(N);
	ll an = 0;
	for (ll i = 0; i <= N - K; i++) {
		an += (A.at(N - 1 - i) * nCk(N - 1 - i, K - 1)) % mod;
		an -= (A.at(i) * nCk(N - 1 - i, K - 1)) % mod;
		if (an < 0)an += mod*4;
		an %= mod;
	}
	cout << an << endl;
}

Measured memory_bytes: 3328
n = int(input())
a = [int(i) for i in input().split()]
a = [0] + a + [0]
dist = 0

for i in range(1,n+2):
    dist = dist + abs(a[i]-a[i-1])

for i in range(1,n+1):
    ans = dist + abs(a[i+1]-a[i-1]) - (abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))
    print(ans)

Measured memory_bytes: 65260
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
const int N=1e5+10;
int n,k,h[N],dp[N];
int main(){
	scanf("%d%d",&n,&k);
	for(register int i=1;i<=n;i++)scanf("%d",&h[i]);
	memset(dp,127/2,sizeof(dp));dp[1]=0;
	for(register int i=2;i<=n;i++)
		for(register int j=max(i-k,1);j<i;j++)
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
char b[10][10];
void bomb(int c,int d){
  b[c][d] = '0';
  for(int i=1;i<=3;i++){
    if(c+i<9&&b[c+i][d]=='1') bomb(c+i,d);
    if(c-i>0&&b[c-i][d]=='1') bomb(c-i,d);
    if(d+i<9&&b[c][d+i]=='1') bomb(c,d+i);
    if(d-i>0&&b[c][d-i]=='1') bomb(c,d-i);
  }
}
int main(){
  int n,x,y,count=1;
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=1;j<=8;j++){
      for(int k=1;k<=8;k++) cin >> b[j][k];
    }
    cin >> x >> y;
    bomb(y,x);
    cout << "Data " << count << ':' << endl;
    count++;
    for(int j=1;j<=8;j++){
      for(int k=1;k<=8;k++){
	cout << b[j][k];
	if(k==8) cout << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1160
<?php
$N = trim(fgets(STDIN));
$H = explode(" ", trim(fgets(STDIN)));

$ans = 0;
$max = 0;

for ($i = 0; $i <= $N - 1; $i++) {
    if ($H[$i] > $max) {
        $max = $H[$i];
    }
    if ($max <= $H[$i]) {
        $ans++;
    }
}

echo $ans . "\n";

Measured memory_bytes: 4856
n = gets.to_i
f = []#Array.new()
n.times do
  f << gets.split(" ").map(&:to_i)
end
p_i = []#Array.new()
n.times do
  p_i << gets.split(" ").map(&:to_i)
end


part = [0,1].repeated_permutation(10)
ans = []
part.each_with_index do |pa,idx|
  next if idx == 0 #|| idx == 512

  score = 0

  f.each_with_index do |fi,i|
    c = 0
    pa.each_with_index do |bit, j|
      if bit == 1 && fi[j] == 1
        c += 1
      end
    end
    score += p_i[i][c]
  end

#  puts "#{pa} : #{score}"
  ans << score
end

p ans.max

Measured memory_bytes: 3836
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int a, b;
    cin >> a >> b;
    if (a > b) {
        string str;
        for (int i = 0; i < a; i++) {
            str += to_string(b);
        }
        cout << str << endl;
    } else {
        string str;
        for (int i = 0; i < b; i++) {
            str += to_string(a);
        }
        cout << str << endl;
    }

    return 0;
}

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

ll mpow(ll b, ll p) {
  ll res = 1;
  while (p) {
    if (p & 1) {
      res = (res * b) % m;
    }
    p >>= 1;
    b = (b * b) % m;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = mpow(10, n) + mpow(8, n) - 2 * mpow(9, n);
  ans = (ans % m + m) % m;
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3616
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
const int N = 105;
#define singleCase
// #define multipleCase
const int inf = 1e8;
int n,m,dp[N][N];
char grid[N][N];

int dr[] = {0 , 1};
int dc[] = {1 , 0};

bool inside(int r , int c) {
   return r >= 1 && r <= n && c >= 1 && c <= m;
}

int f(int r , int c) {
   if (r == n && c == m) return grid[r][c] == '#';
   int &sol = dp[r][c];
   if (sol != -1) return sol;
   sol = inf;
   for (int i = 0 ; i < 2 ; i++) {
      if (!inside(r + dr[i] , c + dc[i])) continue;
      int nr = r + dr[i], nc = c + dc[i];
      sol = min(sol , f(nr , nc) + (grid[nr][nc] == '.' && grid[r][c] == '#'));
   }
   return sol;
}

void work() {
   memset (dp , -1 , sizeof dp);
   cin >> n >> m;
   for (int i = 1 ; i <= n ; i++) {
      for (int j = 1 ; j <= m ; j++) {
         cin >> grid[i][j];
      }
   }
   printf("%d\n" , f(1 , 1));
   return;
}

int main() {
   #ifdef multipleCase
      int nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   return 0;
}

void in(int &x) {
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-') {
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	  x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 3844
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main() {
    
    int n; cin>>n;
    queue<int> que;
    REP(i,1<<n){
        int t; cin>>t;
        que.push(t);
    }
    
    while(que.size()>1){
        int a=que.front(); que.pop();
        int b=que.front(); que.pop();
        if(a>b)que.push(a-b);
        else if(a<b)que.push(b-a);
        else que.push(a);
    }
    
    cout<<que.front()<<endl;
    
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int a,b,c; cin >> a >> b >> c;
	cout << (a+b >= c? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int i, j;
    int n, m;
    int a[100][100];
    int b[100];
    int c[100];

    for (i = 0; i < 100; i++){
        c[i] = 0;
    }

    scanf("%d %d", &n, &m);

    for (i = 0; i < n; i++){
        for (j = 0; j < m; j++){
            scanf("%d", &a[i][j]);
        }
    }
  
    for (i = 0; i < m; i++){
        scanf("%d", &b[i]);
    }

    for (i = 0; i < n; i++){
        for (j = 0; j < m; j++){
            c[i] += a[i][j] * b[j];
        }
        printf("%d\n", c[i]);
    }

    return 0;
}

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

#define FOR(i, s, e)   for(int i = (s); i < (e); i++)
#define FOR64(i, s, e) for(ll  i = (s); i < (e); i++)
#define ALL(x)         (x).begin(), (x).end()
#define SORT(b, e)     sort((b), (e))
#define REV(b, e)      reverse((b), (e))
#define VSORT(v)       sort((v).begin(), (v).end())
#define VREV(v)        reverse((v).begin(), (v).end())
#define pb(a)          push_back(a)
#define INF            999999999

typedef long long ll;

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

	vector<int> A(N);
	for(int &a : A) cin >> a;

	int odd = 0;
	int even = 0;
	ll sum = 0;

	FOR(i, 0, N){
		sum += A[i];
		if(A[i] % 2 == 0)
			even++;
		else
			odd++;
	}

	if(even == N){
		cout << "second" << endl;
	}
	else{
		cout << "first" << endl;
	}

	return 0;
}



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

int main(){
  int n;
  cin >> n;
  string c;
  cin >> c;
  int t=0;
  rep(i,n){
    if(c[i]=='R')
    t +=1;
  }
  int ans =t;
  rep(i,t){
    if(c[i]=='R')
    ans -=1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3764
<?php

    $s = in();
    if (substr($s, 2, 1) == substr($s, 3, 1) && substr($s, 4, 1) == substr($s, 5, 1)) {
        Yes();
    } else {
        No();
    }
    
    
    /**
    * お手伝い関数さんたち
    */
    function in() {
        return trim(fgets(STDIN));
    }
    function in_int() {
        return (int)in();
    }
    function in_vals() {
        return explode(' ', in());
    }
    function in_ints() {
        return array_map('intval', in_vals());
    }
    function out($s) {
        echo $s . PHP_EOL;
    }
    function yes() {
        out('Yes');
    }
    function no() {
        out('No');
    }
    function factorial($n) { // 階乗
        if ($n > 0) {
            return $n *= factorial($n - 1);
        }
        return 1;
    }
    function is_palindrome($s) {  // 回文か
        return $s == strrev($s);
    }



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

namespace ABC046
{
	class Program
	{
		static void Main()
		{
			bool[] kind = new bool[120];

			List<int> input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();

			foreach(int data in input)
			{
				kind[data] = true;
			}

			Console.WriteLine(kind.Where(x => x).Count());
		}
	}
}


Measured memory_bytes: 3032
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main(void)
{
    char s[100];
  	bool f = false;
    scanf("%s", s);
 	for(int i=0;i<strlen(s);i++){
    	if((i+1)%2==1&&s[i]=='L'){
        	f = true;
        }else if((i+1)%2==0&&s[i]=='R'){
        	f = true;
        }
    }
  	if(f==false){
    	printf("Yes");
    }else{
    	printf("No");
    }
    return 0;
}

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

int main(){
  long long N; cin >> N;
  cout << (N-1) * N / 2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a, b, S, length;
    scanf("%d %d", &a, &b);
    if(a>=1 && b<=100){
        S = a*b;
        length = 2 *(a+b);
        printf("%d %d\n", S, length);
    }
    return 0;
}

Measured memory_bytes: 596
from bisect import bisect_right

n, w = map(int, (input().split()))
lst = [list(map(int, input().split())) for i in range(n)]

sum_v_max = n * 1000
dp = [0] + [float('inf')] * sum_v_max

for i in range(n):
    for j in range(sum_v_max, 0, -1):
        dp[j] = min(dp[j], dp[max(j - lst[i][1], 0)] + lst[i][0])

print(bisect_right(dp, w) - 1)


Measured memory_bytes: 98748
n, m = map(int, input().split())
list_A = [ list(input()) for _ in range(n) ]
list_B = [ list(input()) for _ in range(m) ]
ans = "No"
for i in range(n-m):
    for j in range(n-m):
        cnt = 0
        for k in range(i, i+m):
            for l in range(j, j+m):
                if list_B[k-i][l-j] == list_A[k][l]:
                    cnt += 1
        if cnt == m*m:
            ans = "Yes"

if n == 1 and m == 1:
    if list_A[0][0] == list_B[0][0]:
        ans = "Yes"

print(ans)

Measured memory_bytes: 3188
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int a[1000];

int main() {
    int n, x, m = -1e9 - 1, i;
    long long sum1 = 0, sum2 = 0, ans;
    vector <int> v;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    for (i = 0; i < n; i++) {
        if (a[i] <= 0) {
            if (a[i] > m) {
                m = a[i];
                x = i + 1;
            }
            
            continue;
        }
        
        if (i % 2 == 0) {
            sum1 += a[i];
        } else {
            sum2 += a[i];
        }
    }
    
    if (sum1 == 0 && sum2 == 0) {
        ans = m;
        while (n > x) v.push_back(n--);
        for (i = 1; i < x; i++) v.push_back(1);
    } else {
        int c = 0, l = 0, r = n;
        
        ans = max(sum1, sum2);
        
        if (sum2 > sum1) {
            v.push_back(1);
            l++;
            n--;
        }
        
        if ((r - l) % 2 == 0) {
            v.push_back(n--);
            r--;
        }
        
        while (a[l] <= 0) {
            v.push_back(1);
            v.push_back(1);
            l += 2;
            n -= 2;
        }
        
        while (a[r - 1] <= 0) {
            v.push_back(n--);
            v.push_back(n--);
            r -= 2;
        }
        
        for (i = l; i < r; i += 2) {
            if (a[i] > 0) {
                c++;
            } else {
                v.push_back(c * 2 + 1);
            }
        }
        
        for (i = 1; i < c; i++) v.push_back(2);
    }
    
    printf("%lld\n", ans);
    printf("%d\n", (int)v.size());
    for (i = 0; i < v.size(); i++) printf("%d\n", v[i]);
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;

int main(){

    int x, y;
    cin >> x >> y;
    int ans = 0;
    if(x == 3)  ans += 100000;
    else if(x == 2)  ans += 200000;
    else if(x == 1) ans += 300000;
    if(y == 3)  ans += 100000;
    else if(y == 2)  ans += 200000;
    else if(y == 1) ans += 300000;
    if(x == 1 && y == 1)    ans += 400000;

    cout << ans << endl;
}

Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())
if a+b<=2*c:
  print(a*x+b*y)
else:
  if x>=y:
    total=y*2*c
    if a*(x-y)>=2*c*(x-y):
      total+=2*c*(x-y)
    else:
      total+=a*(x-y)
  else:
    total=x*2*c
    if b*(y-x)>=c*2*(y-x):
      total+=2*c*(y-x)
    else:
      total+=b*(y-x)
  print(total)

Measured memory_bytes: 3064