akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop, heapify
from itertools import product

def solve():
    hq = [(0, y, x) for y, x in product(xrange(m), xrange(n)) 
          if not(0 < y < m - 1 and 0 < x < n - 1)]
    heapify(hq)
    while True:
        cost, cy, cx = heappop(hq)
        if field[cy][cx] == "&":
            return cost
        if memo[cy][cx] <= cost:
            continue
        memo[cy][cx] = cost
        for dx, dy in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            ny, nx = cy + dy, cx + dx
            if 0 <= ny < m and 0 <= nx < n:
                if field[ny][nx] != "#" and field[cy][cx] == "#": 
                    heappush(hq, (cost + 1, ny, nx))
                else:
                    heappush(hq, (cost, ny, nx))

while True:
    n, m = map(int, raw_input().split())
    if n | m == 0:
        break
    memo = [[1 << 20] * n for _ in xrange(m)]
    field = [raw_input() for _ in xrange(m)]    
    print solve()

Measured memory_bytes: 5788
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define mpr make_pair
#define fr first
#define se second
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{
     Senky_Bansal
     IIIT_ALLAHABAD
  
     char p;
     cin>>p;
     if(p=='T') cout<<'A';
     else if(p=='A') cout<<'T';
     else if(p=='C') cout<<'G';
     else cout<<'C';
     
     
      
    
}




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

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

  if (N[1] == N[2] && (N[0] == N[1] || N[2] == N[3]))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(m);
    for (int i = 0; i < m; i++)
    {
        int k;
        cin >> k;
        s[i].resize(k);
        for (int j = 0; j < k; j++)
        {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<int> p(m);
    for (int i = 0; i < m; i++)
    {
        cin >> p[i];
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        int all_cnt = 0;
        for (int i = 0; i < m; i++)
        {
            int cnt_s = 0;
            for (int j = 0; j < s[i].size(); j++)
            {
                if (bit & (1 << s[i][j]))
                {
                    cnt_s++;
                }
            }
            if (cnt_s % 2 == p[i])
            {
                all_cnt++;
            }
        }
        if (all_cnt == m)
        {
            ans++;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
//int m,n;
//int i,j,k,l;
int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
int main(void){
    scanf("%d %d",&a,&b);
    if (a==1)
    {
        if (b==2)
        {
            printf("3\n");
        } else
        {
            printf("2\n");
        }
    }
    if (a==2)
    {
        if (b==1)
        {
            printf("3\n");
        } else
        {
            printf("1\n");
        }
    }
    if (a==3)
    {
        if (b==2)
        {
            printf("1\n");
        } else
        {
            printf("2\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const unsigned long long MAX = 1000000000;

int main()
{
  unsigned long long S;
  cin >> S;
  if (S == MAX * MAX)
  {
    cout << 0 << ' ' << 0 << ' ' << MAX << ' ' << 0 << ' ' << 0 << ' ' << MAX << endl;
    return 0;
  }
  unsigned long long p = S / MAX, r = S % MAX;
  cout << 0 << ' ' << 0 << ' ' << MAX << ' ' << 1 << ' ' << MAX - r << ' ' << p + 1 << endl;
}

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

#define f(x, y, z) for (int x = (y), __ = (z); x < __; ++x)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define mst(x, a) memset(x, a, sizeof(x))

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1 << 27;
const ll LLINF = (ll)1 << 60;
const ll MOD = 1e9+7;

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

int main() {
  int N;
  scanf("%d", &N);
  vector<vector<int>> a(N, vector<int>(N));
  f(i, 0, N) {
    f(j, 0, N) {
      scanf("%d", &a[i][j]);
    }
  }

  int size = 1 << N;
  // dp[mask]: max score only consider these rabbits
  vector<ll> dp(size, 0);
  dp[0] = 0;
  for (int mask = 1; mask < size; mask++) {
    if (mask >= (1 << (N - 1))) mask = (1 << N) - 1;
    // find first ungrouped rabbit, and decide who group with it;
    int i = N - 1;
    while ((mask & (1 << i)) == 0) {
      i--;
    }
    int remain = mask ^ (1 << i);
    // enumerate subset
    int sub = remain;
    do {
      ll acc = 0;
      for (int j = 0; j < i; j++) {
        if (sub & (1 << j)) {
          acc += a[i][j];
          for (int k = 0; k < j; k++) {
            if (sub & (1 << k)) {
              acc += a[k][j];
            }
          }
        }
      }
      dp[mask] = max(dp[mask], acc + dp[remain ^ sub]);
      sub = (sub - 1) & remain;
    } while (sub != remain);
  }

  printf("%lld\n", dp[size - 1]);
}


Measured memory_bytes: 768
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  console.log(' ' + buildMaxHeap(lines.shift().split(' ')).join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && Number(arr[left]) > Number(arr[largest])) largest = left;
    if (right < n && Number(arr[right]) > Number(arr[largest])) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
  return arr;
}



Measured memory_bytes: 88296
#include<stdio.h>

int main()
{
    int a,b,c,d;

    scanf("%d", &a);
    
    b = a/3600;
    c = (a%3600)/60;
    d = (a%3600)%60;
    printf("%d:%d:%d\n",b,c,d);

    return 0;
}


Measured memory_bytes: 2148
S = input()
T = ''
Q = int(input())
flag = True
for i in range(Q):
    que = input()
    if len(que) == 1:
        if flag:
            flag = False
        else:
            flag = True
    else:
        if que[2] == '1':
            if flag:
                T = T+que[4]
            else:
                S = S+que[4]
        else:
            if flag:
                S = S+que[4]
            else:
                T = T+que[4]
if flag:
    U = ''
    for i in range(len(T)):
        U += T[len(T)-i-1]
    print(U+S)
else:
    U = ''
    for i in range(len(S)):
        U += S[len(S)-i-1]
    print(U+T)


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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  int n;
  const int max_n = 8;
  cin >> n;
  double x[max_n + 1];
  double y[max_n + 1];
  for(int i = 0; i < n; i++){
    cin >> x[i] >> y[i];
  }

  vector<int> path(n);
  for(int i = 0; i < n; i++) path[i] = i;
  double ans = 0;
  int s,e;

  do{
    for(int i = 1; i < n; i++){
      e = path[i];
      s = path[i-1];
      ans += sqrt((x[e]-x[s])*(x[e]-x[s]) + (y[e]-y[s])*(y[e]-y[s]));
    }
    // cout << endl;
  }while(next_permutation(path.begin(), path.end()));

  for(int i = 1; i <= n; i++){
    ans /= i;
  }

  cout << fixed << ans << endl;

  return 0;
}

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

using namespace std;

#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ull unsigned long long int

const int INF = 1e9 + 7;
const int N = 1e5+5;


int main() {

	IO;

	int n;
	cin >> n;
	
	vector<pair<int,int>> pr(n);
	int cur = 0, ans = 0;
	
	for (int i = 0; i < n; ++i) {
		cin >> pr[i].first >> pr[i].second;
		
		if (pr[i].first == pr[i].second) {
			++cur;
			ans = max(ans, cur);
		}
		else {
			ans = max(ans, cur);
		    cur = 0;
		}
		
	}
	
	if (ans >= 3) {
		cout << "Yes";
	}
	else cout << "No";
	
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sz(a) (a).size()
#define pb(a) push_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr double EPS = 1e-10;

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

int H, W;
string s[50];
int dis[50][50];

bool contain(int y, int x) {
  return y >= 0 && y < H && x >= 0 && x < W;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> H >> W;
  int sum = 0;
  rep(i, 0, H) {
    cin >> s[i];
    rep(j, 0, W) {
      if (s[i][j] == '#') sum++;
    }
  }

  fill_n((int*)dis, 50*50, INF);
  dis[0][0] = 1;
  queue<pii> que;
  que.emplace(0, 0);
  while (!que.empty()) {
    int y, x;
    tie(y, x) = que.front(); que.pop();
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (contain(ny, nx) && s[ny][nx] != '#' && dis[ny][nx] == INF) {
        dis[ny][nx] = dis[y][x] + 1;
        que.emplace(ny, nx);
      }
    }
  }
  if (dis[H-1][W-1] == INF) {
    cout << -1 << endl;
    return 0;
  }
  cout << H*W-sum-dis[H-1][W-1] << endl;

  return 0;
}

Measured memory_bytes: 256
def rren(): return list(map(int, input().split()))


a = set()
b = dict()
N, K = rren()

for i in range(N):
    a_t, b_t = rren()
    if(a_t not in a):
        a.add(a_t)
        b[a_t] = b_t
    else:
        b[a_t] += b_t

li_a = list(a)
li_a.sort()
count = K
for i in range(K):
    count -= b[li_a[i]]
    if(count <= 0):
        print(li_a[i])
        break


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

using namespace std;

signed main(){
    int N; string S;
    
    cin >> N >> S;
    
    vector<int> East(N), West(N);
    West[0] = 0;
    East[N - 1] = 0;
    
    
    for(int i = 0; i < N - 1; ++i){
        if(S[i] == 'W'){
            West[i + 1] = West[i] + 1;
        } else {
            West[i + 1] = West[i];
        }
    }
    
    for(int i = N - 1; i > 0; --i){
        if(S[i] == 'E'){
            East[i - 1] = East[i] + 1;
        } else {
            East[i - 1] = East[i];
        }
    }
    
    vector<int> Sum(N);
    for(int i = 0; i < N; ++i){
        Sum[i] = East[i] + West[i];
    }
    
    sort(Sum.begin(), Sum.end());
    cout << Sum[0] << endl;
}

Measured memory_bytes: 4228
#include<stdio.h>
#define N 1000
#define Z 500000
int a, b, c, d;
int push(void);
int top(void);
int pop(void);
int A[N][Z];
int size[N];
int front[N];
////////////////////////////////////////////////////////////
int main(void){
    scanf("%d%d", &b, &a);
    while (a-- != 0){
        scanf("%d", &b);
        if (b == 0) push();
        if (b == 1) top();
        if (b == 2) pop();
    }
    return 0;
}
int push(void){
    scanf("%d%d", &c, &d);
    A[c][size[c]] = d;
    size[c]++;
    return 0;
}
int top(void){
    scanf("%d", &c);
    if (size[c] == front[c]) return 0;
    printf("%d\n", A[c][front[c]]);
    return 0;
}
int pop(void){
    scanf("%d", &c);
    A[c][front[c]] = 0;
    if (front[c] == size[c]) return 0;
    if (size[c] == 0){front[c] = 0; return 0;}
    //size[c]--;
    front[c]++;
    return 0;
}


Measured memory_bytes: 6088
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
A=[]
for n in range(N):
	A.append(list(map(int,input().split())))
c=0
for a in A:
	ans=0
	for aa,bb in zip(a,B):
		ans+=aa*bb
	if ans+C>0:
		c+=1
print(c)

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

int main() {
	int n, m, t, k = 1;
	cin >> n >> m;
	t = 1900 * m + 100 * (n - m);
	for (int i = 0; i < m; i++) k = k * 2;
	cout << k * t;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

int n, sumr[1000050], sumw[1000050], ans;

char st[1000050];

int main()
{
    cin >> n;
    scanf("%s", st + 1);

    for (int i = 1;i <= n;i++)
    {
        sumr[i] = sumr[i - 1] + (st[i] == 'R');
        sumw[i] = sumw[i - 1] + (st[i] == 'W');
    }

    ans = 0x7fffffff;

    for (int i = 0;i <= n;i++)
        ans = min(ans,max(sumw[i], sumr[n] - sumr[i]));

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5020
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(s):
        a = []
        for c in s:
            if '0' <= c <= '9':
                if len(a) > 0 and isinstance(a[-1], int):
                    a[-1] *= 10
                    a[-1] += int(c)
                else:
                    a.append(int(c))
            else:
                a.append(c)

        for i in range(len(a)):
            c = a[i]
            if isinstance(c, int):
                a[i] = set([c])

        def _f(a):
            li = None
            l = len(a)
            if l == 1:
                return a

            for i in range(l):
                if a[i] == '(':
                    li = i
            if not li is None:
                ri = None
                for i in range(li+1,l):
                    if a[i] == ')':
                        ri = i
                        break
                t = _f(a[li+1:ri])
                return _f(a[:li] + t + a[ri+1:])

            ts = set()
            for i in range(l):
                c = a[i]
                if isinstance(c, set) or c not in '+-*/':
                    continue
                ls = _f(a[:i])[0]
                rs = _f(a[i+1:])[0]
                for lc in ls:
                    for rc in rs:
                        if c == '+':
                            ts.add(lc+rc)
                        elif c == '-':
                            ts.add(lc-rc)
                        elif c == '*':
                            ts.add(lc*rc)
                        elif c == '/' and rc != 0:
                            if lc * rc < 0:
                                ts.add(-(abs(lc)//abs(rc)))
                            else:
                                ts.add(lc//rc)

            return [ts]

        return len(_f(a)[0])

    while 1:
        s = S()
        if s == '#':
            break
        rr.append(f(s))
        # print('rr', rr[-1])

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 9144
#include <stdio.h>
#include <vector>

std::vector<int> V[200010];
int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<a;i++)
	{
		int b;
		scanf("%d",&b);
		V[b].push_back(i);
	}
	
	for(int i=1;i<=a;i++) printf("%d\n",V[i].size());
}

Measured memory_bytes: 14136
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N,M; cin>>N>>M;
  vector<int> cities(N,0);
  for(int i = 0; i < M; i++) {
    int a,b; cin>>a>>b;
    cities[a-1]++; cities[b-1]++;
  }

  for(auto road : cities) {
    cout << road << endl;
  }
}


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

int main(){
long long num,sol=0;
cin>>num;
long long vett[num];
for(long long i=0;i<num;i++){
	cin>>vett[i];
	if(i>0&&vett[i-1]==1&&vett[i]>0){
		sol++;
		vett[i]--;
	}
	while(vett[i]>1){
		vett[i]-=2;
		sol++;
	}

}
cout<<sol<<endl;
return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
   int a,b,c,i;
   
   scanf("%d", &a);
   
   for(i=1; i<=a; i++){
      if(i%3==0){
         printf(" %d", i);
         continue;}
   	  b = i;
   	    if(b%10==3){
   	     printf(" %d", i);
   	     continue;}
   	while(b>10){
   		 b /= 10;
   	     if(b%10==3){
   	     printf(" %d", i);
   	     break;}}}
	
	printf("\n");
         
   return 0;
}


Measured memory_bytes: 2048
N, M = map(int, input().split())
AC_flags = [False] * N
WA_counter = [0] * N
for _ in range(M):
    p, s = input().split()
    p = int(p) - 1
    if AC_flags[p]:
        continue
    elif s == 'WA':
        WA_counter[p] += 1
    else:
        AC_flags[p] = True
penalty = 0
for i in range(N):
    penalty += AC_flags[i] * WA_counter[i]
print(sum(AC_flags), penalty)



Measured memory_bytes: 10360
import copy
N, K = map(int, input().split())
S = input()
if S.count('0') == 0:
    print(S.count('1'))
    exit()

if N == K:
    print(N)
    exit()

olst = []
zlst = []
tmp = S[0]
tcnt = 1
for i in range(1, N):
    if tmp != S[i]:
        if tmp == '1':
            olst.append(tcnt)
        else:
            zlst.append(tcnt)
        tmp = S[i]
        tcnt = 1
    else:
        tcnt += 1

if tmp == '1':
    olst.append(tcnt)
else:
    zlst.append(tcnt)

index = 0
flst, slst = [], []
if S[0] == '1':
    index = 1
    flst = copy.deepcopy(olst)
    slst = copy.deepcopy(zlst)
else:
    flst = copy.deepcopy(zlst)
    slst = copy.deepcopy(olst)
total = [0] * (len(flst) + len(slst) + 1)
for i in range(1, len(flst) + len(slst) + 1):
    if i % 2 != 0:
        total[i] += flst[i // 2] + total[i - 1]
    else:
        total[i] += slst[i // 2 - 1] + total[i - 1]
ans = 0
tmp1 = (2 * K) - 1
tmp2 = 2 * K
for i in range(1, len(total) - K):
    tmp = 0
    if index == 0:
        if i % 2 != 0:
            if i + tmp1 < len(total):
                tmp += total[i + tmp1] - total[i - 1]
            else:
                tmp += total[-1] - total[i - 1]
        else:
            if i + tmp2 < len(total):
                tmp += total[i + tmp2] - total[i - 1]
            else:
                tmp += total[-1] - total[i - 1]
    else:
        if i % 2 != 0:
            if i + tmp2 < len(total):
                tmp += total[i + tmp2] - total[i - 1]
            else:
                tmp += total[-1] - total[i - 1]
        else:
            if i + tmp1 < len(total):
                tmp += total[i + tmp1] - total[i - 1]
            else:
                tmp += total[-1] - total[i - 1]
    ans = max(ans, tmp)
print(ans)

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

int main()
{
    int n,i,m;
    char s[100];
    scanf("%d",&n);
    scanf("%s",s);
    m=strlen(s);
    if(m<=n)
        printf("%s",s);
    else
        {
            for(i=0;i<n;i++)
                printf("%c",s[i]);
            printf("...");
        }
}


Measured memory_bytes: 2088
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int N, x;
    std::cin >> N >> x;

    std::vector<int> a(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
    }

    std::sort(a.begin(), a.end());

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

    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int p=0;
  string s,t;
  getline(cin,s);
  for(int i=0;i<s.size();i++){
    if(s[i]==','||s[i]=='.'||s[i]==' '){
      if(t.size()>=3&&t.size()<=6){
        if(p)cout<<' ';
        cout<<t;
        p++;
      }
      t="";
    }
    else t+=s[i];
  }
  cout<<endl;
}

Measured memory_bytes: 3136
n = int(input())
# ボタンの番号を 0 ~ n-1 番に読み替え
a = [int(input())-1 for _ in range(n)]
button, count = 0, 0

for _ in range(n):
    count += 1
    button = a[button]
    if button == 1:
        break

if count < n:
    print(count)
else:
    print(-1)


Measured memory_bytes: 7084
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

typedef long long ll;
typedef vector<ll> Vec;
typedef pair<ll, ll> Pair;
#define rep(i, n) for(ll i=0;i<n;i++)

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;
//#define PI 3.14159265359


int main() {
    // input
    ll N, M;
    cin >> N >> M;
    Vec H(N);
    vector<Pair> AB;
    rep(i, N) {
        cin >> H[i];
    }
    rep(i, M) {
        ll A, B;
        cin >> A >> B;
        AB.emplace_back(A - 1, B - 1);
    }

    // process
    Vec good_tower(N, 1);

    rep(i, M) {
        if (H[AB[i].first] < H[AB[i].second]) {
            good_tower[AB[i].first] = 0;
        } else if (H[AB[i].first] > H[AB[i].second]) {
            good_tower[AB[i].second] = 0;
        } else {
            good_tower[AB[i].first] = 0;
            good_tower[AB[i].second] = 0;
        }
    }

    ll ans = 0;
    rep(i, N) {
        ans += good_tower[i];
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 5984
#include <stdio.h>

int main(int argc, char **argv)
{
	long long int n, i, ans = 0;
	char a, b;

	scanf("%lld", &n); getchar();
	
	a = getchar();
	ans ++;
	for (i = 1; i < n; i++){
		b = getchar();
		if (a != b) {
			ans++;
			a = b;
		}
	}
	
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int k, s;
    cin >> k >> s;
    ll ans = 0;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            if(s - (i+j) >= 0 && s - (i+j) <= k){
                ans++;
            }
        }
    }
    
    cout << ans;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	val n = f.readLine().toLong()
	var answer = 0L

	for(k in 1L until n){
		answer += (n-1)/k
	}

	println(answer)
}


Measured memory_bytes: 34232
#include <bits/stdc++.h>
#define ll long long int
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define inputv(a) forall(i,0,a.size()) cin>>a[i]
#define outputv(a) for(auto i:a) cout<<i<<" ";br;
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define br cout<<"\n"
using namespace std;
ll po(ll x,ll n,ll mod){
    ll res = 1;
    while(n>0){
        if(n%2==1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        n = n/2;
    }
    return res%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC";
    else cout<<"ABC";

	return 0;

}


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

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

    int H, W, h, w;
    cin >> H >> W;
    cin >> h >> w;
    
    int diff = h * w;
    
    cout << H*W - (w*H + h*W - diff) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int m,n;
    scanf("%d %d",&n,&m);
    int a[n];
    int v=0;
    int e=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        v+=a[i];
    }
    for(int i=0;i<n;i++){
        if(float(a[i])>=(float(v)/float(4*m))){
            e++;
        }
    }
    if(e>=m)printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

bool kaibun(string s){
  string rev=s;
  reverse(rev.begin(),rev.end());
  return s==rev;
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  string s;
  cin>>s;
  int n=s.size();
  string pre=s.substr(0,(n-1)/2), suf=s.substr((n+1)/2,n-(n+1)/2);
  cout<<(kaibun(s)&&kaibun(pre)&&kaibun(suf)?"Yes":"No")<<endl;

  return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		long[] ary = new long[n];
		for (int i = 0; i < n; i++) {
			ary[i] = sc.nextLong();
		}
		long sum = ary[0];
		long total = 0;
		for (int i = 1; i < n; i++) {
			sum = ary[i - 1] + ary[i];
			if (sum > x) {
				long hiku = sum - x;
				total += hiku;
				//right
				if (ary[i] >= hiku) {
					ary[i] -= hiku;
				} else if (ary[i] > 0) {
					ary[i] = 0;
				}
			}
		}
		System.out.println(total);

	}
}

Measured memory_bytes: 58852
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    long long ans=0;
    cin>>N>>M;
    vector<int> A(N);
    vector<int> B(N);
    map<int,int> mp;
    int visit=-1;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        A.at(i)=a;
    }
    sort(A.begin(),A.end());
    for(int i=0;i<M;i++){
        int B,C;
        cin>>B>>C;
        mp[C]=min(mp[C]+B,N);
    }
    int check=0,rock=0;
    for(auto i=mp.end();i!=mp.begin();--i){
        if(check==0){
            check++;
            continue;  
        }
        int x=i->first;
        int y=i->second;
        for(int j=visit+1;j<visit+1+y;j++){
            B.at(j)=x;
            if(j==N-1){
                rock=54;
                break;
            }
        }
        if(rock==54){
            for(int i=0;i<N;i++){
                ans+=max(B.at(i),A.at(i));
            }
            cout<<ans<<endl;
            return 0;
        }
        visit=max(visit,visit+y);
    }
    int X=mp.begin()->first;
    int Y=mp.begin()->second;
    for(int i=visit+1;i<visit+1+Y;i++){
        B.at(i)=X;
        if(i==N-1){
            break;
        }
    }
    for(int i=0;i<N;i++){
      ans+=max(B.at(i),A.at(i));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8624
// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s; cin >> s;
    for(char& c:s) c = 'x';
    cout << s << endl;
}



Measured memory_bytes: 256
//03/05/2020
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'


#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

//Number Theory
template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}

//Geometry
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan2( double(y1-y2) , double(x1-x2));}


/*Containers*/
vector<ll>v;
deque<ll>dq;
stack<ll>stk;
map<ll,ll>mp;
unordered_map<ll,ll>ump;
set<ll>st;
multiset<ll>mst;
unordered_set<ll>ust;
unordered_multiset<ll>umst;
priority_queue<ll,deque<ll>,greater<ll>>pq;
Pbds<ll>ost;


int main(){
    _fastio
    ll n,k;
    cin>>n>>k;
    ll vis[n+10];
    memset(vis,0,sizeof(vis));

    for(ll i=1;i<=k;i++){
        ll d;
        cin>>d;
        while(d--){
            ll x;
            cin>>x;
            vis[x]=1;
        }
    }

    ll ans=0;
    for(ll i=1;i<=n;i++){
        if(vis[i]==0) ans++;
    }

    cout<<ans<<en;




    return 0;
}


Measured memory_bytes: 3664
N=int(input())
d=[int(s) for s in input().split()]
ans=0
ans_2=sum(d)
ans_li=[]
import math
for i in range(N):
    ans+=d[i]
    ans_2-=d[i]
    ans_li.append(int(math.fabs(ans-ans_2)))
print(min(ans_li))

Measured memory_bytes: 9036
p=input().rstrip()
r=input().rstrip()
t=input().rstrip()
x=list(p)
y=list(r)
z=list(t)
ans = 'a'
while(1):
    if ans=='a':
        if len(x)!=0:
            ans=x[0]
            del(x[0])
        else:
            break;
    elif ans=='b':
        if len(y)!=0:
            ans=y[0]
            del(y[0])
        else:
            break;
    elif ans=='c':
        if len(z)!=0:
            ans=z[0]
            del(z[0])
        else:
            break;
if ans=='a':
    print("A")
elif ans=='b':
    print("B")
elif ans=='c':
    print("C")


Measured memory_bytes: 3064
#include <string>
#include <vector>
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{
    int x;
    for(int i=1;;i++){cin>>x;
    if(x==0)break;
        cout<<"Case "<<i<<": "<<x<<endl;}
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> v(n);
  for (int i=0; i<n; i++) cin >> v.at(i);
  vector<int> c(n);
  for (int i=0; i<n; i++) cin >> c.at(i);
  
  int ans = 0;
  
  for (int i=0; i<n; i++){
    
    int sa;
    sa = v[i] - c[i];
    
    if (sa>0){
      ans += sa;
    }
    
  }
  
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

def search(x,d)
  return 1 if(d > @size)
  if(@memo[x][d] === false)
    p -1
    exit
  end
  return @memo[x][d] if(@memo[x][d] != nil)
  @memo[x][d] = false
  nx = @t[x][d]
  nd = @mem[nx][x]
  hyo = [search(nx,nd),search(x,d+1)].max + 1
  @memo[x][d] = hyo
  return hyo
end

n = inp[0]
@size = n-1
@t= [[nil]*n]
@memo = na2(n+1,n,nil)
@mem = na2(n+1,n,nil)
n.times do
  @t.push([nil]+inp)
end
(1..n).each do |i|
  (1...n).each do|j|
    @mem[i][@t[i][j]] = j+1
  end
end
ans = 0
(1..n).each do |i|
  ans = [ans,search(i,1)].max
end

p ans-1


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

int main() {
    string i;
    getline(cin, i);
    //4 3 2cout << i << endl;


    i.erase (remove (i.begin(), i.end(), ' '), i.end());

    int s = atoi(i.c_str());
    //cout << s << endl;

    if (s % 4 == 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, C;
ll x[100010], v[100010];
ll maL[100010], maR[100010], maLT[100010], maRT[100010];

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

  rep( i, N )
    std::cin >> x[i] >> v[i];

  ll vS = 0;

  rep( i, N )
  {
    vS += v[i];

    maR[i+1] = std::max( maR[i], vS-x[i] );
    maRT[i+1] = std::max( maRT[i], vS-2*x[i] );
  }

  vS = 0;

  repd( i, N )
  {
    vS += v[i];

    maL[i] = std::max( maL[i+1], vS-(C-x[i]) );
    maLT[i] = std::max( maLT[i+1], vS-2*(C-x[i]) );
  }

  ll ans = 0;

  rep( i, N+1 )
  {
    chmax( ans, maR[i]+maLT[i] );
    chmax( ans, maL[i]+maRT[i] );
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 4992
N,M = map(int,input().split())
a = list(map(int,input().split()))

a.sort(reverse=True)
b = 1
su = 0
for i in range(M):
  su += a[i]
  if su > N:
    b = -1
    
  
print(N - su if b > 0 else '-1')

Measured memory_bytes: 9888
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(1,len(p)-1):
    c = p[i]
    l = p[i-1]
    r = p[i+1]
    judge = (l-c)*(r-c)
    if judge < 0:
        count+=1
print(count)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define     siii(a,b,c)       scanf("%d%d%d",&a,&b,&c)
#define     si(a)             scanf("%d",&a)
#define     sii(a,b)          scanf("%d%d",&a,&b)
#define     sl(a)             scanf("%lld",&a);
#define     sll(a,b)          scanf("%lld%lld",&a,&b);
#define     slll(a,b,c)       scanf("%lld%lld%lld",&a,&b,&c);
#define     sd(a)             scanf("%lf",&a);
#define     sdd(a,b)          scanf("%lf%lf",&a,&b);
#define     pb(a)             push_back(a)
#define     deb(a)            printf("### %d ###\n",a)
#define     mp                make_pair
#define     pf                printf
#define     fl(a, b, c)       for(int a= b ;a<c;a++)
#define     mx                100000 //10^5
#define     fread             freopen("input.txt","r",stdin)
#define     fwrite            freopen("output.txt","w",stdout)
#define     CLR(a,b)          memset(a,b,sizeof(a))
#define     ll                long long
#define     D(x)              cout<<#x" = "<<x<<endl;
#define     sz                10000
#define     bl                printf("\n")
#define     spc               printf(" ")
#define     pCase(a)          printf("Case %d: ",a)

int main()
{
    int n, m;
    int p, x;
    int arr[200];
    ll csum = 0;
    si(n);
    fl(i,0,n){
     si(arr[i]);
     csum+=arr[i];
    }
    si(m);
    while(m--)
    {
        sii(p,x);
        cout<<csum-arr[p-1]+x<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int k;
    scanf("%d",&k);
	int a=(k/2);
    int result; 
    if(k%2==0){
    	result=a*a;
    }else{
    	result=a*(a+1);
    }
    // 出力
    printf("%d\n",result);
    return 0;
}


Measured memory_bytes: 128
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      k: usize,
      p: [Usize1; n],
      c: [i64; n]
   }

   let mut lp = vec![];
   let mut used = vec![false; n];
   for i in 0..n {
      if used[i] {
         continue;
      }
      let mut g = vec![];
      let mut now = i;
      while !used[now] {
         g.push(now);
         used[now] = true;
         now = p[now];
      }
      lp.push(g);
   }

   let mut ans: i64 = -1001001001001001001;
   for g in lp {
      let m = g.len();
      let mut b = vec![0; 2 * m + 1];
      for i in 0..2 * m {
         b[i + 1] = b[i] + c[g[i % m]];
      }
      let mut mx: i64 = -1001001001001001001;
      if b[m] <= 0 || k < m {
         for i in 0..m {
            for j in i + 1..=i + m {
               if j - i > k {
                  break;
               }
               mx = max(mx, b[j] - b[i]);
            }
         }
      } else {
         let h = k / m;
         let l = k % m;
         let mut m1: i64 = -1001001001001001001;
         let mut m2: i64 = -1001001001001001001;
         for i in 0..m {
            for j in i + 1..=i + m {
               if j - i > l {
                  m1 = max(m1, b[j] - b[i]);
               } else {
                  m2 = max(m2, b[j] - b[i]);
               }
            }
         }
         mx = max(h as i64 * b[m] + m2, (h - 1) as i64 * b[m] + m1);
      }
      ans = max(ans, mx);
   }
   println!("{}", ans);
}


Measured memory_bytes: 2472
#include<bits/stdc++.h>
using namespace std;
 
int ar[300005];
int vis[300005];
int main()
{
  int n, i, j=1, ok=0,mi=300005;
 
  cin>>n;
 
  for(i=1; i<=n; i++)
  {
    cin>>ar[i];
  }
 
  for(i=1; i<=n; i++)
  {
    mi=min(ar[i],mi);
    if(mi==ar[i])ok++;
  }
 
  cout<<ok<<endl;
  }


Measured memory_bytes: 1024
#include<iostream>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define lvi vector<long long>
#define pi pair<int,int>
#define lpi pair<long long ,long long>
#define mp make_pair
#define pb push_back
#define ll long long 
#define N 100005
#define faltu ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define mod1 1000000000000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>multiordered_set;
ll int pw(ll int a, ll int b,ll md) {
    if (b == 0) return 1;
    ll int t = pw(a, b / 2,md);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
vector<int> pm;
void prm(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
              prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p]) pm.push_back(p);
}
bool cmp(const pair<ll int,ll int> &a,const pair<ll int,ll int> &b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first<b.first;
}
ll int gcd(ll int a,ll int b)
{
    if(!a)return b;
    return gcd(b%a,a);
}
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    for (int i = 2; i < n; i++) 
        if (n % i == 0) 
            return false; 
    return true; 
} 
map<int,int>pa;
int find(int i){
    if(pa[i]==i)return i;
    return pa[i]=find(pa[i]);
}     
void join(int i,int j){
    int a=find(i);
    int b=find(j);
    if(b>=a)pa[b]=a;
    else pa[a]=b;
}               
int ddx[]={-1,-1,-1,0,1,1,1,0};
int ddy[]={-1,0,1,1,1,0,-1,-1};
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int n,m;
ll p[N],h[N],x[N],y[N];
vector<int>ed[N];
int main()
{
    faltu;
    int t=1;
   // cin>>t;
    while(t--)
    {
        ll int n,k,cnt=0;
        cin>>n>>k;
        for(int i=0;i<n;i++)
        {
            ll int x,y;
            cin>>x>>y;
            if(x*x+y*y<=k*k)cnt++;
        }
        cout<<cnt<<endl;
    }
}

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

int main() {
  int n, i, j;
  cin >> n;
  
  vector<string> s(n);
  vector<char> t(10);
  for(i = 0; i < n; i++){
    for(j = 0; j < 10; j++){
      cin >> t.at(j);
    }
    sort(t.begin(), t.end());
    for(j = 0; j < 10; j++){
      s.at(i) += t.at(j);
    }
  }
  
  sort(s.begin(), s.end());
  
  long long ans = 0, count = 1;
  for(i = 1; i < n; i++){
    if(s.at(i - 1) == s.at(i)){
      count++;
    }
    else{
      ans += count * (count - 1) / 2;
      count = 1;
    }
  }
  
  ans += count * (count - 1) / 2;
  
  cout << ans << endl;
}


Measured memory_bytes: 7296
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	int dx = x2 - x1;
	int dy = y2 - y1;

	int x3, y3, x4, y4;
	x3 = x2 - dy;
	y3 = y2 + dx;
	x4 = x1 - dy;
	y4 = y1 + dx;

	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

	return 0;
}


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


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

   long long n;
   cin>>n;

   long long a[n];
   long long h=0;
   for(long long i=0; i<n; i++)
   	 {cin>>a[i]; h=h^a[i];}

   for(long long i=0; i<n; i++)
   	 cout<< (a[i]^h) <<" ";


 }

Measured memory_bytes: 5096
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#define ll long long
using namespace std;

int main() {
	ll m, n,sentoui=-1,sentouj=-1,idoui,idouj;
	cin >> n >> m;
	vector<string>a(n);
	vector<string>b(m);
	vector<vector<ll>>count(n, vector<ll>(n, 0));
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (ll i = 0; i < m; i++) {
		cin >> b[i];
	}
	for (ll i = 0; i <= n-m; i++) {
		for (ll j = 0; j <= n-m; j++) {
			if (a[i][j] == b[0][0]) {
				sentoui = i;
				sentouj = j;
				//cout << sentoui << endl;
				//cout << sentouj << endl;
				//count++;
				for (ll i = sentoui; i-sentoui<m;  i++) {
					for (ll j = sentouj; j-sentouj< m; j++) {
						if (a[i][j] == b[i-sentoui][j-sentouj]) {
							count[sentoui][sentouj]++;
						}
					}
				}
			}
		}
	}
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			if (count[i][j] == m * m) {
				cout << "Yes" << endl;
				exit(0);
			}
		}
	}
	cout << "No" << endl;
	




}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int ans = 0;
    REP(i,5){
        int x; cin >> x;
        if (x == 0) ans = i + 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3596
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=10010	
//Tuvshee
 
#include<iomanip>
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<algorithm>
#include<string>
#include<cctype>
#include<vector>
#include<queue>
using namespace std;
#define I int
#define D double
#define F float
#define C char
#define S string
#define B bool
#define L long long
#define rep(n) for(int i=0;i<n;i++)
#define reps(m,n,c) for(int c=m;c<n;c++)
#define repd(m,n,j) for(int j=n;j>m;j--)
#define whL while
#define eL endl
#define oR ||
#define anD &&
#define rtn return
#define pause system("PAUSE")
#define Max 300
#define max(m,n) ((n<m)?m:n)
#define min(m,n) ((n>m)?m:n)
 
int main()
{
	I v,x;
	cin>>x>>v;
	cout<<x*v<<' '<<2*x+2*v<<eL;
	rtn 0;
}

Measured memory_bytes: 1164
A, B = map(int, input().split())
ans_list = []
ans = ""
b_cnt = len(bin(B)[2:])

a_list = [0] * b_cnt
b_list = [0] * b_cnt
diff = B - A + 1
for i in range(b_cnt):
    a_tmp = A % (2 ** (i + 1))
    b_tmp = B % (2 ** (i + 1))
    a_list[i] = a_tmp
    b_list[i] = b_tmp

for i in range(b_cnt):
    a = a_list[i]
    b = b_list[i]
    cnt = 0
    if i == 0:
        if a == b == 1:
            cnt += diff//2 + 1
        else:
            cnt += diff//2
    else:
        # A の1の個数をカウント
        if 2 ** i > a:
            cnt += 0
        else:
            cnt += 2 ** (i+1) - a
        # B の 1 の個数をカウント
        if 2 ** i > b:
            cnt += 0
        else:
            cnt += b - 2 ** i + 1
    if cnt % 2 == 0:
        ans_list.append("0")
    else:
        ans_list.append("1")

for i in range(len(ans_list) - 1, -1, -1):
    ans += ans_list[i]

print(int(ans, 2))

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

const int maxn=1e6+5;
ll a[maxn];

int main()
{
	ios::sync_with_stdio(false);
	ll n;
	while(cin>>n){
		for(int i=0;i<n;i++){
			cin>>a[i];
			a[i]-=i+1;
		}
		sort(a,a+n);
		ll pivot=a[n/2];
		ll ans=0;
		for(int i=0;i<n;i++){
			ans+=llabs(a[i]-pivot);
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792