akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> >g, tree, g2;
vector<int>vis, degree;
set<pair<int, int> >st;
void dfs(int v, int p){
    if(vis[v] == 1){
        if(st.find(make_pair(v, p)) == st.end()){
            g2[p].push_back(v);
            degree[p]++;
            st.insert(make_pair(v, p));
            st.insert(make_pair(p, v));
        }
    }
    else{
        vis[v] = 1;
        if(p != 0){
            tree[p].push_back(v);
            tree[v].push_back(p);
        }
        for(int i = 0; i < g[v].size(); i++){
            int to = g[v][i];
            if(to != p){
                dfs(to, v);
            }
        }
    }
}
void dfs2(int v, int p){
    for(int i = 0; i < tree[v].size(); i++){
        int to = tree[v][i];
        if(to != p){
            dfs2(to, v);
        }
    }
    if(p != 0){
        if(degree[v] % 2 == 1){
            g2[v].push_back(p);
            degree[v]++;
        }
        else{
            g2[p].push_back(v);
            degree[p]++;
        }
    }
}
int main(){
    int n, m;
    cin >> n >> m;
    g = vector<vector<int> >(n + 3);
    tree = vector<vector<int> >(n + 3);
    g2 = vector<vector<int> >(n + 3);
    vis = vector<int>(n + 3, 0);
    degree = vector<int>(n + 3, 0);
    for(int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    if(m % 2 == 1){
        cout << "-1";
        return 0;
    }
    dfs(1, 0);
    dfs2(1, 0);
    set<pair<int, int> >edge;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < g2[i].size(); j++){
            int k = g2[i][j];
            if(edge.find(make_pair(i, k)) == edge.end()){
                cout << i << ' ' << k << '\n';
                edge.insert(make_pair(i, k));
                edge.insert(make_pair(k, i));
            }
        }
    }
    return 0;
}

Measured memory_bytes: 34336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define d7 1000000007
#define fori(n) for( ll i=0 ; i<n; i++)


long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

int main(){

ll a, b, n;
cin>>n>>a>>b;
ll ans=0;
ans=binpow(2,n, d7);
ans=(ans-1)%d7;
ll x=1, y=1;
fori(a){
y=(y*(i+1))%d7;
x=(x*(n-i))%d7;
}
ll nca=0;
nca=(x*binpow(y, d7-2, d7))%d7;
ll ncb=0;
x=1; y=1;

fori(b){
y=(y*(i+1))%d7;
x=(x*(n-i))%d7;
}

ncb=(x*binpow(y, d7-2, d7))%d7;

ans = (ans -nca -ncb)%d7;
ans= (ans+d7)%d7;
cout<<ans;

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
    string s;
    cin >> s;
  map<char,int> m;
  int sum=0;
  for (int i =0;i < s.size();i++){
      if (m.count(s[i])){
        m[s[i]]++;
      }
    else{
      m[s[i]]=1;
    }
  }
  bool ans=true;
  for (auto r: m){
    auto val=r.second;
    int f;
    f=((int)val)%2;
    if (f){
      cout << "No" << endl;
      ans=false;
      return 0;
    }
  }
  if (ans) cout << "Yes" << endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

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

    ll result = lcm(A, B);
    cout << result << endl;
    return (0);
}

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

int main() {
	string s;
	cin >> s;
	sort(all(s));
	if(s == "abc") cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int N, M, C;
std::vector<int> B;
bool solve(std::vector<int>& A) {
  int point{0};
  for (int i = 0; i < M; i++) {
    point += A[i] * B[i];
  }
  return point + C > 0;
}

int main() {
  std::cin >> N >> M >> C;
  B.resize(M);
  std::vector<std::vector<int>> A(N);
  for (int i = 0; i < M; i++) std::cin >> B[i];
  for (int i = 0; i < N; i++) {
    A[i].resize(M);
    for (int j = 0; j < M; j++) std::cin >> A[i][j];
  }
  int res{0};
  for (int i = 0; i < N; i++) {
    res += solve(A[i]);
  }
  std::cout << res << std::endl;
}

Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> x(N);
    rep(i, N) cin >> x[i];

    int mini = INF;
    rep2(i, 1, 101)
    {
        int sum = 0;
        rep(j, N)
        {
            sum += abs(x[j] - i) * abs(x[j] - i);
        }
        mini = min(sum, mini);
    }
    cout << mini << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int r = fs.nextInt();
        System.out.println( 3 * r * r );
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) {
                return buffer[ptr++];
            } else {
                return -1;
            }
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
                throw new NumberFormatException();
            }
            return (int) nl;
        }

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


Measured memory_bytes: 24916
import math
# a: 時
# b: 分
# 
a, b, h, m = map(int, input().split())

angle_h = h * 30 + m * 0.5
angle_m = m * 6

cos_ = math.cos( math.radians( abs( angle_h - angle_m ) ) )

x = ( a**2 + b**2 - 2*a*b*cos_ ) ** 0.5

print(x)


Measured memory_bytes: 9544
Data = []

def calc(a):
    sum1 = 0
    for d in Data:
        sum1 += (a-d)*(a-d)
    return sum1

N = int(input())
Data = list(map(int,input().split()))
sum1 = sum(Data)
if sum1 % N == 0:
    ave1 = sum1 // N
    ans = calc(ave1)
else:
    ave1 = int(sum1 // N)
    ave2 = ave1-1
    ave3 = ave1+1
    ans = min(min(calc(ave1),calc(ave2)),calc(ave3))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int count[7];
int main(){
	int n,a;

	while(cin >> n && n){
		for(int i=0;i<7;i++){
			count[i] = 0;
		}
		for(int j=0;j<n;j++){
			cin >> a;
			if(a<10) count[0]++;
			else if(a<20) count[1]++;
			else if(a<30) count[2]++;
			else if(a<40) count[3]++;
			else if(a<50) count[4]++;
			else if(a<60) count[5]++;
			else count[6]++;
		}
		for(int i=0;i<7;i++){
			cout << count[i] << endl;
		}
	}

	return 0;
}

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

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--;cw--;dh--;dw--;
  const int INF = 1e9+5;
  vector<vector<char>> s(h, vector<char>(w));
  vector<vector<bool>> ed(h, vector<bool>(w,false));
  vector<vector<int>> d(h, vector<int>(w,INF));
  rep(i,h) rep(j,w) cin >> s[i][j];

  priority_queue<Pip,vector<Pip>, greater<Pip>> pq;
  pq.push(make_pair(0, make_pair(ch, cw)));
  d[ch][cw] = 0;
  while(!pq.empty()) {
    int u = pq.top().first;
    P p = pq.top().second;
    pq.pop();
    int i = p.first;
    int j = p.second;

    ed[i][j] = true;
    if (d[i][j] < u) continue;

    for (int a = -2; a <= 2; a++) {
      for (int b = -2; b <= 2; b++) {
        if (a == 0 && b == 0) continue;
        if (0 <= i+a && i+a < h && 0 <= j+b && j+b < w) {
          if (ed[i+a][j+b] == false && s[i+a][j+b] == '.') {
            int k;
            if ((a == -1 && b == 0) || (a == 1 && b == 0) || (a == 0 && b == 1) || (a == 0 && b == -1)) {
              k = 0;
            } else {
              k = 1;
            }
            if (d[i+a][j+b] > d[i][j] + k) {
              d[i+a][j+b] = d[i][j] + k;
              pq.push(make_pair(d[i+a][j+b], make_pair(i+a, j+b)));
            }
          }
        }
      }
    }
  }
  if (d[dh][dw] == INF) cout << -1 << endl;
  else cout << d[dh][dw] << endl;
  return 0;
}

Measured memory_bytes: 8776
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

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

	int N;
	cin >> N;
	pair<int,int> A[200000];
	for(int i=0;i<N; i++){
		int a;
		cin >> a;
		A[i] = MP(a,i);
	}
	sort(A,A+N);

	set<int> p;
	p.insert(-1);
	p.insert(N);
	LL ans = 0;
	for(int i=0; i<N; i++){
		LL mid = A[i].second;
		auto itr = p.lower_bound(mid);
		LL r = *itr;
		itr--;
		LL l = *itr;
		ans += (r-mid)*(mid-l)*((LL)i+1);
		p.insert(A[i].second);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 11264
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
vector<int> G[1000];
deque<int> que;
int vis[1000];
int to[1000];
bool dfs(int v) {
	vis[v] = 1;
	que.push_back(v);
	for (int to : G[v]) {
		if (vis[to] == 0) {
			if (dfs(to)) return 1;
		}
		else if (vis[to] == 1) {
			while (que.front() != to) que.pop_front();
			return 1;
		}
	}
	vis[v] = 2;
	que.pop_back();
	return 0;
}
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--; B--;
		G[A].push_back(B);
	}
	for (int i = 0; i < N; i++) {
		if (vis[i] == 0 && dfs(i)) break;
	}
	if (que.empty()) {
		cout << -1 << endl;
		return 0;
	}
	set<int> S;
	for (int i = 0; i < que.size(); i++) {
		to[que[i]] = que[(i + 1) % que.size()];
		S.insert(que[i]);
	}
	while (1) {
		bool ok = 0;
		int s = 0;
		for (int v : S) {
			for (int u : G[v]) {
				if (S.count(u) == 0) continue;
				if (u != to[v]) {
					to[v] = u;
					s = v;
					ok = 1;
					break;
				}
			}
			if (ok) break;
		}
		if (!ok) break;
		S.clear();
		S.insert(s);
		int t = to[s];
		while (t != s) {
			S.insert(t);
			t = to[t];
		}
	}
	cout << S.size() << endl;
	int s = *S.begin();
	cout << s + 1 << endl;
	int t = to[s];
	while (t != s) {
		cout << t + 1 << endl;
		t = to[t];
	}
}

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

int main(){
  string S;
  cin >> S;
  long long N = S.size()+1;
  if(S.at(N-2)=='<') S+='>';
  else S+='<';
  vector<long long> a;
  long long cnt=1;
  for(long long i=0; i<N-1; i++){
    if(S.at(i)==S.at(i+1)) cnt++;
    else{
      a.push_back(cnt);
      cnt=1;
    }
  }
  if(S.at(N-2)=='<') a.push_back(0);

  long long ans=0;
  if(S.at(0)=='<'){
    for(long long i=0; i<a.size(); i++){
      if(i%2==0){
        ans+=a.at(i)*(a.at(i)+1)/2;
        if(a.at(i)<a.at(i+1)) ans+=a.at(i+1)-a.at(i);
      }
      else{
        ans+=a.at(i)*(a.at(i)-1)/2;
      }
    }
  }
  else{
    for(long long i=0; i<a.size(); i++){
      if(i==0){
        ans+=a.at(i)*(a.at(i)+1)/2;
      }
      else if(i%2==0){
        ans+=a.at(i)*(a.at(i)-1)/2;
      }
      else{
        ans+=a.at(i)*(a.at(i)+1)/2;
        if(a.at(i)<a.at(i+1)) ans+=a.at(i+1)-a.at(i);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3068
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v; rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

int main() {
	string s, t;
	cin >> s >> t;
	sort(all(s));
	sort(rev(t));
	if (s < t)say("Yes");
	else say("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1000000000+7)

int w[101];
int v[101];
ll dp[100001][101];
int main() {
    ll N, W;
    cin >> N >> W;
    REP(i, N) {
        cin >> w[i+1] >> v[i+1];
    }
    REP(i, W+1) {
        REP(j, N) {
            if (i-w[j+1] >= 0) {
                dp[i][j+1] = max(dp[i-w[j+1]][j]+v[j+1], dp[i][j]);
            } else {
                dp[i][j+1] = dp[i][j];
            }
        }
    }
    
    ll maxv = 0;
    REP(i, N+1) {
        maxv = max(dp[W][i], maxv);
    }
    cout << maxv << endl;
}


Measured memory_bytes: 79104
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

r, D, x = MAP()

for i in range(10):
	next_x = r*x - D
	print(next_x)
	x = next_x


Measured memory_bytes: 59628
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 














int main()
{
     int n,k;
     cin>>n>>k;
     ll left=0,right=0;
     ll ans=0;
     for(int i=1;i<=n+1;i++)
     {
          left+=i-1;
          right+=n+1-i;
          left%=mod;
          right%=mod;
         
          if(i>=k)
          {
               ans+=right-left+1+mod;
               ans%=mod;
          }
          
     }
     cout<<ans;
     
}



















 
 
 
 
 

















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

typedef long long ll;
const ll MOD = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int a,b;
    cin>>a>>b;

    if(a==b)cout<<1;
    else{
        if((a+b)%2==0)cout<<(a+b)/2;
        else cout<<"IMPOSSIBLE";
    }

    return 0;
}


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

typedef long long ll;

int main() {
    string S;
    cin >> S;
    int cnt = 0;

    char prev;
    for (int i = 0; i < S.size(); i++) {
        if (i == 0) {
            prev = S[i];
        } else {
            if (prev != S[i]) {
                prev = S[i];
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 512
N = int(input())
W = list(map(int, input().split()))

sum_W = sum(W)
add_W = 0

for i in range(N):
   add_W += W[i]
   if add_W >= sum_W - add_W:
       print(min(abs(add_W - sum_W + add_W), abs(add_W - W[i] - sum_W + add_W - W[i])))
       break

Measured memory_bytes: 3064
def main():
    N, T = map(int, input().split())
    sw   = [int(a) for a in input().split()]
    total = 0
    for i in range(1, N):
        t = sw[i] - sw[i-1] 
        if t >= T:
            total += T
        else:
            total += t
    total += T
    print(total)
main()

Measured memory_bytes: 25196
solve :: [Double] -> [Double]
solve [a,b,c] =
    let s = (1/2) * a * b * sin (c*pi/180.0) in
    let l = a + b + sqrt (a^2 + b^2 - 2*a*b*cos(c*pi/180)) in
    let h = b * sin (c*pi/180.0) in
    [s,l,h]

main = interact (unlines . map show . solve . map read . words)

Measured memory_bytes: 4124
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>
#define maxn 205
using namespace std;
typedef long long ll;
typedef long double ldouble;

int n;
char s[maxn];
ll b[65], a[maxn];
bool ins(ll x) { // increase?
  for (int i = 59; i >= 0; i--) {
    if (x >> i) {
      if (!b[i]) {
        b[i] = x;
        return true;
      }
      x ^= b[i];
    }
  }
  return false;
}
void solve() {
  memset(b, 0, sizeof(b));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  scanf("%s", s + 1);
  for (int i = n; i >= 1; i--) {
    if (s[i] == '0') ins(a[i]);
    else {
      if (ins(a[i])) {
        puts("1");
        return;
      }
    }
  }
  puts("0");
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std; 
#define ll long long
void solve(int T){
	int k,ans=1;
	int tmp=7;
	scanf("%d",&k);
	/*if(k%2==0){
		puts("-1");
		return;
	}*/
	while(tmp%k){
		tmp=(tmp*10+7)%k;
		ans++;
		if(ans>1e7)break;
	}
	if(ans>1e7)puts("-1");
	else printf("%d",ans);
}
signed main(){
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++){
		solve(i);
	}
}


Measured memory_bytes: 3752
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cout << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)            \
    cerr << #v << ": ";         \
    REP(__i, (v).size())        \
    cerr << ((v)[__i]) << ", "; \
    cerr << endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll BIGINT = 1e9 + 7;

int main()
{
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<bool> a(N + 1);
    int tmp;
    REP(i, M)
    {
        cin >> tmp;
        a[tmp] = true;
    }

    vl dp(N + 1);
    dp[0] = 1LL;
    for (int i = 1; i <= N; ++i)
    {
        if (a[i])
        {
            dp[i] = 0LL;
        }
        else
        {
            dp[i] = dp[i - 1];
            if (i >= 2)
                dp[i] = (dp[i] + dp[i - 2]) % BIGINT;
        }
    }

    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> da(1000,0);
    for(int i=2;i<n+1;i++){
        int k=i;
        for(int j=2;j<32;j++){
            while(k%j==0){
                da[j]++;
                k/=j;
            }
        }
        if(k!=1){
            da[k]++;
        }
    }
    long long ans=1;
    for(int i=0;i<1000;i++){
        ans=(long long)ans*(da[i]+1)%1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define vl vector<ll>
#define pll pair<ll,ll>
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i= 0;i < a;i++)
#define rep1(i,a) for(ll i= 1;i < a;i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define pb push_back
#define sz(v) v.size()
#define all(a) a.begin(), a.end()
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000005
#define MOD 1000000007
#define el "\n"
const ll INF = 2e9+5;
  
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll isPrime(ll n){if(n<=3) return 1;if(n%2==0||n%3==0) return 0;
for(ll j=5;j*j<=n;j+=6){if(n%j == 0||n%(j+2) == 0) return 0;}return 1;}
 
using namespace std;
void solve(){
   ll n,k;
   cin>>n>>k;
   vl h(n);
   rep(i,n)cin>>h[i];
   vl dp(n,INF);
   dp[0] = 0;
   for(ll i=1;i<n;i++){
      foi(j,max(0LL,i-k),i){
         dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
      }
   }
   cout<<dp[n-1];

}
 
int main() {
   #ifndef ONLINE_JUDGE
      freopen("input.txt", "r" , stdin);
      freopen("output.txt", "w" , stdout);
   #endif
   ios::sync_with_stdio(0); 
   cin.tie(0); cout.tie(0);   
   ll t;
   // cin>>t;
   t = 1;
   ll tc=0;
   while(tc++<t){
      // cout<<"Case #"<<tc<<": ";
      solve();
   }
   cerr<<"Time taken : "<<(double)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
   return 0;
}

Measured memory_bytes: 4748
read N M
julia -E"C=zeros(Int,10^5)
for x=split(readline())
C[parse(Int,x)]+=1end
k=2*10^5
M=$M
s=0
C=reverse(conv(C,C))
for c=C
M-=t=min(M,c)
s+=t*k
k-=1end
s"

Measured memory_bytes: 187004
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
ll lcm(ll x,ll y){
	return x/__gcd(x,y)*y;
}
int main() {
	int n;cin>>n;
	int arr[(int)1e5+5]={};
	loop(n,i,0){
		int x;cin>>x;
		arr[x]++;
	}
	int mx=0;
	loop(1e5+3,i,0){
		mx=max(mx,arr[i]+arr[i+1]+arr[i+2]);
	}
	cout<<mx;
}


Measured memory_bytes: 640
N = int(raw_input())
S = raw_input()
S_sub = S
while ("()" in S):
    S = S.replace("()","")
a = 0
b = 0
for x in S:
    if x == ')':
        a += 1
    else:
        break
for x in S:
    if x == '(':
        b += 1
print "(" * a + S_sub + ")" * b


Measured memory_bytes: 2696
#include <stdio.h>

void swap(int *p)
{
	int tmp = p[0];
	p[0] = p[1];
	p[1] = tmp;
}

int main(void)
{
	int x[3000][2];
	int i, j;
	
	for (i = 0; i <3000; i++) {
		scanf("%d %d", &x[i][0], &x[i][1]);
		if (x[i][0] > x[i][1])
			swap(x[i]);
		if (x[i][0] == 0 && x[i][1] == 0)
			break;
	}
	
	for (j = 0; j < i; j++) {
		printf("%d %d\n", x[j][0], x[j][1]);
	}
	
	return 0;
}

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

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

    if(N%2 == 0)
    {
        cout << double(1)/double(2) << '\n';
    }
    else
    {
        int k = N/2;
        cout << double(k+1)/double(N) << '\n';
    }
}


Measured memory_bytes: 256
w,h,n=map(int,input().split())
pnt=[list(map(int,input().split())) for i in range(n)]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  if pnt[i][2]==1:
    x1=max(x1,pnt[i][0])
  if pnt[i][2]==2:
    x2=min(x2,pnt[i][0])
  if pnt[i][2]==3:
    y1=max(y1,pnt[i][1])
  if pnt[i][2]==4:
    y2=min(y2,pnt[i][1])
print(max(x2-x1,0)*max(y2-y1,0))

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

signed main(){
    int K;
    string S;
    cin>>K>>S;
    rep(i,S.size()){
        S[i]=(S[i]-'A'+K)%26+'A';
    }
    cout<<S<<endl;
    return 0;
}

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


int main(){
  int N,A,B,i,G,K,J;
  scanf("%d",&N) ;
  scanf("%d",&A) ;
  scanf("%d",&B) ;

  for(i=0;i<=N;i++){
    G=A*i;
    K=G ;
    if(K>B){
      K=B ;
      break ;
    }
  }
  printf("%d",K) ;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <deque>

using namespace std;

int main()
{
	int H, W;
	cin >> H >> W;
	int C[2];
	int D[2];
	cin >> C[1] >> C[0] >> D[1] >> D[0];
	C[0] = C[0] - 1;
	C[1] = C[1] - 1;
	D[0] = D[0] - 1;
	D[1] = D[1] - 1;
	vector<vector<int>>S(W, vector<int>(H));
	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			char c;
			cin >> c;
			if (c == '.') {
				S[x][y] = 1;
			}
			else {
				S[x][y] = 0;
			}
		}
	}
	deque<pair<int,int>>stack;
	deque<pair<int, int>>stack2;

	pair<int, int> a(C[0], C[1]);
	S[a.first][a.second] = 4;

	int result = 0;
	while (true) {
		while (true) {
			stack2.push_back(a);
			if (a.second + 1 < H&&S[a.first][a.second + 1] == 1) {
				stack.push_back(a);
				S[a.first][a.second + 1] = 4;
				a.second++;
				continue;
			}
			if (a.second - 1 >=0&&S[a.first][a.second-1] == 1) {
				stack.push_back(a);
				S[a.first][a.second - 1] = 4;
				a.second--;
				continue;
			}
			if (a.first + 1 < W&&S[a.first+1][a.second] == 1) {
				stack.push_back(a);
				S[a.first+1][a.second] = 4;
				a.first++;
				continue;
			}
			if (a.first- 1 >= 0&&S[a.first-1][a.second] == 1) {
				stack.push_back(a);
				S[a.first-1][a.second] = 4;
				a.first--;
				continue;
			}


			if (stack.size() == 0) {
				break;
			}
			a = stack.back();
			stack.pop_back();
		}
		if (S[D[0]][D[1]] == 2 || S[D[0]][D[1]] == 4) {
			cout << result;
			return 0;
		}
		bool frag = false;
		for (int i = 0; i < stack2.size(); i++) {
			int x = stack2[i].first;
			int y = stack2[i].second;
			for (int xx = -2; xx < 3; xx++) {
				for (int yy = -2; yy < 3; yy++) {
					if (xx + x >= 0 && xx + x < W&&yy + y >= 0 && yy + y < H&&S[x + xx][y + yy] == 1) {
						S[x + xx][y + yy] = 4;
						stack.push_back({ x+xx,y+yy });
						frag = true;
					}
				}
			}
		}
		stack2.clear();
		if (!frag) {
			cout << -1;
			return 0;
		}
		a = stack[stack.size() - 1];
		stack.pop_back();
		result++;

	}

}

Measured memory_bytes: 7744
n = int(input())
dic = {}
for i in range(1,n+1):
    s,p = map(str,input().split())
    dic.setdefault(s,[])
    dic[s].append([int(p),i])
#print(dic)
sort_list = sorted(dic)
for key in sort_list:
    sort_item = sorted(dic[key],reverse=True)
    #print(sort_item)
    for i in range(len(sort_item)):
        print(sort_item[i][1])


Measured memory_bytes: 9036
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int C = scanner.nextInt();

        Map<Integer, Integer>[] a = new Map[C];
        int[] count = new int[100002];

        for (int i = 0; i < n; i++) {
            int s = scanner.nextInt();
            int t = scanner.nextInt();
            int c = scanner.nextInt() - 1;

            if (a[c] == null)
                a[c] = new HashMap<>();

            a[c].put(s, a[c].getOrDefault(s, 0) + 1);
            a[c].put(t + 1, a[c].getOrDefault(t + 1, 0) - 1);
        }

        for (int i = 0; i < C; i++) {
            for (int j = 1, t = 0; j < 100002; j++) {
                if (a[i] != null && a[i].containsKey(j))
                    t += a[i].get(j);
                count[j] += Math.min(1, t);
            }
        }

        Arrays.stream(count).max().ifPresent(System.out::println);
    }
}

Measured memory_bytes: 107588
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int mod=1e9+7;
inline void add(int &x,int y){
	x+=y;if(x>=mod)x-=mod;
}
const int maxn=2005*2005;
int inv[maxn],fac[maxn],facinv[maxn];
int f[2005][2005];
inline int C(int n,int m){
	return 1ll*fac[n]*facinv[m]%mod*facinv[n-m]%mod;
}
inline void prprpr(){
	inv[1]=1;
	rep(i,2,2000*2000){
		inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	}
	fac[0]=1;facinv[0]=1;
	rep(i,1,2000*2000){
		fac[i]=1ll*fac[i-1]*i%mod;
		facinv[i]=1ll*facinv[i-1]*inv[i]%mod;
	}
}
int main(){
	prprpr();
	int n,k;read(n);read(k);f[0][0]=1;
	if(k==1){
		puts("1");return 0;
	}
	rep(i,0,n)rep(j,0,i){
		if(i+1<=n)add(f[i+1][j],f[i][j]);
		if(j+1<=i)add(f[i][j+1],1ll*f[i][j]*C(n*k-i-(k-1)*j-1,k-2)%mod);
	}
	printf("%lld\n",1ll*f[n][n]*fac[n]%mod);
    return 0;
}


Measured memory_bytes: 60928
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};


int main() {
    int h, w;
    cin >> h >> w;
    char g[h + 2][w + 2];
    rep(i, h + 2) rep(j, w + 2) g[i][j] = '/';
    for (int i = 1; i < h + 1; i++)
        for (int j = 1; j < w + 1; j++) {
            cin >> g[i][j];
        }

    for (int i = 1; i < h + 1; i++) {
        for (int j = 1; j < w + 1; j++) {
            int cnt = 0;
            rep(k,8){
                if(g[i+my8[k]][j+mx8[k]] == '#'){
                    cnt++;
                }
            }
            if(g[i][j] == '#') cout << '#';
            else cout << cnt;
        }
        cout << endl;
    }
}


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

int main() {
  // Nの入力
  int A,B,C;
  cin >> A >> B >> C;

  string result = "No";

  vector<int> vec = {A,B,C};
  sort(vec.begin(), vec.end());

  A = vec.at(0);
  B = vec.at(1);
  C = vec.at(2);

  if( (A == B && B != C) || (A != B && B == C)){
    result = "Yes";
  }

  cout << result << endl;

}

Measured memory_bytes: 256
a, b, c, k = [0] * 4

def format_input(filename = None):
	global a, b, c, k
	if filename == None:
		a, b, c, k = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		a = rng(0, 2 * 10**9)
		b = rng(0, 2 * 10**9 - a)
		c = rng(max(0, 1-a-b), 2 * 10**9 - a - b)
		k = rng(1, a + b + c)
		print(a, b, c, k)

def get_answer():
	answer = 0

	if a >= k:
		answer = k
	elif a + b >= k:
		answer = a
	else:
		answer = 2 * a + b - k

	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 9164
# -*- coding: utf-8 -*-
import math
Q = int(input())

ls = []
rs = []
for n in range(Q):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)
    num = 0

max_r = max(rs)

def eratos(n):
    if n == 1:
        return set()
    primes = [1 for i in range(n+1)]
    primes[0] = 0
    primes[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if primes[i] == 1:
            j = i + i
            while j <= n:
                primes[j] = 0
                j = j + i
    return primes


def count_similar(era, n):
    count_similar = [0 for i in range(n+1)]
    for i in range(1,n+1):
        count_similar[i] = count_similar[i-1]
        if era[i] == 1 and era[int((i+1)/2)] == 1:
            count_similar[i] += 1
    return count_similar




era = eratos(max_r)
cnt = count_similar(era, max_r)

for l, r in zip(ls, rs):
    print(cnt[r] - cnt[l-1])



Measured memory_bytes: 13324
#include<iostream>
#include <string.h>
#include<string>

using namespace std;

int main()
{
	/*long long h, a, attacks = 0;
	cin >> h >> a;
	while (h > 0)
	{
	attacks++;
	h -= a;
	}
	cout << attacks << endl;*/
	/*long long n;
	string s;
	cin >> n;
	getline(cin, s);
	getline(cin, s);
	char currentchar = s[0];
	int cnt = 1;

	for (int i = 1; i < s.size(); i++)
	{
	if (s[i] != currentchar)
	{
	currentchar = s[i];
	cnt++;
	}
	}

	cout << cnt << endl;*/

	/*int a, b, c;
	cin >> a >> b >> c;
	if ((a == b && a != c) || (a == c && a!=b) || (b == c && b!=a))
	cout << "Yes" << endl;
	else
	cout << "No" << endl;*/

	/*string S;
	getline(cin, S);
	//getline(cin, S);
	bool StingEnd = false;

	while (true)
	{
	int i;
	if (S.empty())
	break;
	for (i = 0; i < S.size()-1; i++)
	{

	if (S[i] == 'S' && S[i + 1] == 'T')
	{
	S.erase(i, 2);
	if (S.empty())
	break;
	//break;
	}
	}
	if (i == S.size()-1)
	break;
	}
	cout << S.size() << endl;*/

	int N, occurrence = 0;
	char S[100];
	cin >> N;
	cin >> S;
	for (int i = 0; i<N - 2; i++)
	{
		if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
			occurrence++;
	}
	cout << occurrence << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;

int main(void)
{
	string S;
	int N, K;
	cin >> N >> K;
	cin >> S;
	S[K - 1] = tolower(S[K - 1]);
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import math
import heapq
from collections import deque
from itertools import combinations
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

H,W=LI()
MP=[input() for _ in range(H)]
CORD=[(i,j) for i in range(H) for j in range(W)]

max_dist = 0
for i in range(len(CORD)):
    st = CORD[i]
    if MP[st[0]][st[1]] == ".":
        QUE=deque()
        visited = [[0]*W for i in range(H)]
        visited[st[0]][st[1]] = 1
        QUE.append((st[0], st[1], 0))
        res = 0
        while QUE:
            ii, jj, dist = QUE.popleft()
            max_dist = max(max_dist, dist)
            for iii, jjj in [(ii-1,jj),(ii+1,jj),(ii,jj-1),(ii,jj+1)]:
                if iii >= 0 and jjj >= 0 and iii < H and jjj < W and MP[iii][jjj] != '#' and not visited[iii][jjj]:
                    QUE.append((iii, jjj, dist+1))
                    visited[iii][jjj] = 1


print(max_dist)


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;
typedef long long ll;

int main(){
    int n;
    while(cin >> n,n) {
        vi a;
        int tmp;
        rep(i,n){
            cin >> tmp;
            a.pb(tmp);
        }
        sort(a.begin(),a.end());
        ll sum = 0;
        REP(i,1,n - 1){
            sum += a[i];
        }
        cout << sum / (n - 2) << endl;
    }
    return 0;
}



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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(ll size) {
        size = max((int) sqrt(size) + 1, 101010);
        prime.resize(size, 1);
        prime[0] = 0;
        prime[1] = 0;
        for (size_t i = 2; i * i <= size; ++i)
            if (prime[i]) {
                for (size_t j = 2; i * j <= size; ++j)prime[i * j] = false;
            }
    }
};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

string s;
ll N, K;
double X[100], Y[100];
double eps = 1e-9;

double fy(double y) {
    double l = -1000, r = 1000, m1 = 0, m2 = 0;
    while (r - l > eps) {
        double x1 = (l * 2 + r) / 3, x2 = (l + r * 2) / 3;
        m1 = 0, m2 = 0;
        REP(i, N) {
            m1 = max(m1, sqrt((x1 - X[i]) * (x1 - X[i]) + (y - Y[i]) * (y - Y[i])));
            m2 = max(m2, sqrt((x2 - X[i]) * (x2 - X[i]) + (y - Y[i]) * (y - Y[i])));
        }
        if (m1 > m2)l = x1;
        else r = x2;
    }
    return max(m1, m2);
}

double fx() {
    double l = -1000, r = 1000;
    while (r - l > eps) {
        double x1 = (l * 2 + r) / 3, x2 = (l + r * 2) / 3;
        if (fy(x1) > fy(x2))l = x1;
        else r = x2;
    }
    return max(fy(l), fy(r));
}


int main() {
    cin >> N;
    REP(i, N)cin >> X[i] >> Y[i];
    printf("%.10f\n", fx());
    return 0;
}


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

using i64 = long long;
using P   = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

} 

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B) {
    atcoder::dsu d(N);
    rep(i, M) {
        A[i]--;
        B[i]--;
        d.merge(A[i], B[i]);
    }
    i64 ans       = 0;
    rep(i, N) ans = max(ans, (i64)d.size(i));
    cout << ans << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0; i < M; i++) {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


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

int main(){
    int n=200, count=0, N;
    int a[n], flag=0;
    cin >> N;
    for(int i=0; i<N; i++) cin >> a[i];
    for(int i=0; i<N; i++){
        if(a[i]%2 ==1){
            flag = 1;
            continue;
            }
            }
    while(flag == 0){
        for(int i=0; i<N; i++){
            a[i] = a[i]/2;
            if(a[i]%2 ==1){
                flag = 1;
                continue;
            }
        }
        count++;
    }
    cout << count << endl;;
}

Measured memory_bytes: 256
from itertools import combinations

n,m,x = map(int,input().split())
cost_lists = [list(map(int,input().split())) for _ in range(n)]

# print(cost_lists)

min_cost = 10**9
unst_flag = False

for i in range(1, n+1):
    combi_lists = list(combinations(range(n), i))

    for combi_list in combi_lists:
        tmp_list = list()
        for j in range(1,m+1):
            tmp_unst = 0
            for k in combi_list:
                tmp_unst += cost_lists[k][j]

            tmp_list.append(tmp_unst)
        
        if min(tmp_list) >= x:
            tmp_cost = 0
            for k in combi_list:
                tmp_cost += cost_lists[k][0]

            min_cost = min(min_cost, tmp_cost)
            unst_flag = True

if unst_flag:
    print(min_cost)
else:
    print(-1)


Measured memory_bytes: 9212