akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int x,n; cin >> x >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  set<int> st;
  for(int i=-100;i<101;i++){
     st.insert(i+1);
  }
  rep(i,n){
    if(st.count(p[i])) st.erase(p[i]);
  }
  int mnsa=inf;
  int ans=x;
  for(auto v:st){
    if(abs(v-x)<mnsa){
      mnsa=abs(v-x);
      ans=v;
    }
  }
  if(st.count(x)) ans=x;
  cout << ans << endl;
}

Measured memory_bytes: 3644
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int A, B;
  ci(A, B);
  if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0){
    co("Possible");
  }
  else{
    co("Impossible");
  }
}

Measured memory_bytes: 256
n=gets.to_i
arr=gets.chomp.split(" ").map(&:to_i)
arr.sort!.reverse!
alice = 0
bob = 0
flg = true
arr.each do |i|
  if flg
    alice += i
  else
    bob += i
  end
  flg ^= true
end
puts alice - bob

Measured memory_bytes: 1788
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

cnt = [0] * N
ex = [0] * N
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            cnt[i] += 1
for i in range(N):
    for j in range(i):
        if A[i] > A[j]:
            ex[i] += 1

ans = 0
for i in range(N):
    ans += cnt[i] * ((K + 1) * K // 2) % MOD
for i in range(N):
    ans -= ex[i] * K
print(ans % MOD)

Measured memory_bytes: 9520
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] a = new int[n+2];
      int sum = 0;
      for(int i = 1;i <= n;i++)a[i]=sc.nextInt();
      for(int i = 0;i <= n;i++)sum += Math.abs(a[i+1]-a[i]);
      for(int i = 1;i <= n;i++)System.out.println(sum-Math.abs(a[i+1]-a[i])-Math.abs(a[i]-a[i-1])+Math.abs(a[i+1]-a[i-1]));
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}

Measured memory_bytes: 62356
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = new int[N];
		int next =1;

		for(int i=0;i<N;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=0;i<N;i++) {
			if(array[next-1] == 2) {
				System.out.println(i+1);
				System.exit(0);
			}
			next = array[next-1];
		}
		System.out.println(-1);
	}
	public static int sample() {
		return 1;
	}

}


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

int n, m, a[111][111], b[111][111], b2[111][111];

int G[111][111], pre[111], usd[111];

int fin(int x){
    for (int y=0;y<n;++y){
        if (usd[y]||!G[x][y]) continue;
        usd[y]=1;
        if (pre[y]==-1||fin(pre[y])){
            pre[y]=x;
            return 1;
        }
    }
    return 0;
}

int main(){
    cin>>n>>m;
    for (int i=0;i<n;++i)
        for (int j=0;j<m;++j){
            cin>>a[i][j]; --a[i][j];
        }
    for (int c=0;c<m;++c){
        memset(G,0,sizeof G);
        for (int i=0;i<n;++i)
            for (int j=0;j<m;++j)
                if (~a[i][j]) G[i][a[i][j]/m]=1;
        memset(pre,-1,sizeof pre);
        for (int i=0;i<n;++i){
            memset(usd,0,sizeof usd);
            fin(i);
        }
        for (int i=0;i<n;++i){
            int pi=pre[i];
            for (int j=0;j<m;++j)
                if (~a[pi][j]&&a[pi][j]/m==i){
                    b[pi][c]=b2[i][c]=a[pi][j];
                    a[pi][j]=-1;
                    break;
                }
        }
    }
    for (int i=0;i<n;++i){
        for (int j=0;j<m;++j)
            cout<<b[i][j]+1<<' ';
        cout<<endl;
    }
    for (int i=0;i<n;++i){
        for (int j=0;j<m;++j)
            cout<<b2[i][j]+1<<' ';
        cout<<endl;
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 1005

struct LOC{

	void set(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}
	int row,col;
};

struct Info{
	Info(int arg_row,int arg_col,int arg_sum_dist){
		row = arg_row;
		col = arg_col;
		sum_dist = arg_sum_dist;
	}
	int row,col,sum_dist;
};

int N;
int H,W;
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
int min_dist[SIZE][SIZE];
char base_map[SIZE][SIZE];
LOC loc[10];


bool rangeCheck(int row,int col){

	return row >= 0 && row <= H-1 && col >= 0 && col <= W-1;
}

int calc(int start_index){

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){

			min_dist[row][col] = BIG_NUM;
		}
	}

	queue<Info> Q;
	min_dist[loc[start_index].row][loc[start_index].col] = 0;

	Q.push(Info(loc[start_index].row,loc[start_index].col,0));

	while(!Q.empty()){

		for(int i = 0; i < 4; i++){
			int adj_row = Q.front().row+diff_row[i];
			int adj_col = Q.front().col+diff_col[i];

			if(rangeCheck(adj_row,adj_col) == false || base_map[adj_row][adj_col] == 'X' ||
					min_dist[adj_row][adj_col] <= Q.front().sum_dist+1)continue;


			min_dist[adj_row][adj_col] = Q.front().sum_dist+1;

			//辺コスト1のQueue処理なので、最初に到達した状態が最小コストのはず
			if(adj_row == loc[start_index+1].row && adj_col == loc[start_index+1].col){

				return min_dist[adj_row][adj_col];
			}
			Q.push(Info(adj_row,adj_col,min_dist[adj_row][adj_col]));
		}
		Q.pop();
	}

	return -1;
}

int main(){

	scanf("%d %d %d",&H,&W,&N);

	for(int row = 0; row < H; row++){

		scanf("%s",base_map[row]);
		for(int col = 0; col < W; col++){
			if(base_map[row][col] == 'S'){

				loc[0].set(row,col);

			}else if(base_map[row][col] >= '1' && base_map[row][col] <= '9'){

				loc[base_map[row][col]-'0'].set(row,col);
			}
		}
	}

	int ans = 0;

	for(int i = 0; i <= N-1; i++){

		ans += calc(i);
	}

	printf("%d\n",ans);

	return 0;
}



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

int main(){
    int n; cin >> n;
    while(n>=10){
        n%=10;
    }
    if (n==2 || n==4 || n==5 || n==7 || n==9){
        cout << "hon" << endl;
    } else if (n==0 || n==1 || n==6 || n==8){
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }
}

Measured memory_bytes: 3584
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int w = sc.nextInt();
        int h = sc.nextInt();

        int x = sc.nextInt();
        int y = sc.nextInt();

        double sqr = (double)w*h/2;
        System.out.println(sqr);

        if ((w%2!=0)|(h%2!=0)){
            System.out.println(0);
        } else if ((x==w/2)&(y==h/2)){
                System.out.print(1);
            } else {
            System.out.print(0);
        }


    }
}



Measured memory_bytes: 23124
def C_TypicalStairs():
    N, M = map(int, input().split())
    am = [int(input()) for i in range(M)]
    n_list = [i for i in range(N+1)]
    can_move = True
    num_move = 0
    if(M == 0):
        num_move = fib(len(n_list))
    else:
        # 到達不可を除く
        for i in range(M-1):
            if ((am[i] + 1) == am[i+1]):
                can_move = False
        if (can_move):
            num_move = fib(len(n_list[:am[0]]))
            if (M <= 1):
                pass
            else:
                for i in range(M-1):
                    num_move *= fib(len(n_list[am[i]+1:am[i+1]]))
            num_move *= fib(len(n_list[am[M-1]+1:]))
    print(num_move % 1000000007)

def fib(n):
    if (n <= 1):
        a0 = n
    else:
        a0, a1 = 0, 1
        for _ in range(n):
            a0, a1 = a1, a0 + a1
    return a0
if __name__ == "__main__":
    C_TypicalStairs()

Measured memory_bytes: 11024
/*
  Lower bound: first element that is greater-or-equal.
  int i=lower_bound(a,a+n,x)-a;
  Upper bound: first element that is strictly greater.
  #include<boost/multiprecision/cpp_int.hpp>
  namespace mp=boost::multiprecision;
  mp::cpp_int u=1; for(unsigned i=1;i<=n;i++) u*=i;
*/
#pragma GCC optimize("O3")  
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
#define eps 1e-7
#define I (int)
const int mod=(int)1e9+7;
const long long INF = 1000000000000000000LL;
const int WASTE=(int)2e5+6e3;
//#define int long long
int power(int a,int b,int m){
	int i=1;
	while(b){
		if(b%2)
			i=(i*a)%mod;
		b/=2;
		a=(a*a)%mod;
	}
	return i;	
}
const int N=1e5+5;
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    if(x%y)
    	cout<<x;
    else
    	cout<<-1;
    
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
// const int N = 300005;
// set<int> S[N];

int32_t main() {

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

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

    vector<pii> bt(60,{0,0});

    int left = 0;
    for(int i = 0; i < 60; i++) {
    	
    	int right = 1;
    	for(int j = i+1, k = 0; j < 60; k++, j++) {
    		if(B&(1ll<<j)) right += (1ll << k);
    	}
    	
    	int ans = (right) * (1ll << i) + left+1;
    	if(B&(1ll<<i)) bt[i].Y += ans;
    	else bt[i].X += ans;

    	// left += (1ll << i);
    	if(B&(1ll<<i)) left += (1ll<<i);
    	
    }
    left = 0;
    for(int i = 0; i < 60; i++) {
    	
    	int right = 1;
    	for(int j = i+1, k = 0; j < 60; k++, j++) {
    		if(A&(1ll<<j)) right += (1ll << k);
    	}
    	// int left = (1ll << i) - 1;
    	int ans = (right) * (1ll << i) + left+1;
    	if(A&(1ll<<i)) bt[i].Y -= (ans - 1);
    	else bt[i].X -= (ans - 1);   

    	if(A&(1ll<<i)) left += (1ll<<i);	
    }

    int ans = 0;
    rep(i,60) {
    	// db3(bt[i].Y,i,"1");
    	// if(i==1) {
    	// 	db2(bt[i].X,bt[i].Y);
    	// }
    	if(bt[i].X < 0) {
    		bt[i].Y -= (A + bt[i].X);
    	}
    	else if(bt[i].Y < 0) {
    		bt[i].Y += (B + 1  - bt[i].X);
    	}
    	else if(bt[i].X > 0) {
    		// db2(i,bt[i].X);
    		bt[i].Y = B - A + 1 - bt[i].X;
    	} 
    	// db3(bt[i].Y,i,"2");
    	// if(i==1) {
    	// 	db2(bt[i].X,bt[i].Y);
    	// }    	
    	if(bt[i].Y % 2) ans += (1ll << i);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
int n,m,l;
int main ()
{
	scanf("%d%d%d",&n,&m,&l);
	printf("%d\n",min(n*m,l));
	return 0;
}


Measured memory_bytes: 256
#ABC126C - Dice and Coin
N, K = list(map(int,input().split()))
p = 0
if N <= K:
    for i in range(1,N+1):
        count = 0
        while i < K:
            i = i*2
            count+= 1
        p += (1/(2**count))*(1/N)
    print(p)
elif N > K:
    for i in range(1,N+1):
        count = 0
        while i < K:
            i = i*2
            count+= 1
        p += (1/(2**count))*(1/N)
    print(p)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))

a.sort()

is_divisible = [-1] * (10 ** 6 + 1)
is_divisible[0] = 1

ans = 0
for num in a:
    if is_divisible[num] == -1:
        ans += 1
        is_divisible[num] = 0
        for i in range(num * 2, 10 ** 6 + 1, num):
            is_divisible[i] = 1
    elif is_divisible[num] == 0:
        ans -= 1
        is_divisible[num] = 1
    else:
        continue

print(ans)


Measured memory_bytes: 106156
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using cd = complex<ld>;

const int N = 410'000;

struct node {
  unordered_map<char, int> next;
  int subtreeSize;
  int parent;
  int prefixCount;
  char realCount;

  int &operator[](char c) {
    return next[c];
  }
};

node trie[N];
map<int, int[26][26]> cnt;
int lastMem = 1;

int addString(string const &s) {
  int v = 0;
  for (char c : s) {
    if (trie[v][c] == 0) {
      trie[v][c] = lastMem++;
    }
    trie[trie[v][c]].parent = v;
    v = trie[v][c];
  }
  trie[v].realCount++;
  int addNode = v;
  while (v != 0) {
    trie[v].subtreeSize++;
    v = trie[v].parent;
  }
  trie[0].subtreeSize++;
  return addNode;
}

int sum[26][26];

void compress(int v) {
  trie[v].prefixCount += trie[v].realCount;
  if (trie[v].realCount > 0) {
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < 26; j++) {
        cnt[v][i][j] = sum[i][j];
      }
    }
  }
  for (auto const &e : trie[v].next) {
    for (auto const& f : trie[v].next) {
      if (f != e) {
        sum[e.first - 'a'][f.first - 'a'] += trie[f.second].subtreeSize;
      }
    }
    trie[e.second].prefixCount = trie[v].prefixCount;
    compress(e.second);
    for (auto const& f : trie[v].next) {
      if (f != e) {
        sum[e.first - 'a'][f.first - 'a'] -= trie[f.second].subtreeSize;
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> nodes(n);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    nodes[i] = addString(s);
  }
  compress(0);
//  for (int i = 1; i < lastMem; i++) {
//    cout << i << " -> " << trie[i].parent << endl;
//    for (auto const &e : trie[i].next) {
//      cout << "\t(" << e.first << ", " << e.second << ")\n";
//    }
//  }
  int q;
  cin >> q;
  while (q-- > 0) {
    int id;
    string order;
    cin >> id >> order;
    vector<int> invOrder(26);
    for (int i = 0; i < 26; i++) {
      invOrder[order[i] - 'a'] = i;
    }
    --id;
    int v = nodes[id];
    int res = trie[v].prefixCount;
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < 26; j++) {
        if (invOrder[i] > invOrder[j]) {
          res += cnt[v][i][j];
        }
      }
    }
    cout << res << "\n";
  }

  return 0;
}


Measured memory_bytes: 306736
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    unsigned long long int a,b,c;
	cin>>a>>b>>c;
	if (a%c==0){
		cout<<(b/c-a/c)+1<<endl;
		}
	else cout<<b/c-a/c<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		//????????£?????????????????§????????????????????????
		//????????\???
		Scanner sc = new Scanner(System.in);
		

				//int??????????????????
			     int a = sc.nextInt();
			     //int????????????????¨?
			     int b = sc.nextInt();
			     //??¢????????¨?????????
			     System.out.println(a*b+" "+ (2 * a + 2*b));
	}
}

Measured memory_bytes: 26116
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 266666,inf=0x3f3f3f3f;
int n,m,q,res;char S[N],T[N];
int qz1[N][2],hz1[N][2],hz0[N][2],qz0[N][2];//0:- 1:+
int Abs(int x){return x>0?x:-x;}
void dfs(int x1, int y1, int x2, int y2, int cur, bool dir, int dep){
	if(dep>4)return;
//	printf("dfs %d %d %d %d\n",x1,y1,dir,cur);
	if(!dir){
		if(S[x1]=='E'){
			if(x1==x2&&y1<y2){umin(res,cur+Abs(x2-x1)+Abs(y2-y1));return;}
			if(hz1[y1][0])dfs(x1,hz1[y1][0],x2,y2,cur+Abs(hz1[y1][0]-y1),dir^1,dep+1);
			if(hz1[y1][1])dfs(x1,hz1[y1][1],x2,y2,cur+Abs(hz1[y1][1]-y1),dir^1,dep+1);
			if(y2>y1&&hz1[y2][x2>x1])dfs(x1,hz1[y2][x2>x1],x2,y2,cur+Abs(hz1[y2][x2>x1]-y1),dir^1,dep+1);
		}
		else{
			if(x1==x2&&y1>y2){umin(res,cur+Abs(x2-x1)+Abs(y2-y1));return;}
			if(qz1[y1][0])dfs(x1,qz1[y1][0],x2,y2,cur+Abs(qz1[y1][0]-y1),dir^1,dep+1);
			if(qz1[y1][1])dfs(x1,qz1[y1][1],x2,y2,cur+Abs(qz1[y1][1]-y1),dir^1,dep+1);
			if(y2<y1&&qz1[y2][x2>x1])dfs(x1,qz1[y2][x2>x1],x2,y2,cur+Abs(qz1[y2][x2>x1]-y1),dir^1,dep+1);
		}
	}
	else{
		if(T[y1]=='S'){
			if(y1==y2&&x1<x2){umin(res,cur+Abs(x2-x1)+Abs(y2-y1));return;}
			if(hz0[x1][0])dfs(hz0[x1][0],y1,x2,y2,cur+Abs(hz0[x1][0]-x1),dir^1,dep+1);
			if(hz0[x1][1])dfs(hz0[x1][1],y1,x2,y2,cur+Abs(hz0[x1][1]-x1),dir^1,dep+1);
			if(x2>x1&&hz0[x2][y2>y1])dfs(hz0[x2][y2>y1],y1,x2,y2,cur+Abs(hz0[x2][y2>y1]-x1),dir^1,dep+1);
		}
		else{
			if(y1==y2&&x1>x2){umin(res,cur+Abs(x2-x1)+Abs(y2-y1));return;}
			if(qz0[x1][0])dfs(qz0[x1][0],y1,x2,y2,cur+Abs(qz0[x1][0]-x1),dir^1,dep+1);
			if(qz0[x1][1])dfs(qz0[x1][1],y1,x2,y2,cur+Abs(qz0[x1][1]-x1),dir^1,dep+1);
			if(x2<x1&&qz0[x2][y2>y1])dfs(qz0[x2][y2>y1],y1,x2,y2,cur+Abs(qz0[x2][y2>y1]-x1),dir^1,dep+1);
		}
	}
}
int main() {
	read(n);read(m);read(q);
	scanf("%s%s",S+1,T+1);
	per(i,m,1){
		memcpy(hz1[i],hz1[i+1],sizeof(hz1[i+1]));
		if(T[i]=='N')hz1[i][0]=i;else hz1[i][1]=i;
	}
	rep(i,1,m){
		memcpy(qz1[i],qz1[i-1],sizeof(qz1[i-1]));
		if(T[i]=='N')qz1[i][0]=i;else qz1[i][1]=i;
	}
	per(i,n,1){
		memcpy(hz0[i],hz0[i+1],sizeof(hz0[i+1]));
		if(S[i]=='W')hz0[i][0]=i;else hz0[i][1]=i;
	}
	rep(i,1,n){
		memcpy(qz0[i],qz0[i-1],sizeof(qz0[i-1]));
		if(S[i]=='W')qz0[i][0]=i;else qz0[i][1]=i;
	}
	while(q--){
		int x1,y1,x2,y2;
		read(x1);read(y1);read(x2);read(y2);
		res=inf;dfs(x1,y1,x2,y2,0,0,0);dfs(x1,y1,x2,y2,0,1,0);
		printf("%d\n",res<inf?res:-1);
	}
	return 0;
}


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


int main() {
  
  int N;
  cin >> N;
  
  map<string, long long> MAP;
  
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    MAP[s]++;
  }
  
  long long ans = 0;
  
  for (auto p : MAP) {
    long long a = p.second;
    ans += a * (a - 1) / 2;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define INF 1e18
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int r;
    cin >> r;
    print(r*r);
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;

int main(){
  int V,E,cnt[10000];
  vector<int> G[10000],ans;
  scanf("%d %d",&V,&E);
  fill(cnt,cnt+V,0);
  for(int i=0;i<E;i++){
    int s,t;
    scanf("%d %d",&s,&t);
    G[s].push_back(t);
    cnt[t]++;
  }
  queue<int> q;
  for(int i=0;i<V;i++){
    if(cnt[i]==0) q.push(i);
  }
  while(!q.empty()){
    int v = q.front(); q.pop();
    ans.push_back(v);
    for(int i=0;i<G[v].size();i++){
      cnt[G[v][i]]--;
      if(cnt[G[v][i]]==0) q.push(G[v][i]);
    }
  }
  for(int i=0;i<V;i++) printf("%d\n",ans[i]);
  return 0;
}

Measured memory_bytes: 3416
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる

bool ok(ll n, ll k) {
  if((n-1)%k==0) return true;
  else if (n==k) return true;
  else if (n%k==0) return ok(n/k,k);
  else return false;
}

ll ans(ll n) {
  ll cnt=2;
  for(ll i=2;i*i<=n-1;i++){
    if((n-1)%i==0) {
      if(n-1==i*i) cnt+=ok(n,i);
      else cnt+=ok(n,i)+ok(n,(n-1)/i);
    }
  }
  for(ll i=2;i*i<=n;i++){
    if(n%i==0) {
      if(n==i*i) cnt+=ok(n,i);
      else cnt+=ok(n,i)+ok(n,n/i);
    }
  }  
  return cnt;
}


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

  ll n;
  cin>>n;

  if(n==2){
    cout << 1 << endl;
    return 0;
  }

  cout << ans(n) << endl;

}


Measured memory_bytes: 3564
#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>
using namespace std;
int main(){
    long n,m,a[101][101],b[101],sum=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=m;i++){
        cin>>b[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            sum+=a[i][j]*b[j];
        }
        cout<<sum<<endl;
        sum=0;
    }
    return 0;
}

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

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

int main() {
    string s;cin>>s;
    int n = s.size();
    
    int a[2];
    a[0] = a[1] = 0;
    rep(i,n){
        if(s[i]=='0')++a[0];
        if(s[i]=='1')++a[1];
    }
    cout<<2*min(a[0],a[1])<<endl;
	return 0;
}

Measured memory_bytes: 3772
#include<stdio.h>
int main(void){
  int a,j,i;
  scanf("%d",&a);
  for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
      if(i*j==a){
        printf("Yes\n");
        return 0;
      }
    }
  }printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

vector<int> i2g;          // i2g[i] := アイテム i の所属するグループの番号(find)
vector<vector<int>> g2i;  // g2i[g] := グループ g に所属するアイテムたち
map<pii,int> g[101010];

void union_init(int n) {
  i2g.resize(n);
  g2i.resize(n);
  for (int i = 0; i < n; ++i) {
    // 最初はアイテム i はグループ i に所属
    i2g[i] = i;
    g2i[i].assign(1, i);
  }
}

int find(int i){
  return i2g[i];
}

// アイテム ia の所属するグループとアイテム ib の所属するグループを 1 つにする
void merge(int ia, int ib) {
  if(i2g[ia]==i2g[ib])return;
  // ia の所属するグループが ib の所属するグループより小さくならないようにする
  if (g2i[i2g[ia]].size() < g2i[i2g[ib]].size()) {
    swap(ia, ib);
  }
  int ga = i2g[ia], gb = i2g[ib];
  // グループ gb に所属する全てのアイテムをグループ ga に移す
  for (int j : g2i[gb]) i2g[j] = ga;
	g2i[ga].insert(g2i[ga].end(), g2i[gb].begin(), g2i[gb].end());
	for(auto x:g[gb]){
		g[ga].insert(x);
	}
  g2i[gb].clear();
}

// アイテム ia とアイテム ib は同じグループに所属しているか？
bool is_same_group(int ia, int ib) {
  return i2g[ia] == i2g[ib];
}


int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n,m;
	cin>>n>>m;
	vector<int> a(n);
	vector<int> alive(n,1);
	union_init(n);
	FOR(i,0,n){
		cin>>a[i];
		g[i][MP(a[i],i)]=1;
	}
	FOR(i,0,m){
		int a,s;
		cin>>a>>s;
		if(!is_same_group(a,s)){
			int tmp=i2g[a]+i2g[s];
			merge(a,s);
			alive[tmp-i2g[a]]=0;
		}
	}
	if(m==n-1){
		cout<<0<<endl;
		return 0;
	}
	priority_queue<pii,vector<pii>,greater<pii>> pq;
	LL ans=0;
	int c=0;
	FOR(i,0,n){
		if(alive[i]){
			c++;
			int a=(*(g[i2g[i]].begin())).ST.ST;
			g[i2g[i]].erase((*(g[i2g[i]].begin())).ST);
			ans+=a;
			for(const auto x:g[i2g[i]]){
				int aa=x.ST.ST;
				pq.push(MP(aa,i2g[i]));
			}
		}
	}
	if(c-1>n/2){
		cout<<"Impossible"<<endl;
		return 0;
	}
	FOR(i,0,(c-1)*2-c){
		auto pr=pq.top();pq.pop();
		ans+=pr.ST;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 33196
using System;
namespace kozaiyApp
{
    public class MultipleClocks
    {
        static void Main()
        {
            ulong N = ulong.Parse(Console.ReadLine());
            ulong[] T = new ulong[N];

            ulong m = ulong.Parse(Console.ReadLine());
            ulong n;

            // 最小公倍数を求めていく
            for (ulong i = 0; i < N - 1; i++)
            {
                n = ulong.Parse(Console.ReadLine());
                m = LeastCommonMultiple(m, n);
            }

            Console.WriteLine(m);
        }

        // 最大公約数 m > n ユークリッドの互除法 
        public static ulong Gcd(ulong m, ulong n)
        {
			if (n == 0) return m;
			return Gcd(n, m % n);
        }

        // 最小公倍数 m > n
        public static ulong LeastCommonMultiple(ulong m, ulong n)
        {
            return m / Gcd(m, n) * n;
        }
    }
}


Measured memory_bytes: 13140
read n;

E=echo
l=`sed 's/ /\\\n/g'`

s() {
  ($E -e $l | awk 'NR%2=='"$1"'' | sort -n | uniq -c | sort -rn; $E 0 0) | head -2
}

ss() {
  $E -e $l | awk 'NR%2=='"$1"'' | sort -rn | uniq -c | sort -rn
}

g() {
  $E $((a=$1+$7,b=$3+$5,$2!=$6?n-$1-$5:a>b?n-a:n-b))
  # echo $a $b
}

# echo ">>111"
# s 1
# echo "<<"
# echo ">>222"
# s 0
# echo "<<"
g `s 1; s 0`


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

#define ff(i,a,b)       for(int i=(a), _b=(b); i <= _b; ++i)
#define gg(i,a,b)       for(int i=(a), _b=(b); i >= _b; --i)
#define REP(i ,b)       for(int i=(0), _b=(b); i <  _b; ++i)
#define long            long long
#define ALL(v)          v.begin(), v.end()
#define endl            '\n'
#define Love(a)         {cerr << #a << " = " << a << endl;}
#define _               << " , " <<
#define X               first
#define Y               second

#define NAME            "arc085E"

using namespace std;
const int N = 107, M = N*N;
const long INF = (long)1e18 + 7;

struct edge {
    int x, y;
    long f, c;
    edge () {}
    edge (int x, int y, long f, long c) : x(x), y(y), f(f), c(c) {}
}e[2*M];

int n, a[N], link[2*M], head[N];
long sum, C;

void Build(int k, int x, int y, long f, long c) {
    e[k] = edge(x, y, f, c);
    link[k] = head[x];
    head[x] = k;
}

struct LuongCucDai {
    int E, S, T, save[N];
    void AddEdge(int x, int y, long c) {
        ++E;
        Build(E*2, x, y, 0, c);
        Build(E*2+1, y, x, 0, 0);
    }
    bool FindPath() {
        queue<int> Q;
        fill_n(save, n+2, 0);
        save[S] = -1;
        Q.push(S);
        while (Q.size()) {
            int u = Q.front(); Q.pop();
            for (int i = head[u]; i; i = link[i])
                if (e[i].c - e[i].f > 0) {
                    int v = e[i].y;
                    if (!save[v]) {
                        Q.push(v);
                        save[v] = i;
                        if (v == T) return true;
                    }
                }
        }
        return false;
    }
    long UpFlow() {
        long mimi = INF, v, i;
        v = T;
        while (v != S) {
            i = save[v];
            mimi = min(mimi, e[i].c - e[i].f);
            v = e[i].x;
        }

        v = T;
        while (v != S) {
            i = save[v];
            e[i].f += mimi;
            e[i^1].f -= mimi;
            v = e[i].x;
        }
        return mimi;
    }
    long MaxFlow(int s, int t) {
        S = s;  T = t;
        long res = 0;
        while (FindPath()) {
            res += UpFlow();
        }
        return res;
    }
    void Result() {
        int dap[N];
        fill_n(dap, n+2, 0);
        ff(i,1 , n)
            if (save[i] != 0) {
                ff(z, 1, n/i) dap[i*z] = true;
            }
        long res = 0;
        ff(i, 1, n)
            if (!dap[i]) res += a[i];

        cout << res << endl;
    }
}flow;

void Enter() {
    cin >> n;
    ff(i, 1, n) cin >> a[i], sum += a[i];

    ff(i, 1, n)
        ff(z, 2, n/i) flow.AddEdge(i, z*i, INF);


    ff(i, 1, n)
        if (a[i] <= 0) {
            flow.AddEdge(0, i, -a[i]);
            C += -a[i];
        }
        else
           flow.AddEdge(i, n+1, a[i]);
}

void Process() {
    flow.MaxFlow(0, n+1);
    flow.Result();
}

int main() {
    ios_base::sync_with_stdio(0);  cin.tie(0);
   // freopen(NAME".inp", "r", stdin);
    //freopen(NAME".out", "w", stdout);
    Enter();
    Process();
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll mod = pow(10, 9) + 7;
  vector<ll> dp(60);
  dp.at(0) = 1;
  for (ll i = 0; i < 59; ++i) {
    dp.at(i + 1) = dp.at(i) * 2;
  }
  ll N;
  cin >> N;
  vector<ll> num(60, 0);
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    for (ll j = 0; j < 60; ++j) {
      if ((a & dp.at(j)) != 0) {
        num.at(j) += 1;
      }
    }
  }
  ll ans = 0;
  for (ll i = 0; i < 60; ++i) {
    ll temp = num.at(i) * (N - num.at(i)) % mod;
    temp = (temp * (dp.at(i) % mod)) % mod;
    ans = (ans + temp) % mod;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

class Point {
  public:
  long double x, y;

  Point(long double x = 0, long double y = 0): x(x), y(y) {}

  Point operator + (Point &p) {
    return Point(x + p.x, y + p.y);
  }

  Point operator - (Point &p) {
    return Point(x - p.x, y - p.y);
  }

  Point operator * (long double k) {
    return Point(x * k, y * k);
  }

  Point operator / (long double k) {
    return Point(x / k, y / k);
  }

  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }
};

long double norm(Point p) {
  return p.x * p.x + p.y * p.y;
}

long double abs(Point p) {
  return sqrt(norm(p));
}

long double dot(Point p1, Point p2) {
  return p1.x * p2.x + p1.y * p2.y;
}

long double cross(Point p1, Point p2) {
  return p1.x * p2.y - p1.y * p2.x;
}

int ccw(Point p0, Point p1, Point p2) {
  Point v1 = p1 - p0, v2 = p2 - p0;
  if (cross(v1, v2) > 0) return 1;
  else if (cross(v1, v2) < 0) return -1;
  else if (dot(v1, v2) < 0) return 2;
  else if (norm(v1) < norm(v2)) return -2;
  else return 0;
}

bool intersect(Point p1, Point p2, Point p3, Point p4) {
  return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

long double getDistanceLP(Point p1, Point p2, Point p3) {
  return fabs(cross(p2-p1, p3-p1) / abs(p2-p1));
}

long double getDistanceSP(Point p1, Point p2, Point p3) {
  if (dot(p2-p1, p3-p1) < 0) return abs(p3-p1);
  else if (dot(p1-p2, p3-p2) < 0) return abs(p3-p2);
  else return getDistanceLP(p1, p2, p3);
}

long double getDistanceTS(Point p1, Point p2, Point p3, Point p4) {
  if (intersect(p1, p2, p3, p4)) return 0;
  long double ans = INF;
  ans = min(ans, getDistanceSP(p1, p2, p3));
  ans = min(ans, getDistanceSP(p1, p2, p4));
  ans = min(ans, getDistanceSP(p3, p4, p1));
  ans = min(ans, getDistanceSP(p3, p4, p2));
  return ans;
}

int main() {
  int q;
  cin >> q;
  Point p0, p1, p2, p3, ans;
  long double d1, d2, t;
  rep(i, q) {
    cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
    d1 = getDistanceLP(p0, p1, p2);
    d2 = getDistanceLP(p0, p1, p3);
    t = d1 / (d1 + d2);
    p2 = p2 * (1-t);
    p3 = p3 * t;
    ans = p2 + p3;
    if (equals(ans.x, 0)) ans.x = 0;
    if (equals(ans.y, 0)) ans.y = 0;
    cout << setprecision(15) << ans.x << " " << ans.y << endl;
  }


  
  return 0;
}


Measured memory_bytes: 3280
#include<stdio.h>


int main(void)


{


int W,H,x,y,r;


scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);


if(H>=y+r&&W>=x+r&&x-r>=0&&y-r>=0)


{


printf("Yes\n");


}else{


printf("No\n");


}


return 0;


}

Measured memory_bytes: 1012
n = int(input())
f = [0]*n
for i in range(n):
  f[i] = [int(x) for x in input().split()]

p = [0]*n
for i in range(n):
  p[i] = [int(x) for x in input().split()]

ans = -10**9-7

for i in range(2**10):
  o = [0]*10
  for j in range(10):
    if (i >> j) & 1:
      o[j] = 1
  if not any(o):
    continue
  sub = 0
  for k in range(n):
    key = 0
    for j in range(10):
      if o[j] and f[k][j]:
        key += 1
    sub += p[k][key]
  if sub > ans:
    ans = sub

print(ans)

Measured memory_bytes: 42992
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int main() {

    string str;
    std::cin >>str;

    int length;
    length=str.size();        

    std::vector<int> stone(length);

    ll first;
    first=0;
    int number=0;
    for(int i=0;i<length;i++){
        if(str[i]=='B'){
            stone[i]=1;
            first +=i;
            number++;
        }else{
            stone[i]=0;
        }
    }
    
    int j;
    ll after;
    after=0;
    for(j=0;j< number;j++){
        after+=length-1 -j;
    }

    printf("%llu\n",after-first);

    return 0;
}


Measured memory_bytes: 1412
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    int n;
    cin >> n;
    int h[n+1] = {};
    inrep(n,h);

    int ans = 0;

    while(1){
        int cnt = 0,m =0;
        rep(i,0,n+1){
            if(h[i] == 0){
                if(m > 0)cnt++;
                m = 0;
            }else{
                m++;
                h[i]--;
            }
        }

        if(cnt == 0)break;
        ans += cnt;

       // rep(i,0,n)PS(h[i]);
       // P(ans);
    }
    P(ans);
	return  0;
}

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

int main(){
  int count=0;
  int N;
  cin>>N;
  vector<int>X(N);
  rep(i,N){
    cin>>X[i];
  }
  rep(i,N){
    int x=0;
    cin>>x;
    X[i]=X[i]-x;
  }
  rep(i,N){
    if(X[i]>=0){
      count+=X[i];
    }
  }
  cout<<count;
  
}


Measured memory_bytes: 256
/* 
      Life before Death
      Strength before Weakness
      Journey before Destination
*/
                           
#include <bits/stdc++.h>
using namespace std;
                 
typedef long long ll;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,n,a) for (ll i=n;i>a;i--)
#define te ll t; std::cin >> t; while(t--)
#define SZ 500010
//# define M_PIl  3.141592653589793238462643383279502884L 
/*------Just DO IT--------------------------------------*/

ll p[60], b[60] , a[60];

ll f( ll n,ll x){
  if(n==0) return 1;
  if(x<=n) return 0;
  else if(x<=a[n]/2) return f(n-1,x-1);
  else if(x<=a[n]/2 + 2) return p[n-1] + 1;
  else if(x < a[n] - n) return p[n-1]  + 1 + f(n-1 ,x-a[n]/2 -1);
  else return p[n];
}

ll solve(){
  ll n,k;
  cin>>n>>k;
  p[0] =1; a[0] = 1;
  rep(i,1,n+1) {
    p[i] = 2*p[i-1] + 1;
    b[i] = 2*b[i-1] + 2;
    a[i] = 2*a[i-1] + 3;
  }
  cout<<f(n,k)<<endl;
}

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

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(N):
    B.append(A[i] - i-1)
c = sorted(B)
ans = float('inf')
l = 0
r = sum(c)
for i in range(N):
    b = c[i]
    l += c[i]
    r -= c[i]
    tmp = b*((i+1) - (N - i - 1)) + r - l
    if tmp < ans:
        ans = tmp
print(ans)

Measured memory_bytes: 101204
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  vector<string> pats = {"dream", "erase", "eraser", "dreamer"};

  auto tail = [&](int i, const string& s) {
    int m = s.size();
    if (i - m + 1 < 0) return false;
    return S.substr(i - m + 1, m) == s;
  };

  auto good = [&]() {
    for (int i = S.size() - 1; i >= 0;) {
      for (string& s : pats) {
        if (tail(i, s)) {
          i -= s.size();
          goto HOGE;
        }
      }
      return false;
    HOGE:;
    }
    return true;
  };

  cout << (good() ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int max(const void *a, const void *b){return *(int*)b - *(int*)a;}

int main(void)
{
    int n,c;
    scanf("%d",&n);
    
    c = 0;
    for(int i=1;i<=n;i++)
    {
        int a;
        scanf("%d",&a);
        if (a!=i) c++;
    }

    printf("%s\n",c==0||c==2? "YES" : "NO" );
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> p(N);
	
	int sum = 0;

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

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

	for(int i = 0; i < K; i++){
		sum += p.at(i);	
	}
	cout << sum << "\n";	
}


Measured memory_bytes: 3144
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.List;

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int x=sc.nextInt();
        int l[]=new int[n];
        for (int i=0;i<n;i++){
            l[i]=sc.nextInt();
        }
        int d[]=new int[n+1];
        d[0]=0;
        int cnt=0;
        for (int i=1;i<n+1;i++){
            d[i]=d[i-1]+l[i-1];
            if (d[i]<=x){
                cnt++;
            }
        }
        System.out.println(cnt+1);
    }


}



Measured memory_bytes: 21840
package main

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

func main() {
	sc := newScanner(os.Stdin)
	N, M, X := sc.i(), sc.i(), sc.i()
	books := make([][]int, 0, N)
	for i := 0; i < N; i++ {
		book := sc.is(M + 1)
		books = append(books, book)
	}
	ans := 12345678
	all := 1 << N
	for mask := 0; mask < all; mask++ {
		level := make([]int, M)
		cost := 0
		for i := 0; i < N; i++ {
			if mask>>i&1 == 1 {
				cost = cost + books[i][0]
				for j := 0; j < M; j++ {
					level[j] = level[j] + books[i][j+1]
				}
			}
		}
		ok := true
		for i := 0; i < M; i++ {
			if level[i] < X {
				ok = false
			}
		}
		if ok {
			ans = min(ans, cost)
		}
	}
	if ans == 12345678 {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}

}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

func Pow(x, y int) int {
	fx := float64(x)
	fy := float64(y)
	z := math.Pow(fx, fy)
	return int(z)
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 2164
import math
# a=int(input())
# b=input()
# c=[]
# for i in b:
#     c.append(i)
e = list(map(int,input().split()))
#f = list(map(int,input().split()))
j = [int(input()) for _ in range(e[0])]
a = sum(j)
count=e[0]
if a==e[1]:
    count+=0
else:
    count+=(e[1]-a)//min(j)
print(count)

Measured memory_bytes: 9124