akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  int ans;
  if ((a+b) % 2 == 0){
    ans = (a+b)/2;
  } else {
    ans = (a+b)/2 + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};module.exports=I;

function main(input) {
  const o = new I(input);
  
  const L = o.a();

  const A = [];
  for (let i = 0; i < L ; i++) {
    A.push(o.a());
  }

  
  const dp = Array(L + 1).fill().map(() => Array(5).fill());
  dp[0] = [0, 0, 0, 0, 0];

  for (let i = 1; i <= L; i++) {
    let cur = A[i-1];
    let curEven = A[i-1] === 0 ? 2 : cur % 2;
    let curOdd = (cur + 1) % 2;

    dp[i][0] = dp[i-1][0] + cur;
    dp[i][1] = Math.min(dp[i-1][0], dp[i-1][1]) + curEven;
    dp[i][2] = Math.min(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + curOdd;
    dp[i][3] = Math.min(dp[i-1][2], dp[i-1][3]) + curEven;
    dp[i][4] = Math.min(dp[i-1][0], dp[i-1][1], dp[i-1][2], dp[i-1][3], dp[i-1][4]) + cur;
  }

  console.log(Math.min(...dp[L]));
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 87388
s=int(input())
a=s//100
b=s%100
if a<=12 and a>=1 and b<=12 and b>=1:
  print("AMBIGUOUS")
elif (a>=13 or a==0) and b<=12 and b>=1:
  print("YYMM")
elif a<=12 and a>=1 and (b>=13 or b==0):
  print("MMYY")
else:
  print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll n,m,x,c[14],a[14][14],ans=1e18;
    cin >> n >> m >> x;
    rep(i,0,n-1){
        cin >> c[i];
        rep(j,1,m) cin >> a[i][j];
    }
    rep(bit,0,(1l<<n)-1){
        ll mm[14]={0};
        ll co=0;
        bool ok=true;
        rep(i,0,n-1){
            if(bit&(1l<<i)){
                co+=c[i];
                rep(j,1,m) mm[j]+=a[i][j];
            }
        }
        rep(i,1,m){
            if(mm[i]<x) ok=false;
        }
        if(ok){
            chmin(ans,co);
        }
    }
    if(ans==1e18) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#!/usr/bin/perl

my $s  = <STDIN>;

my $s1 = substr($s,0,2) - 0;
my $s2 = substr($s,2,2) - 0;


my $c1 = (( $s1 >=1 and $s1 <= 12 ) ? 1 : undef);
my $c2 = (( $s2 >=1 and $s2 <= 12 ) ? 1 : undef);

if( $c1 and !$c2 ){
  print "MMYY\n";
} elsif( !$c1 and $c2 ){
  print "YYMM\n";
} elsif( $c1 and $c2 ){
  print "AMBIGUOUS\n";
} else {
  print "NA\n";
}
exit(0);




Measured memory_bytes: 640
n, m, q = map(int, input().split())
num = [list(map(int, input().split())) for _ in range(q)]
ans = 0
for i1 in range(1, m+1):
  for i2 in range(i1, m+1):
    for i3 in range(i2, m+1):
      for i4 in range(i3, m+1):
        for i5 in range(i4, m+1):
          for i6 in range(i5, m+1):
            for i7 in range(i6, m+1):
              for i8 in range(i7, m+1):
                for i9 in range(i8, m+1):
                  L = [1, i1, i2, i3, i4, i5, i6, i7, i8, i9]
                  A = []
                  for i in range(n):
                    A.append(L[i])
                  tmp = 0
                  for i in range(q):
                    a = num[i][0] - 1
                    b = num[i][1] - 1
                    c = num[i][2]
                    d = num[i][3]
                    if A[b] - A[a] == c:
                      tmp += d
                  ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 9224
#!/usr/bin/env python3

import sys
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from fractions import gcd                    # for Python3.4.3


def main():
    mod = 10000007                  # 10^9+7
    inf = float('inf')
    input = sys.stdin.readline      # 改行文字が残ることに注意
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def ii():  return int(input())
    def mi():  return map(int, input().rstrip().split())
    def lmi(): return list(map(int, input().rstrip().split()))
    def li():  return list(input().rstrip())
    
    
    n = ii()
    L = []
    for i in range(n):
        line = input().lstrip().split()
        line[1] = int(line[1])
        line.append(i+1)
        L.append(line)
    L.sort(key=lambda x: x[1], reverse=True)
    L.sort(key=lambda x: x[0])
    for elm in L:
        print(elm[2])


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
llong K;
vector<vector<llong>> R;
int main() {
	cin >> K;
	for (int i = 0; i < 10; i++) {
		if (i == 0) {
			vector<llong>tmp;
			for (llong j = 0; j <= 9; j++) {
				tmp.push_back(j);
			}
			R.push_back(tmp);
		}
		else {
			vector<llong> tmp;
			for (int j = 0; j < i; j++) {
				for (int k = 0; k < R[j].size(); k++) {
					llong tmp1 = R[j][k] / pow(10, i - 1);
					if (tmp1 == 0) {
						if (floor(R[j][k] / pow(10, j)) == 1 || R[j][k] == 0) {
							tmp.push_back(pow(10, i) + R[j][k]);
						}
					}
					else {
						if (0 < tmp1 - 1 && tmp1 - 1 < 10) {
							tmp.push_back((tmp1 - 1) * pow(10, i) + R[j][k]);
						}
						if (0 < tmp1 && tmp1 < 10) {
							tmp.push_back(tmp1 * pow(10, i) + R[j][k]);
						}
						if (0 < tmp1 + 1 && tmp1 + 1 < 10) {
							tmp.push_back((tmp1 + 1) * pow(10, i) + R[j][k]);
						}
					}
				}
			}
			sort(tmp.begin(), tmp.end());
			R.push_back(tmp);
		}
	}
	int count = 0;
	for (int i = 0; i < R.size(); i++) {
		for (int j = 0; j < R[i].size(); j++) {
			//cout << R[i][j] << endl;
			if (count == K) {
				cout << R[i][j] << endl;
				return 0;
			}
			count++;
		}
	}
}

Measured memory_bytes: 3104
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

  private static final long MAX = (long) Math.pow(10, 18);

  public static void main(final String[] args) {
    final var scanner = new Scanner(System.in);
    final long N = scanner.nextLong();
    final List<Long> A = new ArrayList<>();

    for (long i = 0; i < N; i++) {
      final long a = scanner.nextLong();
      if (a == 0L) {
        System.out.println(0);
        return;
      }

      A.add(a);
    }

    long result = 1;
    for (final Long a : A) {
      if (!(a < Long.MAX_VALUE / result)) {
        System.out.println(-1);
        return;
      }

      result *= a;
      if (result > MAX) {
        System.out.println(-1);
        return;
      }
    }

    System.out.println(result);
  }
}


Measured memory_bytes: 59256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}


int main() {
	string str;
	cin >> str;
	
	if (str[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}

	int upcount=0,cc=0;
	for (auto c : str) {
		if (c >= 'A'&&c <= 'Z') {
			upcount++;
		}
		if (c == 'C') {
			cc++;
		}
	}
	if (upcount > 2||cc>1||cc==0) {
		cout << "WA" << endl;
		return 0;
	}

	for (int i = 0; i < str.size(); i++) {
		if (str[i] == 'C' && (i<2 || i>str.size() -2)) {
			cout << "WA"<< endl;
			return 0;
		}
	}
	cout << "AC" << endl;
}


Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.IntStream;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		String[] list = new String[N];
		for(int i = 0; i < N; i++) list[i] = in.next();
		
		BigInteger lcm = new BigInteger(list[0]);
		for(int i = 1; i < N; i++){
			BigInteger a = new BigInteger(list[i]);
			lcm = (lcm.multiply(a)).divide(lcm.gcd(a));
		}
		
		System.out.println(lcm);
		
	}
}

Measured memory_bytes: 23252
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

// 1. dp?????????
int dp[201][201];
// 2. n?????????
int D,N;
int T[201];
int A[205],B[205],C[205];

// 7. calc?????????
int calc(int k,int m){
	// 8. dp???????????°??????
	if(dp[k][m]>=0)return dp[k][m];
	if(T[m]<A[k] || T[m]>B[k])return -1;
	// 9. dp????¨????
	for(int i=0;i<N;i++){
		int P=calc(i,m-1);
		if(P>=0)dp[k][m]=max(dp[k][m],abs(C[k]-C[i])+dp[i][m-1]);
	}


	return dp[k][m];
}
int main() {
	cin>>D>>N;

	//3.?????????
	for(int i=0;i<201;i++){
		for(int j=0;j<201;j++){
			dp[i][j]=-1;
		}
	}
	//4.??\???
	for(int i=1;i<D+1;i++){
		cin>>T[i];
	}
	for(int i=0;i<N;i++){
		cin>>A[i]>>B[i]>>C[i];
	}



	//5.???????????¨???
	for(int i=0;i<N;i++){
		if(T[1]>=A[i] && T[1]<=B[i])dp[i][1]=0;
	}


	//6.??????
	int total=0;
	for(int i=0;i<N;i++){
		total=max(total,calc(i,D));
	}

	cout<<total<<endl;



	return 0;
}

Measured memory_bytes: 3200
A, B, Q = map(int, input().split())

INF = 10 ** 11 + 1
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]

def bsr(a, v):
	lo, hi = 0, len(a)
	while lo < hi:
		mi = (lo + hi) // 2
		if v < a[mi]:
			hi = mi
		else:
			lo = mi + 1
	return lo

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	cost = []
	for m in [S[sr], S[sl]]:
		for n in [T[tr], T[tl]]:
			cost += [abs(x - m) + abs(m - n), abs(x - n) + abs(m - n)]
	print(min(cost))


Measured memory_bytes: 16256
class Vertex
	attr_accessor :distance, :predecessor
	def initialize
		@distance = -2000 * 10 ** 9 - 1
		@predecessor = nil
	end
end

N, M = gets.split.map{|i|i.to_i}
V = Array.new(N){Vertex.new}
E = []
M.times{
	a, b, c = gets.split.map{|i|i.to_i}
	E << [a - 1, b - 1, c]
}
V[0].distance = 0

(N - 1).times{
	E.each{|e|
		u, v, w = e
		if V[v].distance < V[u].distance + w
			V[v].distance = V[u].distance + w
			V[v].predecessor = u
		end
	}
}

visited = Array.new(N){false}
e = N - 1
cycle = false
loop{
	unless V[e].predecessor
		break
	end
	if visited[e]
		cycle = true
		break
	end
	visited[e] = true
	e = V[e].predecessor
}

if cycle
	puts "inf"
else
	puts (V[-1].distance)
end


Measured memory_bytes: 2172
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);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;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n,l;
int main(){
    cin>>n>>l;
    int sum=0;
    rep(i,n){
        sum+=l+i+1-1;
    }
    int ans=inf;
    int now=0;
    rep(i,n){
        now=0;
        rep(j,n){
            if((i+1)==(j+1)) continue;
            else now+=l+j+1-1;
        }
        if(abs(sum-now)<abs(sum-ans)) ans=now;
    }
    cout<<ans<<endl;
    return 0;
}

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

#define MAX 100000
#define NIL -1

struct edge{
  int id;
  struct edge *next;
};

typedef struct edge * EdgePointer;

void init(void);
void printList(void);
void insert(int,int);
void assignColor(void);
void bfs(int,int);
void enqueue(int);
int dequeue(void);

EdgePointer Adj_list[MAX];
EdgePointer temp[MAX];
int color[MAX];
int n;
int Queue[MAX],head,tail;

int main(){
  int s,t,m,q;
  int i,j;
  
  scanf("%d %d",&n,&m);

  init();
  
  for (i = 0;i < n;i++)
    temp[i] = Adj_list[i];
  
  for (i = 0;i < m;i++){
    scanf("%d %d",&s,&t);

    insert(s,t);
    insert(t,s);
  }
  
  assignColor();

  scanf("%d",&q);

  for (i = 0;i < q;i++){
    scanf("%d %d",&s,&t);

    if (color[s] == color[t])
      printf("yes\n");

    else
      printf("no\n");
  }
  
  return 0;
}

void init(void){
  int i;

  for (i = 0;i < n;i++){
    Adj_list[i] = (EdgePointer)malloc(sizeof(struct edge));
    Adj_list[i]->next = Adj_list[i];
    temp[i] = Adj_list[i];
  }
}

void printList(void){
  EdgePointer cur;
  int i;

  for (i = 0;i < n;i++){
    printf("Adj[%d] ",i);
    
    for (cur = Adj_list[i]->next;cur != Adj_list[i];cur = cur->next){
      printf("-%d ",cur->id);
    }
    
    printf("\n");  
  }

}

void insert(int s,int t){
  int elid;
  EdgePointer x;
  EdgePointer find_insert;
  
  x = (EdgePointer)malloc(sizeof(struct edge));
  x->id = t;

  for (find_insert = Adj_list[s];find_insert->next != Adj_list[s] && t > find_insert->next->id;find_insert = find_insert->next);

  x->next = find_insert->next;
  find_insert->next = x;
}

void assignColor(void){
  int id = 1;
  int i;

  for (i = 0 ;i < n;i++)
    color[i] = NIL;

  for (i = 0;i < n;i++)
    if (color[i] == NIL)
      bfs(i,id++);
}

void bfs(int x,int stamp){
  int u,v;
  EdgePointer find_x;
  
  color[x] = stamp;
  enqueue(x);
  
  while (head != tail){
    u = dequeue();
   
    for (find_x = Adj_list[u]->next;find_x != Adj_list[u];find_x = find_x->next)
      {
	v = find_x->id;
	
	if (color[v] == NIL){
	  color[v] = stamp;
	  enqueue(v);
	}
	
      }
    
  }
  
}

void enqueue(int u){
  Queue[tail] = u;

  if (tail + 1 == MAX)
    tail = 0;

  else
    tail++;
}

int dequeue(void){
  int ans;

  ans = Queue[head];

  if (head + 1 == MAX)
    head = 0;

  else
    head++;

  return ans;
}



Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;
const int MOD = 1'000'000'007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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

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

// const int MAX = 1010;

int main()
{
    ll x, y;
    cin >> x >> y;
    if (x % y == 0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << x * (y - 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+20 , INF = 0x3f3f3f3f;
int n,a[N],odd[N<<2],even[N<<2];
inline void update(int &x,int y) { if ( a[x] > a[y] ) x = y; }
inline void build(int p,int l,int r)
{
    if ( l == r )
        return ( ( l & 1 ) ? odd[p] = l : even[p] = l ) , void();
    int mid = l + r >> 1;
    build( p<<1 , l , mid ) , build( p<<1|1 , mid+1 , r );
    update( odd[p] , odd[p<<1] ) , update( odd[p] , odd[p<<1|1] );
    update( even[p] , even[p<<1] ) , update( even[p] , even[p<<1|1] );
}
inline int query(int p,int l,int r,int ql,int qr,int op)
{
    if ( ql <= l && qr >= r ) return op ? even[p] : odd[p];
    int mid = l + r >> 1 , res = 0;
    if ( ql <= mid ) update( res , query(p<<1,l,mid,ql,qr,op) );
    if ( qr > mid ) update( res , query(p<<1|1,mid+1,r,ql,qr,op) );
    return res;
}
struct sec
{
    int l,r,ansl,ansr,op;
    sec (int _l,int _r,int _op)
    {
        l = _l , r = _r , op = _op;
        ansl = query(1,1,n,l,r,op);
        ansr = query(1,1,n,ansl+1,r,op^1);
    }
    friend bool operator < (sec x,sec y)
    {
        if ( a[x.ansl] == a[y.ansl] )
            return a[x.ansr] < a[y.ansr];
        return a[x.ansl] < a[y.ansl];
    }
};
set <sec> S;
inline void solve(void)
{
    S.insert( sec(1,n,0) );
    while ( S.size() )
    {
        sec now = *S.begin(); S.erase(now);
        printf("%d %d ",a[now.ansl],a[now.ansr]);
        if ( now.l < now.ansl-1 )
            S.insert(sec(now.l,now.ansl-1,now.op));
        if ( now.ansl+1 < now.ansr-1 )
            S.insert(sec(now.ansl+1,now.ansr-1,now.op^1));
        if ( now.ansr+1 < now.r )
            S.insert(sec(now.ansr+1,now.r,now.op));
    }
}
inline void input(void)
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
}
int main(void)
{
    input();
    a[0] = INF;
    build( 1 , 1 , n );
    solve();
    return puts("") , 0;
}

Measured memory_bytes: 10880
#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);
  for(int i=0;i<n;i++)
    a.at(i)--;
  int ans=0;
  for(int i=0;i<n;i++){
    if(a.at(a.at(i))==i)
      ans++;
  }
  cout << ans/2 << endl;
  return 0;
}

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

#include<atcoder/all>
using namespace atcoder;

int main(void) {
    constexpr ll MOD = 1e9+7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;

    dsu d(n);
    while(m--) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        d.merge(a, b);
    }
    cout << d.groups().size()-1 << endl;

}

Measured memory_bytes: 9044
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 100000;
int N;
ll X;
ll x[MAX_N];

//gcd(a, b)を求める。
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}


int main() {
  cin >> N >> X;
  rep(i, N) cin >> x[i];
  
  rep(i, N) x[i] = abs(x[i] - X);

  ll ans = gcd(x[0], x[1]);
  for (int i = 2; i < N; ++i) {
    ans = gcd(ans, x[i]);
  }

  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <string.h>
#include <stdio.h>
int main(){
  	int W, N, wi, vi;
	std::cin >> N >> W;
	int w[N + 1];
	int v[N + 1];
	w[0] = 0;
	v[0] = 0;
    long V = 0;
	for(int i=1;i<N+1;i++){
    	std::cin >> wi >> vi;
    	w[i] = wi;
    	v[i] = vi;
        V += vi;
	}
    long dp[N + 1][V + 1];
    for(int i=0;i<N+1;i++){
    	for(int j =0;j<V+1;j++){
        	dp[i][j] = 1000000001;
        }
    }
    dp[0][0] = 0;
    int reg = 0;
	for(int i=1;i<N+1;i++){
    	for(int j=0;j<V+1;j++){
        	if(v[i] > j){
            	dp[i][j] = dp[i - 1][j];
        	}else{
            	dp[i][j] = std::min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
        		if(dp[i][j] <= W){
                  if(reg < j){
                  	reg = j;
                  }
                }
            }
    	}
	}
	std::cout << reg;
}

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

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    if(a[0]){
        cout << 0 << endl;
        return 0;
    }

    vector<vector<ll>> dp(n, vector<ll>(3, 0));
    dp[0][0] = 1;
    rep1(i, n){
        int up_idx = -1;
        rep(j, 3){
            if(dp[i-1][j]==a[i]){
                up_idx = j;
                break;
            }
        }
        
        rep(j, 3){
            if(j==up_idx) dp[i][j] = dp[i-1][j] + 1;
            else dp[i][j] = dp[i-1][j];
        }

    }

    // rep(i, n){
    //     rep(j, 3) cout << dp[i][j] << " ";
    //     cout << endl;
    // }

    ll res = 3;
    ll const MOD = 1000000007;
    rep1(i, n){
        ll cand = 0;
        rep(j, 3){
            if(dp[i-1][j]+1 == dp[i][j]){
                rep(k, 3){
                    if(dp[i-1][k]+1 == dp[i][j]) ++cand;
                }
                break;
            }
        }
        res = res%MOD * cand%MOD;
        res %= MOD;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define rev(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ O(logN)
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//



int main() {

    int n;
    cin >> n;
    if (n <= 999) cout << "ABC" << endl;
    else cout << "ABD" << endl;



    return 0;
}








Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
ll n, m, x, c[19], a[19][19], h[19], ans = mod;
int main () {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m>>x;
    for(int i=0;i<n;i++) {
        cin>>c[i];
        for(int j=0;j<m;j++) {
            cin>>a[i][j];
        }
    }
    for(int mask = 0; mask < (1 << n); mask++) {
        ll cost = 0;
        for(int i=0;i<n;i++) {
            if(mask & (1 << i)) {
                cost += c[i];
                for(int j=0;j<m;j++)
                    h[j] += a[i][j];
            }
        }
        bool p = 1;
        for(int j=0;j<m;j++) {
            if(h[j] < x) {
                p = 0;
                break;
            }
        }
        if(p)
            ans = min(ans, cost);
        for(int j=0;j<m;j++)
            h[j] = 0;
    }
    if(ans == mod)
        cout<<-1;
    else
        cout<<ans;
}
/*
 2
 1 1
 1 0
 1 1
 1 1
 */


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

vector<vector<int>> graph;
vector<int> dp;

int dfs(int i) {
    if(dp[i]!=-1) return dp[i];
    if(graph[i].size()==0) return 0;

    for(auto j:graph[i]) {
        dp[i]= max(dp[i],dfs(j)+1);
    }
    return dp[i];
}

int main()
{
    int n,m;
    cin>>n>>m;
    graph.resize(n+1);
    dp.resize(n+1,-1);

    for(int i=0;i<m;i++) {
        int a,b; cin>>a>>b;
        graph[a].push_back(b);
    }

    for(int i=1;i<=n;i++) {
        if(dp[i]==-1) {
            dfs(i);
        }
    }

    cout<<*max_element(dp.begin(),dp.end());
}

Measured memory_bytes: 8192
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
using namespace std;

struct node{
    int key;
    node *p,*l,*r;
};

node *root,*NIL;


void insert(int k){
    node *z;
    z = (node *)malloc(sizeof(node)); //なにこれ
    z->key=k;
    z->l=NIL;
    z->r=NIL;
    node *y=NIL;
    node *x=root;
    while(x != NIL){
        y=x;
        if(k < x->key) x = x->l;
        else x = x->r;
    }
    z->p=y;

    if(y==NIL) root=z;
    else if(k < y->key) y->l=z;
    else y->r=z;
}

void Preorder(node *u){
    cout << ' ' << u->key;
    if(u->l != NIL) Preorder(u->l);
    if(u->r != NIL) Preorder(u->r);
}

void Inorder(node *u){
    if(u->l != NIL) Inorder(u->l);
    cout << ' ' << u->key;
    if(u->r != NIL) Inorder(u->r);
}

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        if(s == "insert"){
            int k;
            cin >> k;
            insert(k);
        }
        else{
            Inorder(root);
            cout << endl;
            Preorder(root);
            cout << endl;
        }
    }
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long double pi=acos(-1);
#define x  first
#define y  second
#define read(n,a) for(int i=0;i<n;i++)cin>>a[i];
#define rep(i,z,n)for(int i=z;i<n;i++)
#define all(v)    v.begin(),v.end()

//int a[200002]={};
//ll b[200002]={};
ll n,m;

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    ///freopen("ss.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        cin>>n;
        int x,y;
        int c=0,ch=0;
        while(n--)
        {
            cin>>x>>y;
            if(x==y)c++;
            else c=0;
            if(c==3)ch=1;
        }
        cout<<(ch? "Yes":"No");
    }
    return 0;
}


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

ll dist(ll a,ll b){
  ll c=abs(a-b);
  return min(c,N-c);
}

ll solve(vector<ll> x,vector<ll> v){
  ll ans=0;
  map< ll , ll > mp;
  ll sum=0;

  for(int i=N-1;i>=0;i--){
    sum+=v[i];
    ll dist=C-x[i];
    mp[i]=sum-dist*2LL;
    if(i+1<N)mp[i]=max(mp[i],mp[i+1]);

    //    cout<<i<<' '<<mp[i]<<' '<<x[i]<<' '<<v[i]<<endl;
  }
  
  sum=0;
  for(int i=0;i<N;i++){
    sum+=v[i];
    ans=max(ans, sum+mp[i+1]-x[i] );
    ans=max(ans, sum-x[i] );
    //    cout<<sum<<' '<<x[i]<<' '<<mp[i+1]<<endl;
  }
  //  cout<<endl;
  return ans;
}


int main(){
  cin>>N>>C;
  vector<ll> x(N), v(N);
  for(int i=0;i<N;i++){
    cin>>x[i]>>v[i];
    x[i]%=C;
  }

  ll fi=solve(x,v);

  typedef pair<ll,ll> P;

  vector< P > tmp;
  for(int i=0;i<N;i++){
    tmp.push_back( P( (C-x[i])%C ,v[i]));
  }
  sort(tmp.begin(), tmp.end());
  vector<ll> nx=x,nv=v;
  for(int i=0;i<N;i++){
    nx[i]=tmp[i].first;
    nv[i]=tmp[i].second;
  }
  
  ll se=solve(nx,nv);

  cout<< max(fi,se) <<endl;
  return 0;
}


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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int ketasu(int64_t N)
{
    int64_t d = 0;
    while (N != 0)
    {
        N /= 10;
        d++;
    }
    return d;
}

int main()
{
    int N;
    cin >> N;
    int keta = ketasu(N);
    if (keta == 1)
        cout << N;
    if (keta == 2)
        cout << 9;
    if (keta == 3)
        cout << (N - 99) + 9;
    if (keta == 4)
        cout << 909;
    if (keta == 5)
        cout << (N - 9999) + 909;
    if (keta == 6)
        cout << 90909;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

string s;
llong k;
llong ans;

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

    llong pre = 0;
    llong back = 0;
    llong mid = 0;

    llong i = 0;
    llong j = s.size() - 1;
    while (i < s.size() - 1 && s[i] == s[i + 1]) {
        pre++;
        i++;
    }
    pre++;

    while (j > 0 && s[j] == s[j - 1]) {
        back++;
        j--;
    }
    back++;

    for (int k = i; k < j; k++) {
        int cnt = 0;
        while (k < j && s[k] == s[k + 1]) {
            cnt++;
            k++;
        }
        cnt++;
        mid += cnt / 2;
    }

    llong concat = 0;
    if (s.back() == s[0]) concat = pre + back;

    if (pre + back == s.size()) {
        ans = pre/2 * k + back/2 * k;
    }
    else if (pre + back >= s.size()) {
        ans = s.size() * k / 2;
    }
    else {
        if (concat == 0) {
            ans = pre/2 * k + back/2 * k + mid*k;
        }
        else {
            ans = pre/2 + back/2 + mid * k + concat/2 * (k - 1);
        }
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

void solve()
{

}

int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
vll a(n);
ll ans=0;
rep(i,0,n-1)cin>>a[i];
sort(all(a));
reverse(all(a));
int cnt=n-2;
ans=a[0];
rep(i,1,n-1)
{
	int cc=2;
	while(cc--)
	{
		if(cnt==0)break;
		ans+=a[i];
		cnt--;
	}
}
ol(ans);
return 0;
}



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

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

    int n; cin >> n;
    ll sum = 0;
    vector<ll> a(n), b(n-1);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }

    b[0] = a[0];
    for (int i = 1; i < n-1; ++i) {
        b[i] = a[i] + b[i-1];
    }

    ll res = 1e15;
    for (int i = 0; i < n-1; ++i) {
        if (res > abs(sum - 2*b[i])) {
            res = abs(sum - 2*b[i]);
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3456
import math

n = int(input())
a = list(map(int, input().split()))

lib = [0] * n

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in a:
    lib[i - 1] += 1

count = 0

for i in lib:
    if i >= 2:
        count += comb(i, 2)

for i in a:
    print(count - (lib[i - 1] - 1))


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

int main()
{
ll n,i,j,k,s;
cin>>n;
s=0;
vector<ll> a(n+1),b(n+1);
for(i=1;i<=n;i++){
    cin>>j;
    b[i]=j+b[i-1];
}
ll d=2e9+1;
for(i=1;i<=n-1;i++){
    d=min(d,abs(b[n]-2*b[i]));
}
cout<<d;

}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#define MAX_V 401
#define INF 1000000000

ll d[MAX_V][MAX_V]; //d[u][v]は辺e=(u,v)のコスト(存在しない場合はINF,d[i][i]=0)
int V; //頂点数

void warshall_floyd(){
    for(int k = 0; k < V; k++)
        for(int i = 0; i < V; i++)
            for(int j = 0; j < V; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main(void){
    ll h, w;
    cin >> h >> w;

    V = h * w;

    rep(i, 0, MAX_V){
        rep(j, 0, MAX_V){
            d[i][j] = INF;
            if(i == j){
                d[i][j] = 0;
            }
        }
    }

    char mp[h][w];
    rep(i, 0, h){
        rep(j, 0, w){
            cin >> mp[i][j];
        }
    }

    rep(i, 0, h){
        rep(j, 0, w){
            if(mp[i][j] == '.'){
                if(i != 0 && mp[i - 1][j] == '.'){
                    d[w * (i - 1)+ j][w * i + j] = 1;
                    d[w * i + j][w * (i - 1) + j] = 1;
                }
                if(i != h - 1 && mp[i + 1][j] == '.'){
                    d[w * (i + 1) + j][w * i + j] = 1;
                    d[w * i + j][w * (i + 1) + j] = 1;
                }
                if(j != 0 && mp[i][j - 1] == '.'){
                    d[w * i + j - 1][w * i + j] = 1;
                    d[w * i + j][w * i + j - 1] = 1;
                }
                if(j != w - 1 && mp[i][j + 1] == '.'){
                    d[w * i + j + 1][w * i + j] = 1;
                    d[w * i + j][w * i + j + 1] = 1;
                }
            }
        }
    }

    warshall_floyd();

    ll ans = 0;
    rep(i, 0, h){
        rep(j, 0, w){
            rep(k, 0, h){
                rep(l, 0, w){
                    if(d[w * i + j][w * k + l] < INF){
                        ans = max(ans, d[w * i + j][w * k + l]);
                    }
                }
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,Q;
  cin >> N >> Q;
  vector<pair<int,pair<int,int>>> XST(N);
  for(int i=0;i<N;i++){
    int s,t,x;
    cin >> s >> t >> x;
    XST.at(i)=m_p(x,m_p(s,t));
  }
  sort(all(XST));

  vector<int> D(Q);
  set<int> S;
  for(int i=0;i<Q;i++){
    cin >> D.at(i);
    S.insert(D.at(i));
  }

  vector<int> ans(Q,-1);
  for(int i=0;i<N;i++){
    int a=XST.at(i).se.fi-XST.at(i).fi;
    int b=XST.at(i).se.se-XST.at(i).fi;
    decltype(S)::iterator it=S.lower_bound(a);
    decltype(S)::iterator last=S.upper_bound(b-1);
    //cout << endl << XST.at(i).se.fi << " " << XST.at(i).se.se << " " << XST.at(i).fi << endl;
    vector<int> tmp;
    while(it!=last){
      int d=*it;
      //cout << d << endl;
      it++;
      tmp.p_b(d);
    }
    for(int j=0;j<sz(tmp);j++){
      int d=tmp.at(j);
      S.erase(d);
      ans.at(lower_bound(D.begin(),D.end(),d)-D.begin())=XST.at(i).fi;
    }
  }
  for(int i=0;i<Q;i++)  cout << ans.at(i) << endl;

  return 0;
}

Measured memory_bytes: 17480
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int board[20][20];
int w, h, ans;
int dx[] = { 1,0,0,-1 }, dy[] = { 0,1,-1,0 };

void dfs(int x, int y, int cnt) {
	if (cnt > 10) return;
	for (int i = 0; i < 4; ++i) {
		int nx = x + dx[i], ny = y + dy[i];
		if (board[nx][ny] == 1) continue;
		while (0 <= nx && nx < h && 0 <= ny && ny < w) {
			if (board[nx][ny] == 3) {
				ans = min(ans, cnt);
				return;
			}
			if (board[nx][ny] == 1) {
				board[nx][ny] = 0;
				dfs(nx - dx[i], ny - dy[i], cnt + 1);
				board[nx][ny] = 1;
				break;
			}
			nx += dx[i], ny += dy[i];
		}
	}
}

int main() {
	while (cin >> w >> h, w) {
		int sx, sy;
		memset(board, 0, sizeof(board));
		ans = 1e9;
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; j++) {
				int d; cin >> d;
				if (d == 2) sx = i, sy = j;
				board[i][j] = d;
			}
		}
		dfs(sx, sy, 1);
		cout << (ans == 1e9 ? -1 : ans) << endl;
	}

	return 0;
}


Measured memory_bytes: 2996
#include<iostream>
#include<vector>
#include<stack>
#include<set>
using namespace std;

void set_color(const vector<vector<int> >& G, vector<int>& color,
                int color_name, int a, int i) {
    for (int i = 0; i < G[a].size(); i++) {
        if (color[G[a][i]] == -1) {
            color[G[a][i]] = color_name;
            set_color(G, color, color_name, G[a][i], 0);
        }
    }
}


bool DFS(const vector<vector<int> >& G, int a, int b) {
    if (G[a].size() == 0 || G[b].size() == 0) return false;
    static vector<int> color(G.size(), -1);
    static int color_name = 0;
    if (color[a] != color[b]) return false;
    if (color[a] == -1) {
        set_color(G, color, color_name++, a, 0);
    }
    if (color[a] == color[b]) return true;
    return false;
}


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

    vector<vector<int> > G(n);

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

// for (int i = 0; i < n; i++) {
//     cout << i << " : ";
//     for (vector<int>::iterator it = G[i].begin(); it != G[i].end(); it++){
//         cout << *it << " ";
//     }
//     cout << endl;
// }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b;
        cin >> a >> b;
        if (DFS(G, a, b)) {
           cout << "yes" << endl;
        } else {
           cout << "no"  << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 11672
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int R, B, W, G;
    cin >> R >> B >> W >> G;
    cout << R + B + W + G << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        int X, Y, Z;
        cin >> X >> Y >> Z;

        cout << (X - Z) / (Y + Z) << endl;

        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll n, k, ans;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> k;
    if (k % 2) {
        ll p = n/k;
        ans = p*p*p;
    } else {
        ll p = (n + (k/2))/k, q = n/k;
        ans = p*p*p + q*q*q;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String s=sc.next();
		String t=sc.next();
		String str="";
		for(int i=0;i<n;i++) {
			str+=s.substring(i,i+1)+t.substring(i,i+1);
		}
		System.out.println(str);
	}
}

Measured memory_bytes: 21204
n,k = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))
p = [pi-1 for pi in p]

ans = -1e18
for i in range(n):
  cur = p[i]
  loop = [c[cur]]
  cnt = 1
  ans = max(ans,c[cur])
  while cur != i and cnt<k:
    cur = p[cur]
    tmp = loop[-1]+c[cur]
    loop.append(tmp)
    ans = max(ans,tmp)
    cnt += 1
  #print(loop)
  if cnt==k or loop[-1]<=0:continue
  a = k//len(loop) * loop[-1]
  b = (k//len(loop)-1) * loop[-1]
  ans = max(ans,a,b)
  for _ in range(k%len(loop)):
    a += c[cur]
    ans = max(ans,a)
    cur = p[cur]
  cur = i
  for _ in range(len(loop)):
    b += c[cur]
    ans = max(ans,b)
    cur = p[cur]
print(ans)

Measured memory_bytes: 80208
using System;
using System.Collections.Generic;
using System.Linq;

class Hello
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).Distinct().ToArray();
        Console.WriteLine(a.Length % 2 == 0 ? a.Length - 1 : a.Length);
    }
}


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

using namespace std;
int main() {
	int N, M; cin >> N >> M; 
	int L = -114514; int R = 114514;  
	for(int i = 0; i < M; i++){
		int l, r; cin >> l >> r; 
		L = max(L, l); R = min(R, r); 
	}
	if(L <= R) cout << R - L + 1 << endl; 
	else cout << 0 << endl; 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)

int main(){
   int a;
   cin >> a;
   if(a >= 30 ){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }

   


}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <utility>
#include <map>

int main() {
    long long n, m, ret = 0;
    std::cin >> n >> m;
    std::vector<long long> a(n + 1, 0ll);
    std::map<long long, long long> s;
    
    s[0]++;
    for (auto i = 1ll; i <= n; i++) {
        std::cin >> a[i];
        a[i] += a[i - 1];
        s[a[i] % m]++;
    }

    for (auto it = s.begin(); it != s.end(); it++) {
        if (it->second > 1) ret += it->second * (it->second - 1) / 2;
    }

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

    return 0;
}

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

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

using namespace std;

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

bitset<MX> b;
bitset<MX> fr;
bitset<MX> go;
int dd[MX];
queue<int> qu;

int main() {
	int k;
	cin >> k;
	while (k % 2 == 0)
		k /= 2;
	while (k % 5 == 0)
		k /= 5;
	if (k == 1) {
		cout << 1 << "\n";
		return 0;
	}
	ll cur = 1;
	while (true) {
		if (b[cur])
			break;
		b[cur] = 1;
		cur = (cur * 10) % k;
	}
	for (int i = 0; i < k; ++i) {
		dd[i] = 100000;
	}
	for (int i = 0; i < k; ++i) {
		if (b[i]) {
			dd[i] = 1;
			qu.push(i);
		}
		else
			fr[i] = 1;
	}
	while (!qu.empty()) {
		int x = qu.front();
		if (x == 0) {
			cout << dd[x] << "\n";
			return 0;
		}
		qu.pop();
		go = (b << x) | (b >> (k - x));
		go &= fr;
		while (go.any()) {
			int y = go._Find_first();
			go[y] = 0;
			dd[y] = dd[x] + 1;
			fr[y] = 0;
			qu.push(y);
		}
	}
	return 0;
}




Measured memory_bytes: 1152