akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

int h, w;
string s[400];
int group[400][400];
long long nb[400 * 400];
long long nw[400 * 400];

bool check(int y,int x) {
	if (y < 0 || h <= y || x < 0 || w <= x)return false;
	return true;
}

void dfs(int y,int x, int g) {
	if (group[y][x] != -1)return;
	group[y][x] = g;
	if (s[y][x] == '#')nb[g]++;
	else nw[g]++;

	if (check(y - 1, x) && s[y][x] != s[y - 1][x])dfs(y - 1, x, g);
	if (check(y + 1, x) && s[y][x] != s[y + 1][x])dfs(y + 1, x, g);
	if (check(y, x - 1) && s[y][x] != s[y][x - 1])dfs(y, x - 1, g);
	if (check(y, x + 1) && s[y][x] != s[y][x + 1])dfs(y, x + 1, g);
}


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

	cin >> h >> w;
	rep(i, h)cin >> s[i];

	memset(group, -1, sizeof(group));
	int cnt = 0;
	rep(y,h)rep(x,w) {
		if (group[y][x] == -1) {
			dfs(y, x, cnt);
			cnt++;
		}
	}

	long long ans = 0;
	rep(i, h*w) {
		ans += nb[i] * nw[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 18560
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main(void)
{
	int n,m,i,j,d,v,vm[101],sum;
	while(1)	{
		scanf("%d %d",&n,&m);
		if(m==0 && n==0)	break;
		for(i=1;i<=m;i++)	vm[i]=0;
		for(i=0;i<n;i++)	{
			scanf("%d %d",&d,&v);
			vm[d]=max(vm[d],v);
		}
		sum=0;
		for(i=1;i<=m;i++)	sum+=vm[i];
		printf("%d\n",sum);
	}
	return 0;
}


Measured memory_bytes: 2576
fun main(args: Array<String>) {
    val S = next()
    val N = S.length
    val s1 = S.substring(0 .. (N - 1) / 2 - 1)
    val s2 = S.substring((N + 3) / 2 - 1 .. N - 1)
    fun isPal(s: String) = (s == s.reversed())
    val ans = isPal(S) && isPal(s1) && isPal(s2)
    println(if (ans) "Yes" else "No")
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun nextLong() = java.lang.Long.parseLong(next())
fun nextLong(offset: Long = 0L) = nextLong() + offset
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }
fun listOfLong(offset: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + offset }
fun listOfDouble() = listOfString().map { it.toDouble() }


Measured memory_bytes: 31868
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    vector<queue<int> > vec(n);

    int flag, t, x;
    for (int i = 0; i < q; i++)
    {
        scanf("%d", &flag);
        switch (flag) {
        case 0:
            scanf("%d %d", &t, &x);
            vec[t].push(x);
            break;
        case 1:
            scanf("%d", &t);
            if (!vec[t].empty())
            {
                printf("%d\n",vec[t].front());
            }
            break;
        case 2:
            scanf("%d", &t);
            if (!vec[t].empty())
            {
                vec[t].pop();
            }
            break;
        default:
            break;
        }
    }


    return 0;
}



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

int main(){
  string s;cin>>s;
  
  if(s[1]=='S'){
    if(s[0]=='R'||s[2]=='R')cout<<1<<endl;
    else cout<<0<<endl;
  }else{
    if(s[0]=='R'&&s[2]=='R')cout<<3<<endl;
    else if(s[0]=='R'||s[2]=='R')cout<<2<<endl;
    else cout<<1<<endl;
  }
  return 0;
}

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

int n;

int main()
{
	cin>>n;
	for(int i=1;i<=9;i++)
		if(n%i==0)
		{
			if(n/i<=9)
				return !(cout<<"Yes\n");
		}
	cout<<"No\n";
	
	return 0;
}

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

using namespace std;

using ll = long long int;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp; 
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

// [beg, end)の範囲を，添え字indexでループするfor文に置換します
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

int main() {
    int N;

    cin >> N;

    cout << (N -2) * 180;

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define N 8
#define NOT_FREE 1
#define FREE 0

int row[N],col[N],dpos[2*N-1],dneg[2*N-1],flag[N][N];

void printBoard(void){
  int i,j;

  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      if(flag[i][j] == 1 && row[i] != j) return;
    
      

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void putQ(int i){
  int j;
  if(i == N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE) continue;
    /*タテナナメヨコに被る所がある場合には次のるーぷへ*/

    row[i] = j; /*j行目のクイーンが何列目にいるのかという配列row*/
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;/*タテナナメヨコをNOTFREEにする*/
    
  
    putQ(i+1);
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;/*次のパターンのためにタテヨコナナメをフリーにする*/
  }
  
}

int main(){
  int k,r,c,i,j;
 
  
  for(i=0;i<N;i++){
    col[i] = FREE;
    for(j=0;j<N;j++){
      flag[i][j] = FREE;
    }
  }
  for(i=0;i<2*N;i++){
    dpos[i] = dneg[i] = FREE;/*dposはナナメ上、dnegナナメ下二つ分を表しているので２N*/
  }
  
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    flag[r][c] = NOT_FREE; /*入力されたQを埋める*/
  }
  
  putQ(0);
 
  return 0;
}



Measured memory_bytes: 2052
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), m = scan.nextInt();
		long count = 0;
		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(Comparator.reverseOrder());
		for (int i = 0; i < n; i++) {
			pq.add(scan.nextInt());
		}

		for (int i = 0; i < m; i++) {
			pq.add(pq.poll() / 2);
		}
		for (int i = 0; i < n; i++) {
			count += pq.poll();
		}

		System.out.println(count);
	}
}


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

int main() {
  int n;
  uint64_t a=0;
  cin>>n;
  for(int i=1;i<n+1;i++)
    if(i%3 != 0 && i%5 != 0)
      a+=i;
  cout<<a<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; ++i)
#define frab(i, a, b) for (int i = a; i < b; ++i)
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef double ld;

const int N = 1e5 + 10;
const int INF = 1e9 + 10;

int a[N];

int main() {
    //freopen("a.in", "r", stdin);
    int n, m;
    cin >> n >> m;
    fr(i, m) {
        int v, u;
        cin >> v >> u;
        a[--v]++;
        a[--u]++;
    }
    fr(i, n)
        if (a[i] % 2) {
            cout << "NO";
            return 0;
        }
    cout << "YES";
}


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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int l = stdIn.nextInt();
		
		int cnt = 0;
		int min = Integer.MAX_VALUE;
		int index = 0;
		int [] apples = new int[n];
		
		
		for(int i = 0; i < n; i++) {
			cnt += l+i;
			int abs = Math.abs(l+i);
			apples[i] = l+i;
			
			if(min > abs) {
				min = abs;
				index = i;
			}
			
		}
		
		System.out.println(cnt-apples[index]);
		
		
		
		
	}

}


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

using namespace std;

int main() {
    pair <int, int> A, B;
    cin >> A.first >> A.second;
    cin >> B.first >> B.second;
    if (A.first > B.first)
        swap(A, B);
    int ans = min(A.second, B.second) - B.first;
    if (ans < 0)
        ans = 0;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, m, k = map(int, input().split())


#
# Union-Find(素集合データ構造)
# uf = UnionFind(n)
# https://note.nkmk.me/python-union-find/
#
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(n)
ans = [-1]*n
for i in range(m):
    a, b = list(map(int, input().split()))
    ans[a-1] -= 1
    ans[b-1] -= 1
    uf.union(a-1, b-1)

for i in range(k):
    c, d = list(map(int, input().split()))
    if uf.same(c-1,d-1):
        ans[c-1] -= 1
        ans[d-1] -= 1

for i in range(n):
    ans[i] += uf.size(i)
print(*ans)


Measured memory_bytes: 13420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder170
{
    class ProgramC
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var inputList = input.Split(" ");
            int.TryParse(inputList[0], out var X);
            int.TryParse(inputList[1], out var N);

            if (N == 0)
            {
                Console.WriteLine(X);
                return;
            }

            var input2 = Console.ReadLine();
            var inputList2 = input2.Split(" ").Select(int.Parse);

            if (!inputList2.Any(d => d == X))
            {
                Console.WriteLine(X);
                return;
            }

            var abs = 1;
            while (true)
            {
                if (!inputList2.Any(d => d ==  X - abs))
                {
                    Console.WriteLine(X - abs);
                    return;
                }
                if (!inputList2.Any(d => d == X + abs))
                {
                    Console.WriteLine(X + abs);
                    return;
                }

                abs++;
            }
        }
    }
}


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

const int ALPHABET = 26;

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

  int n = (int)s.size();
  vector<vector<int>> freq(ALPHABET);
  for (int i = 0; i < (int)s.size(); i++) {
    freq[(s[i] - 'a')].push_back(i + 1);
  }

  ll ans = 0;
  int last = 0;
  int current = 0;
  for (int i = 0; i < (int)t.size(); i++) {
    int c = t[i] - 'a';
    if(freq[c].empty()) {
      cout << -1 << '\n';
      return 0;
    }
    auto itr = upper_bound(freq[c].begin(), freq[c].end(), current);
    if(itr == freq[c].end()) {
      ans += n;
      last = freq[c].front();
    } else {
      last = *itr;
    }
    current = last;
  }
  ans += last;
  cout << ans << '\n';
}


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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    for(int i = 0; i < n - 1; i++){
        if(s[i] == 'B' && s[i + 1] == 'C'){
            s[i] = 'd';
            s[i + 1] = 'e';
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        vector<ll> v;
        ll bc = 0;
        while(s[i] != 'B' && s[i] != 'C' && i < n){
            if(s[i] == 'A') v.push_back(bc);
            if(s[i] == 'd') bc++;
            i++;
        }
        int l = v.size();
        for(int j = 0; j < l; j++){
            ans += bc - v[j];
        }
    }
    cout << ans << endl;
}

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

int main() {
  int X, A;
  cin >> X >> A;
  if (X < A) cout << 0 << endl;
  else cout << 10 << endl;

  return 0;
}


Measured memory_bytes: 256
n,C = map(int,input().split())
d = [list(map(int,input().split())) for _ in range(C)]
c = [list(map(int,input().split())) for _ in range(n)]

num = []
for i in range(C):
    for j in range(C):
        if i == j:
            continue
        else:
            for k in range(C):
                if i == k or j == k:
                    continue
                else:
                    num.append((i,j,k))
                    
col = [[0]*C for _ in range(3)]

for i in range(n):
    for j in range(n):
        x = c[i][j]-1
        y = (i+j) % 3
        
        col[y][x] += 1
    
ans = 1145141919810
for ll in num:
    a = 0
    for i in range(3):
        for j in range(C):
            a += col[i][j] * d[j][ll[i]]
            
    ans = min(ans,a)
    
print(ans)

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

int main(){
    int n;
    long r;
    while(cin>>n){
        r=0;
        for(int a=0;a<=1000;a++){
            for(int b=0;b<=1000;b++){
                int s=n-a-b;
                if(s<=1000&&s>=0){
                    r+=s+1;
                }else if(s<=2000&&s>1000){
                    r+=2001-s;
                }
            }
        }
        cout<<r<<endl;
    }
    return(0);
}

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

int main(){
//    freopen("C:\\Users\\ehab\\Desktop\\problems\\in.txt" , "r" , stdin);

    int x; cin >> x;

    long long res = 0;
    int _500 = x / 500;
    x %= 500;

    int _5 = x / 5;
    res = 1000*_500 + 5*_5;
    cout << res;
    return 0;
}

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

signed main(){
	int N, M, K, i, j, k, count, ans = 0;
	scanf("%lld%lld", &N, &K);
	int *a = (int *)malloc(sizeof(int) * (N + 1));
	int *s = (int *)malloc(sizeof(int) * (N + 1));
	s[0] = 0;
	for(i = 1; i <= N; i++){
		scanf("%lld", &a[i]);
		s[i] = s[i - 1] + a[i];
	}
	M = (N * (N + 1)) / 2;
//	printf("M = %lld\n", M);
	int *b = (int *)malloc(sizeof(int) * M);
	int *arive = (int *)malloc(sizeof(int) * M);
	for(i = 0, k = 0; i < N; i++){
		for(j = i; j < N; j++){
//			printf("k = %lld\n", k);
//			printf("(i, j) = (%d, %d)\n", i, j);
			b[k] = s[j + 1] - s[i];
//			printf("b[%lld] = %lld\n", k, b[k]);
			arive[k] = 1;
			k++;
		}
	}
	for(k = 50; k >= 0; k--){
//		printf("k = %d\n", k);
		for(i = 0, count = 0; i < M; i++){
			if((b[i] | ((int)1 << k)) == b[i] && arive[i] == 1){
				count++;
			}
		}
//		printf("count = %d\n", count);
		if(count >= K){
			ans += ((int)1 << k);
		}
		for(i = 0; i < M; i++){
			if((b[i] | ans) != b[i]){
				arive[i] = 0;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 8064
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

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

int h, w;
ll ans = 0;



ll solve(int i, int j, vector<string> &s){
	ll res = -1;
	vector<vint> dist(h);
	rep(i, h) dist[i].resize(w, INF);
	dist[i][j] = 0;
	queue <tuple<int, int, int>> que;
	que.push(make_tuple(i, j, 0));
	while(!que.empty()){
		tuple<int, int, int> t = que.front(); que.pop();
		int y = get<0>(t);
		int x = get<1>(t);
		int cost = get<2>(t);
		if(cost > dist[y][x]) continue;
		rep(i, 4){
			int ny = y+dy[i];
			int nx = x+dx[i];
			if(ny < 0 || h <= ny || nx < 0 || w <=nx) continue;
			if(s[ny][nx] == '#') continue;
			if(dist[ny][nx] != INF) continue;
			dist[ny][nx] = cost+1;
			que.push(make_tuple(ny, nx, cost+1));
			res = max(res, (ll)cost+1);
		}
	}
	return res;
}

int main(void){
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h){
		cin >> s[i];
	}

	rep(i, h){		
		rep(j, w){
			if(s[i][j] == '#') continue;
			ans = max(ans, solve(i, j, s));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N=gets.to_i
A=gets.chomp
B=gets.chomp
C=gets.chomp
c=0
for i in 0...N do
    if A[i]!=B[i] && B[i]!=C[i] && C[i]!=A[i] then
        c+=2
    elsif A[i]!=B[i] then
        c+=1
    elsif B[i]!=C[i] then
        c+=1
    elsif C[i]!=A[i] then
        c+=1
    end
end
p c

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
map<int,int>mp;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>d(n);
    rep(i,n){
        cin >> d[i];
        mp[d[i]]++;
    }
    int m;
    cin >> m;
    vector<int>t(m);
    rep(i,m){
        cin >> t[i];
        if(mp[t[i]]){
            mp[t[i]]--;
        }else{
            cout <<"NO" << endl;
            return 0;
        }
    }
    cout <<"YES" << endl;
    return 0;
}

Measured memory_bytes: 11264
#include <iostream>

using namespace std;

typedef long long int ll;
#define REP(i, I, N) for (int i = I; i < N; ++i)
#define rep(i, N) REP(i, 0, N)

int main() {
    int A, B;
    cin >> A >> B;
    if (6 <= A && A <= 12) {
        B /= 2;
    } else if (A <= 5) {
        B = 0;
    }

    cout << B << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]==5&&a[1]==5&&a[2]==7) puts("YES");
	else puts("NO");
	return 0;
}


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

int main()
{
    int n;
    scanf("%d",&n);
    if((n%10==2)||(n%10==4)||(n%10==5)||(n%10==7)||(n%10==9)) printf("hon\n");
    else if((n%10==0)||(n%10==1)||(n%10==6)||(n%10==8)) printf("pon\n");
    else if(n%10==3) printf("bon\n");
    return 0;
}


Measured memory_bytes: 1620
#include<stdio.h>
#include<stdlib.h>
int top = 0;

void push(int stack[], int n, int k) {
	if (top == n)
		return; 
	stack[top++] = k;
}
int pop(int stack[]) {
	if (top == 0)
		return -1;
	return stack[--top];
}
int main(void) {
	int n, m;
	scanf("%d %d", &n, &m);
	int i, j;
	int** a = malloc(sizeof(int*) * n);
	for (i = 0; i < n; i++) {
		a[i] = malloc(sizeof(int) * n);
	}
	int start, end;
	for (i = 0; i < m; i++) {
		scanf("%d %d", &start, &end);
		a[start - 1][end - 1] = 1;
		a[end - 1][start - 1] = 1;
	}
	int k, count = 0;
	int p;
	int count_visit = 0;
	int *stack = malloc(sizeof(int)*n);
	int* check = malloc(sizeof(int) * n);
	for (i = 1; i < n; i++) {
		for (j = 0; j < i; j++) {
			if (a[i][j] == 1) {
				for (k = 0; k < n; k++)
					check[k] = 0;
				p = 0;
				check[0] = 1;
				count_visit = 1;
				a[i][j] = 0;
				a[j][i] = 0;
				top = 0;
				
				while (1) {
					if (count_visit == n) {
						break;
					}
					for (k = 0; k < n; k++) {
						if (a[p][k] == 1 && check[k] == 0) {
							push(stack, n, k);
							check[k] = 1;
						}
					}

					p = pop(stack);
					if (p == -1) {
						count++;
						break;
					}
					count_visit++;
					
				}
				a[i][j] = 1;
				a[j][i] = 1;
			}
		}
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#define INF 2e9
#define rep(i,m) for(int i=0;i<m;i++)
#define repn(i,n,m) for(int i=n;i<m;i++)


using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;

	return 0;
}
	

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int h = sc.nextInt();
			int w = sc.nextInt() + 2;
			sc.nextLine();

			String[] gazo = new String[h];
			//gazo[0] = String.format("%", args)
			for (int i = 0; i < h; i++) {
				gazo[i] = new StringBuilder().append("#").append(sc.nextLine()).append("#").toString();
			}

			IntStream.range(0, w).forEach(i -> System.out.print("#"));
			System.out.println();
			Arrays.stream(gazo).forEach(s -> System.out.println(s));
			IntStream.range(0, w).forEach(i -> System.out.print("#"));
			System.out.println();

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 28244
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

//Berlekamp-Massey algorithm(mod p)
//n個の項を引いてn次以下の漸化式を返す(n/2次以上なら項数不足)
//例えばフィボナッチ数列を引くと{1,-1,-1}がかえる
ll*BM(ll*s,int n,int p){
	ll *c=(ll*)calloc(n*2,sizeof(ll));
	ll *cl=(ll*)calloc(n*2,sizeof(ll));
	ll *t=(ll*)calloc(n*2,sizeof(ll));
	ll L=0,l=-1,d,dl=1;
	c[0]=cl[0]=1;

	rep(i,0,n){
		d=0;
		rep(j,0,L+1)d=(d+c[j]*s[i-j])%p;
		if(d!=0){
			rep(j,0,n)t[j]=c[j];
			rep(j,0,n)c[j+i-l]=((c[j+i-l]-d*invp(dl,p)%p*cl[j])%p+p)%p;
			if(2*L<=i){
				l=i;
				rep(j,0,n)cl[j]=t[j];
				dl=d;
				L=i+1-L;
			}
		}
	}
	free(cl);
	free(t);
	return c;
}

//きたまさ法（線形漸化式の第n項(0-based)をmodmで高速に求める）
int kitamasa(ll*coe,ll*A,int size,ll n,int m){
	/*
	例：フィボナッチ数列
	size=2;//特性方程式の次数
	coe[]={1,1};//特性方程式の最高次の係数を-1にして、消したもの
	A[]={0,1};//初期値
	*/

	ll*temp=(ll*)calloc(2*size,sizeof(ll));
	ll*s=(ll*)calloc(size,sizeof(ll));
	ll*ans=(ll*)calloc(size,sizeof(ll));

	s[1]=1;
	ans[0]=1;

	while(n){
		if(n%2){
			rep(i,0,2*size)temp[i]=0;
			rep(i,0,size)rep(j,0,size)temp[i+j]=(temp[i+j]+ans[i]*s[j])%m;
			for(ll i=2*size-2;i>=size;i--)rep(j,0,size)temp[i-size+j]=(temp[i-size+j]+temp[i]*coe[j])%m;
			rep(i,0,size)ans[i]=temp[i];
		}
		rep(i,0,2*size)temp[i]=0;
		rep(i,0,size)rep(j,0,size)temp[i+j]=(temp[i+j]+s[i]*s[j])%m;
		for(ll i=2*size-2;i>=size;i--)rep(j,0,size)temp[i-size+j]=(temp[i-size+j]+temp[i]*coe[j])%m;
		rep(i,0,size)s[i]=temp[i];
		n/=2;
	}
	ll ss=0;
	rep(i,0,size)ss=(ss+ans[i]*A[i])%m;
	free(temp);
	free(s);
	free(ans);
	return ss;
}


ll fact[100010];
ll invfact[100010];
void makefact(int n,ll m){
	fact[0]=1;
	rep(i,0,n)fact[i+1]=fact[i]*(i+1)%m;
	invfact[n]=invp(fact[n],m);
	for(int i=n;i>0;i--)invfact[i-1]=invfact[i]*i%m;
}
ll choose(int n,int r,int m){return n<0||r<0||n-r<0?0:fact[n]*invfact[r]%m*invfact[n-r]%m;}

ll f(int n){
	ll ans=0;
	rep(i,5,n+1){
		ans+=choose(i+4,9,MOD)*choose((n-i)/2+5,5,MOD);
		ans%=MOD;
	}
	return ans;
}

#define N 100
ll a[N+10];
ll coe[N+10];
int main(){
	makefact(N+10,MOD);
	rep(i,0,N)a[i]=f(i);
	ll*p=BM(a,N,MOD);
	int deg=0;
	rep(i,0,N)if(p[i])deg=i;
	rep(i,0,deg)coe[i]=(MOD-p[deg-i])%MOD;

	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		printf("%d\n",kitamasa(coe,a,deg,n,MOD));
	}
}



Measured memory_bytes: 1744
using System;

namespace Range
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int[] data = getInputdata (" ");
			string ans;
			if (data [0] < data [1] && data [1] < data [2])
				ans =  "Yes";
			else
				ans = "No";

			Console.WriteLine (ans);
		}

		public static int[] getInputdata (string token)
		{
			string[] data = Console.ReadLine ().Split (token.ToCharArray ());
			int[] idata = new int[data.Length];

			for (int i = 0; i < data.Length; i++) {
				idata [i] = int.Parse (data [i]);
			}
			return idata;
		}

	}
}

Measured memory_bytes: 5252
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
  int N, A[20], B[50], C[50], ans, prev;
  prev = -1;
  ans = 0;
  cin >> N;
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<N;i++)cin>>B[i];
  for(int i=0;i<N-1;i++)cin>>C[i];
  for(int i=0;i<N;i++){

    if (prev+1 == A[i])
    	ans += C[prev-1];
    prev = A[i];
	ans+=B[A[i]-1];

  }
  cout << ans << "\n";

  return 0;
}
    
  

Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]
p = [(0,1,2), (0,1,3), (0,1,4), (0,2,3), (0,2,4), (0,3,4), (1,2,3), (1,2,4), (1,3,4), (2,3,4)]
march = [0] * 5
for i in s:
    if i[0] == "M": march[0] += 1
    if i[0] == "A": march[1] += 1
    if i[0] == "R": march[2] += 1
    if i[0] == "C": march[3] += 1
    if i[0] == "H": march[4] += 1
ans = 0
for a, b, c in p:
    ans += march[a] * march[b] * march[c]
print(ans)

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 062 A / Link: http://abc062.contest.atcoder.jp/tasks/abc062_a  ----- */


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

	LL x, y; cin >> x >> y;
	VI a({ -1,0,2,0,1,0,1,0,0,1,0,1 });
	LL ans = a[x]==a[y];
	
	
	cout << (ans?"Yes":"No") << "\n";

	return 0;
}


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

int main() {
	//cout<<"GfG!";
	long long int n, a[1000000], i, j, k, f = 1 ;
	unsigned long long int tot = 1, M = 1000000007;
	cin>>n;
	for (i = 0; i < n; i++)
	{
	    cin>>a[i]; 
	}
	sort(a, a + n);
	i = 0;  j = 0; 
	while (i < n)
	{
	    if (n == 1)
	    {   break;  }
	    else if (a[i] == 0 && a[i+1] != 0)
	    {
	        i++;   
	    }
	    else if (a[i] == 0 && a[i+1] == 0)
	    {       f = 0;  break;  }
	    else
	    {
	        if (i == n - 1)
	        {       f = 0;  break;  }
	        else if(a[i+1] == a[i] && (a[j+2] - a[j] == 2))
	        {
	            tot = (tot * 2) % M;
	            i += 2;   j += 2;   
	            if (j == n - 2)
	                j = 0;
	                
	        }
	        else
	        {
	            f = 0;  break;
	        }
	    }
	     
	}
	if (f)
	    cout<<tot;
	else
	    cout<<"0";
	return 0;
}


Measured memory_bytes: 2816
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

N, M = l_inpl()
a = { i_inpl(): True for _ in range(M)}
# for _ in range(M):
#     ai = i_inpl()
#     a.append(ai)

dp = [None] * (N+1)

dp[N] = 1
# print(dp)
for i in range(N-1, -1, -1):
    if i in a:
        dp[i] = 0
    else:
        if N-1 == i:
            dp[i] = 1
        else:
            if i+1 in a and i+2 in a:
                dp[i] = 0
            elif i+1 in a:
                dp[i] = dp[i+2]
            elif i+2 in a:
                dp[i] = dp[i+1]
            else:
                dp[i] = dp[i+1] + dp[i+2]

print(dp[0] % 1000000007)

Measured memory_bytes: 469160
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define vs vector<string>
#define vc vector<char>
#define vvc vector< vector<char> >

#define all(a) (a).begin(),(a).end()
using namespace std;

bool check(string s){
	for (ll i = 0; i < s.size(); ++i) if (s[i] != s[s.size() - 1 - i]) return 0;
	return 1;
}

int main(){
	ll a, b; cin >> a >> b;
	ll ans = 0;
	for (ll i = a; i <= b; ++i) if (check(to_string(i))) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define classname SubtreeSumHash

const int maxn = 50 + 5;
ll dp[maxn][maxn][maxn * maxn];
ll a[maxn];

void solve()
{
    ll A;
    int n;
    cin >> n >> A;
    
    ll mx = n * A;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i + 1];
        mx = max(mx, a[i + 1] * n);
    }
    
    dp[0][0][0] = 1;
    for(int i = 1; i <= n; i++)
    {
        dp[i][0][0] = 1;
        for(int k = 1; k <= i; k++)
        {
            for(int j = 0; j <= mx; j++)
            {
                dp[i][k][j] = dp[i - 1][k][j];
                if(j - a[i] >= 0)
                {
                    dp[i][k][j] += dp[i - 1][k - 1][j - a[i]];
                }
                //cout << i << " " << k << " " << j << " " << dp[i][k][j] << "\n";
            }
        }
    }
    
    ll res = 0;
    for(ll i = 1; i <= n; i++)
    {
        res += dp[n][i][i * A];
    }
    cout << res << "\n";
}


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    solve();
    return 0;
}


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

int main(){
  int x; cin >> x;
  if((x == 3) or (x == 5) or (x == 7)){
    printf("%s", "YES");
    return 0;
  }else{
    printf("%s", "NO");
    return 0;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans=0,maxnum=0;
    rep(i,n){
        if(s[i]=='I'){
            ans += 1;
        }else{
            ans -= 1;
        }
        maxnum = max(maxnum,ans);
    }
    cout << maxnum << endl;

    return 0;
}

Measured memory_bytes: 256
#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 104

ll d[MAX_V][MAX_V]; //d[u][v]は辺e=(u,v)のコスト(存在しない場合はINF,d[i][i]=0)
ll V; //頂点数
ll nex[MAX_V][MAX_V]; //iからjへの最短経路におけるiの1つ後の点

ll path[MAX_V][MAX_V];

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

void print_path(int start, int goal){
    for(int cur = start; cur != goal; cur = nex[cur][goal]){
        path[cur][nex[cur][goal]] = 1;
        path[nex[cur][goal]][cur] = 1;
    }
}

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

    V = n;

    rep(i, 0, V){
        rep(j, 0, V){
            path[i][j] = -1;
            if(i == j){
                d[i][j] = 0;
            }else{
                d[i][j] = 100000000;
            }
        }
    }

    rep(i, 0, m){
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        d[a][b] = c;
        d[b][a] = c;
        path[a][b] = 0;
    }

    warshall_floyd();
    rep(i, 0, V){
        rep(j, 0, V){
            print_path(i, j);
        }
    }

    ll sum = 0;
    rep(i, 0, V){
        rep(j, 0, V){
            if(path[i][j] == 0){
                sum++;
            }
        }
    }
    cout << sum << endl;
    return 0;

}


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

int main(){
  int a,b,c,x;
  cin>>a>>b>>c;
  if((a==b)&&(b==c)){
    cout<<1<<endl;
    return 0;
  }
  if((a==b)||(b==c)||(a==c)){
    cout<<2<<endl;
    return 0;
  }
  cout<<3<<endl;
  return 0;

}


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

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll x; cin >> x;
    ll amt = 100L;
    int y = 0;
    while(amt < x){
        ++y;
        amt += (amt/100L);
    }
    cout << y << '\n';
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> L(87);
  L.at(0) = 2;
  L.at(1) = 1;
  if(N < 2){
    cout << L.at(N);
  }
  else{
    for(int i = 2; i < N + 1; i++){
      L.at(i) = L.at(i-1) + L.at(i-2);
    }
    cout << L.at(N);
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <random>
int D;
int c[26];
int l[367][26];
int s[366][26];
int t[366];
long long m = 3000000;
int  p, q, d, k, pp, dd, f;
int ans, bans;
unsigned long long a;
int main() {
	scanf("%d", &D);
	for (int i = 0; i < 26; i++) {
		scanf("%d", c + i);
	}
	for (int i = 1; i <= D; i++) {
		for (int j = 0; j < 26; j++) {
			scanf("%d", s[i] + j);
		}
	}
	std::mt19937_64 rd(468);
	for (int i = 1; i <= D; i++) {
		a = rd();
		t[i] = a % 26;
	}
	for (int i = 1; i <= D; i++) {
		ans += s[i][t[i]];
		for (int j = 0; j < 26; j++) {
			l[i][j] = l[i - 1][j] + 1;
		}
		l[i][t[i]] = 0;
		for (int j = 0; j < 26; j++) {
			ans -= c[j] * l[i][j];
		}
	}
	for (long long i = 0; i < m; i++) {
		a = rd();
		if (f) {
			d = dd;
			q = pp;
		}
		else {
			d = a % D + 1;
			q = a % 26;
			p = t[d];
		}
		if (p != q) {
			bans = ans;
			t[d] = q;
			ans -= s[d][p];
			ans += s[d][q];
			k = d;
			while (l[k][q] && k <= D) {
				ans -= c[q] * (k - d - l[k][q]);
				l[k][q] = k - d;
				k++;
			}
			k = d;
			do {
				ans -= c[p] * (l[k - 1][p] + 1 - l[k][p]);
				l[k][p] = l[k - 1][p] + 1;
				k++;
			} while (l[k][p] && k <= D);
			a = rd();
			f = 0;
			if (ans < bans && (a % (m * m)) < 2 * m * i - i * i) {
				f = 1;
				pp = p;
				dd = d;
			}
		}
	}
	for (int i = 1; i <= D; i++) {
		printf("%d\n", t[i] + 1);
	}
}

Measured memory_bytes: 1812
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int p, q, r, ans = 0;
    cin >> p >> q >> r;
    ans = p + q + r - max({p, q, r});
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>

using namespace std;
typedef long long ll;

int main()
{
	int N, M;
	int A[10000];
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		cin >> A[i];
	}
	
	int needed = 0;
	for(int i = 0; i < M; i++){
		needed += A[i];
	}
	
	if(needed <= N){
		cout << N - needed << endl;
	}else{
		cout << -1 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  cout << v.at(n-1) << ' ';
  if (v.at(n-1)%2 == 0) {
    ll tmp1 = v.at(n-1)/2;
    ll res, dif = INF;
    rep(i, n-1) {
      ll tmp = abs(v.at(i)-tmp1);
      if (dif > tmp) {
        dif = tmp;
        res = v.at(i);
      }
    }
    cout << res << endl;
  } else {
    ll tmp1 = v.at(n-1)/2, tmp2 = v.at(n-1)/2+1;
    ll res, dif = INF;
    rep(i, n-1) {
      ll tmp = abs(v.at(i)-tmp1) + abs(v.at(i)-tmp2);
      if (dif > tmp) {
        dif = tmp;
        res = v.at(i);
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}

int main() {
	ll n, m;
	cin >> n >> m;
	
	ll ans=n*(n-1)/2;
	ans += m*(m-1)/2;

	cout << ans << endl;
}

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

int main(){
set<char> d;
char x;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++)
{
  d.insert(s[i]);
}
char a = 'a';
bool p = true;
string ans;

for (char a='a';a <= 'z'; a++)
{
  if(!(d.count(a))){
    ans = a;
    p = false;
    break;
  }
}
if(p){
  ans = "None";
}


 cout << ans << endl;
}

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

int main() {
  
  int num;
  cin >> num;
  int start, end;
  int sum = 0;
  
  for (int i = 0; i < num; i++) {
    cin >> start >> end;
    sum += (end - start) + 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())
res = 0
while True:
    if A%2 + B%2 + C%2 > 0:
        break
    A, B, C = B//2 + C//2, C//2 + A//2, A//2 + B//2
    if A == B and B == C:
        res = -1
        break
    res += 1
print(res)


Measured memory_bytes: 9128
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  string S;
  cin >> S;
  int count = 0;
  int max_count = 0;
  for (int i=0; i < S.size(); i++) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
       count++;
       if (count > max_count) {
         max_count = count;
       }
    } else {
       count = 0;
    }
  }
  cout << max_count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<map>
using namespace std;
typedef long long ll;
const int N=440,D=4,P=10000007;
int i,j,k,n,m,ch,ff;
ll A[N],ans;
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(ll x) {
	if (x<0) putchar('-'),x=-x;
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
void rev(ll &a) {
	ll t=a&1023;
	(a>>=10)|=t<<30;
}
void change(ll &a) {
	ll t1=(a>>10)&1023,t3=(a>>30)&1023;
	a^=(t1<<10)|(t3<<30);
	a^=(t3<<10)|(t1<<30);
}
void read(ll &a) {
	for (int i=0;i<D;i++) {
		int x;
		R(x);
		(a<<=10)|=x;
	}
}
struct ha {
	int En,h[P];
	struct edge { int n,val;ll s;} E[P];
	int get(ll x) {
		int t=x%P;
		for (int k=h[t];k;k=E[k].n) if (E[k].s==x) return E[k].val;
		return 0;
	}
	void add(ll x,int y) {
		int t=x%P;
		for (int k=h[t];k;k=E[k].n) if (E[k].s==x) {
			E[k].val+=y;
			return;
		}
		E[++En].s=x;E[En].val=y;
		E[En].n=h[t];h[t]=En;
		return;
	}
} ha;
ll work(ll a,ll b) {
	int i,j,k;
	ll t,ans=1;
	for (i=0;i<D;i++) {
		t=0;
		(t<<=10)|=(b>>((i+1)%D*10))&1023;
		(t<<=10)|=(b>>(i*10))&1023;
		(t<<=10)|=(a>>(i*10))&1023;
		(t<<=10)|=(a>>((i+1)%D*10))&1023;
		ans*=ha.get(t);
		for (k=0;k<D;k++) {
			rev(t);
			ha.add(t,-1);
		}
	}
	for (i=0;i<D;i++) {
		t=0;
		(t<<=10)|=(b>>((i+1)%D*10))&1023;
		(t<<=10)|=(b>>(i*10))&1023;
		(t<<=10)|=(a>>(i*10))&1023;
		(t<<=10)|=(a>>((i+1)%D*10))&1023;
		for (k=0;k<D;k++) {
			rev(t);
			ha.add(t,1);
		}
	}
	return ans;
}
int main() {
	R(n);ans=0;
	for (i=1;i<=n;i++) {
		read(A[i]);
		for (k=0;k<D;k++) {
			rev(A[i]);
			ha.add(A[i],1);
		}
	}
	for (i=1;i<=n;i++) {
		for (k=0;k<D;k++) {
			rev(A[i]);
			ha.add(A[i],-1);
		}
		for (j=i+1;j<=n;j++) {
			for (k=0;k<D;k++) {
				rev(A[j]);
				ha.add(A[j],-1);
			}
			change(A[j]);
			for (k=0;k<D;k++) {
				rev(A[i]);
				ans+=work(A[i],A[j]);
			}
			change(A[j]);
			for (k=0;k<D;k++) {
				rev(A[j]);
				ha.add(A[j],1);
			}
		}
		for (k=0;k<D;k++) {
			rev(A[i]);
			ha.add(A[i],1);
		}
	}
	W(ans/3);puts("");
}

Measured memory_bytes: 120960
#include <stdio.h>

int main(){
  int i,n,q,count = 0;
  int right,left,mid;
  int S[100000],T[50000];

  scanf("%d",&n);

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

  scanf("%d",&q);

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

  for(i = 0; i < q; i++){
    left = 0;
    right = n;
    while(left < right){
      mid = (left + right) / 2;
      if(S[mid] == T[i]){
	count++;
	break;
      }
      else if(T[i] < S[mid]) right = mid;
      else left = mid + 1;
    }
  }

    printf("%d\n",count);
    
  return 0;
}



Measured memory_bytes: 2308
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
	using namespace std;
	int main() {
		long long int n, a[100000], count[100001] = {}, yan, max = 0;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			count[a[i]]++;
		}
		if (n == 1) {
			cout << 1 << endl;
			return 0;
		}

		for (int i = 1; i < n ; i++) {
			yan = count[i - 1] + count[i] + count[i + 1];
			if (max < yan) {
				max = yan;
			}
		}
		cout << max << endl;
	}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    double x, a, b;
    cin >> x >> a >> b;
    if (abs(a - x) < abs(b - x))
    {
        cout << "A";
    }
    else
    {
        cout << "B";
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func main() {
	S := oneStr()
	f := S[0:2]
	b := S[2:4]
	if isMM(f) {
		if isMM(b) {
			fmt.Print("AMBIGUOUS")
			return
		} else {
			fmt.Print("MMYY")
			return
		}
	} else {
		if isMM(b) {
			fmt.Print("YYMM")
			return
		}
	}
	fmt.Print("NA")
}

func isMM(s string) bool {
	months := []string{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}
	for _, month := range months {
		if month == s {
			return true
		}
	}
	return false
}

Measured memory_bytes: 640