akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int n,w,x,y;
    cin>>n>>w>>x>>y;
    double s=(double)n*(double)w/2.0;
   printf("%.6f\n",s);
    
    if(n%2==0&&n/2==x&&w%2==0&&w/2==y){
        cout<<1<<endl;
    }
    else cout<<0<<endl;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int formerx = 0;
    int formery = 0;
    int formertime = 0;

    for(int i=0; i<n; i++){
        int t,x,y;
        cin >> t >> x >> y;
        int dist, disx, disy;
        dist = t - formertime;
        disx = abs(x - formerx);
        disy = abs(y - formery);
        int temp = dist - disx - disy;
        if(temp < 0 || temp & 1){
            cout << "No" << '\n';
            return 0;
        }

        
        formertime = t;
        formerx = x;
        formery = y;
         
        
    }

    cout << "Yes" << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  vector<int> l(N);
  for(int j=0;j<N;j++){
    for(int k=0;k<1000000000;k++){
      if(A.at(j)%2==0){
        A.at(j)/=2;
        l.at(j)++;
      }
      else{
        break;
      }
    }
  }
  sort(l.begin(),l.end());
  cout<<l.at(0)<<endl;
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;

  vector<bool>isprime(N+1,true);
  isprime[0]=false;
  isprime[1]=false;
  for(int i=2;i<=N;i++){
    if(isprime[i])for(int j=i+i;j<=N;j+=i){
      isprime[j]=false;
    }
  }

  map<int,int>m;
  for(int i=1;i<=N;i++){
    for(int j=2;j<=i;j++){
      int n=i;
      while(true){
        if(n%j==0&&isprime[j])m[j]++,n/=j;
        else break;
      }
    }
  }
  ll ans=1;
  for(auto it:m)ans=(ans*(it.second+1))%MOD;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 1e3 + 5;
ll x, y, z, k, mx, a[N], b[N], c[N];
vector<ll>tmp, ans;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> x >> y >> z >> k;
    for(int i = 0; i < x; i++)
        cin >> a[i];
    for(int i = 0; i < y; i++)
        cin >> b[i];
    for(int i = 0; i < z; i++)
        cin >> c[i];
    for(int i = 0; i < x; i++)
        for(int j = 0; j < y; j++)
            tmp.push_back(a[i] + b[j]);
    sort(tmp.rbegin(), tmp.rend());
    sort(c, c + z, greater<ll>());
    for(int i = 0; i < min(k, x * y); i++){
        for(int j = 0; j < z; j++)
            ans.push_back(tmp[i] + c[j]);
    }
    sort(ans.rbegin(), ans.rend());
    for(int i = 0; i < k; i++)
        cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 42980
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int X,Y,Z;
  ll a[SIZE], b[SIZE], c[SIZE], d[SIZE];
  pair<pair<ll,ll>,int > p[SIZE];
  ll ans1 = 0;
  
  scanf("%d%d%d",&X,&Y,&Z);

  int n = X+Y+Z;
  
  for(int i=0;i<X+Y+Z;i++){
    scanf("%lld%lld%lld",a+i,b+i,c+i);

    a[i] -= c[i];
    b[i] -= c[i];
    d[i] = a[i]-b[i];
    ans1 += c[i];

    p[i] = { {a[i], b[i]}, i};
  }

  sort(p,p+n,greater<pair<pair<ll,ll>,int>>());

  priority_queue<pair<ll,int> > pq1; // {a-b , i}
  priority_queue<pair<ll,int> > pq2; // {-(a-b) , i}
  priority_queue<pair<ll,int> > pq3; // {b , i}
  priority_queue<pair<ll,int> > pq4; // {-(b) , i}

  bool inpq2[SIZE] = {};
  bool inpq34[SIZE] = {};
  ll ans2 = 0;
  
  for(int i=0;i<X+Y;i++){
    int t = p[i].second;
    pq1.push({a[t]-b[t], t});
    ans2 += b[t];
  }

  for(int i=X+Y;i<n;i++){
    int t = p[i].second;
    pq3.push({b[t], t});
    inpq34[t] = true;
  }

  int pq2_minus = 0;

  ll ans = 0;
  
  for(int i=0;i<=Y;i++){

    while((int)pq2.size() - pq2_minus < X){
      auto p1 = pq1.top(); pq1.pop();
      if(inpq34[p1.second]) continue;
      
      p1.first *= -1;
      pq2.push(p1);
      inpq2[p1.second] = true;

      ans2 -= b[p1.second];
      ans2 += a[p1.second];
    }

    while(pq4.size() < i){
      auto p3 = pq3.top(); pq3.pop();
      p3.first *= -1;
      pq4.push(p3);

      ans2 += b[p3.second];
    }

    while(pq3.size() && pq4.size() && pq3.top().first > -pq4.top().first){
      auto p3 = pq3.top(); pq3.pop();
      auto p4 = pq4.top(); pq4.pop();

      p3.first *= -1;
      p4.first *= -1;

      ans2 -= b[p4.second];
      ans2 += b[p3.second];

      pq3.push(p4);
      pq4.push(p3);
    }

    int t = p[X+Y-1-i].second;

    ans = max(ans, ans1 + ans2);

    if(i == Y) break;
    
    if(inpq2[t]){
      pq2_minus++;
      ans2 -= a[t];
    }else{
      ans2 -= b[t];
    }

    pq3.push({b[t],t});
    inpq34[t] = true;
  }

  printf("%lld\n",ans);
  
  
  return 0;
}


Measured memory_bytes: 10736
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
MOD = 10 ** 9 + 7

for digit in range(60):
    one = np.count_nonzero(A & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % MOD
    ans %= MOD
    A >>= 1

print(ans)


Measured memory_bytes: 48828
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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; }

__attribute__ ((constructor))
void init() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

signed main(){
    int d,t,s;
    cin >> d >> t >> s;
    if(s*t < d)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}

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

int main(){
    int A,B,x,y,z;
    cin>>A>>B;
    x=A+B;
    y=A-B;
    z=A*B;

    int max=x;
    if(y>x)
       max=y;
    if(z>max)
       max=z;
    cout<<max<<endl;
    return 0;
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 201;
string f[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    forn(i, n) cin >> f[i];
    int ans = -1;
    forn(v, n) {
        vi q = {v}, dist(n, 1e9);
        dist[v] = 0;
        forn(cur, q.size()) {
            int u = q[cur];
            forn(w, n) if (f[u][w] == '1' && dist[w] > 1e8) {
                dist[w] = dist[u] + 1;
                q.pb(w);
            }
        }
        bool ok = true;
        forn(i, n) forn(j, n) if (f[i][j] == '1') ok &= abs(dist[i] - dist[j]) == 1;
        if (ok) uax(ans, *max_element(all(dist)) + 1);
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
package main

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

type Tuple struct {
	R int
	D int
}

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()

	edge := make([][]Tuple, N+1)
	for i := 0; i < N+1; i++ {
		edge[i] = make([]Tuple, 0)
	}

	for i := 0; i < M; i++ {
		L := sc.NextInt()
		R := sc.NextInt()
		D := sc.NextInt()
		edge[L] = append(edge[L], Tuple{R, D})
		edge[R] = append(edge[R], Tuple{L, -D})
	}
	checked := make([]bool, N+1)
	posMap := map[int]int{}
	for i := 1; i < N+1; i++ {
		if checked[i] {
			continue
		}
		queue := make([]int, 0)
		queue = append(queue, i)

		queue_pos := make([]int, 0)
		queue_pos = append(queue_pos, i)

		start := 0
		posMap[i] = start
		for cur := 0; cur < len(queue); cur++ {
			nx := queue[cur]
			nx_pos := queue_pos[cur]

			for _, v := range edge[nx] {
				if checked[v.R] {
					if posMap[v.R] != nx_pos+v.D {
						fmt.Println("No")
						//println(nx, v.R, posMap[v.R], nx_pos+v.D)
						return
					}
					continue
				}
				checked[v.R] = true
				queue = append(queue, v.R)
				queue_pos = append(queue_pos, nx_pos+v.D)

				posMap[v.R] = nx_pos + v.D
				//println(nx, v.R, posMap[v.R], nx_pos+v.D)

			}
		}

	}
	fmt.Println("Yes")

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 28800
#include<stdio.h>
int main()
{
	double xa, ya, xb, yb, xc, yc, xd, yd;
	while (~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd)) {
		puts((xa-xb)*(xc-xd)+(ya-yb)*(yc-yd)==0 ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n;
    string s, t, ans;
    cin >> n >> s >> t;
    for (int i=0; i<2*n; i++) {
        if (i % 2) ans += t[i/2];
        else ans += s[i/2];
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
rl = 0
lr = 0
count = [0, 0]
ans = [0] * n
prev = s[0]
for i in range(n):
    if s[i] != prev:
        if s[i] == 'L':
            rl = i
            ans[rl - 1] += count[0]
            ans[rl] += count[1]
            count = [0, 0]
            #print(ans)
        if s[i] == 'R':
            lr = i
            ans[rl] += count[0]
            ans[rl - 1] += count[1]
            count = [0, 0]
            #print(ans)
    if s[i] == 'L':
        count[(i - rl) % 2] += 1
    if s[i] == 'R':
        count[(i - lr) % 2] += 1
    prev = s[i]
    #print(count)
ans[rl] += count[0]
ans[rl - 1] += count[1]

print(' '.join(map(lambda x: str(x), ans)))








Measured memory_bytes: 51568
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<char>> c(3,vector<char>(3));
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      cin>>c.at(i).at(j);
  for(int i=0;i<3;i++)
    cout<<c.at(i).at(i);
  cout<<endl;
}

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

int main(void){
  int n, m, frag, max = 0, i, j;
  std::string str;
  std::cin >> n;
  std::vector<std::string> s(n);
  std::vector<int> c(n);
  
  for(i=0; i<n; i++){
    std::cin >> str;
    for(j=0, frag=0; j<i; j++){
      if(s.at(j) == str){
        c.at(j)++;
        frag = 1;
        break;
      }
    }
    if(frag == 1) continue;
    s.at(i) = str;
    c.at(i)++;
  }
  
  std::cin >> m;
  for(i=0; i<m; i++){
    std::cin >> str;
    for(j=0; j<n; j++){
      if(s.at(j) == str && c.at(j) > 0){
        c.at(j)--;
        break;
      }
    }
  }
  
  for(i=0; i<n; i++) max = (c.at(i) > max) ? c.at(i) : max;
  std::cout << max << std::endl;
  return 0;
}

Measured memory_bytes: 3648
n, m = map(int, input().split())
h = list(map(int, input().split()))
is_tower_good = [1]*n
for j in range(m):
    bridge = list(map(int, input().split()))
    if h[bridge[0] - 1] > h[bridge[1] - 1]:
        is_tower_good[bridge[1] - 1] = 0
    elif h[bridge[0] - 1] < h[bridge[1] - 1]:
        is_tower_good[bridge[0] - 1] = 0
    else:
        is_tower_good[bridge[1] - 1] = 0
        is_tower_good[bridge[0] - 1] = 0


print(is_tower_good.count(1))



    

Measured memory_bytes: 20036
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int MAX = 1e9;

int main() {
    int n; cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    } 
    sort(A.begin(), A.end());
    ll ans = 0;
    int cnt = 1, t;
    for (int i = 0; i < n - 1; i++) {
        t = A[i];
        if (t == A[i + 1]) { 
            cnt++;
        } else {
            if (t < cnt) ans += cnt - t;
            else if (t == cnt) cnt = 1;
            else ans += cnt;
            cnt = 1;
        }
    }
    t = A[n - 1];
    if (t < cnt) ans += cnt - t;
    else if (t == cnt) cnt = 1;
    else ans += cnt;
    cnt = 1;
    cout << ans << endl;
}

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

char S[11];
int len;
long ans = 0;

void solve(int a[], int depth) {
	int b[depth+1];
	int i;
	
	for(i=0;i<depth;i++) b[i] = a[i];
	
	if(depth == len - 1) {
		long sum = S[0] - '0';
		for(i=0;i<len-1;i++) {
			if(b[i]) {
				//printf("%d + ", sum);
				ans += sum;
				sum = S[i+1] - '0';
			} else {
				sum = sum * 10 + S[i+1] - '0';
			}
		}
		//printf("%d\n", sum);
		ans += sum;
		return;
	}
	
	b[depth] = 0;
	solve(b, depth + 1);
	b[depth] = 1;
	solve(b, depth + 1);
}

int main() {
	int a[1] = {0};
	
	scanf("%s", S);
	len = strlen(S);
	
	solve(a, 0);
	
	printf("%ld\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
//
// Created by bytedance on 2020/4/10.
//


#include <bits/stdc++.h>
//#include <fstream>

using namespace std;
const int maxn = 2e5 + 5;

int a[maxn];
int b[maxn];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", b + i);
    }
    reverse(b, b + n);
    int l = 0, r = n - 1;
    while (l < n && a[l] != b[l]) l++;
    while (r >= 0 && a[r] != b[r]) r--;
    int tl = l, tr = r;
    for (int i = 0; i < tl && l <= r; i++) {
        if (b[i] != a[l] && a[i] != b[l]) {
            swap(b[i], b[l]);
            l++;
        } else {
            break;
        }
    }
    for (int i = n - 1; i > tr && l <= r; i--) {
        if (b[i] != a[r] && a[i] != b[r]) {
            swap(b[i], b[r]);
            r--;
        } 
        else {
            break;
        }
    }
    if (l <= r) {
        printf("No\n");
    } else {
        printf("Yes\n");
        for (int i = 0; i < n; i++) {
            printf("%d%c", b[i], i == n - 1 ? '\n' : ' ');
        }
    }
    return 0;
}

Measured memory_bytes: 5332
#include<stdio.h>

int main(void) {

	int height = 0;	scanf("%d", &height);
	int width = 0;	scanf("%d", &width);

	while(1) {
		
		if ((height == 0) && (width == 0)) {
			break;
		}
		else {
			for (int i = 0; i < height; i++) {
				for (int j = 0; j < width; j++) {
					if (((i + 1) + (j + 1)) % 2 == 0) {
						printf("#");
					}
					else {
						printf(".");
					}
				}
				printf("\n");
			}
			printf("\n");
			scanf("%d %d", &height, &width);
		}
	}
	return 0;
}


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


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<P> v(n);
    for(int i=0; i<n; i++) cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());

    ll cnt = 0;
    for(int i=0; i<n; i++){
        cnt += v[i].second;
        if(cnt >= k){
            cout << v[i].first << endl;
            break;
        }
    }
    return 0;
}

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


int main() {
	string a, b;
	cin >> a >> b;
	if (a.size() < b.size()) cout << "LESS" << endl;
	else if  (a.size() > b.size()) cout << "GREATER" << endl;
	else {
		if (a < b) cout << "LESS" << endl;
		else if (a > b) cout << "GREATER" << endl;
		else cout << "EQUAL" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
console.log((args=>{
  const [_N,S] = args.trim().split`\n`;
  const N = _N|0;
  const w = Array(N).fill(0), e = Array(N).fill(0);
  for ( let i = 1; i < N; i++ ) {
    w[i] = w[i-1] + (S[i-1]==='W');
    e[N-i-1] = e[N-i] + (S[N-i]==='E');
  }
  let min = N;
  for ( let i = 0; i < N; i++ ) {
    const v = w[i] + e[i];
    if ( min > v ) min = v;
  }
  return min;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 38248
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
ans = 1
cnt = [0] * N
for a in A:
    if a != 0 and cnt[a] == 1:
        ans = ans * 2 % mod
    elif a == 0 and cnt[a] != 0 or cnt[a] > 1:
        ans = 0
    cnt[a] += 1
print(ans)

Measured memory_bytes: 53028
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007LL
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    rep(i, sz(v)) cout << v[i] << ",";
    cout << "]";
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N;
int A[100001][3];
int _dp[100001][3];
int (*dp)[3] = _dp+1;

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    cin >> N;
    rep(i, N) rep(j, 3) cin >> A[i][j];
    rep(i, N) rep(j, 3) rep(k, 3) if (j != k) get_max(dp[i][j], dp[i-1][k]+A[i][j]);

    cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << endl;
}

Measured memory_bytes: 2560
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0 && W==0) break;
            for(int i = 0; i<H; i++){
                for(int j = 0; j<W; j++){
                    if(i%2==0){
                        if(j%2==0){
                            System.out.printf("#");
                        }else{
                            System.out.printf(".");
                        }
                    }else{
                        if(j%2==0){
                            System.out.printf(".");
                        }else{
                            System.out.printf("#");
                        }
                    }   
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
        sc.close();
    }
}


Measured memory_bytes: 60532
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){

    int n;
    cin>>n;
    
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    
    sort(a.begin(), a.end(), greater<int>());
    
    int cnt=1;
    for(int i=1; i<n; i++){
        if(a[i-1]>a[i]){
            cnt++;
        }
    }
    
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=1;
    for(int i=1;i<n;i++)
    {
        if(s[i]==s[i-1]) continue;
        else ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
using namespace std;

#define rep(i,N) for(int i=0; i<N; i++)
#define revrep(i,N) for(int i=N-1; i>=0; i--)
#define coutline cout<<"------------ ("<<__LINE__<<")"<<endl;

typedef long long ll;

int main(void)
{
    int A, B;
    cin >> A >> B;

    int ret = 0;
    if (A >= 13) {
        ret = B;
    } else if (6 <= A && A <= 12) {
        ret = B/2;
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

template <class T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from = -1, int to = -1, T cost = 1) : from(from), to(to), cost(cost){};

    bool operator<(const Edge<T>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<T>& e) const { return this->cost > e.cost; }
};

template <class T = int>
class Graph {
public:
    explicit Graph(int N = 0) : size(N) { path.resize(size); }
    void span(int u, int v, T cost = 1) { path[u].push_back(Edge<T>(u, v, cost)); }
    std::vector<Edge<T>> operator[](int v) const { return path[v]; }

    int size;
    std::vector<std::vector<Edge<T>>> path;
};

template <class T>
T prim(const Graph<T>& graph) {
    std::vector<bool> used(graph.size, false);
    used[0] = true;

    std::priority_queue<Edge<T>, std::vector<Edge<T>>, std::greater<Edge<T>>> que;
    for (auto e : graph[0]) que.push(e);

    T ans = 0;
    while (!que.empty()) {
        auto e = que.top();
        que.pop();

        if (used[e.to]) continue;
        ans += e.cost;
        used[e.to] = true;
        for (auto se : graph[e.to]) que.push(se);
    }

    return ans;
}

int main() {
    int N, M;
    std::cin >> N >> M;

    Graph<int> graph(N);
    for (int i = 0; i < M; ++i) {
        int u, v, d;
        std::cin >> u >> v >> d;
        graph.span(u, v, d);
        graph.span(v, u, d);
    }

    std::cout << prim(graph) << std::endl;
    return 0;
}



Measured memory_bytes: 10056
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul  unsigned long long int
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod
//ll divide(ll a, ll b)  //euler's theorem(a/b)%mod
//{
//   return a*power(b,mod-2)%mod;  //only when mod is prime
//}

ll power(ll x, ll y)
{
    ll res = 1;
   while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
int main()
{
    speed;
    int n,k;
    cin>>n>>k;
    vector<int> v(n+1);
    for(int i=1;i<=n;i++) cin>>v[i];
    int dp[100007];
    for(int i=0;i<100007;i++) dp[i]=INT_MAX;
    dp[1] = 0;
    dp[2] = abs(v[2] - v[1]);
    for(int i=3; i<=n; i++)
    {
    	int a=k;
    	for(int j=i-1;j>=1 && a; j--)
    	{
    		dp[i]=min(dp[i],dp[j]+abs(v[i]-v[j]));
    		a--;
		}
	}
	cout<<dp[n]<<'\n';


	return 0;
}


Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;

template <typename T>
T LinearSearch(vector<T> &vec, T key) {
    for (T i = 0; i < vec.size(); ++i) {
        if (vec[i] == key) return i;
    }
    return -1;
}

int main() {
    // input
    ll N, M;
    cin >> N;
    vector<ll> S(N);
    for (ll i = 0; i < N; i++) cin >> S[i];
    cin >> M;
    vector<ll> T(M);
    for (ll i = 0; i < M; i++) cin >> T[i];
    
    // calculation
    ll res = 0;
    for (ll j = 0; j < M; ++j) {
        if (LinearSearch(S, T[j]) != -1) {
            res++;
        }
    }
    
    cout << res << "\n";
    return 0;
}



Measured memory_bytes: 3152
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<class T>void put_double(T a){cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    Int n, k; cin >> n >> k;
    vint a(n); vin(a);
    
    vint d(n, 0);
    rep(i, n - 1) d[i + 1] = a[d[i]] - 1;
    int l, r;

    set<int> s;
    rep(i, n) {
        if(s.count(d[i]) != 0) {
            r = i - 1;
            break;
        } else {
            s.insert(d[i]);
        }
    }
    rep(i, n) if(d[r + 1] == d[i]) {
        l = i;
        break;
    }
    //put_line(d);
    //cout << l << " " << r << endl;
    int len = r - l + 1;
    
    if(k < l) {
        println(d[k] + 1);
    } else {
        Int m = (k - l) % len;
        println(d[l + m] + 1);
    }

    return 0;
}


Measured memory_bytes: 15664
#include <stdio.h>

int main() {
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x-r<0 || x+r>W || y-r<0 || y+r>H){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}

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

int main()
{
  int x;int n;cin>>x>>n;
  set<int>st;
  
  for(int i=1;i<=n;i++)
  {
    int k;cin>>k;
    st.insert(k);
  }
  int ans=INT_MAX;
  int val=0;
  for(int i=0;i<=200;i++)
  {
    if(st.find(i)!=st.end())
      continue;
    int diff=abs(i-x);
    if(diff<ans)
    {
      ans=diff;
      val=i;
    }
  }
  cout<<val<<endl;
}

Measured memory_bytes: 3628
num = int(input())
d_max = {"rank" : 100000, "point":0}
d_min = {"rank" : 1, "point":1000000000}
for a in range(num):
    temp = input().split(" ")
    if int(temp[0]) < d_max["rank"]:
        d_max["rank"] = int(temp[0])
        d_max["point"] = int(temp[1])
    if int(temp[0]) > d_min["rank"]:
        d_min["rank"] = int(temp[0])
        d_min["point"] = int(temp[1])
    if num == 1:
        d_min["rank"] = int(temp[0])
        d_min["point"] = int(temp[1])
possible_upper = min(d_max["rank"] - 1, 1e9 - d_max["point"])
possible_lower = d_min["rank"]+d_min["point"]
# print("num",num,"p_upp",possible_upper,"p_low",possible_lower)
print(possible_lower)
    
    

Measured memory_bytes: 3188
#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 1

#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <random>
#include <ctime>

#define M 1000000007

const long long INF = 10000000000000000;

using namespace std;



int main(){
	int N;
	cin>>N;
	vector<int> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}

	map<int,int> mp;
	for(int i=0;i<N;i++){
		mp[A[i]]++;
	}
	
	
	if(mp.size()%2==0){
		cout<<mp.size()-1<<endl;
	}else{
		cout<<mp.size()<<endl;
	}
 	return 0;
}



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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 110, M = 1010, INF = 0x3f3f3f3f;

int n, m;
int f[N][N];
struct Edge
{
	int a, b, c;
}e[M];

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= n; j ++ )
			if (i == j) f[i][j] = 0;
			else f[i][j] = INF;
			
	for (int i = 0; i < m; i ++ )
	{
		int a, b, c;
		cin >> a >> b >> c;
		
		e[i] = {a, b, c};
		f[a][b] = f[b][a] = c;
	}
	
	for (int k = 1; k <= n; k ++ )
		for (int i = 1; i <= n; i ++ )
			for (int j = 1; j <= n; j ++ )
				f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
	
	int res = 0;
	for (int i = 0; i < m; i ++ )
		if (e[i].c != f[e[i].a][e[i].b])
			res ++ ;
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let nk = lines.shift().split(/\s/).map((v) => v - 0);
    let N = nk[0], K = nk[1];
    let S = lines.shift().trim();
    let Nums = [];
    let now = 1;
    let cnt = 0;
    for (let i = 0; i < N; i++) {
        if (S.charAt(i) == now) cnt++;
        else {
            Nums.push(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt != 0) Nums.push(cnt);
    if (Nums.length % 2 == 0) Nums.push(0);
    let Add = 2 * K + 1;
    let ans = 0;
//尺取法
    let left = 0;
    let right = 0;
    let tmp = 0;
    for (let i = 0; i < Nums.length; i += 2) {
        let nextLeft = i;
        let nextRight = Math.min(i + Add, Nums.length);
        while (nextLeft > left) {
            tmp -= Nums[left];
            left++;
        }
        while (nextRight > right) {
            tmp += Nums[right];
            right++;
        }
        ans = Math.max(tmp, ans);
    }
    console.log(ans);
}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

using namespace std;

struct peo {
	long long int h;
	long long int s;

	bool operator<(const peo &in) const {
		return s<in.s;
	};
};

void PV(vector<long long int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int n;
	long long int ans = 0;
	vector<peo> v;
	vector<long long int> vs, vh;

	cin>> n;
	v.resize(n);
	rep(i, n) {
		cin >> v[i].h;
		v[i].s = i + 1 + v[i].h;
		//cout << s[i] << endl;
	}

	sort(v.begin(), v.end());
	//PV(s);

	vs.resize(n);
	vh.resize(n);
	rep(i, n) {
		vs[i] = v[i].s;
		vh[i] = v[i].h;
	}
	/*PV(vs);
	cout << endl;
	PV(vh);*/

	rep(i, n) {
		auto l1 = lower_bound(vs.begin(), vs.end(), vs[i] - 2 * vh[i]);
		auto u1 = upper_bound(vs.begin(), vs.end(), vs[i] - 2 * vh[i]);
		ans += u1 - l1;
		/*auto l2 = lower_bound(s.begin(), s.end(), s[i] - 2* (i + 1));
		auto u2 = upper_bound(s.begin(), s.end(), s[i] - 2* (i + 1));
		ans += u2 - l2;*/
		//cout << u1-vs.begin() SP <<l1 - vs.begin() << endl;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9596
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;


int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];

    sort(h.begin(), h.end());//10 11 12 14 15
    ll ans = 10101010000000;
    rep(i, n-k+1){
        ans = min(ans, h[i+k-1]-h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4036
// by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

// DELETE the debugging information!
#define debug(x) std::cerr << #x << " = " << (x) << std::endl

const int N_MAX = 100003;
int a[N_MAX], b[N_MAX];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a + i);
  memcpy(b + 1, a + 1, sizeof(a[0]) * n);
  std::sort(b + 1, b + n + 1);
  int ans = 0;
  for (int i = 1; i <= n; i += 2) {
    // debug(*std::lower_bound(b + 1, b + n + 1, a[i]));
    // debug(std::lower_bound(b + 1, b + n + 1, a[i]) - b);
    if (((std::lower_bound(b + 1, b + n + 1, a[i]) - b) & 1) == 0)
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

int n;
pair<int,int> v[100];

int simulate(int p,int q){
    int ans = 0;

    for(int i = 1;i <= n;i++){
        int cost = 1;
        for(int j = 1;j < i;j++){
            if(v[j].first + p == v[i].first && v[j].second + q == v[i].second){
                cost = 0;
                break;
            }
        }
        ans += cost;
    }

    return ans;
}

int main() {

    scanf("%d",&n);

    for(int i = 1;i <= n;i++){
        scanf("%d %d",&v[i].first,&v[i].second);
    }

    sort(v + 1,v + 1 + n);

    int ans = n;

    for(int i = 1;i <= n;i++){
        for(int j = i + 1;j <= n;j++){
           ans = min(simulate(v[j].first - v[i].first,v[j].second - v[i].second),ans);
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    string s;
    cin >> s;
    int N=s.size();

    if(s[0]=='0' || s[N-1]=='1'){
        cout << -1 << endl;
        return 0;
    }

    for(int i=0; i<N/2; i++){
        if(s[i]!=s[N-2-i]){
            cout << -1 << endl;
            return 0;
        }
    }

    int j=1;
    for(int i=0; i<(int)s.size()-1; i++){
        cout << j << ' ' << i+2 << '\n';
        if(s[i]=='1'){    
            j=i+2;
        }
    }
}

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

int main(void)
{
	int K,count,i;
	char S[101];
	scanf("%d",&K);
	scanf("%s",S);
	count=strlen(S);
	if(K>=count){
		for(i=0;i<count;i++)printf("%c",S[i]);
	}else{
		for(i=0;i<K;i++)printf("%c",S[i]);
		printf("...");
	}
	return 0;
}

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

using namespace std;
bool other(int i, vector<int> v, int N) {
  int sum = 0;
  for (int j = 0; j < N; j++) {
    if (j == i) {
    } else {
      sum = sum + v[j];
    }
  }
  if (v[i] >= sum) {
    return false;
  } else {
    return true;
  }
}

int main(void) {
  int N;
  vector<int> v;
  int tp;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> tp;
    v.push_back(tp);
  }

  for (int i = 0; i < N; i++) {
    if (!other(i, v, N)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << 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)
using ll = long long;
using P = pair<int, int>;

double r, ans;
double pi = 3.1415926535;

int main() {
  cin >> r;
  ans = pi * r * 2;
  cout << fixed << ans << endl;
  return 0;
}


Measured memory_bytes: 3784
using System;
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int n = int.Parse(input[0]);
    int d = int.Parse(input[1]);
    
    int kanshi = d * 2 + 1;
    int person = n / kanshi;
    if (n % kanshi != 0) person++;
    Console.WriteLine(person);
  }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  bool like[N + 1][M + 1];
  for (int i = 0; i < N + 1; i++) {
    for (int j = 0; j < M + 1; j++) {
      like[i][j] = false;
    }
  }

  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int A;
      cin >> A;
      like[i][A] = true;
    }
  }

  int ans = 0;
  for (int i = 0; i < M + 1; i++) {
    int cnt = 0;
    for (int j = 0; j < N + 1; j++) {
      if (like[j][i]) cnt++;
    }
    if (cnt == N) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
vll vec[100001];
bool vis[100001];
void dfs(ll node)
{
    vis[node]=true;
    for(auto x:vec[node])
    {
        if(!vis[x])
        {
            dfs(x);
        }
    }
}
int main()
{
    fio;
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n,m;
        cin>>n>>m;
        rep(i,m)
        {
            ll u,v;
            cin>>u>>v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        memset(vis,false,sizeof(vis));
        ll cc=0;
        for(int i=1;i<=n;i++)
        {
            if(!vis[i])
            {
                cc++;
                dfs(i);
            }
        }
        cout<<cc-1<<endl;
    }
}

Measured memory_bytes: 10408
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
bool sf;
int T,st1,st2,x;
    int a[20],b[20],s[20];
void dfs(int i)
{
    if(i==10)
    {
        sf=1;
        return ;
    }
    if(sf)return ;
    if(a[st1]<s[i])
    {
        a[++st1]=s[i];
        dfs(i+1);
        a[st1]=0;
        st1--;
    }
    if(b[st2]<s[i])
    {
        b[++st2]=s[i];
        dfs(i+1);
        b[st2]=0;
        st2--;
    }

}
int main()
{
   // freopen("input.txt","r",stdin);

    cin>>T;
    while(T--)
    {
        for(int i=0;i<10;i++)
            cin>>s[i];
        sf=0;
        dfs(0);
        if(sf)cout<<"YES\n";
        else cout<<"NO\n";

    }





    return 0;
}





Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch RemainderMinimization2019 | diff RemainderMinimization2019.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address RemainderMinimization2019.cpp && ./a.out

/*
 
 7/7/2019
 
 5:07-5:28 AC
 
 https://img.atcoder.jp/abc133/editorial.pdf
 
 */

LL L,R;

void solve() {
  LL res=2019;
  if(R-L>=5000) res=0;
  else {
    FORE(a,L,R)FOR(b,L,a) SMIN(res,(LL)a*b%2019);
  }
  cout<<res<<endl;
}

LL f(LL x) {
  if(x<0) return 0;
  return x/2019+1;
}
void solve_org() {
  map<LL,LL> cnt;
  REP(r,2019) {
    LL x=f(R-r)-f(L-1-r);
    if(x>0)cnt[r]=x;
  }
//  dumpc(cnt);
  map<LL,vector<pair<LL,LL>>> pairs;
  REP(a,2019) pairs[a*a%2019].emplace_back(a,a);
  REP(b,2019)REP(a,b) pairs[a*b%2019].emplace_back(a,b);
  LL res=-1;
  FORR(kvp,pairs) FORR(p,kvp.second) {
    LL a,b; tie(a,b)=p;
    if(cnt.count(a)==0||cnt.count(b)==0) continue;
    cnt[a]--,cnt[b]--;
    if(cnt[a]>=0&&cnt[b]>=0) {
      res=kvp.first;
      goto fin;
    }
    cnt[a]++,cnt[b]++;
  }
fin:
  assert(res!=-1);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>L>>R;
  solve();
  
  return 0;
}


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

int main(){
  
  int N,l,r;
  int A = 0;
  
  cin >> N;
  
  for(int i = 0; i < N; i++){
    
    cin >> l >> r;
    A += r-l+1;
      
  }
  
  cout << A << endl;
  
}

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

int64_t N, Q, L, R, A[200000], D[200000], X[200000], S[200000], T[200000];

int64_t calc(int64_t v){
    for(int i=0; i<Q; i++){
        if(D[i] == 1 && X[i] <= v) v = T[i]*(v+S[i]);
        if(D[i] == 2 && v <= X[i]) v = (v-S[i])/T[i];
    }
    return v;
}

int main(){
    cin >> N >> Q >> L >> R;
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<Q; i++) cin >> D[i] >> X[i] >> S[i] >> T[i];

    int64_t mx = *max_element(A, A+N), mn = *min_element(A, A+N);
    int64_t rok = mn-1, rng = mx+1;
    while(rng-rok>1){
        int64_t mid = (rng+rok)/2;
        (calc(mid) <= R ? rok : rng) = mid;
    }
    int64_t lng = mn-1, lok = mx+1;
    while(lok-lng>1){
        int64_t mid = (lng+lok)/2;
        (calc(mid) >= L ? lok : lng) = mid;
    }
    int ans = 0;
    for(int i=0; i<N; i++) if(lok <= A[i] && A[i] <= rok) ans++;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 10740
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const N = readln.chomp.to!long;
    auto Hs = readln.split.to!(long[]);
    foreach_reverse(i; 0..N-1) {
        if (Hs[i] > Hs[i+1]+1) {
            writeln("No");
            return;
        } else if (Hs[i] == Hs[i+1]+1) {
            Hs[i]--;
        }
    }
    writeln("Yes");
}



Measured memory_bytes: 4176
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<char>> a(h+2, vector<char>(w+2));
  vector<vector<int>> b(h+2, vector<int>(w+2));
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      cin >> a.at(i).at(j);
    }
  }
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      if(a.at(i).at(j) =='#'){
        b.at(i).at(j) -=1000;
        b.at(i-1).at(j-1)++;
        b.at(i).at(j-1)++;
        b.at(i+1).at(j-1)++;
        b.at(i-1).at(j)++;
        b.at(i+1).at(j)++;
        b.at(i-1).at(j+1)++;
        b.at(i).at(j+1)++;
        b.at(i+1).at(j+1)++;
      }
    }
  }
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      if(b.at(i).at(j)<0)cout<<"#";
      else cout<<b.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a1 := make([]int, n+1)
	a2 := make([]int, n+1)
	for i := 1; i < n+1; i++ {
		var a int
		fmt.Scan(&a)
		a1[i] = a1[i-1] + a
	}
	for i := 1; i < n+1; i++ {
		var a int
		fmt.Scan(&a)
		a2[i] = a2[i-1] + a
	}
	max := func (x, y int) int {
		if x < y {
			return y
		} else {
			return x
		}
	}
	ans := 0
	for i := 1; i < n+1; i++ {
		ans = max(ans, a1[i] + a2[n] - a2[i-1])
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512