akhauriyash/Code-Regression huggingface dataset:
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<usize>();
    let (n, p) = (line[0], line[1]);
    let a = read_as_vec::<usize>();

    let mut counters: Vec<usize> = vec![0;2];
    for elem in a{
        counters[elem%2] += 1;
    }

    let base: u64 = 2_u64.pow(counters[0] as u32);
    if p == 1{
        if counters[1] == 0{
            println!("0");
            return;
        }else{
            println!("{}", 2_u64.pow(n as u32-1));
        }
    }else{
        if counters[1] == 0{
            println!("{}", base);
        }else{
            println!("{}", 2_u64.pow(n as u32-1));
        }
    }


}


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

int main() {
  int a,b;
  cin>>a;
  vector<string> A(a);
  for(int i=0;i<a;i++){
    cin>>A.at(i);
  }
  cin>>b;
  vector<string> B(b);
  for(int i=0;i<b;i++){
    cin>>B.at(i);
  }
  int max=0;
  for(int i=0;i<a;i++){
    int C=0;
    for(int j=i;j<a;j++){
      if(A.at(i)==A.at(j)){
        C+=1;
      }
    }
    for(int j=0;j<b;j++){
      if(A.at(i)==B.at(j)){
        C-=1;
      }
    }
    if(C>max){
      max=C;
    }
  }
  cout<<max<<endl;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (int i = 0; i <n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i <n; i++) {
        cin >> b[i];
    }

    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > b[i]) {
            if (b[i] + cnt >= a[i]) {
                cnt -= a[i] - b[i];
                continue;
            }
            b[i] += max(cnt, 0LL);
            cnt = min(cnt, 0LL);
            cnt -= (a[i] - b[i]);
        } else {
            cnt += (b[i] - a[i]) / 2;
        }
    }
    cout << (cnt >= 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
	return 0;
}

Measured memory_bytes: 3584
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var: ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        d: usize,
        x: [[i64; d]; n],
    }
    let mut ans = 0;
    for i in 0..n {
        for j in i + 1..n {
            let dist = (0..d)
                .map(|k| (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]))
                .sum::<i64>();
            let dist_sqrt = (dist as f64).sqrt() as i64;
            if dist == dist_sqrt * dist_sqrt {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
#include <string.h>
using namespace std;

#define N 100005
#define mod 1000000007

int add(int x,int y) {
  int ret = (x+y);
  if(ret<0) {
    ret += mod;
  }
  if(ret>=mod) {
    ret -= mod;
  }
  return ret;
}

int mul(int x,int y) {
  return (long long)x*y%mod;
}

int mypow(int x,int c) {
  int ret = 1;
  while(c>0) {
    if(c&1) {
      ret = mul(ret,x);
    }
    c/=2;
    x = mul(x,x);
  }
  return ret;
}

char s[N];
int dp[N][2];
void solve() {
  scanf("%s ", s);
  int n = strlen(s);
  dp[0][1] = 1;

  for(int i=0;i<n;++i) {
    for(int st=0;st<2;++st) {
      int lim = 2;
      if(st==1 && s[i]=='0') {
        lim = 1;
      }

      for(int bit=0;bit<lim;++bit) {
        int nst = st & ( (char('0'+bit)==s[i]) );
        dp[i+1][nst] = add(dp[i+1][nst], dp[i][st]);
        if(bit==1) {
          dp[i+1][nst] = add(dp[i+1][nst], dp[i][st]);
        }
      }
    }
  }
  int ret = add(dp[n][1],dp[n][0]);
  printf("%d\n", ret);
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Measured memory_bytes: 1152
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    a=sys.stdin.readlines()
    #print(a)
    N,X=int(a[0].rstrip()),a[-1].rstrip()
    #print(N)
    slept=0
    ans=0
    for i in range(1,1+N):
        t,l=a[i].rstrip().split()
        #print(t,l)
        
        if slept:ans+=int(l)
        if t==X:slept=1
    print(ans)
#%%submit!
resolve()

Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int main() {
	LL n;
	cin >> n;
	LL ret = 0;
	for(LL k =1; k*k <= n; k++){
		if (n % k == 0) {
			LL m = n / k - 1;
			if(m!=0)if(n /m == n %m)ret += m;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
#define int  long long
#define endl '\n'
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const int N = 1e6 + 10;

struct IOsetup{
  IOsetup(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
}IO;

int32_t main(){
  int n;
  cin >> n;
  if (n <= 1 or n % 2){
    cout << 0 << endl;
    exit(0);
  }
  int ret = 0;
  int den = 5 * 2;
  while (den <= n){
    ret += n / den;
    den *= 5;
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(a,l,r) (l<=a && a<=r)
using namespace std;
typedef long long ll;
typedef long double D;

ll n;
pair<ll,ll> c[100100];
int use[100100];
const ll inf = 1e15;
const D sq2 = sqrt(2), PI = acos(-1), EPS = 1e-8;

int main(){
  scanf("%lld",&n);
  ll maxy = -inf, miny = inf;
  pair<ll,ll> left(inf,inf);

  for(int i=0;i<n;i++){
    scanf("%lld%lld",&c[i].first,&c[i].second);
    complex<D> p(c[i].first,c[i].second);
    p *= complex<D>(cos(PI/4),sin(PI/4));
    c[i].first = (ll)(p.real() * sq2 + (p.real()>0?+EPS:-EPS));
    c[i].second = (ll)(p.imag() * sq2) + (p.imag()>0?+EPS:-EPS);

    maxy = max(maxy, c[i].second);
    miny = min(miny, c[i].second);
    left = min(left, c[i]);
  }
  
  ll l=-1,r=1e6;
  while(r-l>1){
    ll mid = (l+r)/2;

    bool ok = false;
    if(maxy <= left.second + mid){
      memset(use,0,sizeof(use));
      for(int i=0;i<n;i++){
	if( range(c[i].first, left.first, left.first+mid)
	    && range(c[i].second, maxy-mid, maxy) )use[i] = 1;
      }

      ll rl = inf, rr = -inf, rd = inf, ru = -inf;
      for(int i=0;i<n;i++){
	if(!use[i]){
	  rl = min(rl, c[i].first); rr = max(rr, c[i].first);
	  rd = min(rd, c[i].second); ru = max(ru, c[i].second);
	}
      }
      if(rr-rl<=mid && ru-rd<=mid)ok = true;
    }

    if(miny >= left.second - mid){
      memset(use,0,sizeof(use));
      for(int i=0;i<n;i++){
	if( range(c[i].first, left.first, left.first+mid)
	    && range(c[i].second, miny, miny+mid) )use[i] = 1;
      }

      ll rl = inf, rr = -inf, rd = inf, ru = -inf;
      for(int i=0;i<n;i++){
	if(!use[i]){
	  rl = min(rl, c[i].first); rr = max(rr, c[i].first);
	  rd = min(rd, c[i].second); ru = max(ru, c[i].second);
	}
      }
      if(rr-rl<=mid && ru-rd<=mid)ok = true;
    }

    if(ok)r = mid;
    else l = mid;
  }

  cout << r << endl;
}

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

int const N = 300000;
int x[N + 1], n, a, b;

void fn(int a, int l){
	int i = 1, sg = n + a, st = n + a + 1;
	while (i <= n){
		if (st <= sg){
			if (i != 1)printf(" ");
			printf("%d", x[st]);
			++st;
			++i;
		}
		else if (i <= l){
			sg -= a;
			st = sg - min(a - 1, l - i);
		}
		else {
			while (i <= n){
				printf(" %d", x[n - i + 1]);
				++i;
			}
		}
	}
	printf("\n");
	exit(0);
}

int main(){
	scanf("%d%d%d", &n, &a, &b);
	f(i, 1, n + 1)x[i] = i;
	f(i, a, n + 1){
		int o = (i + a - 1) / a + n - i;
		if (o == b)fn(a, i);
	}
	reverse(x + 1, x + n + 1);
	swap(a, b);
	f(i, a, n + 1){
		int o = (i + a - 1) / a + n - i;
		if (o == b)fn(a, i);
	}
	printf("-1\n");
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using namespace std;
int ans;
string s;
int main(){
	cin>>s;
	for(int i =0;i<s.size();i++){
		if(s[i]=='?')s[i]='D';
	}
	cout<<s<<endl;

}

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

using namespace std;

typedef long long  ll;

int n, q;
vector<int> a;

int Solve(int pos, int sum, const int m)
{
    if (m == sum)
        return true;
    else if (m < sum)
        return false;

    if (pos == n)
        return false;

    if (Solve(pos + 1, sum + a[pos], m))
        return true;
    if (Solve(pos + 1, sum, m))
        return true;

    return false;
}

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

    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    int m;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> m;
        if (Solve(0, 0, m))
            cout << "yes\n";
        else
            cout << "no\n";
    }

    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	int gs[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
	vector<int> a(m);
	for( auto &k : a ) cin >> k;
	sort( a.begin(), a.end(), greater<int>() );
	vector<int> dp(12345, -10000);
	dp[0] = 0;
	for( int i = 2; i <= n; ++i ){
		for( int j = 0; j < m; ++j ){
			if( i >= gs[a[j]] ){
				dp[i] = max(dp[i], dp[i-gs[a[j]]] + 1);
			}
		}
	}
	/*
	for( int i = 0; i <= n; ++i ){
		cout << "dp[" << i << "]: " << dp[i] << endl;
	}
	*/
	const int bound = dp[n];
	for( int i = 0; i < bound; ++i ){
		for( int j = 0; j < m; ++j ){
			if( n - gs[a[j]] >= 0 && dp[n] == dp[n-gs[a[j]]] + 1 ){
				cout << a[j];
				n -= gs[a[j]];
				// cout << "match: " << a[j] << endl;
				// cout << "n left: " << n << endl;
				break;
			}
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
lists1 = []
lists2 = []
N.times do
  s, t, u = gets.split.map(&:to_i)
  if u != 0
    lists1 << [s, t, u]
  else
    lists2 << [s, t, u]
  end
end

(0..100).each do |i|
  (0..100).each do |j|
    pre = nil
    check = true
    dist = nil
    lists1.each do |x, y, z|
      dist = z + (i - x).abs + (j - y).abs
      if (pre ||= dist) != dist
        check = false
        break
      end
    end
    next if !check

    lists2.each do |x, y, z|
      dist = (i - x).abs + (j - y).abs
      if pre > dist
        check = false
        break
      end
    end
    if check
      puts "#{i} #{j} #{pre}"
      exit
    end
  end
end

Measured memory_bytes: 1788
#include <iostream>
#include <map> 
#include <numeric>
using namespace std;
using LL = long long;

const LL MOD = 1000000007;

using std::ostream;

template<int N = 1000000007>
struct ModInt {
    long long v;
    ModInt() {
        this->v = 0;
    }
    ModInt(signed long long v) {
        signed long long w = v % N;
        if(w < 0) w += N;
        this->v = w;
    }
    bool operator==(const ModInt& rhs) {
        return this->v == rhs.v;
    }
    ModInt& operator+=(ModInt rhs) {
        if((this->v += rhs.v) >= N) {
            this->v -= N;
        }
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if((this->v -= rhs.v) < 0) {
            this->v += N;
        }
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        this->v = this->v * rhs.v % N;
        return *this;
    }
    ModInt& operator++() {
        if(this->v >= N - 1) this->v = 0;
        else ++this->v;
        return *this;
    }
    ModInt& operator--() {
        if(this->v <= 0) this->v = N - 1;
        else --this->v;
        return *this;
    }
    ModInt operator++(int) {
        ModInt ret = *this;
        ++*this;
        return ret;
    }
    ModInt operator--(int) {
        ModInt ret = *this;
        --*this;
        return ret;
    }

    ModInt operator+(ModInt rhs) const {
        return ModInt(*this) += rhs;
    }
    ModInt operator-(ModInt rhs) const {
        return ModInt(*this) -= rhs;
    }
    ModInt operator*(ModInt rhs) const {
        return ModInt(*this) *= rhs;
    }
    ModInt pow(ModInt const& mi) const {
        return this->pow(mi.v);
    }
    ModInt pow(long long n) const {
        ModInt tmp = *this;
        ModInt ans = 1;
        while(n > 0) {
            if(n & 1) ans *= tmp; 
            tmp *= tmp;
            n >>= 1;
        }
        return ans;
    }

    template<int _N>
        friend ostream& operator<<(ostream& os, const ModInt<_N>& mi);
};
template<int N>
ostream& operator<<(ostream& os, const ModInt<N>& mi) {
    os << mi.v;
    return os;
}
using mint = ModInt<>;

LL N;
map<pair<LL, LL>, pair<mint, mint>> m;

int main() {
    cin >> N;
    int ans0 = 0;
    for(int i = 0; i < N; ++i) {
        LL x, y;
        scanf("%lld%lld", &x, &y);
        if(x == 0 && y == 0) {
            ans0++;
            continue;
        }

        LL g = gcd(x, y);
        x /= g;
        y /= g;

        if(y < 0 || (y == 0 && x < 0)) {
            x *= -1;
            y *= -1;
        }
        bool rot = false;
        if(x <= 0) {
            rot = true;
            LL tmp = x;
            x = y;
            y = -tmp;
        }

        if(rot) {
            m[{x, y}].second += 1;
        } else {
            m[{x, y}].first += 1;
        }
    }

    mint ans = 1;
    for(const auto& p : m) {
        mint tmp = 1;
        tmp += mint(2).pow(p.second.first) - 1;
        tmp += mint(2).pow(p.second.second) - 1;
        ans *= tmp;
    }
    ans -= 1;
    ans += ans0;

    cout << ans << endl;
}


Measured memory_bytes: 19116
n,m=map(int,input().split())
array=[]
cost=0
for i in range(n):
    a,b=map(int,input().split())
    array.append([a,b])
array.sort()
for i in array:
    if m<=i[1]:
        cost+=i[0]*m
        break
    else:
        cost+=i[0]*i[1]
        m-=i[1]
        
print(cost)

Measured memory_bytes: 20056
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<set>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;

int main(){//A
    /*
    string s;
    string t;
    cin>>s>>t;
    if(t.substr(0,s.length())==s) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    */
   //B
   int a,b,c,k;
   cin>>a>>b>>c>>k;
   if(k<=a) cout<<k<<endl;
   else if(k<=a+b) cout<<a<<endl;
   else cout<<a-(k-a-b)<<endl;
}

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

const int cnMaxArray = 1000033;

long long fnStrToLnglng(string sKey)
{
  int iElement;
  int iBase = 1;
  long long llKey = 0;
  for (int i = sKey.size() - 1; i >= 0; i--)
  {
    switch (sKey[i])
    {
      case  'A': iElement = 1;
                 break;
      case  'C': iElement = 2;
                 break;
      case  'G': iElement = 3;
                 break;
      case  'T': iElement = 4;
                 break;
      default:   iElement = 0;
    }
    llKey += iBase * iElement;
    iBase *= 5;
  }
  return llKey;
}

int fnHash1(long long a_llKey) { return (a_llKey % cnMaxArray); }
int fnHash2(long long a_llKey) { return (1 + (a_llKey % (cnMaxArray - 1))); }

void fnDictionary(string a_stasDictionary[])
{
  int iCommandCnt;
  cin >> iCommandCnt;

  for (int i = 0; i < iCommandCnt; i++)
  {
    string sCommand;
    string sKey;
    cin >> sCommand >> sKey;

    long long llKey = fnStrToLnglng(sKey);
    int iCnt = 0;
    for (iCnt = 0; ;iCnt++)
    {
      int ix = (fnHash1(llKey) + iCnt * fnHash2(llKey)) % cnMaxArray;
      if (a_stasDictionary[ix] == sKey)
      {
        if (sCommand[0] == 'i')
          break;
        else if (sCommand[0] == 'f')
        {
          cout << "yes" << endl;
          break;
        }
      }
      else if (a_stasDictionary[ix].size() == 0)
      {
        if (sCommand[0] == 'i')
        {
          a_stasDictionary[ix] = sKey;
          break;
        }
        else if (sCommand[0] == 'f')
        {
          cout << "no" << endl;
          break;
        }
      }
    }
  }
}

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

  static string stasDictionary[cnMaxArray];
  fnDictionary(stasDictionary);
  
  return 0;
}

Measured memory_bytes: 21948
import numpy as np
N,K,Q=map(int,input().split())
A=[int(input()) for i in range(Q)]

if K-Q<=0:
  L=[K-Q for i in range(N)]
  for i in range(Q):
    L[A[i]-1]=L[A[i]-1]+1
  for i in range(N):
    if L[i]>0:
      print('Yes')
    else:
      print('No')
else:
  for i in range(N):
    print('Yes')

Measured memory_bytes: 34460
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
int a[110];
int ans,mn=INF;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=100;i++){
		int cur=0;
		for(int j=1;j<=n;j++)cur+=(a[j]-i)*(a[j]-i);
		if(mn>cur)ans=i,mn=cur;
	}
	cout<<mn<<endl;
	return 0;
}


Measured memory_bytes: 256
/**
 *	author:		Yoseph Weissman
 *	created:	27.06.2020 19:54:07
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a;
	cin >> a;
	cout << a + a*a + a*a*a << "\n";
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//long long MOD = 1e9 + 7;

long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;


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

    ll n;
    cin >> n;
    vector<double> x(n);
    vector<double> y(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
        cin >> y[i];
    }

    auto distance = [](double x_i, double x_j, double y_i, double y_j) -> double {
        return std::sqrt((x_i - x_j) * (x_i - x_j) + (y_i - y_j) * (y_i - y_j));
    };

    double ans = 0.0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            ans += distance(x[i], x[j], y[i], y[j]) / (double)n;
        }
    }
    cout << std::setprecision(9) << ans << endl;
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var nk = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        var p = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        if(p.Length == 1)
        {
            Console.WriteLine(p[0]);
            return;
        }

        if(p.Length == 2)
        {
            if(k == 1)
            {
                Console.WriteLine(Math.Min(p[0], p[1]));
                return;
            }
            else
            {
                Console.WriteLine(p[0]+p[1]);
                return;
            }
        }

        p = p.OrderBy(t => t).ToArray();

        var mins = p.Take((int)k);

        Console.WriteLine(mins.Sum());
    }
}


Measured memory_bytes: 28600
// https://atcoder.jp/contests/abc168/tasks/abc168_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N, M;
  cin >> N >> M;

  VVL edge_list(N, VL());

  rep(i, M) {
    ll u, v;
    cin >> u >> v;
    --u, --v;
    edge_list[u].emplace_back(v);
    edge_list[v].emplace_back(u);
  }

  // 見終えた点を push
  queue<ll> q;
  q.emplace(0);

  VL res(N, -1);

  while (!q.empty()) {
    ll u = q.front();
    q.pop();

    for (ll v : edge_list[u]) {
      unless(res[v] == -1) continue;
      res[v] = u;
      q.emplace(v);
    }
  }

  cout << "Yes"
       << "\n";

  rep(i, N) {
    if (i == 0) continue;
    cout << res[i] + 1 << "\n";
  }
}


Measured memory_bytes: 12928
#include <stdio.h>
int main()
{
  int a,b,d,r;
  double f;
  
  scanf("%d%d",&a,&b);
  
  d=a/b;
  r=a%b;
  f=(double)a/(double)b;
  
  printf("%d %d %f\n",d,r,f);
  
  return 0;
  
}

Measured memory_bytes: 632
#ABC097B
x = int(input())
ans=[1]
i =1
while i <= x//2:
    i += 1
    j = 1
    tmp = 0
    while True:
        j+=1
        tmp = i**j
#         print(i,j,tmp)
        if tmp<=x:
            ans.append(tmp)
        else:
            break
print(max(ans))

Measured memory_bytes: 3060
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

V<ll> ans;
VV<PLL> edges;

void dfs(ll now, ll pre, bool col) {
    ans[now] = (ll)col;
    for(PLL ele : edges[now]) {
        ll nxt, w;
        tie(nxt, w) = ele;
        if(nxt == pre) continue;
        dfs(nxt, now, (w & 1 ? !col : col));
    }
}

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

    ans.resize(N);
    edges.resize(N);

    for(ll i = 1; i < N; i++) {
        ll u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        edges[u].emplace_back(v, w);
        edges[v].emplace_back(u, w);
    }

    dfs(0, -1, true);
    for(ll e : ans) cout << e << endl;
    return 0;
}


Measured memory_bytes: 10752
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int[] arr = new int[] { int.Parse(input[0]), int.Parse(input[1]), int.Parse(input[2]) };
    Array.Sort(arr);
    Console.WriteLine(arr[0]+arr[1]);
  }
}

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << " : " << x << endl;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

template<class T,class U> void chmax(T& a, U b) {if(a<b)a=b;}
template<class T,class U> void chmin(T& a ,U b) {if(b<a)a=b;}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int a,b;
    cin>>a>>b;

    string sa = "", sb="";
    rep(i, b) sa += (char)(a + '0');
    rep(i, a) sb += (char)(b + '0');
    vector<string> v;
    v.push_back(sa);
    v.push_back(sb);
    sort(all(v));
    cout << v[0] << endl;

    return 0;
}


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

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

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

int main() {
  int n, k;
  cin >> n >> k;
  int r, s, p;
  cin >> r >> s >> p;
  string t;
  cin >> t;

  string t_sub[k];
  rep(i, n) {
    int mod = i % k;
    t_sub[mod] += t[i];
  }

  ll ans = 0;

  rep(i, k) {
    string t_tmp = t_sub[i];

    // dp[i][j]: i回目にjを出した時にi回目までに得られる最高得点
    int dp[100010][3];
    dp[0][0] = 0; // 0: グー, 1: チョキ, 2: パー
    dp[0][1] = 0; // 0: グー, 1: チョキ, 2: パー
    dp[0][2] = 0; // 0: グー, 1: チョキ, 2: パー
    repi(j, 1, t_tmp.size() + 1) {
      if (t_tmp[j - 1] == 'r') {
        dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]);
        dp[j][1] = max(dp[j - 1][2], dp[j - 1][0]);
        dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]) + p;
      } else if (t_tmp[j - 1] == 's') {
        dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]) + r;
        dp[j][1] = max(dp[j - 1][2], dp[j - 1][0]);
        dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]);
      } else if (t_tmp[j - 1] == 'p') {
        dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]);
        dp[j][1] = max(dp[j - 1][2], dp[j - 1][0]) + s;
        dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]);
      }
    }
    ans +=
        max(dp[t_tmp.size()][0], max(dp[t_tmp.size()][1], dp[t_tmp.size()][2]));
  }

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


Measured memory_bytes: 5120
from collections import deque

MOD = 10**9 + 7

N = int(input())
G = [[] for i in range(N)]
G0 = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    G[x-1].append(y-1)
    G[y-1].append(x-1)

I = []
que = deque([0])
used = [0]*N; used[0] = 1
while que:
    v = que.popleft()
    gv = G0[v]
    I.append(v)
    for w in G[v]:
        if used[w]:
            continue
        gv.append(w)
        used[w] = 1
        que.append(w)
dp = [None for i in range(N)]
for v in reversed(I):
    r0 = r1 = 1
    for w in G0[v]:
        a, b = dp[w]
        r0 = (r0 * (a + b)) % MOD
        r1 = (r1 * a) % MOD
    dp[v] = (r0, r1)
print(sum(dp[0]) % MOD)

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

using namespace std;
using ll = long long;

int main()
{
    int n,i,j;
    cin >> n;

    int a[n+1];
    int b[200005] = {0};
    for(i=2; i<=n; i++){
        cin >> a[i];
        b[a[i]]++;
    }

    for(i=1; i<=n; i++){
        cout << b[i] << endl;
    }
    
    return 0;
}

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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)

int N, Q;
vector<vector<int>> g;
vector<int> ans, homon;
void dfs(int v, int x){
  ans[v] += x;
  x = ans[v];
  homon[v] = 1;
  for(auto nv : g[v]){
    if(homon[nv]) continue;
    dfs(nv, x);
  }
}
int main(){
  cin >> N >> Q;
  g.resize(N);
  REP(i, N-1){
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ans.resize(N, 0);
  while(Q--){
    int p, x;
    cin >> p >> x;
    p--;
    ans[p]+= x;
  }
  homon.resize(N, 0);
  dfs(0, 0);
  REP(i, N){
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 21120
#include<bits/stdc++.h>
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define int	    int64_t
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
int n,i,j,k,l,sum=0,flag=0,t,ans=0,w[101],v[101],W;
int dp[101][100001];
int f(int pos , int weight){
	if(pos==n)
		return 0;
	if(dp[pos][weight]!=-1)
		return dp[pos][weight];
	int ans= 0 ;
	if(weight+w[pos]<=W)
		ans=v[pos]+f(pos+1,weight+w[pos]);
	ans=max(ans,f(pos+1,weight));
	return dp[pos][weight] = ans;
}
void solve(){
	memset(dp,-1,sizeof dp);
    cin>>n>>W;
    for(int i=0;i<n;i++){
    	cin>>w[i]>>v[i];
    }
    cout<<f(0,0)<<endl;
}
signed main()
{
    ios
    int test = 1;
    //cin>>test;
    while(test--){
    	solve();
    }
    return 0;
}

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

int main() {
  int n;string s;
  cin >> n;
  cin >> s;
  bool flg = true;
  int harf = n /2;
  if(n % 2 != 0) flg = false;
  for(int i = 0; i < harf; i++){
    if(s[i] != s[i+harf]) flg = false;
  }
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int n, m;
bool a[100010];

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=0; i<2*m; ++i){
		int t;
		cin >> t;
		a[t] = !a[t];
	}
	for(int i=0; i<n; ++i)
		if(a[i]){
			cout << "NO\n";
			return 0;
		}
	cout << "YES\n";
}

Measured memory_bytes: 384
from collections import deque
while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    *S, = map(int, input().split())
    D = sorted(map(int, input().split()))

    SA = sum(S)
    rest = sum(d-SA for d in D if SA <= d)

    memo = {2**n-1: rest}
    def dfs(state, su, idx):
        if state in memo:
            return memo[state]
        res = 10**18
        for i in range(n):
            if (state >> i) & 1 == 0:
                s = 0; j = idx
                nxt = su + S[i]
                while j < m and D[j] <= nxt:
                    s += min(nxt - D[j], D[j] - su); j += 1
                res = min(res, s + dfs(state | (1 << i), su + S[i], j))
        memo[state] = res
        return res
    print(dfs(0, 0, 0))

Measured memory_bytes: 13008
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n,m;
	cin>>n>>m;
	if(n==1||m==1)
		cout<<1;
	else
		cout<<n*m/2+((n*m)%2);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1000000007;
int a[10001];
int res[10001];
int sum[10001];
signed main()
{
	int n,k;
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		for(int j=1;j<=i;j++)
			if(a[j]>a[i])
				res[i]++;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
			if(a[j]>a[i])
				sum[i]++;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=1ll*(1ll*k*(k-1)/2)%mod*sum[i]%mod;
		ans%=mod;
		ans+=1ll*k*res[i]%mod;
		ans%=mod;
	}
	printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////
int main(){
    long long n, W;
    cin >> n >> W;
    vector<long long> w(n+1), v(n+1);
    for (int i = 1;i <= n;i++){
        cin >> w[i] >> v[i];
    }
    vector<long long> dp(n*1e3 + 1, 1e18);
    dp[0] = 0;
    for (int i = 1;i <= n;i++){
        for (int j = n*1e3;j >= v[i];j--){
            if (j - v[i] >= 0) {
                dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
            }
        }
    }
    long long ans = 0;
    for (int i = n * 1e3;i >= 1;i--){
        if (dp[i] <= W){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{

    int a[7],k;
    for(int i=0;i<5;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d",&k);
    sort(a,a+5);
    if(a[4]-a[0]>k) printf(":(");
    else printf("Yay!");

    return 0;
}


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

using namespace std;

int main() {
	int n, x[100] = { 0 }, y[100] = { 0 }, i;
	double Dinf = 0, D1 = 0, D2 = 0, D3 = 0;
	cin >> n;
	for (i = 0; i<n; i++){
		cin >> x[i];
	}
	for (i = 0; i<n; i++){
		cin >> y[i];
	}
	for (i = 0; i<n; i++) {
		D1 += abs(x[i] - y[i]);
		D2 += pow(x[i] - y[i], 2);
		D3 += pow(abs(x[i] - y[i]), 3);
		Dinf = max((double)abs(x[i] - y[i]), Dinf);
	}
	printf("%.8f %.8f %.8f %.8f\n", D1, sqrt(D2), cbrt(D3), Dinf);
}

Measured memory_bytes: 1272
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
using namespace std;

int n, m;
int a[50], b[50];
int c[50], d[50];

signed main() {
	int i, j;
	
	cin >> n >> m;
	for (i = 0; i < n; i++) cin >> a[i] >> b[i];
	for (i = 0; i < m; i++) cin >> c[i] >> d[i];
	
	for (i = 0; i < n; i++) {
		int minDist = 1145141919;
		int id = -1;
		for (j = 0; j < m; j++) {
			int dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (dist < minDist) {
				minDist = dist;
				id = j;
			}
		}
		cout << id + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  cin >> N >> A;
  B = N % 500;
	if (A >= B) {
		cout << "Yes" << endl;
		}
 	else {
      cout << "No" << endl;
    }
}

Measured memory_bytes: 3596
n=int(input())
t,a=map(int,input().split())
hlist=list(map(int,input().split()))
def temp(t,x):
  temp = t-0.006*x
  return temp

diff = []
min=1000000
index=0
diff = 0
for i,h in enumerate(hlist):
  diff = abs(temp(t,h) - a)
  if min > diff:
    min = diff
    index = i
print(index+1)
    

Measured memory_bytes: 38256
#include <iostream>

using namespace std;

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

    int A;
    bool ans = true;
    for (int i = 0; i < N; i++) {
        cin >> A;
        if (A % 2 == 0) {
            if ((A % 3 != 0) && (A % 5 != 0)) {
                ans = false;
                break;
            }
        }
    }

    cout << (ans ? "APPROVED" : "DENIED") << endl;
}

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

int main() {
    int a[3], b[3], c[3];
    for (int i = 0; i < 3; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < 3; i++) {
        scanf("%d", &b[i]);
    }
    for (int i = 0; i < 3; i++) {
        scanf("%d", &c[i]);
    }
    string ans = "Yes";
    int tmp;
    if (a[0] < b[0]) {
        tmp = b[0] - a[0];
        a[0] += tmp;
        a[1] += tmp;
        a[2] += tmp;
    }
    if (a[0] > b[0]) {
        tmp = a[0] - b[0];
        b[0] += tmp;
        b[1] += tmp;
        b[2] += tmp;
    }
    if (a[0] > c[0]) {
        tmp = a[0] - c[0];
        c[0] += tmp;
        c[1] += tmp;
        c[2] += tmp;
    }
    if (a[0] < c[0]) {
        tmp = c[0] - a[0];
        a[0] += tmp;
        a[1] += tmp;
        a[2] += tmp;
        b[0] += tmp;
        b[1] += tmp;
        b[2] += tmp;
    }
    for (int i = 0; i < 3; i++) {
        if (a[i] != b[i] || a[i] != c[i] || b[i] != c[i]) ans = "No";
    }


    cout << ans << endl;

    
    
    return 0;
}


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

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

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  int h,w; cin >> h >> w;
  char s[h][w]; for(int i=0;i<h;i++) { cin >> s[i]; }

  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      if(s[i][j] == '#') { continue; }

      int cnt=0;
      for(int k=i-1;k<i+2;k++) {
        if(k < 0 || k > h-1) { continue; }
        for(int l=j-1;l<j+2;l++) {
          if(l < 0 || l > w-1) { continue; }
          if(s[k][l] == '#') { cnt++; }
        }
      }

      s[i][j] = '0' + cnt; //cout << cnt << endl;
    }
  }

  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) { cout << s[i][j]; }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
def main():
    from itertools import accumulate as ac
    n = int(input())
    s = input()
    R_list = [0]*n
    G_list = [0]*n
    B_list = [0]*n
    for i, j in enumerate(s):
        if j == "R":
            R_list[i] += 1
        elif j == "G":
            G_list[i] += 1
        else:
            B_list[i] += 1
    R_list = list(ac(R_list[::-1]))[::-1]
    G_list = list(ac(G_list[::-1]))[::-1]
    B_list = list(ac(B_list[::-1]))[::-1]
    RG_list = [0]*n
    RB_list = [0]*n
    GR_list = [0]*n
    GB_list = [0]*n
    BR_list = [0]*n
    BG_list = [0]*n
    for i, j in enumerate(s[:-1]):
        if j == "R":
            RG_list[i] += G_list[i+1]
            RB_list[i] += B_list[i+1]
        elif j == "G":
            GR_list[i] += R_list[i+1]
            GB_list[i] += B_list[i+1]
        else:
            BR_list[i] += R_list[i+1]
            BG_list[i] += G_list[i+1]
    RG_list = list(ac(RG_list[::-1]))[::-1]
    RB_list = list(ac(RB_list[::-1]))[::-1]
    GR_list = list(ac(GR_list[::-1]))[::-1]
    GB_list = list(ac(GB_list[::-1]))[::-1]
    BR_list = list(ac(BR_list[::-1]))[::-1]
    BG_list = list(ac(BG_list[::-1]))[::-1]
    ans = 0
    for i in range(n-1):
        if s[i] == "R":
            ans += GB_list[i+1]
            ans += BG_list[i+1]
        elif s[i] == "G":
            ans += RB_list[i+1]
            ans += BR_list[i+1]
        else:
            ans += RG_list[i+1]
            ans += GR_list[i+1]
    for i in range(n):
        for j in range(i+1, n):
            k = 2*j-i
            if k >= n:
                continue
            else:
                if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                    ans -= 1
    print(ans)


main()


Measured memory_bytes: 69308
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

bool f(ll n, vll& a){
  ll tmp = 1;
  REP(i,0,n){
    tmp -= a[i];
    if(tmp < 0){
      return false;
    }
    tmp *= 2;
    if(tmp > 1e14){
      return true;
    }
  }
  return true;
}

ll g(ll n, vll& a, ll sm){
  ll ans = 0;
  ll cur = 1;
  REP(i,0,n){
    ans += cur;
    cur -= a[i];
    sm -= a[i];
    if(cur * 2 >= sm){
      cur = sm;
    }else{
      cur *= 2;
    }
  }
  return ans;
}

int main(){
  ll n;
  cin >> n;
  vll a(n+1);
  ll sm = 0;
  REP(i,0,n){
    cin >> a[i];
    sm += a[i];
  }
  bool dekiru = f(n,a);
  if(!dekiru){
    cout << -1 << endl;
    return 0;
  }
  cout << g(n, a, sm) << endl;
  
}

Measured memory_bytes: 4052
#include <stdio.h>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <utility>

using namespace std;

#define pb push_back
#define ft first
#define sd second
#define mpr make_pair
#define all(x) begin((x)), end((x))
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define max3(a, b, c) max((a), max((b), (c)))
#define max4(a, b, c, d) max(max((a), (b)), max((c), (d)))
#define min3(a, b, c) min((a), min((b), (c)))
#define min4(a, b, c, d) min(min((a), (b)), min((c), (d)))
#define isz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;

/* <------------------------------------------------------------------------------------> */

map<int, int> cnt;

void solve()
{
    int n;
    scanf("%d", &n);
    forn (i, n)
    {
        int a;
        scanf("%d", &a);
        ++cnt[a];
    }
    ll ans = 0;
    for (auto i : cnt) if (i.sd >= 4) ans = max(ans, 1LL * i.ft * i.ft);
    int a = -1, b = -1;
    for (auto i : cnt) if (i.sd >= 2)
    {
        if (i.ft > a)
        {
            b = a;
            a = i.ft;
        }
        else if (i.ft > b) b = i.ft;
    }
    if (a != -1 && b != -1) ans = max(ans, 1LL * a * b);
    printf("%lld", ans);
}

/* <------------------------------------------------------------------------------------> */

// #define LOCAL
// #define FILE_NAME

int main()
{
    #if defined LOCAL
        freopen("input.txt", "r", stdin);
    #elif defined FILE_NAME
        freopen(FILE_NAME".in", "r", stdin);
        freopen(FILE_NAME".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 4992
def dfs(i, n):
    if n < 6:
        return i + n
    k = 1
    while k * 6 <= n:
        k *= 6
    l = 1
    while l * 9 <= n:
        l *= 9
    return min(dfs(i + 1, n - k), dfs(i + 1, n - l))

N = int(input())
print(dfs(0, N))

Measured memory_bytes: 3060