akhauriyash/Code-Regression huggingface dataset:
use std::io::Read;
use std::collections::VecDeque;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let h: usize = iterator.next().unwrap().parse().unwrap();
    let w: usize = iterator.next().unwrap().parse().unwrap();
    let mut map: Vec<Vec<char>> = Vec::new();
    for _ in 0..h {
        let line: Vec<char> = iterator.next().unwrap().chars().collect();
        map.push(line);
    }

    const INF: usize = 1_000_000_000;
    let mut d: Vec<Vec<usize>> = vec![vec![INF; w]; h];

    let mut q: VecDeque<(usize, usize)> = VecDeque::new();
    for i in 0..h {
        for j in 0..w {
            if map[i][j] == '#' {
                d[i][j] = 0;
                q.push_back((i, j));
            }
        }
    }

    let dh = vec![-1, 0, 1, 0];
    let dw = vec![0, -1, 0, 1];
    while let Some((i, j)) = q.pop_front() {
        for k in 0..4 {
            let ni: isize = i as isize + dh[k];
            let nj: isize = j as isize + dw[k];
            if ni < 0 || ni >= h as isize || nj < 0 || nj >= w as isize {
                continue;
            }
            let ni = ni as usize;
            let nj = nj as usize;
            if d[ni][nj] != INF {
                continue;
            }
            d[ni][nj] = d[i][j] + 1;
            q.push_back((ni, nj));
        }
    }

    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            ans = max(ans, d[i][j]);
        }
    }
    ans.to_string()
}


Measured memory_bytes: 30412
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    vector<ll> b(n);
    vector<ll> c(n);

    rep(i,n) {
        b[i] = (i+1)+a[i];
        c[i] = (i+1)-a[i];
    }

    map<ll, ll> mp;
    ll ans = 0;
    rep(i,n) {
        ans += mp[c[i]];
        mp[b[i]]++;
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

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

    int ringo[N];
    int sum = 0;
    for(int i = 1; i <= N; i++){
        ringo[i] = L + i - 1;
        sum += ringo[i];
    }

    int absp;
    int minp = 100000;
    int ans = 0;
    for(int i = 1; i <= N; i++){
        absp = abs(ringo[i]);
        if(minp > absp){
            minp = absp;
            ans = sum - ringo[i];
        }        
    }       
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    int a[55],b[55];
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        }
        
        int ans[55];    
        for(int i  = 0;i<n;i++){
            ans[i]=0;
        }
        
        for(int i = 0;i<n;i++){\
            for ( int j = 0;j<m;j++){
                if(a[j] == i || b[j] == i){
                    ans[i] += 1;
                }
            }
        }

        for(int i = 0; i < n; i++){
            cout << ans [i] << endl;
        } 
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, m, a[50], b[50];
	cin >> n >> m;
	REP(i, m) cin >> a[i] >> b[i];

	REP(i, n){
		int cnt = 0;
		REP(j, m){
			if(i+1 == a[j]) cnt++;
			if(i+1 == b[j]) cnt++;
		}
		cout << cnt << endl;
	}

	rtn 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  ll K, A, B; cin >> K >> A >> B;
  if (B-A<=2) cout << K+1 << endl;
  else {
    if (K<=A) cout << K+1 << endl;
    else if ((K-A)%2) cout << ((K-A)/2)*(B-A) + B << endl;
    else cout << ((K-A)/2-1)*(B-A) + B +1 << endl;
  }
  // cout << fixed << setprecision(10);
  
  return 0;
}



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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        string S = cin.nextString();

        if (S.CompareTo("2019/04/30") <= 0)
        {
            Console.WriteLine("Heisei");
            return;
        }
        Console.WriteLine("TBD");
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }

    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


Measured memory_bytes: 11232
using System;
class ITP1
{
    static void Main(string[] args)
    {
        Q2_B();
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //System.Console.SetIn(exStdIn);

        //int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<String, int>(s => int.Parse(s)));
    }

    static void Q1()
    {
        int input = int.Parse(Console.ReadLine());

        int h = input / 3600;
        int m = input % 3600 / 60;
        int s = input % 3600 % 60;

        Console.WriteLine(String.Format("{0}:{1}:{2}", h, m, s));
    }

    static void Q2_A()
    {
        int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<String, int>(s => int.Parse(s)));

        String sign = a[0] - a[1] > 0 ? ">" : a[0] - a[1] == 0 ? "==" : "<";

        Console.WriteLine(String.Format("a {0} b",sign));
    }

    static void Q2_B()
    {
        int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<String, int>(s => int.Parse(s)));
        String answer = a[2] - a[1] > 0 ? a[1] - a[0] > 0 ? "Yes" : "No" : "No";

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 8804
#include "bits/stdc++.h"
using namespace std;

int main()
{
	int64_t a, b, c, k;
	cin >> a >> b >> c >> k;

	int64_t ans = 0;
	if (k <= a) {
		ans = k;
	} else if (k <= a + b) {
		ans = a;
	} else {
		ans = a - (k - (a + b));
	}

	cout << ans << endl;
}


Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


int main() {
    int N, M;
    cin >> N >> M;
    vector<int> s(M);
    vector<char> c(M);
    rep(i, M){
        cin >> s[i] >> c[i];
        s[i]--;
    }

    vector<char> num(N, '0');
    vector<bool> seen(N, false);
    rep(i, M){
        if(seen[s[i]] && (num[s[i]] != c[i])){
            cout << -1 << endl;
            return 0;
        }else{
            num[s[i]] = c[i];
            seen[s[i]] = true;
        }
    }
    if(N != 1 && num[0] == '0' && seen[0]){
        cout << -1 << endl;
        return 0;
    }else if(num[0] == '0' && N != 1){
        num[0] = '1';
    }
    for(int i = 0; i < N; i++){
        cout << num[i];
    }
    cout << endl;
    return 0;
}


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int p0,p1,q0,q1,v,pos;
long long ans=0;
int a[200000],b[200000],arr[28][200000],t[200000];
int main()
{
	int i,j,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		scanf("%d",&b[i]);	
	for(i=0;i<28;i++)
	{
		p0=p1=q0=q1=0;
		for(j=0;j<n;j++)
		{
			((a[j]>>i)&0x01)?p0++:p1++;
		}
		for(j=0;j<n;j++)
		{
			((b[j]>>i)&0x01)?q0++:q1++;	
		}
		ans^=(((long long)p0*q1%2+(long long)p1*q0%2)%2)<<i;
	}
	//生成第一排arr[28][n]的
	for(i=0;i<28;i++)
	{
		for(j=0;j<n;j++)
		{
			if(i==0)
				arr[i][j]=0x01&a[j];
			else
				arr[i][j]=arr[i-1][j]|((1<<i)&a[j]);
		}
	} 
	for(i=0;i<28;i++)
		sort(arr[i],arr[i]+n);
	for(i=0;i<28;i++)
	{
		for(j=0;j<n;j++)
		{
			t[j]|=(1<<i)&b[j];
			v=(1<<(i+1))-t[j];	
			pos=lower_bound(arr[i],arr[i]+n,v)-arr[i];
			ans^=((n-pos)%2)<<(i+1);
		}
	}	
	printf("%lld",ans);	 
	return 0;
}

Measured memory_bytes: 24448
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    print(int(input()) * 2 * math.pi)


if __name__ == '__main__':
    main()

Measured memory_bytes: 72820
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;
using mat2d_t = std::vector<std::vector<int64_t>>;

int main(int argc, char **argv) {
    string s;
    int k;
    cin >> s >> k;

    int len = s.size();

    mat2d_t dp0 = mat2d_t(len, std::vector<i64>(4, 0)); // smaller
    mat2d_t dp1 = mat2d_t(len, std::vector<i64>(4, 0)); // smaller?

    dp0[0][0] = 1;

    for (int i = 0; i<len; ++i) {
        s[i] -= '0';
        if (i == 0) {
            dp0[0][1] = s[i]-1;
            dp1[0][1] = 1;
            continue;
        }
        dp0[i][0] = 1;
        for (int j=1; j<=k; ++j) {
            dp0[i][j] += dp0[i-1][j-1] * 9;
            dp0[i][j] += dp0[i-1][j];

            if (s[i]) {
                dp0[i][j] += dp1[i-1][j];
                dp0[i][j] += dp1[i-1][j-1] * (s[i]-1);
                dp1[i][j] += dp1[i-1][j-1];
            } else {
                dp1[i][j] = dp1[i-1][j];
            }
        }
    }

    cout << dp0[len-1][k] + dp1[len-1][k] << endl;

    return 0;
}


Measured memory_bytes: 256
# coding:utf-8

import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


# UnionFind
class UnionFind:
    # 負: ルートで値は木の深さを表す
    # 正: 子で値は次のノードを表す
    def __init__(self, size: int) -> None:
        self.nodes = [-1] * size  # 初期状態では全てのノードがルート

    def get_root(self, x: int) -> int:
        if self.nodes[x] < 0:
            return x
        else:
            self.nodes[x] = self.get_root(self.nodes[x])
            return self.nodes[x]

    def unite(self, x: int, y: int) -> None:
        root_x, root_y = self.get_root(x), self.get_root(y)
        if root_x != root_y:
            if self.nodes[root_x] != self.nodes[root_y]:  # グラフの高さが異なる場合
                # 木のランクが高い方のルートに併合させる
                # 併合後にランクの変動はない
                if self.nodes[root_x] < self.nodes[root_y]:
                    self.nodes[root_y] = root_x
                else:
                    self.nodes[root_x] = root_y
            else:
                # ランクが等しい木同士を併合させるので
                # 併合後は木のランクが1つ上がる
                self.nodes[root_x] += -1
                self.nodes[root_y] = root_x


H, W = LI()
B = [[1 if s == '#' else 0 for s in S()] for _ in range(H)]

uf = UnionFind(H * W)

for h in range(H):
    for w in range(W):
        if w < W - 1 and B[h][w] != B[h][w + 1]:
            uf.unite(h * W + w, h * W + w + 1)
        if h < H - 1 and B[h][w] != B[h + 1][w]:
            uf.unite(h * W + w, (h + 1) * W + w)

black = defaultdict(int)
white = defaultdict(int)
for h in range(H):
    for w in range(W):
        i = h * W + w
        if B[h][w] == 1:
            black[uf.get_root(i)] += 1
        else:
            white[uf.get_root(i)] += 1

ans = 0
for n in black.keys():
    ans += black[n] * white[n]

print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; ++i)
    cin >> W[i];
  int ans = 100000000;
  for (int T = 0; T < N; ++T) {
    int S1 = 0, S2 = 0;
    for (int i = 0; i < T; ++i)
      S1 += W[i];
    for (int i = T; i < N; ++i)
      S2 += W[i];
    ans = min(abs(S1 - S2), ans);
  }
  cout << ans << endl;
}

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

#define rep(n)      for (int i = 0; i < n; ++i)
#define rep2(n)     for (int j = 0; j < n; ++j)
#define mp          make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;

int main() {    
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    bool yes = 0;
    
    rep(3) {
        if (n%10==7) yes = 1;
        n/=10;
    }
    
    cout << (yes?"Yes":"No") << "\n";
    
    return 0;
}


Measured memory_bytes: 3580
// https://atcoder.jp/contests/abc082/tasks/abc082_a

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  double a, b;

  cin >> a >> b;

  cout << ceil((a + b) / 2) << '\n';

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, M, K, ABs, CDs):
    friend_map = [[] for _ in range(N + 1)]
    for a, b in ABs:
        friend_map[a].append(b)
        friend_map[b].append(a)

    block_map = [[] for _ in range(N + 1)]
    for c, d in CDs:
        block_map[c].append(d)
        block_map[d].append(c)

    def dfs(group_num, members, now_n):
        belongs[now_n] = group_num
        members.append(now_n)
        for f in friend_map[now_n]:
            if belongs[f] == -1:
                members = dfs(group_num, members, f)
        return members

    friend_groups = []
    belongs = [-1] * (N + 1)
    for i in range(1, N + 1):
        if belongs[i] == -1:
            m = dfs(len(friend_groups), [], i)
            m.sort()
            friend_groups.append(m)

    ans = ''
    for n in range(1, N + 1):
        block = 0
        group = friend_groups[belongs[n]]
        for b in block_map[n]:
            if belongs[n] == belongs[b]:
                block += 1
        ans += ' ' + str(len(group) - len(friend_map[n]) - block - 1)
    print(ans[1:])


if __name__ == '__main__':
    # # handmade test
    # N, M, K = 2 * 10 ** 5, 10 ** 5, 10 ** 5
    # ABs = [[1, i] for i in range(2, 10 ** 5 + 2)]
    # CDs = [[i, i + 1] for i in range(2, 10 ** 5 + 2)]
    
    # # handmade random
    # import random
    # N, M, K = 20, 10, 10
    # ABs = []
    # while True:
    #     if len(ABs) == M:
    #         break
    #     a = random.randint(1, N - 1)
    #     b = random.randint(a + 1, N)
    #     if not [a, b] in ABs:
    #         ABs.append([a, b])
    # CDs = []
    # while True:
    #     if len(CDs) == K:
    #         break
    #     c = random.randint(1, N - 1)
    #     d = random.randint(c + 1, N)
    #     if not [c, d] in ABs and not [c, d] in CDs:
    #         CDs.append([c, d])
    # print(N, M, K)
    # print(ABs)
    # print(CDs)

    N, M, K = map(int, input().split())
    ABs = [[int(i) for i in input().split()] for _ in range(M)]
    CDs = [[int(i) for i in input().split()] for _ in range(K)]
    solve(N, M, K, ABs, CDs)


Measured memory_bytes: 91724
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if ((a+b) % 3 == 0)
	{
		cout << "Possible" << endl;
	}
	else if (a % 3 == 0)
	{
		cout << "Possible" << endl;
	}
	else if (b % 3 == 0)
	{
		cout << "Possible" << endl;
	}
	else
	{
		cout << "Impossible" << endl;
	}
}

Measured memory_bytes: 256
N, K = map( int, input().split() )
S = input()


# 1と0の切り替わり点を全探索
change_point = [0]
for i in range(N-1):
    if S[i+1] != S[i]:
        change_point.append(i+1)


ans_candidates = []
l = len(change_point)
for i in range(l):
    if i+2*K < l and S[change_point[i]] == '0':
        ans_candidates.append(change_point[i+2*K]-change_point[i])
    elif i+2*K+1 < l and S[change_point[i]] == '1':
        ans_candidates.append(change_point[i+2*K+1]-change_point[i])
    else:
        ans_candidates.append(N-change_point[i])

print( max(ans_candidates) )

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

int main(){
  int n; cin >> n;
  vector<pair<int, int>> s(n);
  for(int i = 0; i < n; i++){
  	int a, b; cin >> a >> b;
  	s[i].first = b; s[i].second = a;
  }
  sort(s.begin(), s.end());
  
  int sum = 0;
  
  for(int i = 0; i < n; i++){
  	sum += s[i].second;
  	if(s[i].first < sum){
    	cout << "No" << endl;
    	return 0;
    }
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 1792
def gcd(a, b):
    
    big = max(a, b)
    small = min(a, b)
    
    r = small
    while r != 0:
        r = big % small
        big = small
        small = r
    
    return big

n = int(input())
a = [int(x) for x in input().split()]

ans = gcd(a[0], a[1])
for i in range(2, n):
    ans = gcd(ans, a[i])
    
print(ans)

Measured memory_bytes: 14252
i = 0
ARGF.each_line do |line|
  i += 1
  break if line == 0
  next if i % 2 == 1

  s = line.split.map(&:to_f)
  
  sum = 0
  s.each do |j|
    sum += j
  end
  avr = sum / s.size
  
  x = 0
  s.each do |j|
    x += (j - avr)**2
  end
  a = Math.sqrt(x / s.size)
  puts a
end

Measured memory_bytes: 6160
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
    return b ? power(a*a%MOD, b/2) * (b%2?a:1)%MOD:1;
}

long perm(int N, int K) {
    long x = 1;
    for(int i = 1; i <= K; i++) x = x * (N-i+1) % MOD;
    return x % MOD;
}

long comb(int N,int K) {
    long x = 1, y = 1;
    for(int i = 1; i <= K; i++) {
        x = x * (N-i+1) % MOD;
        y = y * i % MOD;
    }
    return x * power(y, MOD-2) % MOD;
}

bool isprime(int n) {
    if(n < 2) return false;
    for(int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

void dfs(const vector<vector<int>> &G, int v, vector<int> &seen) {
    seen[v] = true;

    for(int next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

void yes() { cout << "Yes" << endl;}
void no() { cout << "No" << endl;}



int main() {
  
  int r; cin >> r;
  
  cout << 2 * r * M_PI;

}



Measured memory_bytes: 3792
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<int>in(n);
    int ba=0;
    string s;cin>>s;
    rep(i,100){
      if(s[i]=='M')in[i%n]++;
      else if(s[i]=='L'){in[i%n]+=1+ba;ba=0;}
      else {
	ba+=in[i%n]+1;
	in[i%n]=0;
      }
    }
    sort(all(in));
    rep(i,n)cout<<in[i]<<" ";
    cout<<ba<<endl;

  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

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

    ll ans=0;
    rep(i,n-1){
        ans+=min(a*(x[i+1]-x[i]),b);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3980
n = int(input())
l = list(map(int,input().split()))

r = l[::-1]
ans = [0] * n
for i in range(n):
    s = 0
    for j in range(n//(n-i)):
        s += ans[n-i + j*(n-i)-1]

        # print(j,n-i + j*(n-i)-1)
    else:
        if s%2 != l[n-i-1]:
            ans[n-i-1]+=1
            ans[n-i-1]%=2
ansL = []
R = 0
for i , a in enumerate(ans):
    if a == 1:
        R+=1
        ansL.append(i+1)
print(R)
if R >0:
    print(*ansL)

Measured memory_bytes: 15924
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		String s = fs.next();
		int len = s.length();

		long res = 0;
		for(int i=0;i<(1<<(len-1));i++) {
			List<Integer> l = new ArrayList<>();
			for(int j=0;j<len-1;j++) {
				if((i>>(len-2-j)&1)==1)l.add(j);
			}
			List<String> ss = new ArrayList<>();
			StringBuilder sb = new StringBuilder();
			for(int j=0;j<len;j++) {
				if(l.contains(j)) {
					sb.append(s.charAt(j));
					ss.add(sb.toString());
					sb.setLength(0);
				}
				else sb.append(s.charAt(j));
			}
			if(sb.length()!=0)ss.add(sb.toString());
			for(String ts:ss) {
				long t = Long.parseLong(ts);
				res += t;
			}
		}
		System.out.println(res);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
using Graph = vector<vector<int>>;

int main() {
    int x, n;
    cin >> x >> n;
    if(n==0){
        cout << x;
        return 0;
    }
    set<int> p;
    rep(i,n) {
        int X;
        cin >> X;
        p.insert(X);
    }
    vector<int> P;
    for(int i=-2; i<=101;i++){
        if(p.count(i)) continue;
        P.push_back(i);
    }
    vector<int> ans;
    int sa=300;
    rep(i,P.size()){
        int res = abs(x-P[i]);
        if(res<sa) {
            ans.clear();
            ans.push_back(i);
        }
        if(res == sa){
            ans.push_back(i);
        }
        sa = res;
    }
    
    cout << P[ans[0]] << endl;

}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int q=Integer.parseInt(scan.next());
    int sumTime=0;
    Queue<Process> queue=new ArrayDeque<Process>();

    for(int i=0;i<n;i++){
      String namae=scan.next();
      int Time=Integer.parseInt(scan.next());
      queue.add(new Process(namae,Time));
    }

    Queue<Process> ans=new ArrayDeque<>();
    while(!queue.isEmpty()){
      Process buf=queue.remove();
      if(buf.pTime-q<=0){
        int buf2=buf.pTime;
        buf.pTime+=sumTime;
        sumTime+=buf2;
        ans.add(buf);
      }else {
        buf.pTime-=q;
        queue.add(buf);
        sumTime+=q;
      }
    }
    for(Process p:ans){
      System.out.println(p.name+" "+p.pTime);
    }
  }
}
class Process{
  String name;
  int pTime;

  public Process(String name,int pTime){
    this.name=name;
    this.pTime=pTime;
  }
}



Measured memory_bytes: 76644
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N=int(input())
print((1000-N%1000)%1000)


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

int main() {
  string s;
  cin >>s;
  map<char, int> card;
  for(int i=0;i<4;i++){
    if(card.count(s[i])){
      card[s[i]] ++;
    }
    else{
      card[s[i]] =1;
    }
  }

  if(card.size()==2&&card[s[0]]==2) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
using namespace std;

long long  gcd(long long  x, long long y)
{
	if (y == 0)
		return x;
	if (x < y)
		return gcd(y, x);
	else
		return gcd(y, x%y);
}

int main()
{
	long long a, b, ans = 1;

	cin >> a >> b;
	long long c = gcd(a, b);
	long long d = c;

	for (long long i = 2; i <= sqrt(d); i++)
	{
		if (c%i == 0)
		{
			ans++;
			while (c%i == 0)
				c /= i;
		}
		else
			continue;
	}

	if (c != 1)
		ans++;
	cout << ans;
}

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

int  main()
{
	int n, k; cin >> n >> k;
	vector <int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	long sum = 0;
	rep(i, k)
	{
		sum += a[i];
	}
	cout << sum << endl;
	return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> services (n);
  for (int i=0; i<m; i++){
    int x, y;
    cin >> x >> y;
    services[x-1].push_back(y);
    services[y-1].push_back(x);
  }
  vector<int> start = services[0];
  for (int i=0; i<start.size(); i++){
    vector<int> set1 = services[start[i]-1];
    for (int j=0; j<set1.size(); j++){
      if (set1[j] == n){
        cout << "POSSIBLE";
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE";
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

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

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(string s;cin>>s&&s!="#";){
		int w; cin>>w;
		string t;
		for(int i=0;i<s.size();i+=w)
			t+=s[i];
		cout<<t<<endl;
	}
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int a, b;
	cin >> a >> b;
	if (abs(a - b) % 2 == 1) {
		cout << "IMPOSSIBLE\n";
	}
	else {
		cout << (a + b) / 2 << endl;
	}
}


Measured memory_bytes: 256
// Problem : 
// 			B - Making Triangle
// 			Editorial
// 		
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mod (int)1e9+7
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define repf(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define N 100005
int main()
{
	FAST
    int t=1;
    // cin>>t;
    while(t--)
    {
		int n, i;
		cin>>n;
		vi a(n);
		repf(i,0,n) cin>>a[i];
		sort(a);
		int j, k;
		int ans=0;
		repf(i, 0, n-2)
		{
			repf(j, i+1, n-1)
			{
				repf(k, j+1, n)
				{
					if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i] && a[i]+a[j]>a[k])
					ans++;			
				}
			}
		}
		cout<<ans;
    }
    return 0;
} 


Measured memory_bytes: 3632
x1, y1, x2, y2 = [int(_) for _ in input().split()]

dx, dy = x2 - x1, y2 - y1

dx, dy = -dy, dx
x3, y3 = x2 + dx, y2 + dy

dx, dy = -dy, dx
x4, y4 = x3 + dx, y3 + dy

print(x3, y3, x4, y4)


Measured memory_bytes: 2940
// C++ Implementation to Compute Sum of 
// Digits of Number N in Base B 

#include <iostream> 
using namespace std; 

// Function to compute sum of 
// Digits of Number N in base B 
long long int sumOfDigit(long long int n,long long int b) 
{ 
	
	// Initilize sum with 0 
	long long int unitDigit, sum = 0; 
	while (n > 0) { 
		
		// Compute unit digit of the number 
		unitDigit = n % b; 

		// Add unit digit in sum 
		sum ++; 

		// Update value of Number 
		n = n / b; 
	} 
	return sum; 
} 

// Driver function 
int main() 
{ 
	long long int n,b;
	cin>>n>>b;
	cout << sumOfDigit(n, b); 
	return 0; 
} 


Measured memory_bytes: 256
//package com.company;
import java.util.*;

public class Main {
    static final private int MAX_N = (int)(1E6 + 10);
    static final private int MOD = (int)(1E9 + 7);

    static private int multiply(int a, int b) {
        return (int)(((long)a * b) % MOD);
    }

    // fast bin pow
    static private int pow(int a, int p) {
        int cur = a;
        int ans = 1;
        while (p > 0) {
            if (p % 2 == 1)
                ans = (int)(((long)ans * cur) % MOD);
            p /= 2;
            cur = (int)(((long)cur * cur) % MOD);
        }
        return ans;
    }

    static private int inv(int x) {
        return pow(x, MOD - 2);
    }

    public static void main(String[] args) {
        // inp
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = sc.nextInt();

        // sieve
        int[] sieve = new int[MAX_N];
        for (int i = 2; i < MAX_N; i++)
            if (sieve[i] == 0) {
                sieve[i] = i;
                for (int j = i + i; j < MAX_N; j += i)
                    sieve[j] = i;
            }

        // count powers
        int[] cnt = new int[MAX_N];
        for (int i = 0; i < n; i++) {
            int x = a[i];
            while (x > 1) {
                int p = sieve[x];
                int pw = 0;
                while (sieve[x] == p) {
                    x /= p;
                    pw++;
                }
                cnt[p] = Math.max(cnt[p], pw);
            }
        }

        // count lcm
        int s = 1;
        for (int i = 2; i < MAX_N; i++)
            s = multiply(s, pow(i, cnt[i]));

        // count ans
        int res = 0;
        for (int i = 0; i < n; i++) {
            res += multiply(s, inv(a[i]));
            res %= MOD;
        }

        // output
        System.out.println(res);
    }
}


Measured memory_bytes: 46512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    string s;
    cin >> s;
    bool flag = false;
    for(int i=0; i<s.length()-1; i++){
        if (s[i] == s[i+1]) flag=true;
    }
    if (flag) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

void dijkstra(){
  int i,u,v,min;
  int d[MAX],c[MAX];

  for(i=0;i<n;i++){
    d[i]=INFTY;
    c[i]=WHITE;
  }

  d[0]=0;
  c[0]=GRAY;
  while(1){
    min=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(min>d[i]&&c[i]!=BLACK){
        u=i;
        min=d[i];
      }
    }
    if(u==-1)break;
    c[u]=BLACK;
    for(v=0;v<n;v++){
      if(c[v]!=BLACK && M[u][v]!=INFTY){
       if(d[v]>M[u][v]+d[u]){
         d[v]=M[u][v]+d[u];
         c[v]=GRAY;
       }
     }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,(d[i]==INFTY?-1:d[i]));
      }
}

  int main(){
    int i,j,k,u,v,c;

    scanf("%d",&n);

    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        M[i][j]=INFTY;
      }
    }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }

  dijkstra();

  return 0;
}


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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 1;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n;
	cin>>n;
	Array a(n);
	REP(i,n) cin>>a[i];
	
	map<ll,ll> mp;
	REP(i,n) mp[a[i]]++;
	
	sort(all(a));
	ll ans=0;
	rep2(i,1,n){
		ll con1=mp[a[i]];
		if(con1==0) continue;
		ll num=1;
		while(num<=a[i]) num*=2;
		ll con2=mp[num-a[i]];
		if(num==a[i]*2){
			ans+=con1/2;
			mp[a[i]]-=con1;
			continue;
		}
		ans += min(con1,con2);
		mp[a[i]] = 0;
		mp[num-a[i]] -= min(con1,con2);
	}
	cout<<ans<<en;
}

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

	solve();
    return 0;
}

Measured memory_bytes: 26880
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define f(i,n) for(int i=0 ; i<n ; i++)
#define fll(i,n) for(ll i=0 ; i<n ; i++)
#define f1(a,b,i) for(ll i=a ; i<b ; i++)
#define fd(i,n) for(int i=n-1 ; i>=0 ; i--)
#define ll long long
#define ld long double
#define vi vector<int>
#define  pii pair<int,int>
#define vl vector<ll>
#define INF 1e9
#define epsn 1e-12

using namespace std ;
int M=1e9+7 ;
ll pow(ll a, ll b){
    if(b==0)return 1 ;
    else if(b%2)return a*pow(a,b-1) ;
    else return pow(a,b/2)*pow(a,b/2) ;
}

int main(){
    ll n ;
    cin>>n ;
    vector<ll>h(n) ,dp(n,1e9);
    fll(i,n)cin>>h[i] ;
    dp[0]=0 ;
    fll(i,n)
        for(ll j=1 ; j<3 && i+j<n ; j++)
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i])) ;

    cout<<dp[n-1]<<"\n" ;
    return 0 ;
}


Measured memory_bytes: 4364
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>

using namespace std;

bool check(const vector<int>& h, int64_t a, int64_t b, int64_t k) {
  int64_t bar = (int64_t)b * k;
  int64_t d = a - b;
  int64_t rem = d * k;
  for (int x : h) {
    if (x <= bar) continue;
    rem -= ((x - bar) / d + int((x-bar)%d != 0)) * d;
    if (rem < 0) {
      //cout << k << " " << x << " " << rem << " " << bar << endl;
      return false;
    }
  }
  return true;
}

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

  int n, a, b;
  cin >> n >> a >> b;
  vector<int> h(n);
  for (int& x : h) {
    cin >> x;
  }
  int l = 0;
  int r = 1100000000;
  while (l < r) {
    int mid = l + (r-l) / 2;
    if (check(h, a, b, mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }

  cout << l << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  string s;
  ll k;
  cin >> s >> k;
  ll n = SZ(s);
  vector<vector<vector<ll>>> dp(n + 1,
                                vector<vector<ll>>(k + 1, vector<ll>(2, 0)));
  dp[0][k][0] = 1;
  REP(i, n) REP(j, k + 1) {
    ll x = s[i] - '0';
    if (x == 0) {
      // 0
      dp[i + 1][j][0] += dp[i][j][0];
      // 0
      dp[i + 1][j][1] += dp[i][j][1];
      if (j - 1 >= 0) {
        // 1,2,...,9
        dp[i + 1][j - 1][1] += 9 * dp[i][j][1];
      }
    } else {
      if (j - 1 >= 0) {
        // 1,2,...,x-1
        dp[i + 1][j - 1][1] += (x - 1) * dp[i][j][0];
        // 1,2,...,9
        dp[i + 1][j - 1][1] += dp[i][j][1] * 9;
        // x
        dp[i + 1][j - 1][0] += dp[i][j][0];
      }

      // 0
      dp[i + 1][j][1] += dp[i][j][0] + dp[i][j][1];
    }
  }

  cout << dp[n][0][1] + dp[n][0][0] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
const int MOD=1e9+7;
int n,a=1,b=1,c=1;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n;i++){
		a*=10,a%=MOD;
		b*=9,b%=MOD;
		c*=8,c%=MOD;
	}
	a+=MOD+MOD;
	int ans=(a-b-b+c)%MOD;
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3640
H, N = map(int, input().split())
attack = []
cost = []
highest_attack = 0

for i in range(N):
    a, c = map(int, input().split())
    attack.append(a)
    cost.append(c)

    highest_attack = max(highest_attack, a)

dp_cost = [float('inf')] * (H+highest_attack)
dp_cost[0] = 0
dp_cost[0] = 0

best_cost = float("inf")


for h in range(H+highest_attack): 
    for i in range(N):
        a, c = attack[i], cost[i]

        if h - a >= 0:
            dp_cost[h] = min(dp_cost[h], dp_cost[h-a] + c)

    if h >= H:
        best_cost = min(best_cost, dp_cost[h])

print(best_cost)

Measured memory_bytes: 44380
using System;

namespace ABC134
{
    class Program
    {
        static int Main(string[] args)
        {
            problemA();
            return 0;
        }



        static void problemA()
        {
            string input = Console.ReadLine();

            int r = int.Parse(input);

            Console.WriteLine(3*r*r);
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        String str1 = sc.next();
        // スペース区切りの整数の入力

        String str2 = "7";

        int result = str1.indexOf(str2);
        if (result != -1) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 35524
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int a[14],b[7],i;
		for(i=0;i<14;i++){
			cin>>a[i];
		}
		b[0]=a[0]-a[1];
		b[1]=a[2]-a[3];
		b[2]=a[4]-a[5];
		b[3]=a[6]-a[7];
		b[4]=a[8]-a[9];
		b[5]=a[10]-a[11];
		b[6]=a[12]-a[13];
		for(i=0;i<7;i++){
		cout<<b[i]<<endl;
		}
	return 0;
}

Measured memory_bytes: 1164
/* A */

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    string s;
    cin >> s;
    if((s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) || (s[0]==s[2] && s[1]==s[3] && s[0]!=s[1]) || (s[0]==s[3] && s[1]==s[2] && s[0]!=s[1])) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ll n , a , b ;


    cin >>n >> a >> b ;
    if((b-a-1)&1){
         cout << "Alice" << endl;
    }
    else{
        cout << "Borys" << endl;
    }

}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main(){
	var a, b, c int
	num := 0
	fmt.Scan(&a, &b, &c)
	for i := a; i <= b; i++{
		if c % i == 0{
			num++
		}
	}
	fmt.Println(num)
}


Measured memory_bytes: 1156