akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli a, b, k;
int main() {
  cin >> a >> b >> k;
  for (lli i=100, c=0; i>0; --i) {
    if (a%i==0 && b%i==0) {
      ++c;
      if (c==k) {
        cout << i << '\n';
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s = ['.' * (w + 2)] + ['.' + input() + '.' for _ in range(h)] + ['.' * (w + 2)]
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == '#':
            if s[i - 1][j] == '.' and s[i + 1][j] == '.' and s[i][j - 1] == '.' and s[i][j + 1] == '.':
                print('No')
                exit(0)
print('Yes')
exit(0)


Measured memory_bytes: 38896
#include <stdio.h>
#include <string.h>
int main()
{
long long int a;
int  i = 0, remain;
scanf("%lld", &a);
char str[100];
while(a != 0){
	remain = a % 26;
	
	if(remain == 0){
		str[i++] = 'z';
		a = a/26 - 1;
	}else{
		str[i++] = remain + 96;
		a = a/26;
	}	
}
str[i] = '\0';
for(int j = strlen(str) - 1;j >= 0; j--){
	printf("%c",str[j]);
}


return 0;
}

Measured memory_bytes: 1652
H,W = map(int,input().split())
Ch, Cw = map(lambda x: int(x)-1,input().split())
Dh, Dw = map(lambda x: int(x)-1,input().split())
S = []
for i in range(H):
  S.append(input())


from collections import deque

def bfs(sh,sw):
  queue = deque([(sh,sw)])
  d = [[None]*W for _ in range(H)]
  now = set()
  d[sh][sw]=0
  
  while queue:
    h,w = queue.popleft()
    now.add((h,w))
    for nh,nw in [(h-1,w),(h+1,w),(h,w-1),(h,w+1)]:
      if (0<=nh<=H-1 and 0<=nw<=W-1 and S[nh][nw] == '.' and d[nh][nw] is None) == False: continue
      queue.append((nh,nw))
      now.add((nh,nw))
      d[nh][nw]=d[h][w]

    if queue: continue
    for h,w in now:
      for i in range(-2,3):
        for j in range(-2,3):
          if i==0 and abs(j)<=1: continue
          if j == 0 and abs(i)<=1: continue
          nh,nw = h-i,w-j
          if (0<=nh<=H-1 and 0<=nw<=W-1 and S[nh][nw] == '.' and d[nh][nw] is None) == False: continue
          d[nh][nw] = d[h][w]+1
          queue.append((nh,nw))
    now = set()
    #print(queue)
  return d

d = bfs(Ch,Cw)
if d[Dh][Dw] == None: 
  print(-1)
  exit()
print(d[Dh][Dw])

Measured memory_bytes: 107076
#include<bits/stdc++.h>
using namespace std;
int arr[200007],brr[200007],crr[200007],drr[200007],pre[200007],suf[200007];
int f(int x){
  //  assert(x<0);
    if(!x) return 0;
    int one=__builtin_popcount(x);
    x%=one;
    return f(x)+1;
}
int main()
{
    string s;
    int n;
    cin>>n>>s;
    reverse(s.begin(),s.end());
    int cnt=0;
    for(int i=0;i<n;i++){
        cnt+=(s[i]=='1');
    }
    int ans=1,ans2=1;
    for(int i=0;i<n;i++){
        if(cnt>1)crr[i]=ans%(cnt-1);
        drr[i]=ans2%(cnt+1);
        ans*=2;
        ans2*=2;
        if(cnt>1) ans%=cnt-1;
        else ans=0;
        ans2%=cnt+1;

        if(s[i]=='1'){
            arr[i]=crr[i];
            brr[i]=drr[i];
            pre[i]=crr[i];
            suf[i]=drr[i];
        }
    }

    for(int i=1;i<n;i++){
        arr[i]+=arr[i-1];
        brr[i]+=brr[i-1];
    }
    for(int i=n-1;i>=0;i--){
        pre[i]+=pre[i+1];
        suf[i]+=suf[i+1];
        if(cnt>1)pre[i]%=(cnt-1);
        suf[i]%=(cnt+1);
    }


    for(int i=n-1;i>=0;i--){
        if(s[i]=='0'){
            int ans=drr[i];
            ans=(suf[0]+ans)%(cnt+1);
            cout<<f(ans)+1<<endl;
        }
        else {
            ans=pre[0];
            if(cnt==1) {
                cout<<0<<endl;
            }
            else{
                ans-=crr[i];
                ans%=(cnt-1);
                ans+=(cnt-1);
                ans%=(cnt-1);
                cout<<f(ans)+1<<endl;
            }
        }
    }

    return 0;
}


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

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

// Dado un arreglo y una operacion asociativa con neutro:
// get(i, j) opera sobre el rango [i, j).
typedef int node; // Tipo de los nodos
#define MAXN 100000
#define operacion(x, y) __gcd(x, y)
const int neutro = 0;
struct RMQ {
	int sz;
	node t[4*MAXN];
	node &operator [](int p){ return t[sz + p]; }
	void init(int n){ // O(n lg n)
		sz = 1 << (32 - __builtin_clz(n));
		forn(i, 2*sz) t[i] = neutro;
	}
    void updall(){//O(n)
        dforsn(i,0, sz){
            t[i] = operacion(t[2*i], t[2*i + 1]);
        }
    }
	node get(int i, int j){ return get(i, j, 1, 0, sz); }
	node get(int i, int j, int n, int a, int b){ // O(lg n)
		if(j <= a || i >= b) return neutro;
		if(i <= a && b <= j) return t[n];
		int c = (a + b)/2;
		return operacion(get(i, j, 2*n, a, c), get(i, j, 2*n + 1, c, b));
	}
	void set(int p, node val){ // O(lg n)
		for(p += sz; p > 0 && t[p] != val;){
			t[p] = val;
			p /= 2;
			val = operacion(t[p*2], t[p*2 + 1]);
		}
	}
} rmq;

int main() {
	fastio;
	
    int n; cin >> n;
    rmq.init(n);
    forn(i,n) cin >> rmq[i]; 
    rmq.updall();
    int res = rmq.get(0,n);
    forn(i,n){
        int bk = rmq.get(i,i+1);
        rmq.set(i,0);
        res = max(res,rmq.get(0,n));
        rmq.set(i,bk);
    }
    cout << res << endl;
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>

#define MOD 1000000007

using namespace std;

vector<long long int> fact(100010);
vector<long long int> inv_fact(100010);

long long int comb(int n, int r){
    return (((fact[n]*inv_fact[n-r]) % MOD)*inv_fact[r]) % MOD;
}

int main(){
    fact[0] = 1;
    for (int i=1; i<fact.size(); i++){
        fact[i] = (i*fact[i-1])%MOD;
    }
    for (int i=0; i<inv_fact.size(); i++){
        inv_fact[i] = 1;
        long long int x = fact[i], y=MOD-2;
        while (y){
            if (y & 1)  inv_fact[i] = (inv_fact[i] * x) % MOD;
            x = (x * x) % MOD;
            y >>= 1;
        }
    }

    int n, k;
    cin >> n >> k;
    vector<long long int> a(n), asum(n+1, 0);
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    for (int i=0; i<n; i++){
        asum[i+1] = (asum[i] + a[i]) % MOD;
    }

    

    long long int ans = 0;
    for (int i=k; i<=n; i++){
        ans += (comb(i-2, k-2) * ((asum[n]-asum[i-1])-asum[n-i+1])) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	char y[3];

	cin >> y[0] >> y[1] >> y[2];

	if (y[0] != y[1])
	{
		if (y[1] != y[2])
		{
			if (y[0] != y[2])
			{
				cout << "Yes";
			}
			else
			{
				cout << "No";
			}
		}
		else
		{
			cout << "No";
		}
	}
	else
	{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
const int lim = 1e6 + 1;
int dp[lim];
LL dfs_count(LL H) {
  if (H == 1) {
    return 1;
  }
  if (H < lim) {
    if (dp[H] != -1) {
      return dp[H];
    } else {
      dp[H] = 1 + 2 * dfs_count(H / 2);
    }
    return dp[H];
  } else {
    return 1 + 2 * dfs_count(H / 2);
  }
}

int main() {
  LL H;
  cin >> H;
  REP(i, 0, lim) dp[i] = -1;
  cout << dfs_count(H) << endl;

  return 0;
}


Measured memory_bytes: 4224
#pragma GCC optimize "O3"

#define F first
#define S second
#define ALL(x) x.begin(), x.end()

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<LL, int> PLI;

constexpr int N = 19, INF = INT_MAX / 2;
const int di[9] = {-1, -1, -1,  0, 0, 0,  1, 1, 1};
const int dj[9] = {-1,  0,  1, -1, 0, 1, -1, 0, 1};

int h, w, chts, digs, idigs[N], jdigs[N], ichts[N*N], jchts[N*N];
LL pw10[N];
char t[N][N];
bool poss[N][N];
map<PLI, int> dp;

inline bool in_border(int i, int j) {
  return i >= 0 && j >= 0 && i < h && j < w;
}
PLI init() {
  chts = digs = 0;
  dp.clear();
  for(int i = 0; i < h; ++i) {
    scanf("%s", t[i]);
    fill_n(poss[i], w, false);
  }
  PLI cur = {0, 0};
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      if(isdigit(t[i][j])) {
        idigs[digs] = i;
        jdigs[digs] = j;
        cur.F += pw10[digs] * (t[i][j] - '0');
        ++digs;
        for(int k = 0; k < 9; ++k) {
          int ni = i + di[k], nj = j + dj[k];
          if(in_border(ni, nj) && t[ni][nj] != '.')
            poss[ni][nj] = true;
        }
      }
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      if(poss[i][j]) {
        ichts[chts] = i;
        jchts[chts] = j;
        ++chts;
      }
  return cur;
}
inline bool is_near(int i, int j) {
  return abs(idigs[i] - ichts[j]) <= 1 && abs(jdigs[i] - jchts[j]) <= 1;
}
inline bool not_enough(PLI cur) {
  for(int i = 0; i < digs; ++i) {
    int tcnt = 0;
    for(int j = cur.S; j < chts; ++j)
      if(is_near(i, j))
        ++tcnt;
    if(tcnt < cur.F % pw10[i+1] / pw10[i])
      return true;
  }
  return false;
}
bool can_put(PLI cur) {
  for(int i = 0; i < digs; ++i)
    if(is_near(i, cur.S) && cur.F % pw10[i+1] / pw10[i] == 0)
      return false;
  return true;
}
LL process(PLI cur) {
  for(int i = 0; i < digs; ++i)
    if(is_near(i, cur.S))
      cur.F -= pw10[i];
  return cur.F;
}
int dfs(PLI cur) {
  if(dp.count(cur))
    return dp[cur];
  if(not_enough(cur))
    return dp[cur] = INF;
  if(cur.S == chts)
    return dp[cur] = 0;
  int rtn = INF;
  if(can_put(cur))
    rtn = min(rtn, dfs({process(cur), cur.S+1}) + 1);
  rtn = min(rtn, dfs({cur.F, cur.S+1}));
  dp[cur] = rtn;
  return rtn;
}
int main() {
  pw10[0] = 1;
  for(int i = 1; i < N; ++i)
    pw10[i] = pw10[i-1] * 10;
  while(scanf("%d %d", &h, &w) && (h+w))
    printf("%d\n", dfs(init()));
}



Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<int> v;
    map<int, int> m;
    for(int i = 0 ; i < n ; i ++){
        int k; cin >> k;
        v.push_back(k);
        m[k] ++;
    }
    int ans = 0;
    for(int i = 0; i < n ; i ++){
        int f = 1;
        for(int j = 1; j <= sqrt(v[i]); j ++){
            if(v[i] % j == 0){
                if(j == v[i] && m[j] >= 2){
                    f = 0;
                    break;
                }
                if(j != v[i] && m[j] >= 1){
                    f = 0;
                    break;
                }
                if(v[i] / j == v[i] && m[v[i] / j] >= 2){
                    f = 0;
                    break;
                }
                if(v[i] / j != v[i] && m[v[i] / j] >= 1){
                    f = 0;
                    break;
                }
            }
        }
        if(f) ans ++; 
    }
    cout << ans;
}

Measured memory_bytes: 32804
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();

			if(n == 0){
				break;
			}

//			System.out.println("n = "+n);
			PolygonalLine plines[] = new PolygonalLine[n + 1];

			for(int i = 0; i <= n; i++){
				int m = sc.nextInt();

				plines[i] = new PolygonalLine(m);
				for(int j = 0; j < m; j++){
					int x = sc.nextInt();
					int y = sc.nextInt();

					plines[i].addPoint(x, y);
				}
			}

			solve(plines);
			System.out.println("+++++");
		}
	}

	static void solve(PolygonalLine[] plines){
		int n = plines.length - 1;

		Point[] originalVectors = makeVectors(plines[0]);

//		printPoints(originalVectors);

		for(int i = 1; i <= n; i++){
//			System.out.println("i = "+i);
//			System.out.println("normal");
//			printPoints(makeVectors(plines[i]));
//			System.out.println("reverse");
//			printPoints(makeVectors(plines[i].reverseLine()));
			//順方向比較
			if(isSamePoints(originalVectors, makeVectors(plines[i]))){
				System.out.println(i);
			}

			//逆方向比較
			else if(isSamePoints(originalVectors, makeVectors(plines[i].reverseLine()))){
				System.out.println(i);
			}
		}
	}

	//debug
	static void printPoints(Point[] points){
		for(int i = 0; i < points.length; i++){
			System.out.print("("+points[i].x+", "+points[i].y+") ");
		}
		System.out.println();
	}
	static boolean isSamePoints(Point[] points1, Point[] points2){
		int n = points1.length;
		int m = points2.length;

		if(n != m){
			return false;
		}

		for(int i = 0; i < n; i++){
			if(!points1[i].equals(points2[i])){
				return false;
			}
		}

		return true;
	}

	static Point[] makeVectors(PolygonalLine pline){
		int n = pline.points.length;

		Point[] result = new Point[n - 1];

		int dx0 = pline.points[1].x - pline.points[0].x;
		int dy0 = pline.points[1].y - pline.points[0].y;
		for(int i = 0; i < n - 1; i++){
			int dx = pline.points[i + 1].x - pline.points[i].x;
			int dy = pline.points[i + 1].y - pline.points[i].y;

			result[i] = new Point(dx, dy);

			//初手は必ず右向きになるように回転
			if(dy0 > 0){
//				System.out.println("rotate -90");
				result[i].x = dy; result[i].y = -dx;
			}
			else if(dx0 < 0){
				result[i].x = -dx; result[i].y = -dy;
			}
			else if(dy0 < 0){
//				System.out.println("rotete -270");
				result[i].x = -dy; result[i].y = dx;
			}
		}

		return result;
	}

}

class PolygonalLine {
	private int m;
	private int index = 0;

	Point[] points;
	public PolygonalLine(int m) {
		this.m = m;
		points = new Point[m];
	}

	public void addPoint(int x, int y){
		points[index++] = new Point(x, y);
	}

	public PolygonalLine reverseLine(){
		PolygonalLine clone = new PolygonalLine(m);

		for(int i = 0; i < m; i++){
			clone.addPoint(this.points[m - i - 1].x, this.points[m - i - 1].y);
		}

		return clone;
	}
}

class Point {
	int x;
	int y;

	Point(int x, int y){
		this.x = x;
		this.y = y;
	}

	public boolean equals(Point p){
		if(this.x == p.x && this.y == p.y){
			return true;
		}
		else {
			return false;
		}
	}
}


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

int main()
{
  string S;

  vector<char> vec(4);

  for (int i = 0; i < 4; i++)
  {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());

  cout << (vec.at(0) == vec.at(1) && vec.at(1) != vec.at(2) && vec.at(2) == vec.at(3) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#define pi acos(-1)
using namespace std;
int main()
{
    int a,b,m,h;
    double p;
    cin>>a>>b>>h>>m;
    double diff=abs(m-(double)m/12.0-h*5) * pi/30;

    double c=sqrt(a*a+b*b-2*a*b*cos(diff));
    printf("%0.21lf",c);;

    return 0;
}


Measured memory_bytes: 4160
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scanf("%d", &n)
	if n == 1 {
		fmt.Println("Hello World")
	} else {
		fmt.Scanf("%d", &a)
		fmt.Scanf("%d", &b)
		fmt.Println(a + b)
	}
}

Measured memory_bytes: 512
h,w = map(int, input().split())
ch, cw = map(int, input().split())
ch -= 1
cw -= 1
dh,dw = map(int, input().split())
dh -= 1
dw -= 1

def trans(s):
    res = []
    for i in s:
        if i == '.':
            res.append(-1)
        else:
            res.append(-2)
    return res

def move(x,y,dq,dq_next):
    for ix,iy in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
        if ix > h-1 or ix < 0 or iy > w-1 or iy < 0:
            continue
        if (m[ix][iy] == -1) or (m[ix][iy] > m[x][y]):
            m[ix][iy] = m[x][y]
            dq.append((ix, iy))
    for ix, iy in [(x-2, y-2), (x-2, y-1), (x-2, y), (x-2, y+1), (x-2, y+2),
                        (x-1, y-2), (x-1, y-1), (x-1, y+1), (x-1, y+2),
                        (x, y-2), (x, y+2),
                        (x+1, y-2), (x+1, y-1), (x+1, y+1), (x+1, y+2),
                        (x+2, y-2), (x+2, y-1), (x+2, y), (x+2, y+1), (x+2, y+2)]:
        if ix > h-1 or ix < 0 or iy > w-1 or iy < 0:
            continue
        if m[ix][iy] == -1:
            m[ix][iy] = m[x][y] + 1
            dq_next.append((ix, iy))
            
m = [trans(input()) for _ in range(h)]

from collections import deque

m[ch][cw] = 0

def main():
    dq = deque()
    dq_next = deque()
    dq.append((ch,cw))
    s_moved = set()
    while True:
        while len(dq)>0:
            xx, yy = dq.popleft()
            if not (xx, yy) in s_moved:
              if xx == dh and yy == dw:
                  return m[xx][yy]
              move(xx, yy, dq, dq_next)
              s_moved.add((xx, yy))
        if len(dq_next) > 0:
            dq = dq_next.copy()
            dq_next = deque()
        else:
            return -1
          
print(main())


Measured memory_bytes: 167676
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

vector<int> a;

// index が条件を満たすかどうか
bool isOK(int index, int key) {
    if (a[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int key) {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}


int main() {
  int N;
  cin >> N;
  a.resize(N);

  rep(i, N){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int b = binary_search(a[N-1]/2);
  double c = a[N-1]/2; // 5.5とか
  if(b>0){
    if(abs((double)a[b] - c) > abs((double)a[b-1] - c)) {
      if(abs((double)a[b+1] - c) > abs((double)a[b-1] - c)) {
        b--;
      } else {
        b++;
      }
    }
  } else {
    if(abs((double)a[b] - c) > abs((double)a[b+1] - c)) {
      b++;
    }
  }

  if(N==2&&a[b]==100) b--;
  
    
  cout << a[N-1] << " " << a[b] << endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>

using namespace std;
string s;
int ans;
int main()
{
	cin >> s;
	for(int i = 0; i < 3; i++){
		if(s[i] == '1'){
			ans++;
		}
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int h, w, k;
int s[15][1010];

int minCut = -1;

int belongs[15];

void doCut(int curLine, int curCut) {
	if (curLine >= h) {
//		for (int i = 0 ; i < h ; i++) {
//			printf("%d ", belongs[i]);
//		}
//		printf("\n");
		
		int newCut = curCut;
		
		int nums[15];	//每个区块的总数
		int secNum[15];
		memset(nums, 0, sizeof(nums));
		for (int i = 0 ; i <= curCut ; i++)
			secNum[i] = 0;
			
		int iC = 0;
		int q;
		bool isOverFlow;
		
		while (iC < w) {
			for (int r = 0 ; r < h ; r++) {
				q = belongs[r];
				secNum[q] = secNum[q] + s[r][iC];
			}
			
			for (int i = 0 ; i <= curCut ; i++) {
				if (secNum[i] > k)
					return;
			}
						
			isOverFlow = false;
			for (int i = 0 ; i <= curCut ; i++) {
				nums[i] = nums[i] + secNum[i];
				if (nums[i] > k) {
					isOverFlow = true;
					break;
				}
			}
			
			if (true == isOverFlow) {
				newCut++;
				for (int i = 0 ; i <= curCut ; i++)
					nums[i] = secNum[i];
			}
			iC++;
			
			for (int i = 0 ; i <= curCut ; i++)
				secNum[i] = 0;
		}
		
		if ((minCut == -1) || (minCut > newCut))
			minCut = newCut;
	} else {
		belongs[curLine] = curCut;
		doCut(curLine + 1, curCut);
		
		if (curLine != 0) {
//			curCut++;
			belongs[curLine] = curCut + 1;
			doCut(curLine + 1, curCut + 1);
		}
	}
	
}

int main()
{
	scanf("%d%d%d\n", &h, &w, &k);
	
	char temp[1010];
	for (int r = 0 ; r < h ; r++) {
		scanf("%s\n", temp);
		for (int c = 0 ; c < w ; c++) {
			s[r][c] = temp[c] - '0';
		}
	}
	
	memset(belongs, 0, sizeof(belongs));
	doCut(0, 0);
	
	printf("%d\n", minCut);
	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


main(){
    //制約的に半分全列挙が間に合う
    //前後半にわけて後半を反転そいつらを2つにわけることを考える
    //同じようにわけれればいい。
    int n;
    cin>>n;
    string s;
    cin>>s;
    string s1="",s2="";
    for(int i=0;i<n;i++){
        s1+=s[i];
        s2+=s[i+n];
    }
    reverse(ALL(s2));
    map<pair<string,string>,ll> m1,m2;
    for(int i=0;i<(1<<n);i++){
        string t11="",t12="",t21="",t22="";
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                t11+=s1[j];
                t21+=s2[j];
            }
            else{
                t12+=s1[j];
                t22+=s2[j];
            }
        }
        m1[make_pair(t11,t12)]++;
        m2[make_pair(t21,t22)]++;
    }
    ll ans=0;
    
    for(auto x:m1){
        /*
        前半部分について
        x.firstのペアのようにわけるのがx.secondある
        後半部分について
        x.firstのペアのようにわけるのがm2[x.first]個ある
        それらはすべて条件を満たすのでかけて加えてあげる
         */
        ans+=m2[x.first]*x.second;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 108288
def main():
    N,M = map(int,input().split())
    switches = []
    for i in range(M):
        switches.append(list(map(int,input().split()))[1:])
    P = list(map(int,input().split()))
    ans = 0
    for i in range(2**N):
        on = [False]*N
        for j in range(N):
            if (2**j) & i :
                on[j] = True

        for j in range(M):
            count = 0
            for s in switches[j]:
                if on[s-1]:
                    count += 1
            if count % 2 != P[j]:
                break
            else:
                continue
            break
        else:
            ans += 1
    print(ans)










main()

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

#define N 8
#define FREE 0
#define NOT_FREE 1

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

void printBoard(){
  int i,j;
   for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(A[i][j]){
	if(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");
  }
  return;
}


void putQueen(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;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    putQueen(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}

int main(){
  int i,j,x,y,n;
  
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
    
    for(j=0;j<N;j++){
      A[i][j]=0;
    }
  }

  for(j=0;j<2*N-1;j++){
    dpos[j]=FREE;
    dneg[j]=FREE;
  }

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&x,&y);
    A[x][y]=1;
  }     
  putQueen(0);

}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
using namespace std;
ll t,n,m,k;
ll i,j;
ll a[500005], b[500005];
vector<ll>v;
int32_t main(){
    cin>>n>>m>>k;
    ll ans=0;
    for(i=n;i<=m;i++){
        if(i%k==0) ans++;
    }
    cout<<ans;
    return 0;
}


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

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

  int n;
  cin >> n;

  vector<int> a(n), b(n), c(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; i++) {
    cin >> c[i];
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll aCount = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    ll cCount = c.end() - upper_bound(c.begin(), c.end(), b[i]);

    ans += aCount * cCount;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
/* Shivam Sharma
	`They call me Hei$enBerg (~_^)`
	ABV-Indian Institute of Information Technology and Management, Gwalior
	*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector< vector<ll> > vvi;
typedef pair<ll,ll> pii;
typedef map<string,ll> msi;
typedef set<ll> si;
typedef vector< pair<ll,ll> > vpii;


#define T() 	ll t;	cin>>t;		while(t--)
#define p_b		 push_back
#define p_f 		push_front
#define pop_b 		pop_back()
#define pop_f 		pop_front()
#define m_p		make_pair
#define l_b(v,l)     lower_bound (v.begin(), v.end(), l)
#define u_b(v,l)   	 upper_bound (v.begin(), v.end(), l)
#define min_pos(a)		 min_element(a.begin(),a.end())-a.begin()
#define max_pos(a) 		 max_element(a.begin(),a.end())-a.begin()
#define min_el(a) 		 *min_element(a.begin(),a.end())
#define max_el(a)		 *max_element(a.begin(),a.end())
#define cnt(a,l) 		 count(a.begin(),a.end(),l)
#define sort_a(a) 		 sort(a.begin(),a.end())
#define sort_d(a) 		 sort(a.begin(),a.end(),greater<ll>() )
#define summ(a)  	 accumulate(a.begin(),a.end(),0)
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define all(x) x.begin(),x.end()
#define mod  1000000007
#define inf      1e9
#define FF first
#define SS second
#define rep(i,a,b)      for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrep(i,a,b)      for(ll i=(ll)(a);i>=(ll)(b);i--)
#define mset(a,b)    	memset(a,b,sizeof(a));
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
///==========INPUT=============///
	#define     sc(a)           scanf("%lld",&a);
	#define     sc2(a,b)        scanf("%lld%lld",&a,&b);
	#define     sc3(a,b,c)      scanf("%lld%lld%lld",&a,&b,&c);
	#define     sc4(a,b,c,d)    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
///==========PRINTING=============///
	#define     prarr(arr)      rep(i,0,sizeof(arr)/sizeof(ll)) cout<<arr[i]<<" "; nl
	#define     prvec(v)        rep(i,0,v.size()) cout<<v[i]<<" "; nl
	#define     pr(x)           cout<<x<<"\n";
	#define     pr2(x, y)       cout<<x<<" "<<y<<"\n";
	#define     pr3(x, y, z)    cout<<x<<" "<<y<<" "<<z<<"\n";
///==========DEBUGGING=============///
    #define 	debug(a) 		cout<<"*"<<a<<endl;
   	#define 	debug2(a,b) 	cout<<"$"<<a<<" "<<b<<endl;
   	#define 	debug3(a,b,c) 	cout<<"$"<<a<<" "<<b<<" "<<c<<endl;
	#define 	bug 			cout<<"#"<<endl;
   	#define 	nl 				cout<<'\n';
   //	#define     endl            '\n'
   
ll powermod(ll _a,ll _b,ll _m)	{ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}

/*bool comp(pair<string,pii> p1,pair<string,pii> p2)
{
	if(p1.FF==p2.FF)
	{
		return p1.SS.FF>p2.SS.FF;
	}
	else return false;
 } 
 */
int main()
{
	ll n;
	cin>>n;
	pair<pair<string,ll>,ll>  p[n+5];
	rep(i,0,n)
	{
		ll x;
		cin>>p[i].FF.FF>>x;
		p[i].FF.SS=-1*x;
		p[i].SS=i+1;
	}
	sort(p,p+n);
//	sort(p,p+n,comp);
	rep(i,0,n)
		cout<<p[i].SS<<endl;
}


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

ll n, k, ans;

ll mypow(ll base, ll exp) {
	ll ret = 1;
	while (exp) {
		if (exp & 1) ret = ret * base % MOD;
		base = base * base % MOD;
		exp >>= 1;
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k;
	vector<ll> cnt(k+1);
	for (ll i = k; i >= 1; i--) {
		cnt[i] = mypow(k/i, n);
		for (ll j = 2*i; j <= k; j += i)
			cnt[i] = (cnt[i] - cnt[j] + MOD) % MOD;
		ans = (ans + i*cnt[i]) % MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3992
#include <iostream>
#include <algorithm>
static const int  NMAX = 1000;

static const int INFTY = (1 << 29);
using namespace std;

int main(){
    int n,m,maxPrice;
    int product[NMAX];
    while(true){
      maxPrice = -1;
      cin >> n >> m;
      if(n == 0 && m == 0) break;

      for(int i = 0; i < n ; i++){
        cin >> product[i];
      }
      for(int i = 0; i < n ; i++){
        for(int j = i + 1 ; j < n ; j++){
          if(product[i] + product[j] <= m) maxPrice = max((product[i] + product[j]),maxPrice);
        }
      }
      if(maxPrice == -1) cout << "NONE" << endl;
      else cout << maxPrice << endl;
    }
  return 0;
}



Measured memory_bytes: 3056
#include<bits/stdc++.h>
#include<vector>
#define N 100005
#define LL long long
using namespace std;
vector<int> G[N],E[N];
int n,m,f[N],col[N],cnt[3],sz[N],xzy,tot; LL ans;
int find(int x){ return f[x] ? f[x]=find(f[x]) : x;}
void dfs(int t)
{
	int i; cnt[col[t]]++,tot+=G[t].size();
	for(i=0;i<G[t].size();i++){
		if(col[G[t][i]]!=-1){
			if(col[G[t][i]]!=((col[t]+E[t][i]+3)%3)) xzy=0;
			continue;
		  }
		col[G[t][i]]=(col[t]+E[t][i]+3)%3;
		dfs(G[t][i]);
	  }
}
void solve(int t)
{
	col[t]=cnt[0]=cnt[1]=cnt[2]=tot=0,xzy=1;
	dfs(t);
	if(!xzy) ans+=1LL*sz[t]*sz[t];
	else{
		if(cnt[0]&&cnt[1]&&cnt[2])
			ans+=1LL*cnt[0]*cnt[1]+1LL*cnt[1]*cnt[2]+1LL*cnt[2]*cnt[0];
		else ans+=tot/2;
	  }
}
int main()
{
	int i,x,y;
	scanf("%d %d",&n,&m);
	memset(col,-1,sizeof(col));
	for(i=1;i<=m;i++){
		scanf("%d %d",&x,&y);
		G[x].push_back(y);
		E[x].push_back(+1);
		G[y].push_back(x);
		E[y].push_back(-1);
		x=find(x),y=find(y);
		if(x!=y) f[x]=y;
	  }
	for(i=1;i<=n;i++) sz[find(i)]++;
	for(i=1;i<=n;i++)
		if(find(i)==i) solve(i);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 18176
from collections import Counter

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    x,y=map(int, input().split())
    a = [300000, 200000, 100000]
    ans = 0
    if x < 4:
        ans += a[x-1]
    if y < 4:
        ans += a[y-1]
    if x == y == 1:
        ans += 400000
    print(ans)
main()


Measured memory_bytes: 3444
N=int(input())
A=sorted(list(map(int,input().split())))
m=A[-1]
dp=[True]*m
ans,p,q=0,0,False
for a in A:
  if p==a and q:
    ans-=1
    q=False
  if dp[a-1]:
    p,q=a,True
    ans+=1
    aa=a
    while m>=aa:
      dp[aa-1]=False
      aa+=a
print(ans)

Measured memory_bytes: 32080
#include<bits/stdc++.h>
using namespace std;
#define spd  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

 void solve(){
  char c;  cin>>c;
  if(isupper(c))cout<<"A\n";
  else cout<<"a\n";
}
int main()
{    spd
     solve();
     return 0;
}



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

class D
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();

		var r = new List<string>();
		AddLines(r, '#', '.', h[0] - 1);
		AddLines(r, '.', '#', h[1] - 1);

		Console.WriteLine($"{r.Count} 100");
		Console.WriteLine(string.Join("\n", r));
	}

	static void AddLines(List<string> r, char b, char x, int count)
	{
		int c;
		r.Add(new string(b, 100));
		while (count > 0)
		{
			count -= c = Math.Min(50, count);
			r.Add(string.Join("", Enumerable.Repeat($"{x}{b}", c)).PadRight(100, b));
			r.Add(new string(b, 100));
		}
	}
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  map<int, int> even, odd, seven, sodd;
  set<int> S;
  vector<int> A(N);
  REP(i, N) {
    cin >> A[i];
    S.insert(A[i]);
    (i % 2 == 0 ? even : odd)[A[i]]++;
  }
  sort(ALL(A));
  REP(i, N) (i % 2 == 0 ? seven : sodd)[A[i]]++;

  int ecnt = 0, ocnt = 0;
  for (auto k : S) {
    //cout << k << ':' << even[k] << ',' << odd[k] << ',' << seven[k] << ',' << sodd[k] << endl;
    assert(even[k] + odd[k] == seven[k] + sodd[k]);
    if (even[k] > seven[k]) {
      ecnt += even[k] - seven[k];
    } else {
      assert(odd[k] >= sodd[k]);
      ocnt += odd[k] - sodd[k];
    }
  }
  //cout << ecnt << ' ' << ocnt << endl;
  assert(ecnt == ocnt);
  cout << ecnt << endl;
  return 0;
}


Measured memory_bytes: 24064
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

const int N = 1e5 + 2;

int n, m, dp[N], deg[N];
vector<vector<int>> g;

int calc(int u)
{
    int &ret = dp[u];
    if (ret != -1)
    {
        return ret;
    }
    ret = 0;
    for (auto v : g[u])
    {
        ret = max(ret, calc(v) + 1);
    }
    return ret;
}

int main()
{
    memset(dp, -1, sizeof dp);
    scanf("%d%d", &n, &m);
    g.resize(n);
    int u, v;
    while (m--)
    {
        scanf("%d%d", &u, &v);
        --u, --v;
        g[u].push_back(v);
        deg[v]++;
    }
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        if (deg[i] == 0)
        {
            ans = max(ans, calc(i));
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>

int dice[3][2];
#define MOVE_DICE(a, b, c) swap1(a, b); swap2(c); break;

void swap1(int a, int b)
{
  int i, temp[2];
  for (i=0; i<2; i++) {
    temp[i] = dice[a][i];
    dice[a][i] = dice[b][i];
  }
  for (i=0; i<2; i++)
    dice[b][i] = temp[i];
}

void swap2(int a)
{
  int i, temp;
  temp = dice[a][0];
  dice[a][0] = dice[a][1];
  dice[a][1] = temp;
}

void dice_init()
{
  int i;
  for (i=0; i<3; i++) {
      dice[i][0] = i+1;
      dice[i][1] = 7-(i+1);
    }
}

int move_dice(char *direction)
{
  char d = direction[0];
  switch (d) {
    case 'N': MOVE_DICE(0, 1, 1)
    case 'E': MOVE_DICE(0, 2, 0)
    case 'W': MOVE_DICE(0, 2, 2)
    case 'S': MOVE_DICE(0, 1, 0)
    case 'R': MOVE_DICE(1, 2, 2)
    case 'L': MOVE_DICE(1, 2, 1)
    default : return -1;
  }
  return dice[0][0];
}

int main(int argc, char const *argv[])
{
  int i, n, sum;
  char direction[6];

  while (scanf("%d", &n), n) {
    dice_init();
    for (sum=1; n--;) {
      scanf("%s", direction);
      sum += move_dice(direction);
    }
    printf("%d\n", sum);
  }
  return 0;
}

Measured memory_bytes: 604
n,m,x=map(int,input().split())
A = [int(x) for x in input().split()]
right = 0
left =0
for i in range(x,n+1):
  if i in A:
    right +=1
for i in range(x):
  if i in A:
    left +=1
print(min(right,left))

Measured memory_bytes: 3064
#include "bits/stdc++.h"

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    int N, M;
    cin >> N >> M;
    ull ans = 1;
    if(N != M + 1 and M != N + 1 and N != M){
        ans = 0;
    }else {
        for (int i = N; i >= 1; i--) {
            ans *= i;
            ans %= MOD;
        }
        for (int i = M; i >= 1; i--) {
            ans *= i;
            ans %= MOD;
        }
        if(N == M) {
            ans *= 2;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int n,sum=0;
	cin>>n;
	if(n==1){
		cout<<'0'<<endl;
		return 0;
	} 
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			int p=0;
			while(n%i==0)n/=i,p++;
			int ans=sqrt(p*2);
			if(ans*(ans+1)>p*2)ans--;
			sum+=ans;
		}
	}
	if(n>1){
		sum++;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		
		
		Console.WriteLine("{0}",(s[0]==s[1]&&s[1]==s[2])?"Yes":"No");
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <math.h>
int main(){
	int n;
	int x[8]={};
	int y[8]={};
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &x[i],&y[i]);
	}
	double sum=0;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			sum+=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
		}
	}
	printf("%.7f\n", sum/n*2);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll ans = 0;
  ll M,D; cin>>M>>D;

  repn(i,M){
    repn(j,D){
      if(j%10 >= 2 and j/10 >= 2){
        if(i == (j%10) * (j/10)){
          // cout<<i<<" "<<j<<endl;
          ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL((a))), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, C;
  cin >> N >> C;
  VVI D(C, VI(C));
  REP(i, C) REP(j, C) cin >> D[i][j];
  VVI c(N, VI(N));
  REP(i, N) REP(j, N)
  {
    cin >> c[i][j];
    c[i][j]--;
  }
  int ans = INF;
  VVI Sum(3, VI(C, 0));
  REP(color, C) REP(i, N) REP(j, N) Sum[(i+j) % 3][color] += D[c[i][j]][color];
  REP(i, C) REP(j, C) REP( k, C)
  {
    if (i == j || i == k || j == k) continue;
    ans = min(ans, Sum[0][i] + Sum[1][j] + Sum[2][k]);
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    string input;
    cin >> input;
    string target;
    cin >> target;

    vvi table(input.size(), vi(30, -1));

    {
        vi tmp(30, -1);
        for (int i = input.size()-1; i >= 0; i--) {
            tmp[input[i]-'a'] = i;
            rep(j, table[i].size()) {
                if (table[i][j] == -1) table[i][j] = tmp[j];
            }
        }
        for (int i = input.size()-1; i >= 0; i--) {
            tmp[input[i]-'a'] = i;
            rep(j, table[i].size()) {
                if (table[i][j] == -1) table[i][j] = tmp[j];
            }
        }
    }

    int ans = 0, cnt = 0;
    rep(i, target.size()) {
        int tmp = table[ans][target[i]-'a'];
        if (tmp == -1) {
            std::cout << -1 << std::endl;
            return 0;
        } else {
            if (ans > tmp) {
                cnt++;
            }
            ans = tmp + 1;
            if (ans == input.size()) {
                ans = 0;
                cnt++;
            }
        }
    }

    cout << cnt * input.size() + ans << endl;



    return 0;
}





Measured memory_bytes: 27856
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,c[190901],ans;
char a[100011];
int main()
{
	scanf("%s",a);
	m=strlen(a);
	if(a[0]==a[m-1])
	{
	if(m%2==1)printf("Second");
	else printf("First");
	}
	else
	{
	if(m%2==0)printf("Second");
	else printf("First");
	}
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

i64 dp[400][400];
i64 a[400];
i64 cum[401];

auto dfs(i32 l, i32 r) -> i64 {
	if (dp[l][r] > 0) {
		return dp[l][r];
	}
	if (l == r) {
		return 0;
	}

	i64 x = 1LL << 60;
	for (i32 i = l; i < r; i += 1) {
		x = std::min(x, dfs(l, i) + dfs(i + 1, r));
	}
	dp[l][r] = x + cum[r + 1] - cum[l];
	return dp[l][r];
}

auto main() -> i32 {
	i32 n;
	scanf("%d", &n);
	for (i32 i = 0; i < n; i += 1) {
		scanf("%ld", a + i);
		cum[i + 1] = cum[i] + a[i];
	}
	i64 ans = dfs(0, n - 1);
	printf("%ld\n", ans);
	return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 30;
const ll MOD = 1000000007;

int H, W;
vector<string> field;

int tate[2100][2100] = {};
int yoko[2100][2100] = {};

void lightcount_tate(int h, int w){
    if(field[h][w] == '#'){
        return;
    }
    if(tate[h][w] != 0){
        return;
    }
    int count = 1;
    int lim = 0;
    for(lim = h + 1; lim < H; ++lim){
        if(field[lim][w] == '.'){
            ++count;
        }
        else{
            break;
        }
    }
    for(int i = h; i < lim; ++i){
        tate[i][w] = count;
    }
}

void lightcount_yoko(int h, int w){
    if(field[h][w] == '#'){
        return;
    }
    if(yoko[h][w] != 0){
        return;
    }
    int count = 1;
    int lim = 0;
    for(lim = w + 1; lim < W; ++lim){
        if(field[h][lim] == '.'){
            ++count;
        }
        else{
            break;
        }
    }
    for(int i = w; i < lim; ++i){
        yoko[h][i] = count;
    }
}


int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> H >> W;
    field.resize(H);
    for(int i = 0; i < H; ++i){
        cin >> field[i];
    }

    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            lightcount_tate(i, j);
            lightcount_yoko(i, j);
        }
    }

    int ans = 0;
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            ans = max(ans, tate[i][j] + yoko[i][j] - 1);
        }
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 38016
#include <cstdio>
#include <cstring>
int main(void){
int N,ans=0;
char to[30],read[105];
int tol,rel;

scanf("%d%s",&N,to);
tol=strlen(to);
int i,j,k,p;
for(i=0;i<N;i++){
  scanf("%s",read);
  rel=strlen(read);
  for(j=0;j<rel;j++){
  for(k=1;k<=rel;k++){
    for(p=0;p<tol;p++){
      if(j+k*p>=rel || to[p]!=read[j+k*p])goto fail;
    }
    ans++;
    goto next;
fail:;
  }
  }
next:;
//printf("%d ",ans);
}
printf("%d\n",ans);
return 0;
}

Measured memory_bytes: 1028