akhauriyash/Code-Regression huggingface dataset:
MODULE graphMod
      implicit none
! 重みなしのグラフを扱うためのモジュール
! 重み付きは接頭辞Wをつける．別ファイルに作る．
! 双方向，単方向の使い分けはメインプログラムで．

      integer(16),parameter,private :: prec = 8
      
      type :: nodes
        integer(prec),allocatable :: next(:)
        integer(prec) :: degree = 0
        contains
        procedure,public,pass :: appendNode
      end type
      
      contains
      subroutine appendNode( node, nodeNumber )
        implicit none
        class(nodes),intent(inout) :: node
        integer(prec),intent(in)   :: nodeNumber
        integer(prec),allocatable  :: buffer(:)
        
        if(.not.(allocated(node%next)))then
          allocate(node%next(1))
          node%degree = 0
        end if
        
        if( node%degree==0 )then
          node%next(1) = nodeNumber
          node%degree = 1
          return
        end if
        
        node%degree = node%degree + 1
        buffer = node%next(1:node%degree-1)
        if( size(node%next)<node%degree )then
          deallocate( node%next )
          allocate( node%next(node%degree*2) )
        end if
        node%next(1:node%degree) = [buffer(1:node%degree-1), nodeNumber]
        deallocate( buffer )
      end subroutine appendNode
      
      END MODULE graphMod
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      PROGRAM connectCites
      use graphMod
      IMPLICIT NONE
      INTEGER,PARAMETER :: p = 8
      integer(p) :: n,m, i,a,b
      type(nodes),allocatable :: city(:)
      integer(p),allocatable :: visited(:),ans(:)
      
      
      read*,n,m
      allocate( city(n),visited(n),ans(n) )
      do i = 1,m
        read*,a,b
        call city(a)%appendNode(b)
        call city(b)%appendNode(a)
      end do
      
      
      visited = 0
      
      do i = 1,n
        if( visited(i)/=0 ) cycle
        
     !   print*,i,'piyo'
        
        visited(i) = i
        call goNext( city(i) )
      end do
      
      ans = 0
      do i = 1,n
        ans(visited(i)) = 1
      end do
      
      
      print*,sum(ans)-1
      
      stop
      !debugg
      
      print*,'visited'
      print*,visited
      
      do i = 1,n
        print*,city(i)%next
      end do
      
      contains
      recursive subroutine goNext( now )
        implicit none
        type(nodes),intent(in) :: now
        integer(p) :: k
        
        do k = 1,now%degree
          if( visited(now%next(k))/=0 ) cycle
          
          visited(now%next(k)) = i
          call goNext( city(now%next(k)) )
        end do
      end subroutine
      
      
      END PROGRAM

Measured memory_bytes: 16788
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (inline read-line-into))
(defun read-line-into (buffer-string &key (in *standard-input*) (terminate-char #\Space))
  (declare (simple-base-string buffer-string))
  (loop for c of-type base-char =
           #-swank (code-char (read-byte in nil #.(char-code #\Newline)))
           #+swank (read-char in nil #\Newline)
        for idx from 0
        until (char= c #\Newline)
        do (setf (schar buffer-string idx) c)
        finally (when (< idx (length buffer-string))
                  (setf (schar buffer-string idx) terminate-char))
                (return (values buffer-string idx))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (k (read))
         (string (make-string n :element-type 'base-char))
         (s (make-array n :element-type 'bit :initial-element 0))
         (cumul (make-array (1+ n) :fill-pointer 0 :initial-element 0 :element-type 'uint32)))
    (declare (uint31 n k))
    (read-line-into string)
    (dotimes (i n)
      (setf (aref s i) (- (char-code (aref string i)) 48)))
    (vector-push 0 cumul)
    (loop with base = 0
          with base-bit = (aref s 0)
          for i below n
          do (unless (= base-bit (aref s i))
               (vector-push (- i base) cumul)
               (setf base i
                     base-bit (aref s i)))
          finally (vector-push (- i base) cumul))
    (dotimes (i n)
      (incf (aref cumul (1+ i)) (aref cumul i)))
    (println
     (loop for l below (length cumul)
           for width = (if (zerop (aref s 0))
                           (if (evenp l)
                               (* 2 k)
                               (+ (* 2 k) 1))
                           (if (evenp l)
                               (+ (* 2 k) 1)
                               (* 2 k)))
           for r = (min n (+ l width))
           maximize (- (aref cumul r) (aref cumul l))))))

#-swank(main)


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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORD(i, m, n) for (int i = m; i >= n; i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 0; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

	int n;
	char s;
	cin>>n;
	bool key=false;
	REP(i, n) {
		cin>>s;
		if(s=='Y'){
			key=true;
		}
	}
	if(key)cout << "Four" << endl;
	else cout << "Three" << endl;
	
}

Measured memory_bytes: 3592
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#include <numeric>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
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; }


int main() {
    string n;
    cin >> n;
    ll w = 0;
    rep(i, n.size() ){
        w += n[i] - '0';
        w %= 9;
    }
    if (w %9== 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}






        






























  

























Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <climits>
#include <random>

#define ll long long

using namespace std;

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int n;
    scanf("%d", &n);
    vector<vector<int>> a(n + 1, vector<int>(3 + 1));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= 3; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    vector<vector<int>> dp(n + 1, vector<int>(3 + 1));
    dp[1][1] = a[1][1];
    dp[1][2] = a[1][2];
    dp[1][3] = a[1][3];
    for (int i = 2; i <= n; i++) {
        dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]);
        dp[i][1] += a[i][1];
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]);
        dp[i][2] += a[i][2];
        dp[i][3] = max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][3] += a[i][3];
    }
    printf("%d", max({dp[n][1], dp[n][2], dp[n][3]}));
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
int main(void){
    ll n,k;cin>>n>>k;
    ll ans=0;
    for(ll i=1;i<=n-k;i++){
        ans+=i*(n/(k+i))+max((ll)0,n%(k+i)-k+1);
        if(k==0)ans--;
    }
    cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		int t = in.nextInt();
		for(int i = 0; i < t; i++){
			int n = in.nextInt();
			int[] a = new int[n];
			for(int j = 0; j < n; j++) a[j] = in.nextInt();
			int b = 0, c = 0;
			for(int j = 0; j < n -1; j++){
				if(a[j] < a[j + 1] && a[j + 1] - a[j] > b) b = a[j + 1] - a[j];
				else if(a[j] - a[j + 1] > c) c = a[j] - a[j + 1]; 
			}
			System.out.println(b + " " + c);
		}
	}

	
	
}

Measured memory_bytes: 35400
#include <stdio.h>
int main(void){
	int a,b;
	char op;
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if(op=='?')break;
		if(op=='+'){
			printf("%d\n",a+b);
		}else if(op=='-'){
			printf("%d\n",a-b);
		}else if(op=='*'){
			printf("%d\n",a*b);
		}else if(op=='/'){
			printf("%d\n",a/b);
		}
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  for (int i = 0; i < n; i++) cin >> s[i] >> t[i];
  string x;
  cin >> x;

  int k;
  for (int i = 0; i < n; i++) {
    if (x == s[i]) k = i + 1;
  }
  int r = 0;
  for (int i = k; i < n; i++) r += t[i];
  cout << r << endl;
}


Measured memory_bytes: 256
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef unsigned long long ULL;
typedef long long LL;

const int inf = 1 << 30;
const int maxn=2e5+5;

ULL n,x;
ULL a[maxn],sum[maxn];

int main(){
	scanf("%llu%llu",&n,&x);
	for(int i=1;i<=n;i++)scanf("%llu",&a[i]),sum[i]=sum[i-1]+a[i];
	ULL ans=1ll<<60;
	for(LL k=1;k<=n;k++){
		ULL res=0,base=5;
		for(LL i=n;i>=1;i-=k){
			ULL tmp;
			if(i-k<=0)tmp=sum[i]-sum[0];
			else tmp=sum[i]-sum[i-k];
//			printf("%llu \n",tmp);
			if(i==n){
				res+=tmp*base;
			}else res+=tmp*base,base+=2;
			if(res+(n+k)*x>ans)break;
		}
		ans=min(ans,res+(n+k)*x);
	}
	printf("%llu\n",ans);

	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	const int intmax  = 1000010;
	ll int e;
	while(cin >> e,e){
		ll int ans = 9999999;
		FOR(y,0,sqrt((double)e)+2){
			FOR(z,0,cbrt((double)e)+2){
				if(e-y*y-z*z*z>=0) ans = min(ans,y+z+(e-y*y-z*z*z));
			}
		}
		cout << ans << endl;
	}
	
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, j) for(int i = 0; i < (int)(j); i++)
constexpr int INF = 1 << 28;
using EdgeList = vector<vector<int>>;
using pii = pair<int, int>;
// ?????£?????????????????°?????? E ???????????????
// O(N + M) N: ????????°, M: ?????°
vector<pii> enumerate_bridges(const EdgeList &E) {
    int N = E.size();
    vector<int> ord(N, -1), low(N);
    int cnt = 0;
    vector<pii> bridges;
    function<void(int, int)> dfs = [&] (int now, int pre) {
        ord[now] = cnt++;
        low[now] = ord[now];
        for(int nxt : E[now]) {
            if(ord[nxt] < 0) {
                // not visited
                dfs(nxt, now);
                low[now] = min(low[now], low[nxt]);
                if(ord[now] < low[nxt]) {
                    bridges.emplace_back(min(now, nxt), max(now, nxt));
                }
            } else if(nxt != pre) {
                // visited
                low[now] = min(low[now], ord[nxt]);
            } 
        }
    };
    // ??£?????°????????????dfs(0)????????§OK?????????
    rep(i, N) if(ord[i] < 0) dfs(i, -1);
    return bridges;
}
// ?????£?????????????????°?????? E ?????¢??????????????????????????????
// O(N + M) N: ????????°, M: ?????°
vector<int> enumerate_articulations(const EdgeList &E) {
    int N = E.size();
    vector<int> ord(N, -1), low(N);
    int cnt = 0;
    vector<int> articulations;
    function<void(int, int)> dfs = [&] (int now, int pre) {
        ord[now] = cnt++;
        low[now] = ord[now];
        
        bool is_articulation = false;
        int dfs_children = 0;
        
        for(int nxt : E[now]) {
            if(ord[nxt] < 0) {
                // not visited
                dfs_children++;
                dfs(nxt, now);
                low[now] = min(low[now], low[nxt]);
                if(pre >= 0 and ord[now] <= low[nxt]) {
                    is_articulation = true;
                }
            } else if(nxt != pre) {
                // visited
                low[now] = min(low[now], ord[nxt]);
            } 
        }
        if(pre < 0 and dfs_children > 1) is_articulation = true;
        if(is_articulation) articulations.push_back(now);
    };
    // ??£?????°????????????dfs(0)????????§OK?????????
    rep(i, N) if(ord[i] < 0) dfs(i, -1);
    return articulations;
}
int main() {
    int N, M; cin >> N >> M;
    EdgeList E(N);
    rep(i, M) {
        int a, b; cin >> a >> b;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    auto ans = enumerate_bridges(E);
    sort(begin(ans), end(ans));
    for(pii p : ans) cout << p.first << " " << p.second << endl;        
    return 0;
}

Measured memory_bytes: 4432
#include <algorithm>
#include <iostream>
#include <limits>

int main() {
    long long L, R;
    std::cin >> L >> R;

    const long long mod = 2019;

    auto ret = std::numeric_limits<long long>::max();
    const auto i_max = std::min(R, L + mod - 1);
    for (long long i = L; i < i_max; ++i) {
        const auto i_mod = i % mod;

        const auto j_max = std::min(R, i + mod);
        for (long long j = i + 1; j <= j_max; ++j) {
            const auto j_mod = j % mod;

            const auto i_j_mod = (i_mod * j_mod) % mod;
            ret = std::min(ret, i_j_mod);
        }
    }

    std::cout << ret << std::endl;
}


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

int main(){
	// sengen
	int n,m;
	// nyuryoku
	cin >> n >> m;
	long long h[n];
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	int a[m],b[m];
	for(int i=0;i<m;i++){
		cin >> a[i] >> b[i];
	}
	// keisan
	int good[n] = {};
	for(int i=0;i<m;i++){
		int min;
		if(h[a[i]-1] > h[b[i]-1]){
			good[b[i]-1]++;
		}else if(h[b[i]-1] > h[a[i]-1]){
			good[a[i]-1]++;
		}else{
			good[b[i]-1]++;
			good[a[i]-1]++;
		}
	}
	int count = 0;
	for(int i=0;i<n;i++){
		if(good[i] == 0){
			count++;
		}
	}
	// syutsuryoku
	cout << count << endl;
}

Measured memory_bytes: 5624
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int,input().split()))
odds_cnt = sum(list(map(lambda x : x % 2,an)))
multiple_of_4_cnt = sum([1 if i %4==0 else 0 for i in an])
ret = "No"
if multiple_of_4_cnt >= odds_cnt or (multiple_of_4_cnt == odds_cnt-1 and odds_cnt+multiple_of_4_cnt==n):
    ret = "Yes"
print(ret)

Measured memory_bytes: 14252
package main

import (
	"fmt"
	"math"
)

func main() {
	n, m, c := Int3()
	blist := IntSlice(m)
	count := 0
	for i := 0; i < n; i++ {
		alist := IntSlice(m)
		ans := c
		for j := 0; j < m; j++ {
			ans += alist[j] * blist[j]
		}
		if ans > 0 {
			count++
		}
	}
	fmt.Println(count)
}

func Str1() string {
	var s string
	fmt.Scan(&s)
	return s
}

func Int1() int {
	var x int
	fmt.Scan(&x)
	return x
}

func Int2() (int, int) {
	var x, y int
	fmt.Scan(&x, &y)
	return x, y
}

func Int3() (int, int, int) {
	var x, y, z int
	fmt.Scan(&x, &y, &z)
	return x, y, z
}

func IntSlice(n int) []int {
	slice := make([]int, n)
	for i := range slice {
		fmt.Scan(&slice[i])
	}
	return slice
}

func SumSlice(slice []int) int {
	total := 0
	for i := range slice {
		total += slice[i]
	}
	return total
}

func Min(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func IntPow(x, pow int) int {
	return int(math.Pow(float64(x), float64(pow)))
}


Measured memory_bytes: 1800
#include<bits/stdc++.h>
using namespace std;
int i,j,m,n,s,t,ans,v,k[11],p[11],b[11][11];
int f()
{
	int w=0;
	for(j=0;j<k[i];j++)w+=((1<<b[i][j]-1)&s)>0;
	return w%2==p[i];
}
int main()
{
	cin>>n>>m;
	for(;i<m;i++)
		for(cin>>k[i],j=0;j<k[i];j++)
			cin>>b[i][j];
	for(i=0;i<m;i++)cin>>p[i];
	for(t=1<<n;s<t;s++)
	{
		for(i=v=0;i<m;i++)v+=f();
		ans+=(v==m);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue> 
#include<cmath>
#include<utility>
#include<set>
#define M 1000000007
using namespace std;
int main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  long long h, x=0;
  cin >> h;
  for(long long i = 1; h >= 1; i*=2)
  {
    x+=i;
    h/=2;
  }
  cout << x << '\n';
}

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

int cmpnum(const void * n1, const void * n2)
{
	if (*(long *)n1 > *(long *)n2)
	{
		return -1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

 
int main(){
  long long N, ans=0;
  long long A[200000];
  long long B[200000];

  scanf("%lld",&N);

  for (int i = 0; i < N; i++)
  {
      scanf("%lld", A + i);
      B[i] = 0;      
  }
  for (int i = 0; i < N; i++)
  {
      B[A[i]-1] += 1;
  }

  for (int i = 0; i < N; i++)
  {
      ans += (B[i]-1) * (B[i]) /2;
  }
    
  for (int k = 0; k < N; k++)
  {
      printf("%lld ", ans - ((B[A[k]-1]-1) * (B[A[k]-1]) /2) + ((B[A[k]-1]-1) * (B[A[k]-1]-2) /2));
  }
  

//   printf("%lf", (double)(L*L*L)/27);
  return 0;
}

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

#define reint register int
#define coint const int

using namespace std;

typedef long long ll;

coint SIZE = 100000 + 5;

int li1[SIZE], li2[SIZE], deg[SIZE << 1];

struct Edge { int v, head; };

int  ecnt, head[SIZE << 1];
Edge edge[SIZE << 1];

inline void addEdge(coint u, coint v) {
    edge[++ecnt] = (Edge) {v, head[u]}, head[u] = ecnt;
    return;
}

int mk[SIZE << 1];

void dfs(coint u, ll &le, ll &ri, ll &ecnt) {
    if (mk[u]) return;
    mk[u] = 1, ecnt += deg[u];
    if (u <= SIZE) ++le;
    else ++ri;

    for (int i = head[u]; ~i; i = edge[i].head) {
        coint v = edge[i].v;
        dfs(v, le, ri, ecnt);
    }

    return;
}

inline int getint(void) {
    reint x = 0, ch = getchar();
    for (; ch < '0' || ch > '9'; ch = getchar());
    for (; ch >= '0' && ch <= '9';
            x = (x << 1) + (x << 3) + ch - '0', ch = getchar());
    return x;
}

int main(void) {
    ecnt = 0, memset(head, -1, sizeof head);

    coint n = getint();
    for (reint i = 1; i <= n; ++i) li1[i] = getint(), li2[i] = getint() + SIZE;

    for (reint i = 1; i <= n; ++i)
        addEdge(li1[i], li2[i]), addEdge(li2[i], li1[i]),
        ++deg[li1[i]], ++deg[li2[i]];

    ll ans = 0;
    for (reint i = 1; i < (SIZE << 1); ++i) {
        ll le = 0, ri = 0, xcnt = 0;
        if (mk[i]) continue;
        dfs(i, le, ri, xcnt), xcnt >>= 1;

        if (le < 2 || ri < 2) continue;
        ans += le * ri - xcnt;
    }

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

    return 0;
}



Measured memory_bytes: 7808
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class ARemainingBalls {
public:
    void solve(std::istream& in, std::ostream& out) {
        string S, T, U;
        int A, B;
        in >> S >> T >> A >> B >> U;
        out << (A - (S == U ? 1 : 0)) << " " << (B - (T == U ? 1 : 0)) << "\n";
    }
};


signed main() {
    ARemainingBalls solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> dp(n+1, INF);
    dp[1] = a[0];
    for(int i = 1; i < n; i++){
        int l = 0;
        int r = n;
        while(r - l > 1){
            int m = (r + l) / 2;
            if(dp[m] < a[i]){
                l = m;
            }else{
                r = m;
            }
        }
        dp[l+1] = a[i];
    }
    int ans;
    for(int i = 1; i <= n; i++){
        if(dp[i] != INF){
            ans = i;
        }
    }
    cout << ans << endl;

    return 0;
}



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

int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<int>>a(h,vector<int>(w));
    vector<int>z1,z2,z3,z4;
    rep(i,h)rep(j,w){
        cin>>a[i][j];
    }
    int ans=0;
    rep(i,h)rep(j,w){
        if(a[i][j]%2!=0){
            if(i==h-1&&j==w-1)continue;
            if(j==w-1){
                a[i][j]--;
                a[i+1][j]++;
                z1.push_back(i);
                z2.push_back(j);
                z3.push_back(i+1);
                z4.push_back(j);
                ans++;
            }
            else{
                a[i][j]--;
                a[i][j+1]++;
                z1.push_back(i);
                z2.push_back(j);
                z3.push_back(i);
                z4.push_back(j+1);
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    rep(i,z1.size()){
        cout<<z1[i]+1<<" "<<z2[i]+1<<" "<<z3[i]+1<<" "<<z4[i]+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 5224
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 100010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;

inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}
 
int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


ll t[N];
ll f[N],g[N];
void query(int now,ll &s){
    if(now==0)return;
    int x=now;
    while(x>0&&s){
        int l=0,r=x-1;
        while(l<=r){
            int m=(l+r)>>1;
            if(t[m]<=s)l=m+1;else r=m-1;
        }
        l--;
        if(l<0)break;
        g[l]+=s/t[l]*g[now];
        s%=t[l];
        x=l;
    }
}
int main(){
    int n,i,j,k,K,T,m=0,Q;
    scanf("%d%d",&n,&Q);
    t[0]=n;
    ll q;
    int now=0,a;
    while(Q--){
        scanf("%lld",&q);
        while(now>=0&&q<=t[now])now--;
        t[++now]=q;
    }
    //rep(i,0,now+1)cerr<<t[i]<<" ";puts("....");
    g[now]=1;
    per(i,0,now+1){
        ll s=t[i];
        query(i,s);
        if(s)f[s]+=g[i];
    }
    per(i,1,n)f[i]+=f[i+1];

    rep(i,1,n+1)printf("%lld\n",f[i]);
    return 0;
}

Measured memory_bytes: 4096
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int N = Integer.parseInt(line[0]);
        int blockStart = Integer.parseInt(line[1]);
        int blockEnd   = Integer.parseInt(line[2]);
        int attend = 0;
        for(int n=0;n<N;n++){
        	int classTime = Integer.parseInt(br.readLine());
        	if(classTime<blockStart || classTime>=blockEnd) attend++;
        }
        
        System.out.println(attend);
    }
}

Measured memory_bytes: 8148
def main():
    n, d = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*n]

    cnt = 0
    for i in range(n):
        for j in range(i+1, n):
            ans = 0
            for k in range(d):
                ans += ((ab[i][k]-ab[j][k])**2)
            if int(ans**0.5)**2 == ans:
                cnt += 1
    print(cnt)


main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

int main(){
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    vl a(n);
    rep(i, n) cin >> a[i];
    sort(rall(a));
    // i番目がOKかどうか
    auto check = [&](int i) {
        dumpL(i);
        if(i < p) return true;
        if(a[i]+m < a[p-1]) return false;
        // dump(a[i]+m), dump(a[p]);
        ll k = v - (p-1 + n - i);
        chmax(k, 0LL);
        dumpL(k);
        if(k == 0) return true;
        ll left = k * m;
        ll ma = a[i] + m;
        // dump(k), dump(ma), cout << endl;
        REP(j, p-1, i) {
            left -= min(m, ma - a[j]);
        }
        return left <= 0;
    };
    int l = p-1, r = n;
    while(r - l > 1) {
        int i = (l + r) / 2;
        if(check(i)) l = i;
        else r = i;
    }
    cout << l + 1 << endl;
    // rep(i, n) {
    //     cout << i << ": " << check(i) << endl;
    // }
    return 0;
}

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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (1e9 + 7)
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long n, r;
        cin >> n >> r;

        if (n < 10) r += 100 * (10 - n);
        printf("%lld\n", r);
    }
}


Measured memory_bytes: 3720
// Chocolate

#include <iostream>

using namespace std;

int main(){
	int N;
	int D, X;
	cin >> N >> D >> X;
	int A[N];
	for (int i = 0; i < N; ++i)
		cin >> A[i];

	int eaten = 0;

	for (int i = 0; i < N; ++i){
		int chocoN = 0;
		for (int j = 1; j <= D; j += A[i])
			chocoN++;
		eaten += chocoN;
	}

	cout << eaten + X << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);

        int n = stdin.nextInt();
        Integer a[] = new Integer[n];

        for (int i = 0; i < n; i++) {
            a[i] = stdin.nextInt();
        }
        Arrays.sort(a, Comparator.reverseOrder());
        
        int Alice = 0;
        int Bob = 0;
        
        for (int i = 0; i < n; i+=2) {
            Alice += a[i];
        }
        for (int i = 1; i < n; i+=2){
            Bob += a[i];
        }
        System.out.println(Alice - Bob);
        
    }
}


Measured memory_bytes: 23764
N = int(input())
B = []
for I in range(N):
    x,y = map(int,input().split())
    B.append([x,y])
B.sort()
minmin = N
for i in range(1,N):
    for j in range(N-i):
        d = [B[j+i][0]-B[j][0],B[j+i][1]-B[j][1]]
        A = [a for a in B]
        L = 1
        st = A.pop(0)
        while len(A)>0:
            next = [st[0]+d[0],st[1]+d[1]]
            if next in A:
                st = next
                A.remove(next)
            else:
                L += 1
                st = A.pop(0)
        if L < minmin:
            minmin = L
print(minmin)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();
		int[] A = new int[N];
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
		}
		for (int trial = 0; trial < N; ++trial) {
			PriorityQueue<PriorityQueue<Integer>> pq = new PriorityQueue<>(new Comparator<PriorityQueue<Integer>>() {
				@Override
				public int compare(PriorityQueue<Integer> o1, PriorityQueue<Integer> o2) {
					return Integer.compare(o1.peek(), o2.peek());
				}
			});
			for (int i = 0; i < N; ++i) {
				int t = i;
				PriorityQueue<Integer> tmp = new PriorityQueue<>();
				while (t < N && A[t] >= A[trial]) {
					tmp.add(A[t]);
					++t;
				}
				if (tmp.size() >= K) {
					pq.add(tmp);
				}
				i = t;
			}
			int cnt = 0;
			int max = 0;
			while (cnt < Q && !pq.isEmpty()) {
				PriorityQueue<Integer> cand = pq.poll();
				++cnt;
				max = Math.max(max, cand.poll());
				if (cand.size() >= K)
					pq.add(cand);
			}
			if (cnt == Q) {
				ans = Math.min(ans, max - A[trial]);
			}
		}
		System.out.println(ans);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 92748
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    string s; cin >> s;
    int r = 0;
    for(int i=0; i<n; ++i){
        if(s[i]=='R'){r++;}
    }
    int res = 0;
    for(int i=0; i<r; ++i){
        if(s[i]=='W'){res++;}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, k;
	cin >> N >> k;
	VI a(N), B(N);
	REP(i, N) {
		cin >> a[i] >> B[i];
	}
	int ma = 0, mask = 0;
	eREP(i, 30) {
		if (i == 0 || (k&(1 << i)) != 0) {
			int cmask = mask | ((k >> (i + 1)) << (i + 1));
			if (i == 0)cmask = k;
			int sum = 0;
			REP(i, N) {
				if ((cmask | a[i]) == cmask)sum += B[i];
			}
			ma = max(sum, ma);
		}
		mask |= (1 << i);
	}

	cout << ma << endl;

	return 0;
}



Measured memory_bytes: 1792
// https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
// TODO: try to AC
// DP使ってやればできそうなんだけど、相変わらず更新のイメージがうまくもてない
// 変数が多すぎて頭がこんがらがってる

fun main() {
    msolutions2020d()
}

fun msolutions2020d() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }
    var soko = Int.MAX_VALUE
    var yama = Int.MIN_VALUE
    var current = 1000L
    var searchSoko = true
    for (value in a) {
        if (searchSoko) {
            if (soko > value) {
                soko = value
            } else {
                searchSoko = false
                yama = value
            }
        } else {
            if (yama < value) {
                yama = value
            } else {
                searchSoko = true
                if (yama > soko) {
                    val buy = current / soko
                    current += buy * (yama - soko)
                }
                soko = value
                yama = Int.MIN_VALUE
            }
        }
    }
    if (yama > soko) {
        val buy = current / soko
        current += buy * (yama - soko)
    }
    println(current)
}

Measured memory_bytes: 36628
fun main(args: Array<String>) {
  val (
    oneCount
    , zeroCount
    , minusOneCount
    , chooseCount
  ) = readLine()!!.split(" ").map(String::toInt)
  
  if (oneCount >= chooseCount) {
    println(chooseCount)
  } else {
    // oneCount < chooseCount
    if (oneCount + zeroCount >= chooseCount) {
      println(oneCount)
    } else {
      val minusCount = chooseCount - oneCount - zeroCount
      println(oneCount - minusCount)
    }
  }
}

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

#define ll long long
#define vl vector<ll>
#define fo(i,a,b) for(ll i=a; i<b; i++)

int main(){
    ll minc = LONG_LONG_MAX;
    ll n, m, x;
    cin >> n >> m >> x;

    vl cost(n);
    vector<vl> learn(n, vl(m));
    fo(i, 0, n){
        cin >> cost[i]; 
        fo(j, 0, m){
            cin >> learn[i][j];
        }
    }
    
    fo(bit, 0, (1<<n)){
        ll c = 0;
        vl algo(m);
        bool comp = true;

        fo(i, 0, n){
            if(bit & (1<<i)){
                c += cost[i];
                fo(j, 0, m) algo[j] += learn[i][j];
            }
        }
        fo(i, 0, m){
            if(algo[i] < x){
                comp = false;
                break;
            }
        }
        if(comp) minc = min(c, minc);
    }

    if(minc == LONG_LONG_MAX) cout << -1 << endl;
    else cout << minc << endl;

}

/*
　 ◇　　　　 ミ ◇
　◇◇　 /￣|　 ◇◇
◇◇＼　 L＿| ◇◇
　　彡Ｏ(・＿・)/
　 　　ヽ Ｐ`Ｏ
　　 ／彡#_|ミ＼
　　　 </LL凵>
　　　　∪ ∪
pass system test !!
*/

Measured memory_bytes: 3632
<?php
  list($a, $b, $r) = explode(" ", trim(fgets(STDIN)));
  $s = 0.5 * ($a * $b) * (sin($r * (M_PI / 180)));
  $l = $a + $b + sqrt(pow($a, 2) + pow($b, 2) - (2 * $a * $b * cos($r * (M_PI / 180))));
  $h = $b * sin($r * (M_PI / 180));
  print($s . "\n" . $l . "\n" . $h);
?>

Measured memory_bytes: 6632
from collections import *
from heapq import*
import sys
input=lambda:sys.stdin.readline()

n=int(input())
d=[[]for _ in[0]*-~n]

for s in range(n-1):
    a,b,c=map(int,input().split())
    d[a].append([b,c])
    d[b].append([a,c])
#defaultdict(<class 'list'>, {1: [[2, 1], [3, 1]], 2: [[1, 1], [3, 3]], 3: [[1, 1], [2, 3]]})

def DIJKSTRA(point,d):
    cost      = [float("inf") for _ in range(len(d))]
    Q         = []  #頂点のリスト
    cost[point]=0  #開始地点のコストをゼロとする（当たり前
    heappush(Q,(point,cost[point]))
    while Q:
        prefnd,tmpC=heappop(Q)
        if cost[prefnd]<tmpC:
            continue
        for node,c in d[prefnd]:
            altC=c+tmpC
            if cost[node]>altC:
                cost[node]=altC
                heappush(Q,(node,altC))
    return cost

q,k=map(int,input().split())
y=DIJKSTRA(k,d)

for i in range(q):
    a,b=map(int,input().split())
    print(y[a]+y[b])

Measured memory_bytes: 95280
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  if (n == m) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int side[3] = {0};
	rep (i, 3){
		cin >> side[i];
	} // end rep

	sort(side, side+3);
	int res = side[0] * side[1] / 2;

	cout << res << endl;

	return 0;
}

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

int main() {
    string s; cin >> s;
    int n=s.size();
    n-=2;
    s=s.substr(0,n);
    int m=n/2;
    
    while(m>0){
        string t1=s.substr(m);
        string t2=s.substr(0,m);
        if(t1==t2) {
            cout << n << endl;
            return 0;
        }
        else{ 
            n-=2;
            m--;
            s=s.substr(0,n);
        }
    }
}

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

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  ll input(n, k);
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  cout << accumulate(a.begin(), a.begin() + k, 0ll) << endl;
}


Measured memory_bytes: 3596
# dpD - Knapsack 1
# 貰うDP
import sys
input = sys.stdin.readline

def main():
    n, w = tuple(map(int, input().rstrip().split()))
    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
    dp = [0] * (w + 1)
    for i in range(n):
        for j in range(w, A[i][0] - 1, -1):
            dp[j] = max(dp[j], dp[j - A[i][0]] + A[i][1])
    print(max(dp))
    


if __name__ == "__main__":
    main()

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

string arr[102];
int n,l;
int main()
{
    cin>>n>>l;
    rep(i,1,n)
        cin>>arr[i];
    sort(arr+1,arr+n+1);
    rep(i,1,n)
        cout<<arr[i];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
# define INF 0x3f3f3f3f 
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
ll gcd(ll a , ll b){if(b==0) return a; a%=b; return gcd(b,a);}
const int N=500023;
bool vis[N];
vector <int> adj[N];

void solve() 
{
    int x, n;
    cin>>x>>n;


    vi p(n);
    rep(i, n) cin>>p[i];

    map<int, int> m;
    rep(i, n)
    {
        m[p[i]]++;
    }

    int min_diff = INT_MAX;
    int ans = -1;
    for(int i = x; i <= 200; i++)
    {
        if(m[i] == 0)
        {
            min_diff = abs(i-x);
            ans = i;
            break;
        }
    }

    for(int i = -1; i <=x; i++)
    {
        if(m[i] == 0 && abs(i-x) <= min_diff)
        {
            min_diff = abs(i-x);
            ans = i;
        }
    }
    cout<<ans<<endl;


}

int main()
{   

    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        // cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 15596
#include<bits/stdc++.h>
using namespace std;
int a[1005],b[1005];
int dp[10005];

int go(int h,int n)
{
	if(h<=0)
		return 0;

	if(dp[h]!=-1)
		return dp[h];

	int res=INT_MAX;
	for(int j=0;j<n;j++)
	{
		res=min(res,b[j]+go(h-a[j],n));
	}

	return dp[h]=res;

}

int main()
{
	int h,n;
	memset(dp,-1,sizeof(dp));
	cin>>h>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	cout<<go(h,n)<<"\n";
	// sort(ratio,ratio+n);
	// int x=ratio[n-1].second;

	return 0;
}

Measured memory_bytes: 896
H,W,K = map(int,input().split())
A = [0]*H
for i in range(H):
    A[i] = input()
s = 10000
for i in range(2**(H-1)):
    count = 0
    B = [0]*H
    B[H-1] = 1
    for j in range(H-1):
        if ((i >> j) & 1):
            B[j] = 1
            count += 1
    C = [0]*(count + 1)
    for j in range(W):
        a = [0]*(count + 1)
        n = 0
        max = C[0]
        maxa = a[0]
        for k in range(H):
            a[n] += int(A[k][j])
            C[n] += int(A[k][j])
            if B[k] == 1:
                if max < C[n]:
                    max = C[n]
                if maxa < a[n]:
                    maxa = a[n]
                n += 1
        if max > K:
            count += 1
            C[:] = a[:]
        if maxa > K:
            count = 10000
            break
    if s > count:
        s = count
print(s)

Measured memory_bytes: 46812
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

H, W = na()
M = ncl(H)
dx, dy = [0, 1, -1, 0], [1, 0, 0, -1]

flag = True
for i in range(H):
    for j in range(W):
        if M[i][j] == '#':
            ok = False
            for k in range(4):
                nx, ny = j + dx[k], i + dy[k]
                if 0 <= nx and nx < W and 0 <= ny and ny < H and M[ny][nx] == '#':
                    ok = True
            if not ok:
                flag = False

print("Yes" if flag else "No")

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<>();
    int heaps[] = new int[n];
    Arrays.fill(heaps, 1);
    int res = 0;
    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }
    for (int i = 0; i < m; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = list.get(a-1);
      int d = list.get(b-1);
      if (c >= d) heaps[b-1] = 0;
      if (c <= d) heaps[a-1] = 0;
    }
    for (int i: heaps) {
      res += i;
    }
    System.out.println(res);
    sc.close();
  }
}

Measured memory_bytes: 63480
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define watch(x) cout << (#x) << " is " << (x) << endl
 
bool isPrime(int i) {
	if(i < 2) {
		return false;
	}
	if(i == 2) {
		return true;
	}
	if(!(i % 2)) {
		return false;
	}
	for(int j = 3; j * j <= i; j += 2) {
		if(!(i % j)) {
			return false;
		}
	}
	return true;
}
void solve() {
	int n;
	cin >> n;
	std::vector<char> v(n);
	F0R(i, n) {
		cin >> v[i];
	}
	int l = 0, r = n - 1;
	int ans = 0;
	while(l < r) {
		if(v[l] == 'W' && v[r] == 'R') {
			// watch(l);
			// watch(r);
			ans++;
			l++;
			r--;
		}
		else {
			if(v[l] != 'W') {
				l++;
			}
			if(v[r] != 'R') {
				r--;
			}
		}
	}
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
    int T = 1; 
    // cin >> T;
    while(T--) {
    	solve();
    }
	return 0;
}


Measured memory_bytes: 3644
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll n; cin >> n;
  vll a(n),l(n),r(n+1),m(n);
  rep(i,n){
    cin >> a[i];
  }
  l[0] = 0;
  r[n] = 0;
  rep(i,n-1){
    l[i+1] = __gcd(l[i],a[i]);
  }
  for(int i = n-1; i >= 0; i--){
    r[i] = __gcd(r[i+1],a[i]);
  }
  rep(i,n){
    m[i] = __gcd(l[i],r[i+1]);
  }
  int max = 0;
  rep(i,n){
    if(max < m[i]){
      max = m[i];
    }
  }
  cout << max;
  return 0;
}


Measured memory_bytes: 3328