akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  int n;
  cin >> n;
  int arr[n];
  int ans = 2e9, rig = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    rig += arr[i];
  }
  int lef = 0;
  ans = min(ans, rig);
  for (int i = 0; i < n; i++) {
    rig -= arr[i];
    lef += arr[i];
    ans = min(ans, abs(rig - lef));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools
H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]
is_searched = [[False for _ in range(W)] for _ in range(H)]


def dfs(p, q):
    if is_searched[p][q] == 1:
        return 0
    count = {'#': 0, '.': 0}
    stack = [[p, q]]
    while stack:
        x, y = stack.pop()
        if is_searched[x][y] != 1:
            is_searched[x][y] = 1
            count[S[x][y]] += 1
            dxy = [[-1, 0], [1, 0], [0, -1], [0, 1]]
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and S[x][y] != S[nx][ny]:
                    stack += [[nx, ny]]
    return count['#'] * count['.']


print(sum([dfs(i, j) for i, j in itertools.product(range(H), range(W))]))


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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < N;i++){
        cin>>a[i];
        if(a[i]%4==0){
            cnt1++;
        }else if(a[i]%2==0){
            cnt2++;
        }
    }
    bool ok = false;

    if(cnt1 >= N/2){
        ok = true;
    }else if(cnt1*2 + cnt2>=N){
        ok = true;
    }
    if(ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
	int n; cin >> n ;
	for(int i=0;i<n;i++){
		int a[10] ;
		for(int j=0;j<10;j++) cin >> a[j] ;
		int stackA[10]={a[0],0}; int stackB[10]={0};
		int na=0;int nb=0;int flag=0;
		for(int j=1;j<10;j++){
			if(flag==1) break;
			if(a[j]>stackA[na-1]) stackA[na++]=a[j];
			else if(nb==0) stackB[nb++]=a[j];
			else if(a[j]>stackB[nb-1]) stackB[nb++]=a[j];
			else flag=1;
		};
		if(flag==1) cout << "NO\n" ;
		else cout << "YES\n" ;
	};
}

Measured memory_bytes: 1120
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
// vector<int> dx={0,1,-1,0};
// vector<int> dy={1,0,0,-1};

struct edge{int to; int cost;};
vector<vector<edge>> graph(0);
vector<int> d(0);
const int MAX_dist=1e9;

void init(int n){
    graph.resize(n);
    d.resize(n,MAX_dist);
}

void dijkstra(int s){
if(d.size()==0){cout<<"You Should init"<<endl;return;}
    priority_queue<P, vector<P>, greater<P>> que;
    d[s]=0;
    que.emplace(0,s);
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,graph[v].size()){
            edge e=graph[v][i];
            if(d[e.to]>d[v]+e.cost){
            d[e.to]=d[v]+e.cost;
            que.emplace(d[e.to],e.to);
            }
        }
    }
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int h,w,Ch,Cw,Dh,Dw;
    cin>>h>>w>>Ch>>Cw>>Dh>>Dw;
    Ch --;
    Cw --;
    Dh --;
    Dw --;
    vector<vector<char>> a(h,vector<char>(w));
    rep(i,h)rep(j,w) cin>>a[i][j];

    init(h*w);
    //左右に行く
    rep(i,h){
        rep(j,w){
            if(a[i][j]=='#') continue;
            if(j!=0 && a[i][j-1]=='.') graph[i*w+j].push_back({i*w+j-1,0});
            if(j!=w-1 && a[i][j+1]=='.') graph[i*w+j].push_back({i*w+j+1,0});
        }
    }
    // //上下に行く
    rep(i,h){
        rep(j,w){
            if(a[i][j]=='#') continue;
            if(i!=0 && a[i-1][j]=='.') graph[i*w+j].push_back({i*w+j-w,0});
            if(i!=h-1 && a[i+1][j]=='.') graph[i*w+j].push_back({i*w+j+w,0});
        }
    }

    rep(i,h)rep(j,w){
        if(a[i][j]=='#') continue;
        for(int k=-2;k<=2;k++){
            if(i+k<0 || i+k>=h) continue;
            for(int l=-2;l<=2;l++){
                if(abs(k)<=1 && l==0) continue;
                if(abs(l)<=1 && k==0) continue;
                if(k==0 && l==0) continue;
                if(j+l<0 || j+l>=w) continue;
                if(a[i+k][j+l]=='#') continue;
                graph[i*w+j].push_back({(i+k)*w+(j+l),1});
            }
        }
    }

    dijkstra(Ch*w+Cw);
    if(d[Dh*w+Dw]==MAX_dist) cout<<-1<<endl;
    else cout<<d[Dh*w+Dw]<<endl;    
    // rep(i,25) cout<<d[i]<<" ";
    // cout<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 101940
#include<stdio.h>
#include<stdlib.h>

typedef struct node{
  int key, priority;
  struct node *left;
  struct node *right;
}node;

int find(node *p, int x){
  while(p != NULL){
    if(p->key == x)     return 1;
    else if(p->key > x) p = p->left;
    else                p = p->right;
  }
  return 0;
}

void inorder(node *p){
  if(p->left != NULL)   inorder(p->left);	
  printf(" %d", p->key);	
  if(p->right != NULL)  inorder(p->right);	 
  return;	
}

void preorder(node *p){
  printf(" %d", p->key);
  if(p->left != NULL)   preorder(p->left);
  if(p->right != NULL)  preorder(p->right);
  return;
	
}

void print(node *p){
  inorder(p);
  printf("\n");
  preorder(p);
  printf("\n");
  return;
}

node * makenode(int x,int y){
  node *new = malloc(sizeof(node));
  new->key = x;
  new->priority = y;
  new->left = NULL;
  new->right = NULL;
  return new;
}

node *rightRotate(node *p){
  node *q  = p->left;
  p->left  = q->right;
  q->right = p;
  return q;
}

node *leftRotate(node *p){
  node *q  = p->right;
  p->right = q->left;
  q->left  = p;
  return q;
}


node* insert(node **t, int key, int priority){
  node *new;
	
  if((*t) == NULL)
    return new = makenode(key, priority);
  if ((*t)->key == key)
    return *t;
	
  if(key < (*t)->key){
    (*t)->left = insert(&(*t)->left, key, priority);
    if((*t)->priority < (*t)->left->priority)
      (*t) = rightRotate((*t));
  }
  else{
    (*t)->right = insert(&(*t)->right, key, priority);
    if((*t)->priority < (*t)->right->priority)
      (*t) = leftRotate((*t));
  }
	
  return *t;
}

node *Delete(node **,int);
node *_delete(node **,int);

node * Delete(node **t, int key){
  if((*t) == NULL)
    return NULL;
		
  if(key < (*t)->key)       (*t)->left = Delete(&((*t)->left),key);
  else if(key > (*t)->key)  (*t)->right = Delete(&((*t)->right),key);	
  else                      return _delete(t,key);
  return *t;
}

node * _delete(node **t,int key){
  if((*t)->left == NULL && (*t)->right == NULL) return NULL;
  else if((*t)->left == NULL)                   (*t) = leftRotate(*t);
  else if((*t)->right == NULL)                  (*t) = rightRotate(*t);
  else{
    if((*t)->left->priority > (*t)->right->priority)    (*t) = rightRotate(*t);
    else                                                (*t) = leftRotate(*t);
  }
  return Delete(t,key);
}


int main(){
  int n, x, y;
  char com[8];
  node *root = NULL;
	
  scanf("%d", &n);
	
  for(int i=0 ; i<n ; i++){
    scanf("%s", com);
		
    switch(com[0]){
		
    case 'i' : scanf("%d %d", &x, &y);
      root = insert(&root, x, y);
      break;
			
    case 'd' : scanf("%d", &x);
      root = Delete(&root, x);
      break;
					
    case 'f' : scanf("%d", &x);
      if(find(root,x)) printf("yes\n");
      else printf("no\n");
      break;

    case 'p' : print(root);
      break;
    }	
  }
	
  return 0;	
}



Measured memory_bytes: 8108
#include <iostream>

using namespace std;

int main(){
  int n,p;
  cin >> n >> p;
  while(1){
    if(n==0)break;
    int have[n]={},i=0,con=0,non=n;
    while(1){
      if(p>0){
        if(have[i]==0)non--;
        have[i]++;
        p--;
        if(p==0 && non==n-1)break;
      }else{
        if(have[i]>0){
          p+=have[i];
          have[i]=0;
          non++;
        }
      }
      i++;
      if(i==n)i=0;
    }
    cout << i << endl;
    cin >> n >> p;
  }
  return 0;
}



Measured memory_bytes: 3088
#include <stdio.h>
#include <stdlib.h>

struct Item {
	long int weight;
	long int value;
} typedef tItem;

int main() {
	long int n, w, aux, i, j, newWeight, newValue;

	scanf("%ld", &n);
	scanf("%ld", &w);

	tItem items[n];
	long int selected[w + 1][n + 1];

	for (i = 0; i < n; i++) {
		scanf("%ld", &aux);
		items[i].weight = aux;

		scanf("%ld", &aux);
		items[i].value = aux;
	}

	for (i = 0; i <= n; i++) {
		for (j = 0; j <= w; j++) {
			if (i == 0) {
				selected[j][i] = 0;
				selected[j][i] = 0;
			} else {
				newWeight = j - items[i - 1].weight;
				newValue = newWeight >= 0 ? selected[newWeight][i - 1] + items[i - 1].value : -1;

				if (newWeight >= 0 && newValue > selected[j][i - 1]) {
					selected[j][i] = newValue;
				} else {
					selected[j][i] = selected[j][i - 1];
				}
			}
		}
	}

	printf("%ld\n", selected[w][n]);

	return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  while(1){
    c-=b;
    if(c<=0){ 
      cout << "Yes"<<endl;
      break;
    }
    a-=d;
    if(a<=0) {
      cout << "No"<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    vector<int> cnt(4);

    rep(i, 6) {
        int a;
        cin >> a;
        a--;
        cnt[a]++;
    }

    sort(all(cnt));

    if (cnt[0] == 1 && cnt[1] == 1 && cnt[2] == 2 && cnt[3] == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int linearSearch(int *,int);

int length=0;

int main(){
  int n=0;
  int q=0;
  int i=0;
  int count=0;
  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  int T[q];
  for(i=0;i<q;i++){
    scanf("%d", &T[i]);
  }
  length=sizeof(S)/sizeof(int);
  for(i=0;i<q;i++){
    if(linearSearch(S,T[i])==1)
      count++;
  }
  printf("%d",count);
  printf("\n");

  return 0;
}

int linearSearch(int *A,int key){
  int i=0;
  A[length]=key;
  while(A[i]!=key){
    i++;
    if(i==length) return 0;
  }
  return 1;
}



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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int l = -1; l < n; l++) {
        for (int r = n; r > l; r--) {
            int x = l + 1;
            int y = n - r;
            if (x + y > k) {
                continue;
            }
            vector <int> b;
            vector <int> c;
            int sum_x = 0, sum_y = 0;
            for (int i = 0; i <= l; i++) {
                b.push_back(a[i]);
                sum_x += a[i];
            }
            for (int i = r; i < n; i++) {
                c.push_back(a[i]);
                sum_y += a[i];
            }
            sort(b.begin(), b.end());
            sort(c.begin(), c.end());
            ans = max(ans, sum_x + sum_y);
            int px = 0, py = 0;
            for (int to : b) {
                px += (to < 0);
            }
            for (int to : c) {
                py += (to < 0);
            }
            for (int xx = 0; xx <= px; xx++) {
                if (xx > 0) {
                    sum_x -= b[xx - 1];
                }
                int nsum = sum_y;
                for (int yy = 0; yy <= py; yy++) {
                    if (xx + yy + x + y > k) {
                        continue;
                    }
                    if (yy > 0) {
                        nsum -= c[yy - 1];
                    }
                    ans = max(ans, sum_x + nsum);
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n,i; cin >> n >> i;
    
    cout << n-i+1 << ln;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
import re

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

S = s_in()
T = s_in()
N = len(S)

rec = []
idxes = [i for i in range(26)]

def alpnum(s):
    return ord(s) - ord('a')

for i in range(N):
    si = alpnum(S[i])
    ti = alpnum(T[i])
    if (idxes[si] != ti):
        if (idxes[si] in rec) or (ti in rec):
            print('No')
            exit()
        idx = idxes.index(ti)
        idxes[si], idxes[idx] = idxes[idx], idxes[si]
    rec.append(ti)
print('Yes')


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

ll solve() {
    ll H, W;
    cin >> H >> W;

    auto func = [](ll h, ll w) {
        ll d_min = h*w;
        for ( int i = 0; i < 2; i++ ) {
            for ( int j = 0; j < 2; j++ ) {
                ll w1 = w/3 + i;
                ll s1 = w1 * h;
                ll w2 = (w - w1)/2 + j;
                ll s2 = w2 * h;
                ll s3 = (w - w1 - w2) * h;
                if ( s1 == 0 || s2 == 0 || s3 == 0) continue;
                ll d = max({s1,s2,s3}) - min({s1,s2,s3});
                if ( d_min > d ) d_min = d;
            }
        }
        for ( int i = 0; i < 2; i++ ) {
            for ( int j = 0; j < 2; j++ ) {
                ll w1 = w/3 + i;
                ll s1 = w1 * h;
                ll h2 = h/2 + j;
                ll s2 = (w - w1) * h2;
                ll s3 = (w - w1) * (h-h2);
                if ( s1 == 0 || s2 == 0 || s3 == 0) continue;
                ll d = max({s1,s2,s3}) - min({s1,s2,s3});
                if ( d_min > d ) d_min = d;
            }
        }
        return d_min;
    };

    ll ans  = min(func(H,W), func(W,H));
    return ans;
}

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

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int res = Math.max(a+b, Math.max(2*a-1, 2*b-1));
		System.out.println(res);
	}
}

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

int INF = 1000000007;

ll dp[2005][2005];
void compute()
{
  for (int i = 0; i < 2005; i++)
  {
    for (int j = 0; j <= i; j++)
    {
      if (j == 0 || i == j)
      {
        dp[i][j] = 1;
      }
      else
      {
        dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % INF;
      }
    }
  }
}

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

  compute();
  for (int i = 1; i <= k; i++)
  {
    cout << (dp[n - k + 1][i] * dp[k - 1][i - 1]) % INF << endl;
  }
}

Measured memory_bytes: 30208
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAX=105;
int M[MAX][MAX];
int main(){
	int n,u,k;
	cin>>n;
	memset(M,0,sizeof(M));
	for(int i=0;i<n;i++){
		cin>>u>>k;
		int v;
		for(int j=0;j<k;j++){
			cin>>v;
			M[u][v]=1;
		}
	}		
	for(int i=1;i<=n;i++){
		int first=1;
			for(int j=1;j<=n;j++){
				if(first)first=0;else putchar(' ');
				cout<<M[i][j];
			}
			cout<<endl;
		}
	return 0;
}


Measured memory_bytes: 3160
n = gets.to_i
a = gets.split.map(&:to_i)
sum = a.inject(:+)
ans = sum
tmp = 0
(n-1).times do |i|
  v = a[i]
  tmp += v
  x = ((sum-tmp).abs - tmp).abs
  ans = x if x < ans
end
p ans

Measured memory_bytes: 18076
S = list(input())
ans = 'AKIHABARA'

while len(S) <= len(ans):
	S.append('') # IndexOut対策に空文字列を追加

isCorrect = True

i = 0
while i<(len(ans)):
	# print(i, S[i], ans[i])
	if S[i] == ans[i]:
		i += 1
		continue

	if ans[i] == 'A':
		if S[i] == '':
			S[i] = 'A'
		else:
			S.insert(i,'A')
		continue

	isCorrect = False
	break

S = [s for s in S if s!=''] # IndexOut対策の空文字列を削除

if isCorrect and len(S)==len(ans):
	print('YES')
else:
	print('NO')

Measured memory_bytes: 3064
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
  
        static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());
            int count = 0;
            while (true)
            {
                count++;
                if (s == 1)
                {
                    count++;
                    break;
                }
                else if (s % 2 == 0)
                {
                    s /= 2;
                }
                else
                {
                    s = s * 3 + 1;
                }
            }
            Console.WriteLine(Math.Max(4, count));
        }
    }
}

Measured memory_bytes: 11220
d = input("")
N = int(d)
d = input("")
list = d.split()
num = []

i = 0
j = 0
while i < N:
    if ( i + 1 ) % 2 == 1:
        num.append (list[i])
        j = j + 1
    i = i + 1

j = 0
len = len(num)
count = 0
while j < len:
    if int(num[j]) % 2 == 1:
        count = count + 1
    j = j + 1

print(count)


Measured memory_bytes: 8936
#include<stdio.h>
#define N 100


int main(){
  int Sec[N],num,i,j,count=0;
  int temp=0,min=0;

  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&Sec[i]);
  }

  for(i=0;i<num-1;i++){
    min=i;
    for(j=i;j<num;j++){
      if(Sec[j]<Sec[min]){
	min=j;
      }
    }
    if(i!=min)count++;
      temp=Sec[i];
      Sec[i]=Sec[min];
      Sec[min]=temp;
  }
  
  for(i=0;i<num-1;i++){
    printf("%d ",Sec[i]);
  }

  printf("%d\n%d\n",Sec[num-1],count);
  return 0;
}



Measured memory_bytes: 2136
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define re register
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,a1,b1,a2,b2,head[1000002],cnt,m;
struct edge{
	int to,next,w;
}e[25000002];
inline void add(re int x,re int y,re int w){
	e[++cnt]=(edge){y,head[x],w};
	head[x]=cnt;
}
struct node{
    int pos,dis;
    bool operator <(const node x)const{
        return dis>x.dis;
    }
}h[1000002];
priority_queue <node> q;
bool v[1000002];
inline int pos(re int x,re int y){
	return (x-1)*m+y;
}
inline void dis(re int s){for(re int i=1;i<=n*m;++i)h[i].dis=1e9,h[i].pos=i;
    h[s].dis=0;
    q.push(h[s]);
    while(!q.empty()){
        while((h[q.top().pos].dis<q.top().dis)){q.pop();if(q.empty())break;
        }
        if(q.empty())break;
        node tmp=q.top();
        q.pop();
        for(re int i=head[tmp.pos];i;i=e[i].next){
            if((tmp.dis+e[i].w)<h[e[i].to].dis){
                h[e[i].to].dis=tmp.dis+e[i].w;
                q.push(h[e[i].to]);
            }
        }
     
    }
}
char s[1002][1002];
int main(){
	n=read(),m=read();
	a1=read(),b1=read(),a2=read(),b2=read();
	for(re int i=1;i<=n;++i)scanf("%s",s[i]+1);
	for(re int i=1;i<=n;++i){
		for(re int j=1;j<=m;++j){
			if(s[i][j]=='.')
			for(re int k=max(i-2,1);k<=min(i+2,n);++k){
				for(re int l=max(j-2,1);l<=min(j+2,m);++l){
					if(abs(i-k)+abs(j-l)<=1)continue;
					if(s[k][l]=='.')
					add(pos(i,j),pos(k,l),1);
				}
			}
		}
	}
	for(re int i=1;i<=n;++i)
		for(re int j=1;j<=m;++j)
			if(s[i][j]=='.'){
				if(s[i-1][j]=='.')add(pos(i,j),pos(i-1,j),0);
				if(s[i+1][j]=='.')add(pos(i,j),pos(i+1,j),0);
				if(s[i][j-1]=='.')add(pos(i,j),pos(i,j-1),0);
				if(s[i][j+1]=='.')add(pos(i,j),pos(i,j+1),0);
			}
	dis(pos(a1,b1));
	if(h[pos(a2,b2)].dis<1e9)printf("%d",h[pos(a2,b2)].dis);
	else puts("-1");
}

Measured memory_bytes: 86048
#ifndef LOCAL
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;

map<int, int> mm;

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		++mm[x];
	}
	int ans = 0;
	for (auto x: mm) {
		if (x.second >= x.first)
			ans += x.second - x.first;
		else
			ans += x.second;
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 4736
#include <iostream>
        #include <vector>
        #include <bits/stdc++.h>
        #define rep(i,n) for (int i = 0; i < (n); ++i)
        using namespace std;
        typedef long long ll;
        typedef pair<int,int> P;
         
        int main(){
            int n,k;
            cin >> n>>k;
          if((n+k)%2!=0){
          cout<<"IMPOSSIBLE"<<endl;
          }else{
          cout << (n+k)/2 <<endl;
        }
        }

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    char s[10];
    scanf("%s",s);
    for(int i=0;i<10;i++){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int k,n,sum=0;
	cin>>n>>k;
	int h[n];

	for(int i=0;i<n;i++)
    {
        cin>>h[i];

    }
    sort(h,h+n,greater<int>());
    for(int i=k;i<n;i++)
    {
        sum+=h[i];
    }
	cout<<sum;
}


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

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

    for (int i = s.size()-2; i >= 0; i-=2) {
        if (s.substr(0, i/2) == s.substr(i/2, i/2)) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

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

ll u[102],d[102];

int main() {
	ll n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin >> u[i];
	}
	for(int j=0;j<n;j++){
		cin>>d[j];
	}
	for(int i=0;i<n;i++){
		u[i+1]=u[i]+u[i+1];
		d[i+1]=d[i]+d[i+1];
	}
	for(int i=0;i<n;i++){
		ll ame=u[i]+d[n-1]-d[i-1];
		ans=max(ans,ame);
	}
	cout <<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()
{
    int n,m,i,c,mn,j;
    string s,t;
    cin>>s;
    cin>>t;
    n=s.size();
    m=t.size();
    for(i=0;i<=n-m;i++)
    {
        c=0;
        for(j=0;j<m;j++)
        {
            if(s[i+j]!=t[j])
                c++;
        }
        if(i==0)
            mn=c;
        else
            mn=min(c,mn);
    }
    cout<<mn<<"\n";
    return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

const int INF = 1001001001;


int main() {

    ll product_count, voucher_count;
    cin >> product_count>> voucher_count;

    priority_queue<ll> prices;

    rep(i, product_count) {
        ll price;
        cin >> price;
        prices.push(price);
    }

    for(ll x = 0 ; x < voucher_count ; x ++) {
        auto price = prices.top();
        prices.pop();
        prices.push(price / 2);
    }

    ll sum = 0;
    while(!prices.empty()) {
        sum += prices.top();
        prices.pop();
    }

    cout << sum << endl;


}


Measured memory_bytes: 1400
N,a,b=map(int,input().split())
MOD=10**9+7
def comb(n,k):
  tmp=1
  for i in range(n-k+1,n+1):
    tmp*=i
    tmp%=MOD
  for i in range(1,k+1):
    tmp*=pow(i,MOD-2,MOD)
    tmp%=MOD
  return tmp
ans = pow(2,N,MOD) - 1 - comb(N,a) - comb(N,b)
print(ans%MOD)

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void pout(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void pout(const T &value, const Args&... args){std::cout << value << " ";pout(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;


std::vector<std::int64_t> divisor_list(std::int64_t n){
  std::vector<std::int64_t> temp, ret;

  {
    std::int64_t i;
    for(i = 1LL; i * i < n; ++i){
      if(n%i == 0){
        temp.push_back(n / i);
        ret.push_back(i);
      }
    }
    if(i * i == n) ret.push_back(i);
  }

  std::reverse(temp.begin(), temp.end());
  ret.insert(ret.end(), temp.begin(), temp.end());
  
  return ret;
}




int main(){
  i64 N;

  while(cin >> N){

    set<i64> ans;

    {
      auto ds = divisor_list(N);

      dump(ds);

      for(auto K : ds){
        if(K == 1) continue;
        auto M = N;

        while(M % K == 0){
          if((M-1) % K == 0) ans.insert(K);
          M /= K;
        }
        if((M-1) % K == 0) ans.insert(K);
      }
    }

    {
      auto ds = divisor_list(N-1);

      for(auto K : ds){
        if(K != 1) ans.insert(K);
      }
    }
    

    pout(ans.size());
  }

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>



constexpr int N = 101;
int n;
int A[2][N];
int C[2][N];

struct Pos{int x, y;};

int main() {
    std::cin >> n;
    for(int i = 0; i < n; i++) {
        std::cin >> A[0][i];
    }
    for(int i = 0; i < n; i++) {
        std::cin >> A[1][i];
    }

    Pos p{0,0};
    C[0][0] = A[0][0];
    C[1][0] = A[1][0] + C[0][0];
    while (true) {
        if (p.x == (n -1)) {
            break;
        }
        C[0][p.x+1] = C[0][p.x] + A[0][p.x + 1];
        C[1][p.x+1] = std::max(C[0][p.x+1]+A[1][p.x+1], C[1][p.x]+A[1][p.x+1]);
        p.x += 1;
    }
    std::cout << C[1][n-1] << std::endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    const int mod = 1e9+7;
    //cout<<mod<<endl;
    int h,w,j;
    char tempChar;
    scanf("%d %d",&h,&w);
    vector<int> prev(w+1,0);
    prev[1]=1;
    while(h--)
    {
        scanf("%c",&tempChar);
        vector<int> dp(1,0);
        for(j=1;j<=w;j++)
        {
            scanf("%c",&tempChar);
            //cout<<"tempChar: "<<tempChar<<endl;
            dp.push_back(0);
            if(tempChar=='.')
            {
                dp[j]+=prev[j];
                if(dp[j]>=mod)
                    dp[j]-=mod;
                //cout<<" "<<prev[j]<<" "<<dp[j]<<endl;

                dp[j]+=dp[j-1];
                if(dp[j]>=mod)
                    dp[j]-=mod;
                //cout<<" "<<dp[j-1]<<" "<<dp[j]<<endl;
            }
        }
        prev=dp;
    }
    printf("%d\n",prev[w]);
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 4223352036854775007
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=100005;
const int NN=2005;
const ll md=998244353;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,k;
    k=1000;
    cin >> n;
    cout << (k-(n%k))%k << E;
    return 0;
}


/*







*/


Measured memory_bytes: 3604
N, M, *xy = map(int, open(0).read().split())
boxes = [{"count": 1, "red": False} for _ in range(N)]
boxes[0]["red"] = True

for x, y in zip(*[iter(xy)] * 2):
    x -= 1
    y -= 1
    if boxes[x]["red"]:
        boxes[y]["red"] = True
        if boxes[x]["count"] == 1:
            boxes[x]["red"] = False
    boxes[x]["count"] -= 1
    boxes[y]["count"] += 1
print(sum(b["red"] for b in boxes))


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

#define all(x) x.begin(), x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, LN = 17, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int H, W, A, B;

ll factorial[MN * 2];

ll fmul(ll x, ll y, ll m) {
    ll ret = 0;
    for (x %= m; y > 0; y >>= 1, x = (x + x) % m)
        if (y & 1) ret = (ret + x) % m;
    return ret;
}

ll fpow(ll x, ll y, ll m) {
    ll ret = 1;
    for (x %= m; y > 0; y >>= 1, x =(x*x)%m)
        if (y & 1) ret = (ret*x)%m;
    return ret;
}

ll inv(int x) {
    return fpow(x, MOD - 2, MOD);
}

ll choose(ll n, ll k) {
    return ((factorial[n] * inv(factorial[k])) % MOD * inv(factorial[n - k])) % MOD;
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    cin >> H >> W >> A >> B;
    if (A == H || B == W) {
        cout << 0 << '\n';
        return 0;
    }
    factorial[0] = 1;
    for (int i = 1; i < 2 * MN; i++) factorial[i] = (factorial[i - 1] * i) % MOD;
    ll ret = 0;
    for (int i = B + 1; i <= W; i++) {
        ll add = fmul(choose(i + H - A - 2, i - 1), choose(A + W - i - 1, A - 1), MOD);
        ret += add;
        if (ret > MOD) ret -= MOD;
    }
    cout << ret << '\n';
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define For( i, j, k ) for( int i = j; i <= k; ++i )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
using std::pair;
using std::cin;
using std::cout;
using std::vector;
using std::make_pair;
const int mod = 1e9 + 7, N = 1007;
int n, A, B, C, D, f[ N ][ N ], fac[ N ], inv[ N ];
inline int POW( int a,int b )
{
 int ret = 1;
 for( ; b; b >>= 1, a = ( long long ) a * a % mod )
  if( b & 1 )
   ret = ( long long ) ret * a % mod; 
 return ret;
}
int main( )
{
 std::ios::sync_with_stdio( false );
 cin >> n >> A >> B >> C >> D;
 fac[ 0 ] = 1;
 For( i, 1, n )
  fac[ i ] = ( long long ) fac[ i - 1 ] * i % mod; 
/* cout << "fac\n";
 For( i, 0, n )
  cout << fac[ i ] << " ";*/
 inv[ n ] = POW( fac[ n ], mod - 2 );
// cout << inv[ n ];
 Rep( i, n - 1, 0 )
  inv[ i ] = ( long long ) ( i + 1 ) * inv[ i + 1 ] % mod;
/* cout << "\ninv\n";
 For( i, 0, n )
  cout << inv[ i ] << " ";*/
 f[ A - 1 ][ 0 ] = 1;
 For( i, A, B )
  For( j, 0, n )
  {
   int &F = f[ i ][ j ];
   F = f[ i - 1 ][ j ];
   for( int k = C, g = POW( inv[ i ], C ); k <= D && k * i <= j; ++k, g = ( long long ) g * inv[ i ] % mod )
   {
//    cout << g << " ";
    int u = n - j + k * i;
    F = ( F + ( long long ) f[ i - 1 ][ j - k * i ] * fac[ u ] % mod * inv[ k * i ] % mod * inv[ u - k * i ] % mod * fac[ k * i ] % mod * g % mod * inv[ k ] % mod ) % mod;
   }
  }
 cout << f[ B ][ n ];
 return 0;
}

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

using namespace std;

int n,i,j,a[100005],cnt[100005];

int main(){
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		scanf("%d", &a[i]);
		cnt[a[i]]++;
	}
	
	sort(a, a + n);
	
	for(i = 0; i < n - 1; i++){
		if(a[i + 1] - a[i] > 1)
		return 0 * printf("No\n");
	}
	
	if(a[0] == a[n - 1]){
		if(a[0] == n - 1 || n >= 2 * a[0])
		printf("Yes\n");
		else
		printf("No\n");
	}
	else{
		if(cnt[a[0]] > a[0])
		return 0 * printf("No\n");
		
		int notunique = (a[n - 1] - cnt[a[0]]);
		
		if(cnt[a[n - 1]] >= 2 * notunique)
		printf("Yes\n");
		else
		printf("No\n");
	}
}


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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i=0; i<7; i++) {
    if (pow(2, i)<=N && N<pow(2, i+1)) ans = pow(2, i);
  }
  cout << ans << endl;
}

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


void solve(long long A, long long B, long long C){
    vector<ll> a{A, B, C};
    sort(a.begin(), a.end());
    cout << (a[0]+ a[1]+ a[2]*10) << endl;
    
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', function() {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    inputString.shift();
    shellSort(inputString.map(v => Number(v)));
});

let count = 0;

const shellSort = (arr) => {
  const G = [];

  let g = 1;
  while (true) {
    if (g > arr.length) break;
    G.push(g);
    g = 3*g + 1;
  }

  console.log(G.length);

  const used = [];

  for (let i=G.length-1; i>=0; i--) {
    used.push(G[i]);
    insertionSort(arr, G[i]);
  }

  console.log(used.join(' '));
  console.log(count);
  console.log(arr.join(' '));
};

const insertionSort = (arr, g) => {
  for (let i=g; i<arr.length; i++) {
    const v = arr[i];
    let j = i - g;
    while (j>=0 && arr[j] > v) {
      arr[j+g] = arr[j];
      j = j - g;
      count++;
    }
    arr[j+g] = v;
  }
};





Measured memory_bytes: 249728
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
 
int main(){
    int n;cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        int a=log10(i)+1;
        if(a%2)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3804
N = int(input())
S = [input() for i in range(N)]

pos = []
neg = []
for s in S:
    sm = 0
    mn = 0
    for c in s:
        if c=='(':
            sm += 1
        else:
            sm -= 1
            mn = min(mn, sm)
    if sm >= 0:
        pos.append((mn,sm))
    else:
        neg.append((mn-sm, -sm))

pos.sort(key=lambda x:-x[0])
neg.sort(key=lambda x:-x[0])

hp = 0
for m,s in pos:
    if hp + m < 0:
        print('No')
        exit()
    hp += s

hn = 0
for m,s in neg:
    if hn + m < 0:
        print('No')
        exit()
    hn += s

print('Yes' if hp==hn else 'No')

Measured memory_bytes: 92152
#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
	long long int n, k,ze,sa;
	cin >> n >> k;
	n = n % k;
	while (labs(n-k) <= n)
	{
		n = labs(n - k);
	}
	cout << n << "\n";
}

Measured memory_bytes: 256
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool is_uruu(int y) {return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;}
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}

/* }}} */

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s[3];

  while (cin >> s[0], s[0] != "0"){
    cin >> s[1] >> s[2];
    bool flg = true;
    REP(i, 3){
      if (s[0][i] == s[1][i] && s[0][i] == s[2][i]){
        if (s[0][i] != '+'){
          print(s[0][i]);
          flg = false;
          break;
        }
      }
    }
    if (flg){
      REP(i, 3){
        if (s[i][0] == s[i][1] && s[i][0] == s[i][2]){
          if (s[i][0] != '+'){
            print(s[i][0]);
            flg = false;
            break;
          }
        }
      }
    }
    if (flg){
      if (s[0][0] == s[1][1] && s[0][0] == s[2][2]){
        if (s[0][0] != '+'){
          print(s[0][0]);
          flg = false;
        }
      }
    }
    if (flg){
      if (s[0][2] == s[1][1] && s[0][2] == s[2][0]){
        if (s[0][2] != '+'){
          print(s[0][2]);
          flg = false;
        }
      }
    }
    if (flg){
      print("NA");
    }
  }

  return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
    ll A,B,C,D,E;cin>>A>>B;
    A--;
    C=A;D=B;E=A;
    int a[50],b[50];
    for(int i=0;i<=40;i++){
        a[i]=C%2;
        b[i]=D%2;
        C/=2;D/=2;
    }
    ll Xor_A=0,Xor_B=0;
    int i=40;
    while(i>=2){
        if(a[i]==1){
            A-=(ll)pow(2,i);
            if(A%2==0)
                Xor_A+=(ll)pow(2,i);
        }
        i--;
    }
    if(A==2)Xor_A+=3;
    if(A==1)Xor_A+=1;
    int j=40;
    while(j>=2){
        if(b[j]==1){
            B-=(ll)pow(2,j);
            if(B%2==0)
                Xor_B+=(ll)pow(2,j);
        }
        j--;
    }
    if(B==2)Xor_B+=3;
    if(B==1)Xor_B+=1;   
    
    ll x;
    if(E!=0) x=Xor_A^Xor_B;
    else x=Xor_B;
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
int main(void) {
    int h, a; cin >> h >> a;
    if(h%a==0)
    cout << h/a << endl;
    else
    cout << h/a + 1 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

const int MAX_N = 400000;

// 親
int par[MAX_N];
// 木の深さ
int depth[MAX_N];

void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    depth[i] = 0;
  }
}

int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) {
    return;
  }

  if (depth[x] < depth[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (depth[x] == depth[y]) {
      depth[x]++;
    }
  }
}

bool same(int x, int y) { return find(x) == find(y); }

int N, K, L;
map<pair<int, int>, int> mp;
vector<int> a, b;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K >> L;
  init(2 * N);
  for (int i = 0; i < K; i++) {
    int pi, qi;
    cin >> pi >> qi;
    unite(pi - 1, qi - 1);
  }

  for (int i = 0; i < L; i++) {
    int ri, si;
    cin >> ri >> si;
    unite(ri + N - 1, si + N - 1);
  }

  a.resize(N);
  b.resize(N);
  for (int i = 0; i < N; i++) {
    a[i] = find(i);
    b[i] = find(i + N);
    mp[make_pair(a[i], b[i])]++;
  }

  for (int i = 0; i < N; i++) {
    if (i != 0) {
      cout << " ";
    }
    cout << mp[make_pair(a[i], b[i])];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define loop(j, n) for(int i=j; i<=n; ++i)
using namespace std;

void printArray(int*, int, int);
void printCharArray(char*, int, int);
void ruffleSort(int*, int);

int t; 

int main(int argc, char const *argv[])
{   
    IOS;
    string s;
    cin >> s;
    if(s=="SSS") cout << 0;
    else if(s=="SSR" || s=="SRS" || s=="RSS" || s=="RSR") cout << 1;
    else if(s=="RRS" || s=="SRR") cout << 2;
    else cout << 3;
    return 0;
}

void printArray(int *a, int start, int end) {
    for(int i=start; i<=end; ++i) {
        cout << *(a+i) << ' ';
    }
}

void printCharArray(char *a, int start, int end) {
    for(int i=start; i<=end; ++i) {
        cout << *(a+i) << ' ';
    }
}

void ruffleSort(int *a, int n) {
    unsigned seed=0;
    shuffle(a, a+n, default_random_engine(seed));
    sort(a, a+n);
}

Measured memory_bytes: 3660
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	vector<int> nums(n); fore(e, nums) cin >> e;
	sort(nums.begin(), nums.end());
	ll ans = 0;
	forl(i, 0, n) {
		forl(j, i+1, n) {
			int tot = nums[i]+nums[j];
			auto it = lower_bound(nums.begin(), nums.end(), tot);
			int amt = it-nums.begin();
			ans += amt-j-1;
		}
	}
	println(ans);
}


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

int Ans = INT_MAX;
int P, Q, R;
inline int Rd() {
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}
inline void ChkMin(int &aa, int bb) {
	if(aa > bb) aa = bb;
	return;
}

int main() {
	P = Rd(), Q = Rd(), R = Rd();
	ChkMin(Ans, P + Q), ChkMin(Ans, P + R), ChkMin(Ans, Q + R);
	printf("%d\n", Ans);
	return 0;
}

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

const int maxn=10;
int Map[maxn][maxn];

void floyd(){
	for(int k=0; k<maxn; k++)    //每次加入一个结点更新全图 
		for(int i=0; i<maxn; i++)
			for(int j=0; j<maxn; j++)
				Map[i][j]=min(Map[i][j], Map[i][k]+Map[k][j]);
}

int main(){
	int H, W, num, temp;
	
	while(scanf("%d%d", &H, &W)!=EOF){
		num=0;
		for(int i=0; i<maxn; i++)
			for(int j=0; j<maxn; j++)
				scanf("%d", &Map[i][j]);
		
		floyd();
		for(int i=0; i<H; i++){
			for(int j=0; j<W; j++){
				scanf("%d", &temp);
				if(temp==-1 || temp==1)
					continue;
				else
					num+=Map[temp][1];
			}
		}
		printf("%d\n", num);	
	}
	
	return 0;
}

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

int min(int a, int b) {

	if (a < b)return a;
	else return b;

}
int main() {

	int N;
	int s[110];
	bool check_not10 = false;
	int all_sum = 0, min_not10 = 2147483647;
	
	cin >> N;
	for (int i = 1; i <= N; i++) {

		cin >> s[i];
		all_sum += s[i];
		if (s[i] % 10 != 0) {

			min_not10 = min(s[i], min_not10);
			check_not10 = true;

		}

	}

	if (all_sum % 10 == 0) {

		if (check_not10)cout << all_sum - min_not10 << endl;
		else cout << 0 << endl;

	}
	else cout << all_sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n; Edg
int d[SZ],fa[SZ];
void dfs(int x,int f=0)
{
	d[x]=d[f]+1; fa[x]=f;
	for esb(x,e,b) if(b!=f)
		dfs(b,x);
}
vector<int> ps[SZ];
ll sol(int x)
{
	dfs(x);
	for(int i=1;i<=n;++i) ps[i].clear();
	for(int i=1;i<=n;++i) ps[d[i]].pb(i);
	ll ans=1;
	for(int i=n;i>=1;--i)
	{
		int ms=0;
		for(auto t:ps[i])
		{
			int s=0;
			for esb(t,e,b) if(d[b]==d[t]+1) ++s;
			ms=max(ms,s);
		}
		if(ms) ans*=ms;
	}
	return ans;
}
ll sol(int x,int y)
{
	d[y]=0; dfs(x,y);
	d[x]=0; dfs(y,x); d[x]=1;
	for(int i=1;i<=n;++i) ps[i].clear();
	for(int i=1;i<=n;++i) ps[d[i]].pb(i);
	ll ans=1;
	for(int i=n;i>=1;--i)
	{
		int ms=0;
		for(auto t:ps[i])
		{
			int s=0;
			for esb(t,e,b) if(d[b]==d[t]+1) ++s;
			ms=max(ms,s);
		}
		if(ms) ans*=ms;
	}
	return ans*2;
}
int main()
{
	scanf("%d",&n);
	for(int i=1,a,b;i<n;++i)
		scanf("%d%d",&a,&b),adde(a,b);
	dfs(1); int a=0;
	for(int i=1;i<=n;++i)
		if(d[i]>d[a]) a=i;
	dfs(a); int b=0;
	for(int i=1;i<=n;++i)
		if(d[i]>d[b]) b=i;
	int t=d[a]+d[b];
	if(!(t&1))
	{
		printf("%d ",t/=2);
		while(d[b]!=t) b=fa[b];
		ll ans=sol(b);
		for esb(b,e,x) ans=min(ans,sol(b,x));
		printf("%lld\n",ans);
	}
	else
	{
		printf("%d ",t/=2);
		while(d[b]!=t+1) b=fa[b];
		printf("%lld\n",sol(b,fa[b]));
	}
}


Measured memory_bytes: 24832
from collections import deque
N, M, K = map(int, input().split())
A = list(map(int, input().split()))

#dp[i][j]: i番目の的をj回目にあてた時のpointの最大値
dp = [0] * (N + 1)
for j in range(K):
    newDP = [0] * (N + 1)
    que = deque()  # val, index
    for i in range(j, N - K + j + 1):
        while que and que[-1][0] < dp[i]:
            que.pop()
        que.append((dp[i], i))
        while que and que[0][1] <= i - M:
            que.popleft()
        newDP[i+1] = que[0][0] + (j+1)*A[i]
    dp = newDP

print(max(dp))

Measured memory_bytes: 223528