akhauriyash/Code-Regression huggingface dataset:
from itertools import product
H, W, K = map(int, input().split())

c = [list(input()) for i in range(H)]

ans = 0
for bity in product([True, False], repeat=H):
    for bitx in product([True, False], repeat=W):
        area = [[0] * W for i in range(H)]
        for i in range(H):
            for j in range(W):
                area[i][j] = c[i][j]
        
        # 数える
        for y in range(H):
            if bity[y]:
                for x in range(W):
                    area[y][x] = '.'
        for x in range(W):
            if bitx[x]:
                for y in range(H):
                    area[y][x] = '.'
        temp = sum([a.count('#') for a in area])
        if temp == K:
            ans+=1
print(ans)                




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

int compareInt(const void* a, const void* b){
    int aNum = *(int*)a;
    int bNum = *(int*)b;

    return aNum - bNum;
}

int main(){
  int n,i,j,p[1000],k,min=1000,m=0,a=0;
  char s[1500000];
    
  
  scanf("%d %d\n",&n,&k);
  fgets(s,sizeof(s),stdin);
  p[0] = atoi(strtok(s, " "));
  
  for(i=1;i<n;i++){
    //printf("a\n");
    p[i] = atoi(strtok(NULL, " "));
    //printf("%d",p[i]);
  }
  
  qsort(p, n, sizeof(int), compareInt);
  for(i=0;i<k;i++){
    a += p[i];
    //printf("%d ",p[i]);
  }
  
  
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 1768
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=(1LL<<63) - 600;
const ll mod=1e9+7 ;

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

int main(){
  int N; ll M; cin >> N >> M; ll a[N];
  rep(i, N){
    cin >> a[i]; 
    if(a[i]%2){
      cout << 0 << endl; return 0;
    }
    a[i]/=2;
  }
  vector<int> power(N); ll tmp = 1;
  rep(i, N){
    while(!(a[i]%2)){
      a[i]/=2; power[i]++;
    }
    if(i>=1&&power[i-1]!=power[i]){
      cout << 0 << endl;
      return 0;
    }
    tmp = tmp*a[i]/gcd(tmp, a[i]);
  }
   rep(i, power[0]){
      M/=2;
    }
  if(tmp>M) {cout << 0 << endl; }
  else{
    M/=tmp;
    cout << (M+1)/2 << endl;
  }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    unordered_map<int, int> mp;
    for(int i=0;i<n-1;i++) 
    {
        int k;
        cin>> k;
        mp[k]++;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<mp[i]<<"\n";
    }
    return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

int n;

long long s[100010];

map<long long, int> h, t;

int p[3010], fg[3010], pt;

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) scanf("%lld", s + i);
	for (int i = 2; i <= 3000; fg[i] ? : p[++pt] = i, ++i)
		for (int j = i << 1; j <= 3000; j += i)
			fg[j] = 1;
	long long mx = 0;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; 1LL * p[j] * p[j] * p[j] <= s[i]; ++j)
		{
			long long t = 1LL * p[j] * p[j] * p[j];
			while (!(s[i] % t)) s[i] /= t;
		}
		++h[s[i]];
		mx = max(mx, s[i]);
		//cerr << "s = " << s[i] << endl;
	}
	int ans = 0;
	t = h;
	for (auto iter : t)
	{
		long long x = iter.first;
		if (x == 1) continue;
		long long y = 1;
		for (int j = 1; j <= pt; ++j)
		{
			int cnt = 0;
			while (!(x % p[j])) x /= p[j], ++cnt;
			if (cnt == 1) y *= p[j] * p[j];
			else if (cnt == 2) y *= p[j];
		}
		if (x != 1)
		{
			long long s = sqrt(x);
			if (x == s * s)
				y *= s;
			else 
				y *= x * x;
		}
		//cerr << iter.first << ", " << y << ", " << x << endl;
		if(!h.count(y) || iter.first < y) ans += max(iter.second, h.count(y) ? h[y] : 0);
	}
	if (h[1]) ++ans;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 13568
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>?5*8},'ruby',$0);def f(v,c)s=m=H[v].size==1?A[v-1]:0;H[v].any?{|e|e==c&&next;s+=n=f(e,v);m=[m,n].max;n<0}||s<(x=2*A[v-1]-s)||x<2*m-s ?-1:x end;G=->{gets.split.map &:to_i};n,_=G[];A=G[];H=Hash.new{|h,k|h[k]=[]};(n-1).times{x,y=G[];H[x]<<y;H[y]<<x};puts f(1,0)==0?:YES: :NO

Measured memory_bytes: 199000
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int row = sc.nextInt();
		int col = sc.nextInt();
		int[][] table = new int[row][col];
		for(int i = 0; i < row; i++) {
			for(int j = 0; j < col; j++) {
				table[i][j] = sc.nextInt();
			}
		}
		int[] rowSum = new int[row];
		int[] colSum = new int[col];
		int sum = 0;
		Arrays.fill(rowSum, 0);
		Arrays.fill(colSum, 0);
		for(int i = 0; i < row; i++) {
			for(int j = 0; j < col; j++) {
				sum += table[i][j];
				rowSum[i] += table[i][j];
				colSum[j] += table[i][j];
			}
		}
		for(int i = 0; i < row; i++) {
			for(int j = 0; j < col; j++) {
				System.out.print("" + table[i][j] + " ");
			}
			System.out.println("" + rowSum[i]);
		}
		for(int j = 0; j < col; j++) {
			System.out.print("" + colSum[j] + " ");
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 37652
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String n = sc.next();
        char[] c = n.toCharArray();
        
        int sum = 0;
        for(char c2: c){
            sum += (c2 - '0');
        }
        
        if(sum % 9 == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 40408
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

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

	auto count = 0;
	for (auto i = 0; i < N; ++i)
	{
		int l, r;
		cin >> l >> r;
		count += r - l + 1;
	}

	cout << count << endl;

	return 0;
}

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


int main(){
  int n;
  while(cin>>n,n){
    int key[101];
    for(int i=0;i<n;i++) cin>> key[i];
    string str;
    cin>>str;

    int idx=0;
    for(int i=0;i<str.size();i++){
      idx%=n;
      int flg=0;
      if(key[idx]>=26&&key[idx]!=52)flg=1;
      char ch=str[i];
      str[i]-=key[idx++]%26;
    
      if(str[i]<'A') str[i]='z'-('A'-str[i])+1;
      else if('a'<=ch&&str[i]<'a') str[i]='Z'-('a'-str[i])+1;


      if(flg&&'a'<=str[i]&&str[i]<='z') str[i]-=32;
      else if(flg) str[i]+=32; 
    }
    cout <<str<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#define ll long long 
using namespace std;

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

int main(){
  int H;
  ll A[251];

  cin>>H;
  for(int i=1;i<=H;i++)cin>>A[i];

  for(int i=1;i<=H;i++){
    cout<<"node "<<i<<": key = "<<A[i]<<", ";
    if(i/2>0) cout<<"parent key = "<<A[parent(i)]<<", ";
    if(0<2*i&&2*i<=H) cout<<"left key = "<<A[left(i)]<<", ";
    if(0<2*i+1&&2*i+1<=H) cout<<"right key = "<<A[right(i)]<<", ";
    cout<<endl;
  }

 
  return 0;
}

Measured memory_bytes: 1168
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out = "";
    while (scanner.hasNext()) {
      long m = scanner.nextLong();
      long n = scanner.nextLong();
      long orgm = m;
      long orgn = n;
      long gcd = 0;
      if (n > m) {
        long temp = m;
        m = n;
        n = temp;
      }
      while (n != 0) {
        long temp = n;
        n = m % n;
        m = temp;
      }
      gcd = m;
      out += gcd + " " + (orgm * orgn) / gcd + "\n";
    }
    System.out.print(out);
  }
}

Measured memory_bytes: 17248
#include <bits/stdc++.h>
#define ENDL '\n'
#define io ios_base::sync_with_stdio(false);cin.tie(0);
#define sayy cout<<"YES"<<ENDL;
#define sayn cout<<"NO"<<ENDL;

using namespace std;

int main(){
    io

    int x,y;
    cin >> x >> y;
    cout << x + (y/2) << ENDL;
    
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include <cstring>
#include<bits/stdc++.h> 
using namespace std;   
int main()
{
	string s;
	cin>>s;
	if (s=="abc") 
	{
		cout<<"Yes";
		return 0;
	}
		if (s=="acb") 
	{
		cout<<"Yes";
		return 0;
	}
		if (s=="bca") 
	{
		cout<<"Yes";
		return 0;
	}
		if (s=="bac") 
	{
		cout<<"Yes";
		return 0;
	}
		if (s=="cab") 
	{
		cout<<"Yes";
		return 0;
	}
		if (s=="cba") 
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
    return 0;  
} 

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

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

const int INF = 1e9;
const int mod = 1e9+7;

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

    if(n == 0){
        cout << 0 << endl;
        return 0;
    }

    ll z = 1;
    string ans; 
    while(n != 0){
        if(n % (2*abs(z))){
            ans.push_back('1');
            n -= z;
        }else{
            ans.push_back('0');
        }
        z *= -2;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
from math import sqrt

deg = int(sqrt(N*2))

if N*2!=deg*(deg+1):
    print('No')
else:
    print('Yes')
    print(deg+1)
    ans = [[] for _ in range(deg+1)]
    now_len = deg
    cnt = 1
    for d in range(deg+1):
        ans[d].extend(list(range(cnt, cnt+now_len)))
        for i, c in enumerate(range(cnt, cnt+now_len), 1):
            ans[d+i].append(c)
        cnt += now_len
        now_len -= 1
    for i in range(deg+1):
        print(deg, *ans[i])

Measured memory_bytes: 12708
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a, b;
  	string s, t, ans;
  	cin >> s >> t;
  	cin >> a >> b;
  	cin >> ans;
  	if(ans == s) {
    	a--;
    }else {
    	b--;
    }
  
  	cout << a << " "<< b << '\n';
  
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, M;
int A[301][301];
int current[301];
int selected[301];
int cnt[301];

inline int solve() {
    int ans = N;
    for(int k = 0; k < M - 1; k++) {
        for(int i = 0; i < M; i++) cnt[i] = 0;
        for(int i = 0; i < N; i++) {
            while(selected[A[i][current[i]]]) current[i]++;
            cnt[A[i][current[i]]]++;
        }
        auto max_id = max_element(cnt, cnt + M);
        ans = min(ans, *max_id);
        selected[max_id - cnt] = 1;
    }
    return ans;
}

int main() {
    fastio();
    cin >> N >> M;
    REP(i, N) REP(j, M) {
        cin >> A[i][j];
        A[i][j]--;
    }
    cout << solve() << "\n";
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int a, b, c; cin >> a >> b >> c;
	int n = a + b + c;
	if (n <= 21) {
		cout << "win" << endl;
	}
	else {
		cout << "bust" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


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


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

  ll N;
  cin >> N;
  VL data(N + 1, 0);

  REP(i, N) {
    ll A;
    cin >> A;
    data[A]++;
  }

  ll itr = N % 2 + 1;
  ll ans = (itr == 2 && data[0] != 1 ? 0 : 1);

  while (true) {
    if (itr > N) {
      break;
    }

    if (data[itr] == 2) {
      ans *= 2;
      ans %= MOD;
    } else {
      ans = 0;
      break;
    }

    itr += 2;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
N = gets.to_i
xyh_list = N.times.map { gets.chomp.split(' ').map(&:to_i) }
xyh = xyh_list.find do |(_, _, h)|
  h >= 1
end

def calc_ph((cx, cy), (x, y, h))
  h + (x - cx).abs + (y - cy).abs
end

def calc_h((cx, cy, ph), (x, y))
  [ph - (x - cx).abs - (y - cy).abs, 0].max
end

(0..100).each do |cx|
  (0..100).each do |cy|
    cp = [cx, cy]
    ph = calc_ph(cp, xyh)
    ok = xyh_list.all? do |(x, y, h)|
      calc_h([cx, cy, ph], [x, y]) == h
    end
    if ok
      ph = calc_ph(cp, xyh)
      puts "#{cx} #{cy} #{ph}"
      exit 0
    end
  end
end


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll inv[1000000];
ll FactorialInv[1000000];
ll Factorial[1000000];
ll beki(ll a, ll b){
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    inv[1] = 1;
    FactorialInv[1] = 1;
    Factorial[1] = 1;
    Factorial[0] = 1;
    FactorialInv[0] = 1;
    inv[0] = 1;
    for(int i = 2; i < 1000000; i++){
        inv[i] = beki(i, mod - 2);
        Factorial[i] = Factorial[i - 1] * i % mod;
        FactorialInv[i] = FactorialInv[i - 1] * inv[i] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    init_combination();
    ll N, M, K;
    cin >> N >> M >> K;
    ll factor = combination(N * M - 2, K - 2);
    ll sum = 0;
    for(ll dm = 1; dm < M; dm++) {
        ll now = M - dm;
        now = now * N * N % mod;
        now = now * dm % mod;
        sum = (sum + now) % mod;
    }
    for(ll dn = 1; dn < N; dn++) {
        ll now = N - dn;
        now = now * M * M % mod;
        now = now * dn % mod;
        sum = (sum + now) % mod;
    }
    cout << sum * factor % mod << endl;
    return 0;
}


Measured memory_bytes: 23680
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int N, M, t, S_h, S_w, ans, a, b, c, d;
  while (cin >> N >> M, N) {
    vector<int> h, w;
    ans = 0;
    for (int i = 0; i < N; ++i) {
      cin >> t;
      h.push_back(t);
    }
    for (int i = 0; i < M; ++i) {
      cin >> t;
      w.push_back(t);
    }
    for (int i = 2; i < N+1; ++i) {
      t = 0;
      for (int j = 0; j < i; ++j) t += h[j];
      h.push_back(t);
      for (int j = i; j < N; ++j) {
	t += h[j];
	t -= h[j-i];
	h.push_back(t);
      }
    }
    sort(h.begin(), h.end());
    for (int i = 2; i < M+1; ++i) {
      t = 0;
      for (int j = 0; j < i; ++j) t += w[j];
      w.push_back(t);
      for (int j = i; j < M; ++j) {
	t += w[j];
	t -= w[j-i];
	w.push_back(t);
      }
    }
    sort(w.begin(), w.end());
    S_h = h.size();
    S_w = w.size();
    a = 0;
    b = 0;
    while (a < S_h && b < S_w) {
      if (h[a] < w[b]) ++a;
      else if (h[a] > w[b]) ++b;
      else {
	c = a;
	d = b;
	while (h[a] == h[c]) ++a;
	while (w[b] == w[d]) ++b;
	ans += (a-c)*(b-d);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 19692
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace How_Many_Ways
{
    class Program
    {
        static int n;
        static int x;
        static int count;

        static void Main(string[] args)
        {
            String str;
            while ((str = Console.ReadLine()) != "0 0")
            {
                count = 0;
                String[] input = str.Split(' ');
                n = int.Parse(input[0]);
                x = int.Parse(input[1]);
                List<int> list = new List<int>();
                search(3, ref list, 0);
                Console.WriteLine(count);
            }
        }

        static void search(int depth,ref List<int> list, int last)
        {
            if (depth == 0) return;
            for (int i = last + 1; i <= n; ++i)
            {
                if (list.Sum() + i == x && depth == 1)
                {
                    ++count;
                    return;
                }
                else
                {
                    list.Add(i);
                    search(depth - 1, ref list, i);
                    list.RemoveAt(list.Count() - 1);
                }
            }
        }
    }
}


Measured memory_bytes: 9700
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;
#define sd(n) scanf("%d", &n)
#define sdd(n, m) scanf("%d%d", &n, &m)
#define sddd(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n, m) printf("%d %d\n", n, m)
#define pddd(n, m, z) printf("%d %d %d\n", n, m, z)
#define pld(n) printf("%lld\n", n)
#define pldd(n, m) printf("%lld %lld\n", n, m)
#define plddd(n, m, z) printf("%lld %lld %lld\n", n, m, z)
#define sld(n) scanf("%lld", &n)
#define sldd(n, m) scanf("%lld%lld", &n, &m)
#define slddd(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
#define sf(n) scanf("%lf", &n)
#define sc(n) scanf("%c", &n)
#define sff(n, m) scanf("%lf%lf", &n, &m)
#define sfff(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define ss(str) scanf("%s", str)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = a; i >= n; i--)
#define mem(a, n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ce i == n ? '\n' : ' '
#define mod(x) ((x) % MOD)
#define gcd(a, b) __gcd(a, b)
#define lowbit(x) (x & -x)
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
	int ret = 0, sgn = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-')
			sgn = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		ret = ret * 10 + ch - '0';
		ch = getchar();
	}
	return ret * sgn;
}
inline void Out(int a) //ê?3?ía1ò
{
	if (a > 9)
		Out(a / 10);
	putchar(a % 10 + '0');
}

ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
///快速幂m^k%mod
ll qpow(ll x, ll n, ll mod)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = (res * x) % mod;
		x = x * x % mod, n >>= 1;
	}
	return res;
}

const int N = 2e5 + 10;

int main()
{
	int s,w;
	sdd(s,w);
	if(s>w)
	puts("safe");
	else
	puts("unsafe");
	return 0;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const long INF = 1e15+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 1e4;
long n, dp[1001][2 * N + 1];

int main()
{
  fastio;
  int h, n; cin >> h >> n;
  for (int i = 0; i <= n; i++){
    for (int j = 0; j <= 2 * N; j++){
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++){
    int x, cost; cin >> x >> cost;    
    for (int j = 0; j <= 2 * N; j++){
      dp[i][j] = dp[i - 1][j];
      if (x <= j) dp[i][j] = min(dp[i][j], min(dp[i][j - x], dp[i - 1][j - x]) + cost);
    }
  }
  long res = INF;
  for (int i = h; i <= 2 * N; i++) res = min(res, 1ll * dp[n][i]);
  cout << res;
  return 0;
}


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

int main()
{
	int n, y;
	cin >> n >> y;
	for (int i = 0; i <= n; i++){
		for (int j = 0; j + i <= n ; j++){
			if (i * 10000 + j * 5000 > y) continue;
			int k = y - 10000 * i - 5000 * j;
			if (k / 1000 == n - i - j){
				cout << i << " " << j << " " << k / 1000 << endl;
				return 0;
			}
		}

	}

	cout << -1 << " " << -1 << " " << -1 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map <string,int> mp;

int main(){
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    mp.clear();
    string a;
    map <string,int> point;
    for(int i=0;i<n;i++){
      int m;
      cin>>a>>m;
      mp[a]=0;
      point[a]=0;
      for(int j=0,b;j<m;j++) cin>>b,mp[a]|=(1<<b);
    }


    for(int i=0;i<=30;i++){
      int sum=n+1;
      for(auto it=mp.begin();it!=mp.end();it++) sum-=((mp[it->first]>>i)&1);

      for(auto it=mp.begin();it!=mp.end();it++)
	if((mp[it->first]&1<<i))point[it->first]+=sum;
    }
    int ans=1e9;
    string str;
    for(auto it=mp.begin();it!=mp.end();it++)
      if(ans>point[it->first])ans=point[it->first],str=it->first;
    cout <<ans<<" " <<str<<endl;
  }
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define mod 998244353 
#define pb push_back
//#define mp make_pair
#define INF 2000000011LL
#define INFLL 1000000000000000011LL
#define eps 1e-9
#define pp pair < pair<ll,ll> , ll> 
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define foll(i,j,k) for(ll i=j;i<=k;i++)
#define clr(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vll vector<ll>
#define sz(a) a.size()
#define len(a) a.length()
#define all(a) a.begin(),a.end()
#define io_file freopen("input_file.in", "r", stdin); freopen("output_file.in", "w", stdout)

const int MAXN = 2e5+5;
using namespace std;
ll power(ll x, ll y)
{
  ll res = 1;
  while(y>0)
  {
    if(y&1)
       {
         res = (res*x)%mod;
        }
     x = (x*x)%mod;
     y = y>>1;
  }
    return res;
}
// std::vector<ll> divi[100004];
// void divisor(int n)
// {
//    for(ll i=1;i<=n;i++)
//    {
//      for(ll j=i;j<=n;j+=i)
//      {
//        divi[j].pb(i);
//      }
//    }
// }

ll a[100004];
ll k;

// bool check(ll val)
// {
// 	for(int i=1;i<=k;i++)
// 	{

// 	}
// }


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // io_file;
    ll q,h,s,d,n;
    cin>>q>>h>>s>>d;
    cin>>n;
    ll two= min(min(d,2LL*s),min(4LL*h,8LL*q));
    ll one = min(s,min(4LL*q,2LL*h));
    ll ans = (n/2LL)*two + (n%2)*one;
    cout<<ans<<endl;
    return 0;
    

}
	

Measured memory_bytes: 764
import numpy as np
X, Y, A, B, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

A = A[0:X]
B = B[0:Y]
D = A+B+C

D.sort(reverse=True)

D = D[0:X+Y]
print(sum(D))

Measured memory_bytes: 31276
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
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;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

const int INF = 2002002002;

void solve(long long N, std::vector<long long> d){
    int ans = 0;
    REP(i, N) {
        for (int j = i + 1; j < N; j++) {
            ans += d[i] * d[j];
        }
    }
    print(ans);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> d(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&d[i]);
    }
    solve(N, std::move(d));
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace().map(|n| n.parse().unwrap());
    let (a, b): (i64, i64) = (iter.next().unwrap(), iter.next().unwrap());
    let arr: [i64; 3] = [a, b, a+b];
    let ans = if arr.iter().any(|x| x % 3 == 0) {
        "Possible"
    } else {
        "Impossible"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


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

    ll ans = 0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                ans += __gcd(__gcd(i, j), k);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3672
def main():
    from fractions import gcd
    from functools import reduce


    MOD = 10 ** 9 + 7

    def lcm_base(x, y):
        return (x * y) // gcd(x, y)

    def lcm(*numbers):
        return reduce(lcm_base, numbers, 1)

    def lcm_list(numbers):
        return reduce(lcm_base, numbers, 1)

    N = int(input())
    A = list(map(int, input().split()))

    tmp = lcm(*A)

    # print (tmp)
    ans = 0
    for a in A:
        ans += tmp // a
    ans %= MOD

    print (ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 6100
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
int v[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int r, g, b;
	cin >> r >> g >> b;
	if ((r * 100 + g * 10 + b) % 4) puts("NO");
	else puts("YES");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 y_0
#define y1 y_1
#define yn y_n
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;

int n,k,a[100005];

inline int cdiv(int a,int b){
	return (a+b-1)/b;
}

int main(){
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	printf("%d\n",cdiv(n-1,k-1));
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

#define MAX_NUM 200000

int main(void){
    char number[MAX_NUM];
    int i;
    int dummy =0;
    int sum =0;

    //入力
    for(i=0;i<MAX_NUM;i++){
        scanf("%c",&number[i]);
        if((48 > number[i]) || (number[i] > 57)) break;
        dummy = (number[i]-48);
        sum = sum + dummy;
        //printf("number = %d, sum = %d",dummy,sum);
    }
    //9の倍数
    if(sum % 9 == 0){
        printf("Yes");
        return 0;
    }else{
        printf("No");
        return 0;
    }

}

Measured memory_bytes: 1860
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;

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

   vector<int> A(N), Ar(N);
   double ave = 0.0;

   rep(i, 0, N) {
     cin >> A.at(i);
     Ar.at(i) = A.at(i) - i - 1;
   }

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

   int b = Ar.at(N / 2);

   ll ans = 0;
   rep(i, 0, N) {
     ans += abs(b - Ar.at(i));
   }
   cout << ans << endl;
 }


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

using namespace std;
            
int main(){

    string str;
    int s;
    
    cin >> str;
    s = str.size();
    
    for(int i = s - 1; i >= 0; --i){
		cout << str[i];
	}
    
    cout << endl;
    
	return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define vt vector
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;
template<typename T> T power(T a,T b){T r=1;while(b){if(b&1)r*=a;b/=2;a*=a;}return r;}

int main()
{
  fastio;
  int n;
  cin>>n;
  vt<ll> a(n),b(n),c(n);
  range(i,0,n)
  {
    int x,y;
    cin>>x>>y;
    a[i]=(x+y);
    b[i]=(y-x);
    c[i]=(x-y);
  }

  sort(all(a));
  sort(all(b));

  ll ans1=(a.back()-a.front()),ans2=(b.back()-b.front());
  ll ans3=(c.back()-c.front());
  cout<<max({ans1,ans2,ans3});

}

Measured memory_bytes: 7948
const fs = require('fs');

function main(input) {
  var arr = input.split('\n');
  var n = parseInt(arr[0], 10);
  var d = arr.slice(1, -1).map(n => parseInt(n, 10));
  d.sort((a, b) => b - a);

  var cur = Infinity;
  var cnt = 0;
  for (var i = 0; i < n; i++) {
    (d[i] < cur) ? cnt++ : NaN;
    cur = d[i];
  }
  console.log(cnt);
}

input = fs.readFileSync('/dev/stdin', 'utf8');
main(input);

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

int main() {
    string a, b;  cin >> a >> b;
    reverse(b.begin(), b.end());
    if (a == b)  cout << "YES" << endl;
    else  cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int>a(n), b(n), c(n);
	rep(i, n) {
		scanf("%d", &a[i]);
	}
	rep(i, n) {
		scanf("%d",& b[i]);
	}
	rep(i, n) {
		scanf("%d",&c[i]);
	}
	sort(all(a));
	sort(all(b));
	sort(all(c));
	vector<int>bc(n);
	rep(i, n) {
		int tmp=upper_bound(all(c), b[i])-c.begin();
		if (tmp < b.size()) {
			bc[i] = b.size() - tmp;
		}
	}
	
	vector<int>ba(n,n);
	rep(i, n) {
		int tmp = lower_bound(all(a), b[i]) - a.begin();
		ba[i] = tmp;		
	}
	
	ll ans = 0;
	rep(i, n) {
		ans += (ll)ba[i] * bc[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 2176
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
d=[0]*m
for i in range(1,m):
  d[i]=a[i]-a[i-1]
d.sort(reverse=True)
print(sum(d[n-1:]))

Measured memory_bytes: 82112
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n;cin>>n;
    vector<pll>ans(0);
    ll s;
    if(n%2)s=n;
    else s=n+1;
    REP(i,1,n+1){
        REP(j,i+1,n+1){
            if(s-i!=j)ans.pb(mp(i,j));
        }
    }
    cout<<ans.size()<<endl;
    rep(i,ans.size()){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cmath>
#include <math.h>
#include <stdio.h>
using namespace std;
int main(){
    double x1,x2,y1,y2;
    
    cin >> x1 >> y1 >> x2 >> y2;
    printf("%.8f\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
    
}


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

cnt = 0
flag = 0

for i in range(N):
    d1, d2 = map(int,input().split())

    if d1 == d2:
        cnt += 1
        if cnt >= 3:
            flag = 1
    else:
        cnt = 0

if flag == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final long k = scanner.nextLong();
        final Long[] eat = new Long[n];
        final Long[] food = new Long[n];

        long all = 0;
        for (int i = 0; i < n; i++) {
            final long tmp = scanner.nextLong();
            eat[i] = tmp;
            all += tmp;
        }

        if (all <= k) {
            System.out.println(0);
            return;
        }

        for (int i = 0; i < n; i++) {
            food[i] = scanner.nextLong();
        }

        Arrays.sort(eat);
        Arrays.sort(food, Comparator.reverseOrder());

        final long max = (long) Math.pow(10, 12);
        final long answer = specialBinarySearch(0, max, k, eat, food);
        System.out.println(answer);
    }

    private static long specialBinarySearch(final long min, final long max, final long base, final Long[] eat, final Long[] food) {
        if (max - min <= 1) {
            return max;
        }

        final long middle = (min + max) / 2;
        long counter = 0;
        for (int i = 0; i < eat.length; i++) {
            final long cost = eat[i] * food[i];
            if (cost > middle) {
                counter += (cost - middle + food[i] - 1) / food[i];
            }
        }

        if (counter > base) {
            return specialBinarySearch(middle, max, base, eat, food);
        } else {
            return specialBinarySearch(min, middle, base, eat, food);
        }
    }

    static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

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

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

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

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


Measured memory_bytes: 64468
#include <stdio.h>

int main(void)
{
    int i,t=0,k=0,g=0;
    char S[4];

    scanf("%s",S);

    for(i=0;i<3;i++){
       if(S[i]=='a')
         t++;}
    for(i=0;i<3;i++){
       if(S[i]=='b')
         k++;}
    for(i=0;i<3;i++){
       if(S[i]=='c')
         g++;}
    if(t==1 && k==1 && g==1)
      printf("Yes\n");
    else
      printf("No\n");
   return 0;
}

Measured memory_bytes: 128
import sys

N, M = map(int, input().split())

d = {}

for i in range(M):
    s, c = map(int, input().split())
    if s not in d:
        d[s] = c
    elif d[s] != c:
        print(-1)
        sys.exit()

# print(d)
# if d[1] == 0:
#     print(-1)
#     sys.exit()
ans = [0 for _ in range(N)]

for i in range(N):
    if i + 1 in d:
        ans[i] = d[i + 1]
if 1 not in d and N != 1:
    ans[0] = 1
if ans[0] == 0 and len(ans) != 1:
    print(-1)
else:
    print(*ans, sep="")


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

int main(){ 
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int c=-100;
    int d=100;
     vector<int> a(n);
     vector<int> b(m);
     for(int i=0;i<n;i++){
         cin>>a[i];
     }
     for(int i=0;i<m;i++){
         cin>>b[i];
     }
     for(int i=0;i<n;i++){
         c=max(c,a[i]);
     }
     for(int i=0;i<m;i++){
         d=min(d,b[i]);
     }
     c=max(c,x);
     d=min(d,y);
     if(c<d){
         cout<<"No War";
     }else{
         cout<<"War";
     }
    return 0;
}



Measured memory_bytes: 256
n=int(input())
k=int(input())
x=list(map(int,input().split()))

total=0
for c in x:
    ax=abs(c-0)
    bx=abs(k-c)
        
    a=2*ax
    b=2*bx
    total +=min(a,b)
    
print(total)        

Measured memory_bytes: 3060
n,m=map(int,input().split())
p=[0]*n
edge=[[]for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  p[a]+=1
  p[b]+=1
  edge[a].append(b)
  edge[b].append(a)
for i in p:
  if i%2:exit(print("No"))
if p.count(6)>=1 or p.count(4)>=3:exit(print('Yes'))
if p.count(4)<2:exit(print('No'))
s,t=[i for i in range(n) if p[i]==4]
ss=[0]*n
ss[s]=1
stack=[s]
visited={s}
for i in stack:
  for j in edge[i]:
    if j in visited:continue
    ss[j]+=ss[i]
    if p[j]==4:continue
    visited.add(j)
    stack.append(j)
if ss[t]==2:print("Yes")
else:print("No")

Measured memory_bytes: 33900
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,c = LI()
print(a*b//2)

Measured memory_bytes: 38256
/* The ASCII value of the lowercase alphabet is from 97 to 122. And, the ASCII value of the uppercase alphabet is from 65 to 90.*/

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

int main(){
  char abc;
  cin >> abc;
  if(abc>='a' && abc<='z'){
    cout << 'a';
  }
  else{
    cout << 'A';
  }
  return 0;
}


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

typedef long long ll;

ll f(ll x){
    if(x == 1)  return 1;
    return f(x/2)*2+1;
}

int main(){
    ll h;
    cin >> h;
    cout << f(h) << endl;
    
    return 0;
}


Measured memory_bytes: 3588
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007;

// b / a ≡ b * modinv(a,n) % n (mod n)
ll modinv(ll a, ll m) {
   	ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main() {
	int n, k;
	cin >> n >> k;
	ll a[n];
	rep(i, n) {
		cin >> a[i];
	}
	sort(a, (a + n));

	ll c[n + 2];
	c[k - 1] = 1;

	for(ll i = k - 1; i <= n; i++) {
		ll cur = ((i + 1) * c[i]) % mod;
		//cout << "i:" << i << " cur:" << cur << " :" << i + 1 - k + 1 << endl;

		c[i + 1] = cur * modinv(i + 1 - k + 1, mod) % mod;
	}
	

	ll plus = 0;
	ll minus = 0;

	for(int i = k - 1; i < n; i++) {
		plus = (plus + a[i] * c[i]) % mod;  
		
	}

	// min
	for (int i = 0; i <= n - k; i++) {

		minus = (minus + a[i] * c[n - i - 1]) % mod;  
	}
	cout << (plus - minus + mod) % mod << endl;

	return 0;
}


Measured memory_bytes: 4336
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{

  string s;
  cin >> s;
  rep(i, s.size())
  {
    if (i % 2 == 0 && s[i] == 'L')
    {
      cout << "No" << endl;
      return 0;
    }
    else if (i % 2 == 1 && s[i] == 'R')
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define MAXN 100005
int Set[MAXN];
int Root(int x)
{return Set[x]==x?x:Set[x]=Root(Set[x]);}
int N,Q;
int fa[MAXN];
int Que[MAXN][2];
int marked[MAXN];
int main()
{
	char op[3];
	int id;
	long long ans;
	while(~scanf("%d%d",&N,&Q)&&N&&Q)
	{
		memset(Que,0,sizeof Que);
		memset(fa,0,sizeof fa);
		memset(Set,0,sizeof Set);
		memset(marked,0,sizeof marked);
		ans=0;
		Set[1]=1;fa[1]=1;
		for(int i=2;i<=N;i++)
		{
			scanf("%d",fa+i);
			Set[i]=fa[i];
		}
		for(int i=1;i<=Q;i++)
		{
			scanf("%s%d",op,&id);
			if(op[0]=='Q')Que[i][0]=1;
			else {Que[i][0]=2;Set[id]=id;marked[id]++;}
			Que[i][1]=id;
		}
		for(int i=Q;i>=1;i--)
		{
			if(Que[i][0]==1)
				ans+=1LL*Root(Que[i][1]);
			else
			{
				marked[Que[i][1]]--;
				if(!marked[Que[i][1]])
					Set[Que[i][1]]=fa[Que[i][1]];
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4728
K, = map(int, input().split())
D, = map(int, input().split())
N = len(str(K))
M = 10**9+7
dp = [[0]*D for _ in range(N+1)]
dp2 = [[0]*D for _ in range(N+1)]
dp[0][0] = 1
dp2[0][0] = 1
for i in range(1, N+1):
    Ki = K%10
    K //= 10
    for j in range(D):
        for k in range(10):
            dp[i][(j+k)%D] = (dp[i][(j+k)%D] + dp[i-1][j])%M
        for k in range(Ki):
            dp2[i][(j+k)%D] = (dp2[i][(j+k)%D] + dp[i-1][j])%M
        dp2[i][(j+Ki)%D] = (dp2[i][(j+Ki)%D] + dp2[i-1][j])%M
print((dp2[N][0]-1)%M)


Measured memory_bytes: 60892
#include<iostream>
using namespace std;
int main(){
    int r,d,x;
    cin>>r>>d>>x;
    int a[1000];
    a[0] = x*r-d;
    cout<<a[0]<<endl;
    for(int i = 1; i<10; i++){
        a[i] = a[i-1]*r-d;
            
            cout<<a[i]<<endl;
            
   }
    
    return 0;
    
    
}

Measured memory_bytes: 256