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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define all(X) (X).begin(), (X).end()
#define sz(X) (int)X.size()

using ll = long long;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

template<typename T>
T power(T x, ll p)
{
    T res = 1;
    while (p)
    {
        if (p & 1) res *= x;
        p >>= 1;
        x *= x;
    }
    return res;
}

template<ll MOD>
struct Mint
{
    ll x;
    Mint(ll x = 0) : x(x % MOD) {};
    Mint inv() const { assert(x != 0); return power(*this, MOD - 2); }
    Mint& operator+=(const Mint& rhs) { x = (x + rhs.x) % MOD; return *this; }
    Mint& operator-=(const Mint& rhs) { x = (x + MOD - rhs.x) % MOD; return *this; }
    Mint& operator*=(const Mint& rhs) { x = (x * rhs.x) % MOD; return *this; }
    Mint& operator/=(const Mint& rhs) { return *this *= rhs.inv(); }
    Mint operator+(const Mint& rhs) const { return Mint(*this) += rhs; }
    Mint operator-(const Mint& rhs) const { return Mint(*this) -= rhs; }
    Mint operator*(const Mint& rhs) const { return Mint(*this) *= rhs; }
    Mint operator/(const Mint& rhs) const { return Mint(*this) /= rhs; }
    bool operator==(const Mint& rhs) const { return x == rhs.x; }
    bool operator<(const Mint& rhs) const { return x < rhs.x; }
};

template<typename T>
class BIT
{
private:
    T op(T x, T y) { return x + y; }
    T inv(T x) { return id - x; }
    int b(int p) { return p & (-p); }
    const int n; const T id;
    vector<T> ft;
    T query(int p)
    {
        T res = id;
        for (int i = p; i >= 1; i -= b(i)) res = op(ft[i], res);
        return res;
    }
public:
    BIT(int n, T id) : n(n), id(id) { ft.assign(n + 1, id); }
    T query(int l, int r) { return op(inv(query(l)), query(r + 1)); }
    void update(int p, T value)
    {
        for (int i = p + 1; i <= n; i += b(i)) ft[i] = op(ft[i], value);
    }
};

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

    constexpr ll MOD = 998244353LL;
    using Mint = Mint<MOD>;

    vector p(n, 0);
    for (int i = 0; i < n; ++i)
    {
        cin >> p[i]; --p[i];
    }

    auto P = Mint(k - 1) / k;

    BIT bit(n, Mint(0));
    BIT cnt(n, 0);

    auto f = [&k](int i) { return max(i + 1 - k, 0); };

    Mint ans = 0;

    for (int i = 0; i < n; ++i)
    {
        auto cur = power(P, f(i));

        ans += cur * bit.query(0, n - 1) / 2;
        ans += Mint(cnt.query(p[i], n - 1)) - cur * bit.query(p[i], n - 1);

        bit.update(p[i], cur.inv());
        cnt.update(p[i], 1);
    }

    cout << ans.x << endl;

    exit(0);
}



Measured memory_bytes: 6776
def init(n):
    global par, rank
    par = [i for i in range(n)]
    rank = [0] * n

def find(x):
    global par
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x, y):
    global par, rank
    x = find(x)
    y = find(y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

def same(x, y):
    return find(x) == find(y)

N, M = map(int, input().split())
init(N)
p = list(map(int, input().split()))
for _ in range(M):
    x, y = map(int, input().split())
    unite(x - 1, y - 1)
ans = 0
for i in range(N):
    if same(i, p[i] - 1):
        ans += 1
print(ans)

Measured memory_bytes: 92720
#include <cstdio>
#include <vector>   
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <random>
#include <ctime>
#include <iomanip>
#include <deque>
#include <queue> 
#include <cmath>
#include <cstring>
#include <cassert>
#include <bitset>
#include <unordered_set>
typedef long long ll;
typedef long double ld;
 
using namespace std;

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);
#endif
    int n;
    scanf("%d", &n);
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    if (a[0]) {
        printf("-1");
        return 0;
    }
    for (int i = 1; i < n; i++) {
        if (a[i] > a[i - 1] + 1) {
            printf("-1");
            return 0;
        }
        b[i - a[i]] = max(b[i - a[i]], a[i]);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
        ans += b[i];
    printf("%lld\n", ans);
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <complex>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef vector<int> vi;

int main() {
	stack<int> S;
	int n;

	while(scanf("%d", &n)!=EOF) {
		if(n>0) S.push(n);
		else {
			printf("%d\n", S.top());
			S.pop();
		}
	}
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int n,m;cin>>n>>m;
    map<int,int>amari;
    map<int,int>equal;
    REP(i,n){
        int a;cin>>a;
      	int d=a%m;
        amari[d]++;
        if(d!=0&&d*2!=m)equal[a]++;
    }
    int ans=0;
    for(auto v:amari){
        if(v.first==0||v.first*2==m)ans+=v.second/2;
        else{
            int d=min(v.second,amari[m-v.first]);
            ans+=d;
            amari[v.first]-=d;
            amari[m-v.first]-=d;
        }
    }
    for(auto v:equal){
      	int d=v.first%m;
        if(amari[d]<2)continue;
      	if(v.second>=amari[d]){
          	ans+=amari[d]/2;
          	amari[d]=0;
          	continue;
        }
        ans+=v.second/2;
        amari[d]-=(v.second/2)*2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 12800
#include<stdio.h>

	int A[100000];

	int partition(int A[],int p,int r){
	int x = A[r-1];
	int i = p,j;
	for(j = p; j<r-1;j++){
	if(A[j] <= x){
	int temp = A[i];
	A[i] = A[j];
	A[j] = temp;
	i++;
	}
	}
	int temp = A[i];
	A[i] = A[r-1];
	A[r-1] = temp;
	 return i;
	}

	int main(){
	  int n,i,ip;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%d",&A[i]);
	}
	ip = partition(A,0,n);
	for(i=0; i<n; i++){
	if(i == ip){
	 printf("[%d]",A[i]);
        }
	else printf("%d",A[i]);
	putchar(i < n -1? ' ' : '\n');
	}
	}




	




Measured memory_bytes: 2104
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int i,j,k,n,m,q;
int tong[2][N],a[2][2];
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;++i)
	{
		scanf("%d",&q);
		++tong[i&1][q];
	}
	for (i=0;i<=1;++i)
		for (j=1;j<=N-5;++j)
			if (tong[i][j]>tong[i][a[i][1]])
			{
				if (tong[i][j]>tong[i][a[i][0]])
					a[i][1]=a[i][0],a[i][0]=j;
				else
					a[i][1]=j;
			}
	if (a[0][0]==a[1][0])
		printf("%d",n-max(tong[0][a[0][0]]+tong[1][a[1][1]],tong[0][a[0][1]]+tong[1][a[1][0]]));
	else
		printf("%d",n-tong[0][a[0][0]]-tong[1][a[1][0]]);
	return 0;
}

Measured memory_bytes: 896
X, Y = map(int,input().split())

T = 0
C = 0

if Y > X * 4:
    print("No")
    exit()

for i in range(X+1):
    T = X - i
    if Y == (T * 4) + (i * 2):
        print("Yes")
        exit()

print("No")

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n, k;
  string s;
  cin >> n >> k >> s;
  vector<int> enc(1, 1);
  for(int i = 1; i < n; ++i)
  {
    if (s[i - 1] == s[i]) enc.back()++;
    else enc.emplace_back(1);
  }

  ll ans = 0;
  bool startWithZero = (s[0] == '0');
  int start_i = startWithZero != (k & 1);

  ll sum = 0;
  if (start_i < enc.size()) sum += enc[start_i];
  for(int i = 1; i <= k; ++i)
  {
    if (start_i - i >= 0) sum += enc[start_i - i];
    if (start_i + i < enc.size()) sum += enc[start_i + i];
  }
  ans = max(ans, sum);
  // cout << start_i << " : " << sum << endl;

  for(int i = start_i + 2; i < enc.size(); i += 2)
  {
    if (i - k - 2 >= 0) sum -= enc[i - k - 2];
    if (i - k - 1 >= 0) sum -= enc[i - k - 1];
    if (i + k - 1 < enc.size()) sum += enc[i + k - 1];
    if (i + k - 0 < enc.size()) sum += enc[i + k];
    // cout << i << " : " << sum << endl;
    ans = max(ans, sum);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct RangeMinQuery{
  P dat[(1<<19)-1];
  int size;

  void init(int n_){
    size=1;
    while(size<n_) size*=2;
    for(int i=0;i<2*size-1;i++)dat[i]=P(INF,INF);
  }

  void update(int k,ll a){
    ll i=k;
    k+=size-1;
    dat[k]=P(a,i);
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }

  P subquery(int a,int b,int k,int l,int r){
    if(r<=a||b<=l)return P(INF,INF);
    if(a<=l&&r<=b)return dat[k];
    else{
      return min(subquery(a,b,k*2+1,l,(l+r)/2),subquery(a,b,k*2+2,(l+r)/2,r));
    }
  }
  
  P query(int a,int b){
    return subquery(a,b,0,0,size);
  }
};

RangeMinQuery sgt;

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

  ll N,M;
  string S;
  cin>>N>>M>>S;
  sgt.init(N+1);
  sgt.update(N,0);
  for(ll i=N-1;i>=0;i--){
    if(S[i]=='1')continue;
    P v=sgt.query(i+1,min(N+1,i+M+1));
    sgt.update(i,v.fi+1);
  }
  {
    P ans=sgt.query(0,1);
    if(ans.fi==INF){
      cout<<-1<<endl;
      return 0;
    }
  }
  vector<ll> res;
  ll crt=0;
  while(crt!=N){
    P p=sgt.query(crt+1,min(N+1,crt+M+1));
    res.push_back(p.se-crt);
    crt=p.se;
  }
  rep(i,res.size())cout<<res[i]<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 9672
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define show(x) cout<<#x<<" "<<x<<" ";
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define ll long long
#define all(A)  A.begin(),A.end()  
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
const int MSIZE = 1e2+5;
const int MOD = 1e9+7;


int arr[MSIZE];
bool dp[(int)(1e5+5)];

int main(){
    FIO
    int n, k; cin>>n>>k;
    f(i,0,n-1)    cin>>arr[i];
    dp[0] = 0;
    f(i,1,k)    {
        dp[i] = 0;
        f(j,0,n-1) {
            if(i>=arr[j] && !dp[i-arr[j]])  { 
                dp[i] = 1;  break;
            }
        }
    }
    cout<<(dp[k]?"First":"Second")<<endl;

 
    return 0;

}
    


Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
	int n, b, f, r, v;
	int mem[4][3][10];


	//initialize
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				mem[i][j][k] = 0;
			}
		}
	}

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		mem[b - 1][f - 1][r - 1] += v;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				printf(" %d", mem[i][j][k]);
			}
			printf("\n");
		}
		if(i<3)printf("####################\n");
	}
	return 0;
}



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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((abs(a-b)<=d&&abs(b-c)<=d )|| abs(a-c)<=d){
    cout << "Yes" << endl;
  } else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int mr[4]={-1,0,0,1};
int mc[4]={0,-1,1,0};
char z[100][100];
int main()
{
    int H,W;
    scanf("%d %d",&H,&W);
    int flag=0;
    for(int i=0;i<H;i++)
    {
        getchar();
        scanf("%s",z[i]);
    }
    for(int i=0;i<H;i++)
    {
        for(int k=0;k<W;k++)
        {
            if(z[i][k]=='#')
            {
                int pp=0;
                for(int p=0;p<4;p++)
                {
                    int nr,nc;
                    nr=i+mr[p];
                    nc=k+mc[p];
                    if(nr>=0 && nc>=0 && nr<H && nc<W)
                    {
                        if(z[nr][nc]=='#')
                            pp=1;
                    }
                }
                if(pp==0)
                    flag=1;
            }
          //  if(flag==1)
          //      printf("%d-%d\n",i,k);
            
        }
        
    }
    if(H==W && H==1 && z[0][0]=='#')
        printf("Yes\n");
    else
    if(!flag)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<string.h>
#include<stdio.h>

struct Process
 {
  char name[100];
  int r;

 };

struct Process Q[1000];

int seisuu;


void enqueue(struct Process x)
 {
  int i;

  for(i = 1; i < seisuu; i++) Q[i]=Q[i+1];


  Q[seisuu]=x;
 }

struct Process dequeue(){ seisuu--;}

int main(){
  int i,q,time=0;
  scanf("%d %d", &seisuu, &q);
  for ( i = 1; i <= seisuu; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].r);
  }
  while(1){
    if(seisuu==0)break;
    if(Q[1].r>q){
      time+=q;
      Q[1].r-=q;
      enqueue(Q[1]);
    }
    else if(Q[1].r<=q){
      time+=Q[1].r;
      printf("%s %d\n",Q[1].name,time);
      enqueue(Q[1]);
      dequeue();
    }
  }
  return 0;
}

Measured memory_bytes: 520
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        Console.WriteLine(int.Parse(Console.ReadLine()) ^ int.Parse(Console.ReadLine()) ^ 1 ^ 2 ^ 3);
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
const int N = 15;

int main()
{
	int a[N]={0};
	for(int i = 0; i <= 9; i++)
	{
		scanf("%d", &a[i]);
	}
	for(int i = 0; i <= 9; i++)
	{
		for(int j = i; j <= 9; j++)
		{
			if(a[i] < a[j])
			{
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	for(int i = 0; i < 3; i++)
	{
		printf("%d\n", a[i]);
	}
	
	return 0;
}


Measured memory_bytes: 2748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int N; cin >> N;
  int count = 0;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    if (a % 2 == 1) count++;
  }
  
  if (count % 2 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<vector>
#include <iostream>
#include<string>
#include <complex>
#include <algorithm>
#include<string>

using namespace std;

int main(){
    int a;
    cin >> a;
    if(a == 1){
        cout << "Hello World" << endl;
    }else if(a == 2){
        int b, c;
        cin >> b;
        cin >> c;
        cout << b + c << endl;
    }
}

Measured memory_bytes: 256
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
n = inp()
s = 0
for i in range(1,n + 1):
    if i % 3 != 0 and i % 5 != 0:
        s += i
print(s)
#print('No')
#print()


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

using namespace std;

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

    set<int> st;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (st.find(a) != st.end()) {
            st.erase(a);
        } else {
            st.insert(a);
        }
    }

    cout << st.size() << endl;
    return 0;
}



Measured memory_bytes: 4864
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    ABC solver = new ABC();
    solver.solve(1, in, out);
    out.close();
  }

  static class ABC {

    public void solve(int testNumber, InputReader in, PrintWriter out) {
      char[] s = in.next().toCharArray();
      char[] t = "abc".toCharArray();
      Arrays.sort(s);
      do {
        if (Arrays.equals(s, t)) {
          out.println("Yes");
          return;
        }
      } while (ArrayUtils.nextPermutation(s));
      out.println("No");
    }

  }

  static class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 13];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (this.numChars == -1) {
        throw new UnknownError();
      } else {
        if (this.curChar >= this.numChars) {
          this.curChar = 0;

          try {
            this.numChars = this.stream.read(this.buf);
          } catch (IOException ex) {
            throw new InputMismatchException();
          }

          if (this.numChars <= 0) {
            return -1;
          }
        }

        return this.buf[this.curChar++];
      }
    }

    public String next() {
      int c;
      while (isSpaceChar(c = this.read())) {
      }

      StringBuilder result = new StringBuilder();
      result.appendCodePoint(c);

      while (!isSpaceChar(c = this.read())) {
        result.appendCodePoint(c);
      }

      return result.toString();
    }

    public static boolean isSpaceChar(int c) {
      return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
    }

  }

  static class ArrayUtils {

    public static boolean nextPermutation(char[] array) {
      int i = array.length - 1;
      while (i > 0 && array[i - 1] >= array[i]) {
        i--;
      }
      if (i <= 0) {
        return false;
      }
      int j = array.length - 1;
      while (array[j] <= array[i - 1]) {
        j--;
      }
      char temp = array[i - 1];
      array[i - 1] = array[j];
      array[j] = temp;
      j = array.length - 1;
      while (i < j) {
        temp = array[i];
        array[i] = array[j];
        array[j] = temp;
        i++;
        j--;
      }
      return true;
    }

  }
}



Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    int a, b;
    while(cin >> a >> b) {
        cout << a + b << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
n=int(input())
from itertools import combinations 
l_=list(map(int,input().split()))

l=list(combinations(l_,3))
#print(l)
cnt=0
for i in range(len(l)):
  
  if len(list(set(l[i])))==len(l[i]):
    
    if max(l[i])<sum(l[i])-max(l[i]):
      cnt+=1
      
print(cnt)
      

Measured memory_bytes: 20624
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
using namespace std;

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

int bad[10];

int isBad(int x) {
    for(; x; x/=10) if(bad[x%10])
        return 1;
    return 0;
}

int main() {
    int i, n, k, t;
    scanf("%d%d", &n, &k);
    for(i=0; i<k; i++) {
        scanf("%d", &t);
        bad[t]=1;
    }
    while(isBad(n)) n++;
    printf("%d\n", n);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define chmax(a, b) a = max(a, b)
using namespace std;
using ll = long long;

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	vector<ll> lucas = {2, 1};
	int N;
	cin >> N;
	if (N == 1) {
		cout << "1\n";
		return 0;
	}
	while (--N) {
		ll l = lucas.at(0) + lucas.at(1);
		lucas.at(0) = lucas.at(1);
		lucas.at(1) = l;
	}
	cout << lucas.back() << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int K;
bool dp[55][100005];
queue<int> Q;
void Solve() {
    read(K);
    for(int i = 1 ; i <= 9 ; ++i) dp[i][i % K] = 1;
    for(int i = 1 ; i <= 50 ; ++i) {
	for(int a = 0 ; a < K ; ++a) {
	    if(dp[i][a]) Q.push(a);
	}
	while(!Q.empty()) {
	    int v = Q.front();Q.pop();
	    if(!dp[i][v * 10 % K]) {
		dp[i][v * 10 % K] = 1;
		Q.push(v * 10 % K);
	    }
	}
	for(int a = 0 ; a < K ; ++a) {
	    if(!dp[i][a]) continue;
	    for(int j = 1 ; j <= 9 ; ++j) {
		if(i + j > 50) break;
		int h = (a * 10 + j) % K;
		dp[i + j][h] = 1;
	    }
	}
    }
    for(int i = 1 ; i <= 50 ; ++i) {
	if(dp[i][0]) {
	    out(i);enter;return;
	}
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 5580
import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._
  val n = readLine.trim.toInt
  val taxi = Array.tabulate(n){_ ⇒
    readLine.trim.split(' ').drop(1).map(_.toInt).toList
  }.reverse.toList
  implicit val queue = new mutable.PriorityQueue[Int]()
  println(
    solve(taxi)
  )
  def solve(taxi: List[List[Int]], res: Long = 0)(implicit queue: mutable.PriorityQueue[Int]): Long = {
    taxi match {
      case Nil ⇒ res
      case h::t ⇒ {
        queue.enqueue(h:_*)
        val top = queue.dequeue()
        solve(t, res + top)
      }
    }
  }
  implicit class ScopedFunc[T](val value: T){
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


Measured memory_bytes: 247140
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<ll,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, sum;

const int MAX = 510000;
const int MOD = 1000000007;

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

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

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

long long kai(ll x, ll y) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
long long mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
long long comb(ll x, ll y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}


int main() {
	//Code Line
	COMinit();
	cin >> n >> b >> c;
	a = (modpow(2, n, mod) - 1 + mod) % mod;

	
	sum = (comb(n, b) + comb(n, c)) % mod;
	

	cout << (a - sum + mod) % mod << endl;
	return 0;
}


Measured memory_bytes: 12160
#include <cstdio>

unsigned long long a,b,c,d;

int main(void)
{
    int i,j,k;

    //freopen("x.in","r",stdin);

    scanf("%llu %llu",&a,&b);
    if(a == b)
        return puts("1"),0;

    d = b - a + 1;
    for(i = 63;i >= 0;--i)
    {
        if((a & (1ull << i)) == (b & (1ull << i)))
            continue;
        a &= (1ull << i) - 1;
        b &= (1ull << i) - 1;
        for(j = i - 1;j >= 0;--j)
        {
            if(!(b & (1ull << j)))
                continue;
            c = 1ull << (j + 1);
            --c;
            break;
        }
        if(c >= a)
            d += 1ull << i;
        else
            d += (1ull << i) - a + c + 1;
        d -= b + 1;
        break;
    }
    printf("%llu\n",d);

    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.ArrayList;
 
public class Main {
	int [][] r;
	public static void main(String args[])throws IOException  {
 
	
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		int ans=0;
		int N=in.nextInt();
		int [] A=in.nextIntArray(N);
		int sum =0;
		for(int i=0; i<A.length;i++)sum+=A[i];
		
		float avg = (float)sum/A.length;
		float curDiff = 101;
	
		for(int i=0;i<A.length;i++){
			if(Math.abs(avg-A[i])<curDiff){
				ans = i;
				curDiff = Math.abs(avg-A[i]);
			
			}
		}
		
		out.print(ans);
		out.close();
	}


    static long gcd(long a, long b) 
    { 
        return b>0?gcd(b, a%b):a; 
    } 

    static long lcm(long a, long b) 
    { 
        return (a*b)/gcd(a, b); 
    } 

	
	
	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;
 
		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}
 
		public int nextInt() {
			return Integer.parseInt(nextString());
		}
 
		public long nextLong() {
			return Long.parseLong(nextString());
		}
 
		public double nextDouble() {
			return Double.parseDouble(nextString());
		}
 
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}
 
		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}
 
		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}
 
		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}
 
		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}
 
		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}
 
		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}
 
		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}
 
	
}


Measured memory_bytes: 21204
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <random>
#include <algorithm>
#include <chrono>
#include <map>
#define tNow chrono::duration_cast<msec>(chrono::system_clock::now().time_since_epoch())
#define INF (1 << 30)
using namespace std;

typedef chrono::milliseconds msec;

int d, lastVal = -INF, bestVal = -INF, times = 0, groups = 0, updates = 0, positiveUpdates = 0;
vector<int> c(27), cur, ans;
vector< vector<int> > s;

int calc() {
    int sum = 0;
    vector<int> last(27, 0);
    for (int i = 1; i <= d; ++i) {
        sum += s.at(i).at(cur.at(i));
        last.at(cur.at(i)) = i;
        for (int j = 1; j <= 26; ++j) sum -= c.at(j) * (i - last.at(j));
    }
    return sum;
}

void update(int curVal) {
    lastVal = curVal;
    if (bestVal < curVal) {
        bestVal = curVal;
        ans = cur;
        ++positiveUpdates;
    }
    ++updates;
}

int main() {
    random_device r;
    msec st = tNow;
    msec lm = st + chrono::milliseconds(1980);
    cin >> d;
    s = vector< vector<int> >(d + 1, vector<int>(27));
    cur.resize(d + 1);
    for (int i = 1; i <= 26; ++i) cin >> c.at(i);
    for (int i = 1; i <= d; ++i) for (int j = 1; j <= 26; ++j) cin >> s.at(i).at(j);
    mt19937 m(r());
    for (int i = 1; i <= d; ++i) cur.at(i) = max_element(s.at(i).begin(), s.at(i).end()) - s.at(i).begin();
    update(calc());
    // cur = {0, 1, 17, 13, 14, 13};
    // update(calc());
    // cout << bestVal << endl;
    // for (int i = 1; i <= d; ++i) cout << ans.at(i) << endl;

    while (tNow < lm) {
        ++groups;
        mt19937 m(r());
        for (int i = 0; i < 100; ++i) {
            int changeAt = m() % d + 1, changeTo = m() % 26 + 1, changedFrom = cur.at(changeAt);
            if (changedFrom == changeTo) continue;
            cur.at(changeAt) = changeTo;
            int curVal = calc();
            if (m() % max(1, (lastVal - curVal) / 24) == 0) update(curVal);
            else cur.at(changeAt) = changedFrom;
            ++times;
        }
    }

    for (int i = 1; i <= d; ++i) cout << ans.at(i) << endl;
    msec ed = tNow;
    #ifdef ___DEBUG
    cout << "Best Value: " << bestVal << endl;
    cout << "Best Score: " << max(bestVal + 1000000, 0) << endl;
    cout << "Tried: " << times << "times, " << groups << "groups\n";
    cout << "Updated: " << updates << "times\n";
    cout << (ed - st).count() << "ms\n";
    #endif
    return 0;
}


Measured memory_bytes: 3696
#include<cstdio>
const int mod = 1000000007;
int h;
int n;
int perm[300100];
long long int d[300100];
long long int ans;
void putleaf(int x, int prt, int val) {
	int y = x;
	long long int mult = val;
	while (y >= prt) {
		mult *= y;
		mult %= mod;
		y /= 2;
	}
	y = perm[x - n] + n;
	while (y >= 1) {
		d[y] += mult;
		d[y] %= mod;
		mult *= y;
		mult %= mod;
		y /= 2;
	}
}
void calcleaf(int x, int prt) {
	int y = x;
	long long int mult = 1;
	while (y > prt) {
		mult *= y;
		mult %= mod;
		y /= 2;
	}
	y = perm[x - n] + n;
	int prevy = -1;
	while (y >= 1) {
		mult *= y;
		mult %= mod;
		ans += mult * d[y];
		ans %= mod;
		if (prevy != -1) {
			ans += mod - (mult*d[prevy] % mod*prevy) % mod;
			ans %= mod;
		}
		prevy = y;
		y /= 2;
	}
}
int main() {
	scanf("%d", &h);
	n = 1 << (h - 1);
	for (int i = 0; i < n; i++) {
		scanf("%d", &perm[i]);
		perm[i]--;
	}
	ans = 0;
	for (int i = 0; i < h - 1; i++) {
		int base = 1 << i;
		for (int p = base; p < 2 * base; p++) {
			for (int leaf = ((p * 2) << (h - i - 2)); leaf < ((p * 2 + 1) << (h - i - 2)); leaf++) {
				putleaf(leaf, p, 1);
			}
			for (int leaf = ((p * 2 + 1) << (h - i - 2)); leaf < ((p * 2 + 2) << (h - i - 2)); leaf++) {
				calcleaf(leaf, p);
			}
			for (int leaf = ((p * 2) << (h - i - 2)); leaf < ((p * 2 + 1) << (h - i - 2)); leaf++) {
				putleaf(leaf, p, mod - 1);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
  int A,B;
  cin >> A >> B;
  int x = 0;
  for(int i = A;i <= B;i++){
   if(i / 1000 == i % 10 *10 + i % 100 / 10){
     x += 1;
   }
  }
    cout << x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


std::string s;

int main(void){
  cin >> s;
  const int n = s.size();
  int res = n;
  FOR(i, 1, n){
    if(s.at(i-1) != s.at(i)) chmin(res, max(i, n-i));
  }
  printf("%d\n", res);
  return 0;
}

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


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

  ll a,v,b,w;
  cin >> a  >>  v >> b >> w;
  ll t;
  cin >> t;
  bool ok = false;
  if(a==b) ok = true;
  else{
    if(w>=v) ok = false;
    else{
      if((v-w)*t >= abs(a-b)) ok = true;
      else ok = false;
    }
  }
  cout << ((ok)?"YES":"NO") << endl;
  
  return 0;
    

}


Measured memory_bytes: 3612
# Aizu Problem 0007: Debt Hell
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N = int(input())
debt = 100000
for week in range(N):
    interest = debt * .05
    iinterest = int(interest / 1000) * 1000
    if interest > iinterest:
        iinterest += 1000
    debt += iinterest

print(debt)
    

Measured memory_bytes: 7644
{-# OPTIONS_GHC -Wall -Werror #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM_)

isParallel ::(Eq a, Num a) => (a, a) -> (a, a) -> String
isParallel (ax, ay) (bx, by) = if ax * by - ay * bx == 0
                                  then "YES"
                                  else "NO"

solve :: (Eq a, Num a) => [a] -> String
solve xs = isParallel a b
  where x1:y1:x2:y2:x3:y3:x4:y4:_ = xs
        a = (x2 - x1, y2 - y1)
        b = (x4 - x3, y4 - y3)

main :: IO ()
main = do
  n <- readLn
  replicateM_ n $ do
    x <- (map read) <$> words <$> getLine :: IO [Float]
    putStrLn $ solve x

Measured memory_bytes: 4356
n = int(input())
s = input()
S = []
for i in s:
    S.append(i)

w = [0,]
for i in range(1, n):
    if S[i-1] == 'W':
        w.append(w[i-1] + 1)
    else:
        w.append(w[i-1])

e = [0 for _ in range(n)]
for i in range(n-2, -1, -1):
    if S[i+1] == 'E':
        e[i] = e[i+1] + 1
    else:
        e[i] = e[i+1]

ans = 100100100100
for i in range(n):
    cost = w[i] + e[i]
    ans = min(ans, cost)
print(ans)

Measured memory_bytes: 20352
#include<bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pq priority_queue
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define elif else if

using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pll=pair<ll,ll>;
using pss=pair<string,string>;
using pdd=pair<ld,ld>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};
const ld E=1e-9;

template<class T> void chmin(T &a, T b){a=min(a, b);}
template<class T> void chmax(T &a, T b){a=max(a, b);}

ll abs1(ll a){if(a>=0)return a;else return -a;}
ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1)ret*=a;
    a*=a;
    if(a>=p)a%=p;if(ret>=p)ret%=p;
    b=b>>1;
  }
  return ret;
}
int digit(ll a,ll b=10){int i=0;while(a!=0){a/=b;i++;}return i;}
ll gcd1(ll a,ll b){
  if(a==0 || b==0)return 0;
  ll n;while(a%b!=0){n=a%b;a=b;b=n;}return b;
}
ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];a[0]=n;b[0]=m;int i=1;
  while(b[i-1]!=0){a[i]=b[i-1];b[i]=a[i-1]%b[i-1];i++;}
  n=i;if(c%a[n-1]!=0)return 0;
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){ll cnt=x;x=y;y=cnt-(a[n-i-1]/b[n-i-1])*y;}
  return x;
}
ll modRev(ll a,ll p=MOD){
  a%=p;ll n=solveLinear(a,p,1);
  n%=p;if(n<0)return n+p;
  return n;
}
ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  ll ret=1;
  for(int i=1;i<=n;i++){ret=ret*i;if(ret>=p)ret%=p;}
  return ret;
}
ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  ll ret=1;
  rep(i,k){ret=ret*(n-i);if(ret>=p)ret%=p;}
  return ret;
}
ll binom(ll n,ll k,ll p=MOD){
  return (perm(n,k,p)*modRev(fact(k)))%p;
}
int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  int i,j,k,cnt=0;
  int n;
  cin>>n;
  int p=pow1(2,n);
  int a[p];
  rep(i,p)cin>>a[i];
  while(p>1){
    for(i=0;i<p/2;i++){
      if(a[2*i]==a[2*i+1])a[i]=a[2*i];
      else a[i]=max(a[2*i],a[2*i+1])-min(a[2*i],a[2*i+1]);
    }
    p/=2;
  }
  cout<<a[0]<<endl;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D; 
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> VP;
const D EPS = 1e-9; 
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) {  return (conj(a)*b).Y;}
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1; 
  if (cross(b,c) < -EPS) return -1;
  if (dot(b,c)   < -EPS) return +2;
  if (norm(b) < norm(c)) return -2;
  return 0;
}
bool isecSS(P a1, P a2, P b1, P b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
         ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}
namespace std {
  bool operator<(const P a, const P b) {
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}
VP convexHull(VP ps) {
  if(ps.size()==1)return ps;
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  VP ch(2*n);
  for (int i = 0; i < n; ch[k++] = ps[i++])
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--])
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}
int main(){
  int n,m;
  double x,y;
  while(cin>>n>>m,n){
    VP v1,v2,v3;
    int f=0;
    set<VP>se;
    rep(i,n){
      cin>>x>>y;
      v1.push_back(P(x,y));
    }
    rep(i,m){
      cin>>x>>y;
      v2.push_back(P(x,y));
    }
    v1=convexHull(v1);
    v2=convexHull(v2);
    se.insert(v1);
    se.insert(v2);
    rep(i,v1.size())v3.push_back(v1[i]);
    rep(i,v2.size())v3.push_back(v2[i]);
    v3=convexHull(v3);
    if(se.count(v3))f++;
    rep(i,v1.size())
      rep(j,v2.size())
        if(isecSS(v1[i],v1[(i+1)%(int)v1.size()],v2[j],v2[(j+1)%(int)v2.size()]))f++;
    L:;cout<<(f?"NO":"YES")<<endl;
  }
}

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifdef LOCAL
//		freopen("in1.txt", "r", stdin);
//		freopen("in1.txt", "w", stdout);
	#endif
	int n;
	cin >> n;
	string s;
	cin >> s;
	int l=0, r=n-1;
	int ans = 0;
	while (l<r) {
		while (l<r && s[l]=='R') l++;
		while (l<r && s[r]=='W') r--;
		if (l==r) break;
		swap(s[l], s[r]);
		ans++;
		l++; r--;
	}
	cout << ans << '\n';
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  for (int i = 0; i < M; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  
  vector<int> cs(N, 0);
  for (int i = 0; i < M; i++) {
    cs.at(a.at(i) - 1)++;
    cs.at(b.at(i) - 1)++;  
  }
  
  for (int i = 0; i < N; i++) {
    cout << cs.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
char t[100000];
int main(int argc, const char * argv[]) {

    char ch;
    while(1){
        scanf("%c",&ch);
        
        if('A' <= ch && ch <= 'Z'){
            ch=ch+32;
        }else if('a' <= ch && ch <= 'z'){
            ch=ch-32;
        }

        printf("%c",ch);

        if (ch =='\n'){
         break;
        }
    }
    return 0;
}


Measured memory_bytes: 2048
while True:
	h,w = map(int,input().split())
	if h==0 and w==0:
		break
	for i in range(h):
		if i==0 or i==h-1:
			for j in range(w):
				if j==w-1:
					print('#')
				else:
					print('#',end='')
		else:
			for j in range(w):
				if j==0:
					print('#',end='')
				elif j==w-1:
					print('#')
				else:
					print('.',end='')
	print()


Measured memory_bytes: 6996
#include<stdio.h>
#include<math.h>
int main(void)
{
	double x1,x2,xq,y1,y2,yq,a,b,c,xe,ye,t;
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&xq,&yq)>0)
	{
		a = y1-y2;
		b = x2-x1;
		c = x1*(y2-y1)-y1*(x2-x1);
		t=(a*xq+b*yq+c)/(a*a+b*b);
		xe = xq-a*t;
		ye = yq-b*t;
		printf("%f %f\n", 2*xe-xq, 2*ye-yq);
	}
	return 0;
}

Measured memory_bytes: 0
n,k = map(int,input().split())
p = [0] + list(map(int,input().split()))
c = [0] + list(map(int,input().split()))
maxsc = -1E20
for s in range(1,n+1):
  x = s
  sc = [0]
  i = 0
  while i<k:
    x = p[x]
    sc.append(sc[i]+c[x])
    i += 1
    if x == s:
      loop = i
      loopsc = sc[i]
      if loopsc > 0:
        baseup = loopsc * int((k-i)/loop)
        for j in range(loop):
          sc[j+1] += baseup
        for j in range((k-i)%loop):
          sc[j+1] += loopsc
      i=k
  sc[0] = -1e20
  maxsc = max(maxsc, max(sc))
print(maxsc)
    


Measured memory_bytes: 97812
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define N 200002
#define M 300007
#define L 345543
using namespace std;

char s[N][11];
int c, p[N], ha[L], hc[L] = {0};

int cmp(int x, int y)
{
	return strcmp(s[x], s[y]) < 0;
}

int hash(char *a)
{
	int h = 1, i;
	for(i = 0; a[i]; i++){
		h = (h * (int)a[i] + i) % M;
	}
	return h;
}

int main() 
{
	int n, i, max = 0, j, pi, t, h;
			
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%s", s[i]);
		for(h = hash(s[i]); hc[h] && strcmp(s[i], s[ha[h]]); h++);
		if(hc[h]) hc[h]++;
		else ha[h] = i, hc[h] = 1;
	}
	for(i = 0; i < L; i++){
		if(hc[i] > max){
			p[0] = ha[i], c = 1, max = hc[i];
		}
		else if(hc[i] == max) p[c++] = ha[i];
	}
	
	sort(p, p + c, cmp);
	for(i = 0; i < c; i++) printf("%s\n", s[p[i]]);
			
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i, n) for( int i=0 ; i<n ; i++ )
#define f(i, a, b) for( int i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
#define MOD 1000000007
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll fact(ll n)
{
    ll ans = 1e14;
    for(ll i = 1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            ll sol = (i - 1) + (n/i - 1);
            ans = min(ans,sol);
        }
    }
    return ans;
}
int visited[200000] = {0};
vector<vector<int> > v(200000);
int dfs(int x)
{
    int ans = 0;
    if(visited[x]==0)
    {
        visited[x] = 1;
        ans++;
        int a = v[x].size();
        for(int j = 0; j<a; j++)
        {
            int data = v[x][j];
            ans = ans + dfs(data);
        }
    }
    return ans;
}
void primefactors(int n)
{
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            cout << i << " ";
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        cout << n << " ";

}
double fib(int n)
{
    double sol1,sol2;
    sol1 = (1 + sqrt(5))/2;
    sol2 = (1 - sqrt(5))/2;
    sol1 = pow(sol1,n);
    sol2 = pow(sol2,n);
    double ans = sol1 - sol2;
    ans = ans/sqrt(5);
    //ans = int(ans);
    return ans;
}

ll digits(ll n)
{
    return floor(log10(double(n))) + 1;
}

ll index(ll n)
{
    n = double(n);
    double sol = n*n + n;
    sol = sol*2 + 1;
    double ans = -1 + sqrt(sol);
    ans = ans/2;
    ans = ll(ans);
    return ans;
}
int main()
{
    int x;
    cin>>x;
    if(x)
        cout<<"0";
    else
        cout<<"1";

}


Measured memory_bytes: 7784
#include <iostream>
#include <map>
#include <vector>
using namespace std;
struct _BQ {
    int B;
    int Q;
};

int main() {
    int64_t N;
    cin >> N;
    map<int64_t, int64_t> A;
    for (int64_t i = 0; i < N; ++i) {
        int64_t a;
        cin >> a;
        A[a]++;
    }

    int64_t ans = 0;
    for (auto &a : A) {
        ans += a.first * a.second;
    }

    int64_t Q;
    cin >> Q;
    vector<struct _BQ> BQ(Q);
    for (auto &&bq : BQ) {
        cin >> bq.B >> bq.Q;
    }

    for (auto &&bq : BQ) {
        ans += (bq.Q - bq.B) * A[bq.B];
        A[bq.Q] += A[bq.B];
        A[bq.B] = 0;
        cout << ans << endl;
    }
}

Measured memory_bytes: 10056