akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a




class SegmentTree:
    def __init__(self, init_val, ide_ele, op):
        n = len(init_val)
        self.num = 2 ** (n - 1).bit_length()
        self.seg = [ide_ele] * 2 * self.num
        self.ide_ele = ide_ele
        self.op = op
        for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]
            # built
        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.op(self.seg[2 * i + 1], self.seg[2 * i + 2])


    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k + 1:
            k = (k - 1) // 2
            self.seg[k] = self.op(self.seg[k * 2 + 1], self.seg[k * 2 + 2])


    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.op(res, self.seg[p])
            if q & 1 == 1:
                res = self.op(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.op(res, self.seg[p])
        else:
            res = self.op(self.seg[p], self.op(res, self.seg[q]))
        return res



n = I()
L = LI()
ST = SegmentTree(L, 0, gcd)
print(max([gcd(ST.query(0, i), ST.query(i + 1, n)) for i in range(n)]))




Measured memory_bytes: 68196
def factorize(n):
    ans=[]
    while n%2==0:
        ans.append(2)
        n//=2
    f=3
    while f**2<=n:
        if n%f==0:
            ans.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        ans.append(n)
    return ans

n=int(input())
import collections

count=0
for i in range(1,n+1):
    if i%2==0:
        continue
    ans = collections.Counter(factorize(i))
    ans = ans.values()
    hoge=1
    for j in ans:
        hoge*=(j+1)
    if hoge==8:
        count+=1
print(count)

Measured memory_bytes: 3316
#include <stdio.h>

int main(void)
{
    double a, a1, b, c, d, e, f;
    double t1, t2;
    double x;
    double y;

    while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
        x = (c * e - f * b) / (a * e - d * b) + 0;
		y = (a * f - d * c) / (a * e - d * b) + 0;
		
		printf("%.3lf %.3lf\n", x, y);
    }
    return (0);
}

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

int main() {
    long h, w, n;
    cin >> h >> w >> n;
    unordered_map<long, int> counter;
    for (int i = 0; i < n; i++) {
        long a, b;
        cin >> a >> b;
        a--; b--;
        for (long i = max(1l, a - 1); i <= min(h - 2, a + 1); i++) {
            for (long j = max(1l, b - 1); j <= min(w - 2, b + 1); j++) {
                if (counter.find(w * i + j) == counter.end())
                    counter[w * i + j] = 0;
                counter[w * i + j]++;
            }
        }
    }
    int count[10];
    fill(count, count + 10, 0);
    for (auto p: counter) {
        count[p.second]++;
    }
    cout << (h * w - 2 * (h + w - 2) - counter.size()) << endl;
    for (int i = 1; i <= 9; i++) {
        cout << count[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 36624
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int N,minj,a,c;
    cin >> N;
    int A[N];
    c = 0;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    
    for(int i=0;i<N-1;i++){
        minj = i;
        for(int j=i;j<N;j++){
            if(A[j] < A[minj]){
                minj = j;
            }
        }
        if(A[i] != A[minj]){
            c++;
        }
        a = A[i];
        A[i] = A[minj];
        A[minj] = a;
    }
    
    cout << A[0];
    for(int i=1;i<N;i++){
        cout << " " << A[i];
    }
    cout << endl;
    cout << c << endl;
}


Measured memory_bytes: 3096
n, k = map(int, input().split())
MOD = 1000000007
ans = 0
c = {}
for i in range(k, 0, -1):
    t = pow(k // i, n, MOD)
    m = 2
    while i * m <= k:
        t -= c[i * m]
        m += 1
    c[i] = t % MOD
print(sum([k * v for k, v in c.items()]) % MOD)


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);
int h,w;
int m[50][50];

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

int dfs(int x, int y, int d){
  if(m[x][y]==0)return d;
  if(visited[x][y])return d;
  visited[x][y]=true;

  REP(i,8){
    int nx = x + dx[i];
    int ny = y + dy[i];

    if(nx < 0 || nx >= h || ny <0 || ny >= w)continue;
    if(m[nx][ny]==0)continue;
    if(visited[nx][ny])continue;

    dfs(nx, ny, d);
  }

  return d+1;
}

int main(){
  while(true){

    cin >> w >> h;
    if(h+w==0)break;
    REP(i,h)REP(j,w)cin >> m[i][j];
    REP(i,h)REP(j,w)visited[i][j]=false;

    int d = 0;
    REP(i,h)REP(j,w){
      d = dfs(i,j,d);
    }
    cout << d << endl;
  }
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
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()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}

// Sieve of Eratosthenes
// (*this)[i] = (divisor of i, greater than 1)
// Example: [0, 1, 2, 3, 2, 5, 3, 7, 2, 3, 2, 11, ...]
// Complexity: Space O(MAXN), Time (construction) O(MAXNloglogMAXN)
struct SieveOfEratosthenes : std::vector<int> {
  std::vector<int> primes;
  SieveOfEratosthenes(int MAXN) : std::vector<int>(MAXN + 1) {
    std::iota(begin(), end(), 0);
    for (int i = 2; i <= MAXN; i++) {
      if ((*this)[i] == i) {
        primes.push_back(i);
        for (int j = i; j <= MAXN; j += i) (*this)[j] = i;
      }
    }
  }
  using T = long long int;
  // Prime factorization for x <= MAXN^2
  // Complexity: O(log x)          (x <= MAXN)
  //             O(MAXN / logMAXN) (MAXN < x <= MAXN^2)
  std::map<T, int> Factorize(T x) {
    assert(x <= 1LL * (int(size()) - 1) * (int(size()) - 1));
    std::map<T, int> ret;
    if (x < int(size())) {
      while (x > 1) {
        ret[(*this)[x]]++;
        x /= (*this)[x];
      }
    }
    else {
      for (auto p : primes) {
        while (!(x % p)) x /= p, ret[p]++;
        if (x == 1) break;
      }
      if (x > 1) ret[x]++;
    }
    return ret;
  }
  std::vector<T> Divisors(T x) {
    std::vector<T> ret{1};
    for (auto p : Factorize(x)) {
      int n = ret.size();
      for (int i = 0; i < n; i++) {
        for (T a = 1, d = 1; d <= p.second; d++) {
          a *= p.first;
          ret.push_back(ret[i] * a);
        }
      }
    }
    return ret; // Not sorted
  }
  // Moebius function Table
  // return: [0=>0, 1=>1, 2=>-1, 3=>-1, 4=>0, 5=>-1, 6=>1, 7=>-1, 8=>0, ...]
  std::vector<int> GenerateMoebiusFunctionTable() {
    std::vector<int> ret(size());
    for (int i = 1; i < int(size()); i++) {
      if (i == 1) ret[i] = 1;
      else if ((i / (*this)[i]) % (*this)[i] == 0) ret[i] = 0;
      else ret[i] = -ret[i / (*this)[i]];
    }
    return ret;
  }
};
SieveOfEratosthenes sieve(1000000);

int main() {
  ll N; cin >> N;
  ll ans = 0;
  vector<ll> tmp; tmp = sieve.Divisors(N);
  vector<ll> tmp0; tmp0 = sieve.Divisors(N - 1);
  ans += tmp0.size() - 1; // 1を除く
  REP(i, tmp.size()) {
    ll res = tmp[i]; ll p = N;
    if(res == 1) continue;
    while(true) {
      if(p % res == 0) p = p / res;
      else {
        if(p % res == 1) ans++;
        break;
      }
      if(p == 1) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 7592
/**
*    created: 04.05.2020 07:59:31
**/

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


int main() {
    ll x;
    cin >> x;
    ll a=0, b=0;
    rep(i,200){
        for (int j = -200; j < 200;j++){
            if(/*i*i*i*i*i-j*j*j*j*j*/pow(i,5)-pow(j,5)==x){
                a = i;
                b = j;
            }
        }
    }
cout << a<<" "<<b << endl;
}

Measured memory_bytes: 4100
#include<bits/stdc++.h>
#define MAX 1000006
#define INF 2e9
using namespace std;
int a[MAX] , b[MAX] , c[MAX] , dp[MAX][4];
int main()
{
    int n;
    cin>>n;
    for(int i =0 ; i < n ; i++) cin>>a[i]>>b[i]>>c[i];

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i =1 ; i < n ; i++ ) {

        for(int j = 0 ; j < 3 ; j++) {

            if(j != 0) dp[i][0] = max(dp[i-1][1] , dp[i-1][2]) + a[i];
            if(j != 1) dp[i][1] = max(dp[i-1][0] , dp[i-1][2]) + b[i];
            if(j != 2) dp[i][2] = max(dp[i-1][0] , dp[i-1][1]) + c[i];
        }
    }

    cout<<max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2]))<<endl;
    return 0;
}



Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;

const int maxn=1111;
const int maxm=2111;
const int mod=1e9+7;
int qpow(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=(LL)ret*x%mod;
		x=(LL)x*x%mod;
		y>>=1;
	}
	return ret;
}

int n,m,eu[maxm],ev[maxm],ew[maxm],ord[maxm],f[maxn],w[maxn][maxn];
int gf(int x){return x==f[x]?x:f[x]=gf(f[x]);}
bool cmp(int x,int y){return ew[x]<ew[y];}

vector<int> vs[maxn];
bool tree[maxm];
LL X;

int main()
{
	scanf("%d%d",&n,&m);scanf("%lld",&X);
	for(int i=1;i<=m;i++)scanf("%d%d%d",eu+i,ev+i,ew+i);
	
	for(int i=1;i<=n;i++)
	{
		f[i]=i;
		vs[i].pb(i);
	}
	for(int i=1;i<=m;i++)ord[i]=i;
	sort(ord+1,ord+m+1,cmp);
	for(int t=1;t<=m;t++)
	{
		int id=ord[t],u=gf(eu[id]),v=gf(ev[id]);
		if(u==v)continue;
		tree[id]=1;
		for(int i=0;i<(int)vs[u].size();i++)for(int j=0;j<(int)vs[v].size();j++)
			w[vs[u][i]][vs[v][j]]=w[vs[v][j]][vs[u][i]]=ew[id];
		f[u]=v;for(int i=0;i<(int)vs[u].size();i++)vs[v].pb(vs[u][i]);
		X-=ew[id];
//		printf("id= %d X= %lld\n",id,X);
	}
	if(X<0)
	{
		puts("0");
		return 0;
	}
	if(X==0)
	{
		int cnt=0;
		for(int i=1;i<=m;i++)if(w[eu[i]][ev[i]]==ew[i])cnt++;
		printf("%d\n",(qpow(2,m)-qpow(2,m-cnt+1)+mod)%mod);
	}
	else
	{
		int c1=0,c2=0;
		for(int i=1;i<=m;i++)if(ew[i]-w[eu[i]][ev[i]]<X)c1++;else if(ew[i]-w[eu[i]][ev[i]]==X)c2++;
//		printf("c1= %d c2= %d\n",c1,c2);
		printf("%d\n",(qpow(2,m-c1+1)-qpow(2,m-c1-c2+1)+mod)%mod);
	}
	return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
int32_t main(){_

   cin>>n;

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

   int ans = 0;
   for (int i = 1; i+1 < n; ++i)
   {
      int curr = a[i];
      vector<int> v;
      v.pb(a[i-1]);
      v.pb(a[i]);
      v.pb(a[i+1]);
      sort(v.begin(), v.end());
      if(v[1] == a[i])ans++;
   }
   
   cout<<ans;

   return 0;
}

Measured memory_bytes: 256
S = input()

mozi = list(S)

n = len(mozi)

count = 0

if n%2 == 0:
  for i in range(int(n/2)):
    if mozi[i] != mozi[n-1-i]:
      count = count + 1
    
if n%2 == 1:
  for i in range(int((n-1)/2)):
    if mozi[i] != mozi[n-1-i]:
      count = count + 1

#print(S)
#print(mozi)
#print(n)
print(count)


Measured memory_bytes: 3060
#include <iostream>

int main()
{
    int r, g, b;
    std::cin >> r >> g >> b;
    if ((r * 100 + g * 10 + b) % 4 == 0) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=1e4+5;
int f[N],son[N],n,val[N],ans[N],m,tot;
queue<int> q;
vector<int> g[N];

void dfs(int x,int fa){
	f[x]=fa;
	son[x]=g[x].size()-(fa>0);
	for(int y:g[x]) if(y^fa) dfs(y,x);
}

signed main(){
	read(n);
	for(int i=1,x,y;i<n;i++){
		read(x,y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++) read(val[i]),tot+=val[i];
	sort(val+1,val+1+n);
	dfs(1,0);
	for(int i=1;i<=n;i++) if(!son[i]) q.push(i);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		ans[x]=val[++m];
		if(!--son[f[x]]) q.push(f[x]);
	}
	write(tot-val[n]);puts("");
	for(int i=1;i<=n;i++) write(ans[i]),putchar(' ');
}

Measured memory_bytes: 4772
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), total=0;
    int A[] = new int[N+1];
    A[0] = 0;
    for(int i=1; i<=N; i++) {
      A[i] = sc.nextInt();
    }
    for(int j=1; j<=N; j++) {
      int a1 = A[j], a2 = A[a1];
      if(j == a2) {
        total++;
      }
    }

    System.out.println(total/2);
  }
}

Measured memory_bytes: 59408
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    ll ans = b / x + 1;
    if (a != 0)
    {
        ans -= (a - 1) / x + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

void swap(int a[3], int m, int n);

int main(void){
    int a[3];
    int t;
    int s;

    scanf("%d %d %d", &a[0], &a[1], &a[2]);

    if ( a[2] < a[0] ) { swap(a, 0, 2); }
    if ( a[1] < a[0] ) { swap(a, 0, 1); }
    if ( a[2] < a[1] ) { swap(a, 1, 2); }

    s = a[2] - a[0];
    printf("%d\n", s);

    return 0;
}

void swap(int a[3], int m, int n){
    int tmp;

    tmp = a[m];
    a[m] = a[n];
    a[n] = tmp;
}

Measured memory_bytes: 128
# frozen_string_literal: true

n, a, b = gets.split.map(&:to_i)
s = gets.chomp
qa = qb = 0

s.each_char.with_index do |c, idx|
  q = qa + qb

  if q == a + b
    (n - idx).times { puts :No }
    exit
  end

  if c == 'a'
    qa += 1
    puts :Yes
  elsif c == 'b' && qb < b
    qb += 1
    puts :Yes
  else
    puts :No
  end
end

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

bool isPalindrome(string s) {
    int numberOfCheck = s.size() / 2;
    for (int i = 0; i < numberOfCheck; ++i)
        if (s[i] != s[s.size() - 1 - i])
            return false;
    return true;
}

int main()
{

    string s;
    int cnt = 0;
    while (getline(cin, s)) {
        if (isPalindrome(s))
            cnt++;
    }
    cout << cnt << endl;

    return 0;
}


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

int main() {
 int a,b,w,x=0;
  cin>>a>>b;
  for(int i=0;i<b-a+1;i++){
  	w=a+i;
   if(w/10000 == w%10 && w/1000%10 == w/10%10){
    x++;
   	}
   }
  cout<<x<<endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;

int dfs(vector<vector<pair<int, int>>>& g, int pos, int prev){
    int res = 1;
    for(auto& nd : g[pos]){
        if(nd.first == prev) continue;
        nd.second = dfs(g, nd.first, pos);
        res += nd.second;
    }
    for(auto& nd : g[pos]){
        if(nd.first == prev) nd.second = g.size() - res;
    }
    return res;
}

long long modPow(long long a, long long p){
    if(p == 0) return 1;
    auto res = modPow(a, p/2);
    res = (res*res)%MOD;
    if(p%2) res = (res*a)%MOD;
    return res;
}

long long calcInv(long long a){
    return modPow(a, MOD-2);
}

int main(){
    int N;
    vector<long long> pow2(2000001, 1);
    for(int i=1;i<pow2.size();i++) pow2[i] = 2 * pow2[i-1] % MOD;
    while(cin >> N){
        vector<vector<pair<int, int>>> g(N);
        for(int i=0;i<N-1;i++){
            int a, b; cin >> a >> b;
            --a; --b;
            g[a].emplace_back(b, -1);
            g[b].emplace_back(a, -1);
        }
        dfs(g, 0, -1);
        long long res = 0;
        for(auto& nd : g){
            long long sub = (pow2[N-1] + MOD - 1) % MOD;
            for(auto& e : nd){
                sub = (sub + MOD - pow2[e.second]) % MOD;
                sub = (sub + 1) % MOD;
            }
            res = (res + sub) % MOD;
        }
        res = (res * calcInv(modPow(2, N))) % MOD;
        cout << res << endl;
    }
}

Measured memory_bytes: 38272
class BigCombination(object):
    __slots__ = ["mod", "factorial", "inverse"]

    def __init__(self, mod: int = 10**9+7, max_n: int = 10**6):
        fac, inv = [1], []
        fac_append, inv_append = fac.append, inv.append

        for i in range(1, max_n+1):
            fac_append(fac[-1] * i % mod)

        inv_append(pow(fac[-1], mod-2, mod))

        for i in range(max_n, 0, -1):
            inv_append(inv[-1] * i % mod)

        self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]

    def get_combination(self, n, r):
        return self.factorial[n] * self.inverse[r] * self.inverse[n-r] % self.mod

    def get_permutation(self, n, r):
        return self.factorial[n] * self.inverse[n-r] % self.mod


import math
def cal(x):
    return (x+1)/2*x
a,b = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
M = 10**9+7
L = l[::-1]
A =0
B =0
Big = BigCombination()
AA = a-1
# print(1,AA)
for i in range(a-b+1):
    k = Big.get_combination(a-i-1, b-1)
    # print(k)
    A+=k*L[i]
    B+=k*l[i]
    # print(A,B)
print((A-B)%M)


Measured memory_bytes: 96604
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int judge(int,int);

int n;
int A[50];

int main(){
  int i,q,m;

  scanf("%d",&n);

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

  scanf("%d",&q);


  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(judge(0,m)){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
  }

  return 0;
}

int judge(int x,int y){

  if(y==0){
    return 1;
  }
  if(x>=n){
    return 0;
  }

  return judge(x+1,y) || judge(x+1,y-A[x]);

}



Measured memory_bytes: 2104
import java.util.*;
class Main{

    public static void main(String args[]){
	int w,n;
	int[][] Edge;
	int[] Ans;
	Scanner in = new Scanner(System.in);
	String[] s;

     
	w = in.nextInt();
	n = in.nextInt();
	Edge = new int[w+1][2];
	Ans = new int[w+1];
	for(int i=1;i<=w;i++)Ans[i] = i;
	for(int i=0;i<n;i++){
	    s = in.next().split(",");
	    Edge[i][0] = Integer.valueOf(s[0]).intValue();
	    Edge[i][1] = Integer.valueOf(s[1]).intValue();
	    int h = Ans[Edge[i][0]];
	    Ans[Edge[i][0]] = Ans[Edge[i][1]];
	    Ans[Edge[i][1]] = h;
	}
    
	for(int i=1;i<=w;i++)System.out.println(Ans[i]);

    }



}


Measured memory_bytes: 25964
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin(),(c).end())
#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define PW(n) (1LL<<(n))
using namespace std;
template <class T> inline bool CHMIN(T& a, T b) { if(a>b) { a=b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if(a<b) { a=b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(ALL(a)); }
template <class T> inline void REV(T& a) { reverse(ALL(a)); }
template <class T> inline void UNI(T& a) { SORT(a); a.erase(unique(ALL(a)),a.end()); }
template <class S, class T> ostream& operator<<(ostream& os, const pair<S,T> a) {
  return os << a.first << ' ' << a.second;
}
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N, H, W;
int x[110];
int a[10010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N >> H >> W;
  REP(i, N) cin >> x[i];
  REP(i, N) {
    int pos = W*i;
    if (i % 2 == 0) pos += x[i];
    else pos -= x[i];
    a[pos]++;
    a[pos+W]--;
  }
  REP(i, N*W) a[i+1] += a[i];
  int ans = 0;
  REP(i, N*W) if (a[i] == 0) {
    ans += H;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int need[301][301];
int fl[301][301];
int n;

int main()
{
	read(n);
	for(int i=1; i<=n; ++i) for(int j=1; j<=n; ++j) read(fl[i][j]);
	for(int s=1; s<=n; ++s){
		vector<pp> d;
		for(int i=1; i<=n; ++i) d.eb(fl[s][i], i);
		sort(all(d));
		for(int j=1; j<n; ++j){
			int p=d[j].y;
			int mp=s, md=fl[s][p];
			for(int k=0; k<j; ++k){
				int b=d[k].y;
				if(fl[s][p] > fl[s][b] + fl[b][p]){
					puts("-1");
					return 0;
				}
				if(fl[s][p] == fl[s][b] + fl[b][p]){
					if(md > fl[b][p]){
						md = fl[b][p];
						mp = b;
					}
				}
			}
			need[p][mp] = need[mp][p] = 1;
		}
	}
	ll ans = 0;
	for(int i=1; i<=n; ++i) for(int j=i+1; j<=n; ++j) if(need[i][j]) ans += fl[i][j];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

int main(){
  int K, N;
  string S;
  cin >> N >> S >> K;
  for(int i=0;i < S.length();i++){
    if(S[i] != S[K-1]){
      cout << "*";
    }else{
      cout << S[i];
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)  # 変更
from bisect import bisect_left,bisect

n = int(input())
x = list(map(int,input().split()))
L = int(input())
t = n.bit_length()
prv = [n-1] * n
for i in range(n):
    prv[i] = bisect(x,x[i]+L) - 1
kprv = [prv]
S = prv
for i in range(t-1):
    kar = [n-1] * n
    for j in range(n):
        kar[j] = S[S[j]]
    kprv.append(kar)
    S = kar

q = int(input())
for _ in range(q):
    a , b = map(lambda x:int(x)-1,input().split())
    if a > b:
        a , b = b , a
    lef = 0
    rig = n-1
    while rig - lef > 1:
        mid = (rig+lef)//2
        p = mid.bit_length()
        now = a
        for i in range(p):
            if (mid>>i) & 1 == 1:
                now = kprv[i][now]
        if now >= b:
            rig = mid
        elif now < b:
            lef = mid
    print(rig)

Measured memory_bytes: 95716
def main():
	s = set()
	ss = set()
	sss = set()
	n=int(input())
	ins = input()
	for i in range(n):
		for t in ss:
			sss.add(t+ins[i])
		for t in s:
			ss.add(t+ins[i])
		s.add(ins[i])
	print(len(sss))

main()

Measured memory_bytes: 3188
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int l;
vector<tuple<int,int,int>> edges;

signed main(){
    cin >> l;
    int nodes = 0;
    int li = l;
    while(li){
        nodes++;
        li /= 2;
    }
    REP(i,nodes-1){
        edges.emplace_back(i+1,i+2,0);
        edges.emplace_back(i+1,i+2,(1LL << i));
    }
    REPN(i,nodes-1){
        int mask = 1LL << i;
        if (mask & l){
            //cerr << i << endl;
            edges.emplace_back(i+1, nodes, (l >> (i+1)) << (i+1));
        }
    }
    cout << nodes << " " << edges.size() << endl;
    for (auto t: edges){
        cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N, -1);
  bool res = true;
  rep(i, M) {
    int s, c;
    cin >> s >> c;
    s--;
    if(ans[s] != -1 && ans[s] != c) {
      res = false;
      break;
    } else {
      ans[s] = c;
    }
  }
  if(res) {
    if(N != 1 && ans[0] == 0) cout << -1 << endl;
    else if(N == 1 && ans[0] == -1) cout << 0 << endl;
    else {
      bool flag = true;
      rep(i, N) {
        if(ans[i] == -1) {
          if(flag) {
            cout << 1;
            flag = false;
          } else {
            cout << 0;
          }
        } else {
          cout << ans[i];
          flag = false;
        }
      }
      cout << endl;
    }
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
bool query(long long x){//if N is lexicographically <x
  if(x==0)return false;
  while(x<=10000000000ll)x=x*10;
  printf("? %lld\n",x-1);
  fflush(stdout);
  char buf[10];
  scanf("%s",buf);
  return buf[0]=='Y';
}
bool onlyone(int x){
  if(x==0)return false;
  while(x%10==0)x/=10;
  return x==1;
}
bool ok(int ans){
  char buf[10];
  printf("? %lld\n",ans*10ll-1);fflush(stdout);
  scanf("%s",buf);
  if(onlyone(ans)){
    return buf[0]=='Y';
  }else{
    return buf[0]=='N';
  }
}
int ans=0;
void getfirst(){
  int l=1,r=9;
  while(l<=r){
    if(l==r&&l==1){
      ans=1;return;
    }
    int mid=(l+r)>>1;
    if(query(mid))r=mid-1;
    else l=mid+1;
  }
  ans=r;
}
int main(){
  getfirst();
  while(1){
    int l=0,r=9;
    while(l<=r){
      int mid=(l+r)>>1;
      if(query(ans*10+mid))r=mid-1;
      else l=mid+1;
    }
    if(r==-1)r++;
    if(r==0&&ok(ans)){
      printf("! %d\n",ans);break;
    }
    ans=ans*10+r;
    if(ans*10ll>1000000000){
      printf("! %d\n",ans);break;
    }
  }
  return 0;
}


Measured memory_bytes: 504
#include<algorithm> 
#include<iostream> 
#include<cstring> 
#include<climits> 
#include<cstdio> 
#include<queue> 
using namespace std;
#define MAXN 500000
struct node{int num,w;}a[MAXN+5]; 
int n; 
priority_queue<int> kkk; 
long long xtime=0; 
bool cmp(node s1,node s2){return s1.w<s2.w;} 
int main() 
{
	while(!kkk.empty())kkk.pop();
	xtime=0;
	scanf("%d",&n); 
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i].num,&a[i].w); 
	sort(a+1,a+n+1,cmp); 
	for(int i=1;i<=n;i++){ 
		if(xtime+a[i].num<=a[i].w){kkk.push(a[i].num);xtime+=a[i].num;} 
		else if(kkk.size()&&kkk.top()>a[i].num) 
			{ 
				xtime-=kkk.top();   
				kkk.pop();   
				kkk.push(a[i].num);   
				xtime+=a[i].num;   
			}
		}
	printf("%s",(kkk.size()==n)?"Yes":"No");
} 

Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <bitset>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);

constexpr int64 MOD = 1000000007;




int main()
{
    int64 n;
    cin >> n;
    
    if (n % 2 == 1)
    {
        cout << 0 << endl;
        return 0;
    }

    int64 ans = n / 10;

    int64 cur = ans;
    while (cur > 0)
    {
        cur /= 5;
        ans += cur;
    }

    cout << ans << endl;

    return 0;
}


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

bool inc(string z, vector<string> list){
  for (string l:list){
    if (z == l) {
      return true;
    }
    else{
      return false;
    }
  }
}


int main(){
  int n,m;
  cin >>n;
  vector<string> blue(n);
  for (int i; i<n; i++){
    cin >> blue[i];
  }
  cin >>m;
  vector<string> red(m);
  for (int j; j<m; j++){
    cin >> red[j];
  }
  vector<string> check(1, "");
  int ans = 0;
  for (string s:blue){
    if (inc(s, check)){
      continue;
    }
    else{
      int ans2 = 0;
      check.push_back(s);
      for (string s2:blue){
        if (s == s2) ans2 ++;
      }
      for (string t:red){
        if (s == t) ans2 --;
      }
      ans = ans<ans2 ? ans2:ans;
    }
  }
  cout << ans << endl;

}
  

Measured memory_bytes: 256
#Template Matching
N, M = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
n = 0
n2 = 1

for i in range(N-M+1):
    for j in range(N-M+1):
        n2 = 1
        for k in range(M):
            if A[i+k][j:j+M] != B[k]:
                n2 = 0
        if n2 == 1:
            n = 1
        
if n == 1:
    print("Yes")
else:
    print("No")

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

int main() {
    int A, B, K;   
    cin >> A >>B>>K;
    
    for(int i=A; i<=B ; i++){
	if(i<A+K)
	    cout << i<< endl;
	else if(B-K<i)
	    cout << i<< endl;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}


int main() {
	int n,sum=0;
	cin >> n;
	string ns;
	ns = to_string(n);
	for (int i = 0; i < ns.size(); i++) {
		sum += ns[i] - '0';
	}
	cout << (n%sum ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
while True:
    s = str(input()).split()
    s[0] = int(s[0])
    s[2] = int(s[2])
    if s[1] == '?':
        break
    if s[1] == '+':
        print(s[0] + s[2])
    elif s[1] == '-':
        print(s[0] - s[2])
    elif s[1] == '*':
        print(s[0] * s[2])
    elif s[1] == '/':
        print(s[0] // s[2])


Measured memory_bytes: 5596
N, Y = map(int, input().split())
for i in range(N+1):
    end = 0
    for j in range(N+1-i):
        k = N-i-j
        if 1000*i+5000*j+10000*k == Y:
            print(k, j, i)
            end = 1
            break
    if end == 1:
        break
else:
    print(-1, -1, -1)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		boolean[] odd = new boolean[n];

		for (int i=0;i<2*m;i++) {
			int x = sc.nextInt();
			odd[x-1] = !odd[x-1];
		}

		boolean ng = false;
		for (int i=0;i<n;i++) {
			ng |= odd[i];
		}

		System.out.println(ng? "NO" : "YES");

	}

}


Measured memory_bytes: 64844
#include <iostream>
using namespace std;
int main() {
    long long n; cin >> n;
    int ans = 0;
    for (long long p = 2; p * p <= n; p++) {
        if (n % p == 0) {
            int e = 0;
            while (n % p == 0) { e++; n /= p; }
            int k = 0;
            while (k * (k + 1) / 2 <= e) k++;
            ans += k-1;
        }
    }
    if (n > 1) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 3624
N = int(input())

import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

for i in range(N,10**6):
    if is_prime(i):
        print(i)
        exit(0)

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

int main() {
    long long n, t, count = 1;
    std::cin >> n;
    std::vector<long long> a(n);
    for (auto i = 0ll; i < n; i++) {
        std::cin >> t;
        a[--t] = i;
    }

    t = 0;
    for (auto i = 1ll; i < n; i++) {
        if (a[i] > a[i - 1]) count++;
        else {
            t = std::max(t, count);  
            count = 1;
        }
    }
    t = std::max(t, count);

    std::cout << n - t << std::endl;

    return 0;
}

Measured memory_bytes: 1792
#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() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	ll ans = 0;
	rep(i, n-1) {
		if (a[i+1] < a[i]) {
			ans += a[i] - a[i+1];
			a[i+1] = a[i];
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4040
package main

import "fmt"

func main() {
  var N, K int
  fmt.Scan(&N, &K)
  
  h := make([]int,N)
  for i:=0; i < N; i++ {
    fmt.Scanf("%d",&h[i])
  }
  
  cnt := 0
  for _, hi := range h {
    if hi >= K {
      cnt += 1
    }
  }
  fmt.Println(cnt)
}

Measured memory_bytes: 5504
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
    string a,b;
    cin>>a>>b;
    int x,y;

    x = a.size();
    y = b.size();

    int i=0;

    while(1){
        if(a[i]!=b[i]){
            break;
        }
        i++;
        if(i>=x || i>=y){
            if(x<y)cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
            return 0;
        }

    }

    for(int i=0;i<x;i++){
        for(int j=i;j<y;j++){
            if(a[i]<b[j]){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }

    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 30;

int main(void){
	int m,n;
	int ans=0;
	cin >> m >> n;
	rep(i,m){
		int rec=0;
		rep(j,n){
			int tmp;
			cin >> tmp;
			rec+=tmp;
		}
		ans=max(ans,rec);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1160
n=int(input())
s=dict()
for i in range(n):
    si=input()
    if si in s:
        s[si]+=1
    else:
        s[si]=0
l=max(s.values())
ans=[]
for i in s:
    if s[i]==l:
        ans.append(i)
ans.sort()
for i in ans:
    print(i)

Measured memory_bytes: 35360
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int A = Integer.parseInt(tokens[0]);
		int B = Integer.parseInt(tokens[1]);
		int X = Integer.parseInt(tokens[2]);

		if (X >= A && X <= A + B) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		in.close();
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define V vector
#define pb push_back
#define mkp make_pair
#define pi pair<int,int>//struct pi {int fi,se;};
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define ln length()
#define sz size()
const int N=100005;
///////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    // int t;cin>>t;while(t--)
    {
        int i,j,k,n,a,m,ans=0,cnt=0,sum=0;
        cin >> a;
        ans = pow(a,2) + pow(a,3) + a;
        cout << ans<<endl;
    }
}

Measured memory_bytes: 4112
#include <cstdio>
#include <vector>
#include <map>

int main() {
  int H, W, N;
  scanf("%d %d %d", &H, &W, &N);

  std::map<std::pair<int, int>, int> pic;
  for (int i=0; i<N; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);

    --a, --b;
    pic[std::make_pair(a, b)] = 1;
  }

  std::map<std::pair<int, int>, int> counter;
  for (const auto &el: pic) {
    std::pair<int, int> p=el.first;
    for (int i=-1; i<=1; ++i)
      for (int j=-1; j<=1; ++j)
        ++counter[std::make_pair(p.first+i, p.second+j)];
  }

  int res[10]={};
  for (const auto &el: counter) {
    std::pair<int, int> p=el.first;
    if (!(1 <= p.first && p.first < H-1))
      continue;

    if (!(1 <= p.second && p.second < W-1))
      continue;

    ++res[el.second];
    --res[0];
  }

  printf("%lld\n", (H-2LL)*(W-2LL)+res[0]);
  for (int i=1; i<=9; ++i)
    printf("%d\n", res[i]);

  return 0;
}


Measured memory_bytes: 62720
#include<stdio.h>

int main(void){
  int N,i,j,ans;
  
  scanf("%d", &N);
  ans = 0;
  for(i = 1; i <= 9; i++){
    for(j = 1; j <= 9; j++){
      if(N == i*j){
        ans = 1;
      }
    }
  }
  if(ans){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

mia = sorted([i for i in a if i < 0], reverse=True)
pla = sorted([i for i in a if i >= 0])

cnt = 1
if len(pla) == 0 and k % 2 == 1:
    for i in mia[:k]:
        cnt = cnt * i % mod
    print(cnt)
    exit()

while k > 0:
    if k == 1 or len(mia) <= 1:
        if len(pla) == 0:
            cnt *= mia.pop()
        elif len(pla) > 0:
            cnt *= pla.pop()
        k -= 1
    elif len(pla) <= 1:
        cnt *= mia.pop() * mia.pop()
        k -= 2
    elif pla[-1] * pla[-2] > mia[-1] * mia[-2]:
        cnt *= pla.pop()
        k -= 1
    elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:
        cnt *= mia.pop() * mia.pop()
        k -= 2
    cnt %= mod
else:
    print(cnt)


Measured memory_bytes: 109888
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	int ans = 0;
	rep(i, n) {
		int a;
		cin >> a;
		while (a % 2 == 0) {
			ans++;
			a /= 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=3500;i++){
        for(int j=1;j<=3500;j++){
            ll x=1ll*n*i*j,y=4*i*j-1ll*n*j-1ll*n*i;
            if(y&&x%y==0&&x/y>=1){
                printf("%d %d %lld\n",i,j,x/y);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 384
import itertools
import math

def dist(i, j):
    return math.sqrt((locations[i][0] - locations[j][0]) ** 2 \
        + (locations[i][1] - locations[j][1]) ** 2)

n = int(input())
locations = []
for i in range(n):
    x, y = map(float, input().split())
    locations.append((x, y))

dists = []
for item in itertools.permutations(range(n)):
    tmp = 0
    for i in range(n-1):
        tmp += dist(item[i], item[i+1])
    dists.append(tmp)

print(sum(dists) / len(dists))


Measured memory_bytes: 43536
#include <stdio.h>
#include <string.h>
 
int main(){
  int i,flag=0,acount=0,bcount=0;
  char s[100001];
  scanf("%s",s);
    for(i=0;i<strlen(s);i++){
      if(flag == 0){
        if(s[i]=='0') acount++;
        else bcount++;
        flag=1;
      }
      else{
        if(s[i]=='1') acount++;
        else bcount++;
        flag=0;
      }
    }
 
    if(acount>bcount) printf("%d",strlen(s)-acount);
    else printf("%d",strlen(s)-bcount);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#ifndef LOCAL_RUN
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("fast-math")
    #pragma GCC target("avx2,tune=native")
#endif*/
#define X first
#define Y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const ll MOD = 1e9 + 7;

int main()
{
    #ifdef LOCAL_RUN
        freopen("input.txt", "r", stdin);
    //#else
        //freopen("cowcode.in", "r", stdin);
        //freopen("cowcode.out", "w", stdout);
    #endif
	ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    ll ans = 0, sum = 0;
    for (int i = 0, t; i < n; i++) {
        cin >> t;
        ans += ll(t) * sum;
        ans %= MOD;
        sum = (sum + t) % MOD;
    }
    cout << ans;

    return 0;
}

// 272472LF


Measured memory_bytes: 3668
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
enum Color{WHITE, GRAY, BLACK};

int n;
int **a;
Color *color;

int prim(){
        color[0] = BLACK;
        int sum=0;
        while(1){
                int p, minp=INT_MAX;
                for(int i=0;i<n;i++){
                        if(color[i]!=BLACK) continue;
                        for(int j=0;j<n;j++){
                                if(color[j]==BLACK||a[i][j]==-1) continue;
                                else if(color[j]==WHITE) color[j] = GRAY;
                                if(minp>a[i][j]){
                                        minp = a[i][j];
                                        p = j;
                                }
                        }
                }
                if(minp==INT_MAX) break;
                sum += minp;
                color[p] = BLACK;
        }
        return sum;
}

int main(){
        cin>>n;
        a = new int*[n];
        for(int i=0;i<n;i++) a[i] = new int[n];
        for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                        cin>>a[i][j];
                }
        }
        color = new Color[n];
        for(int i=0;i<n;i++) color[i] = WHITE;

        cout<<prim()<<endl;

        delete a;
        return 0;
}


Measured memory_bytes: 3112