akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
    using namespace std;
    int main(void){
        unsigned long long w,i,j,k,n,m,l;
        cin>>n>>w;
        unsigned long long stuff[n][2];//stuff[i][0]が重さでstuff[i][1]が価値
        for(i=0;i<n;i++){
            cin>>stuff[i][0]>>stuff[i][1];
        }
        unsigned long long chart[n+1][w+1];
        for(i=0;i<n+1;i++){
            for(j=0;j<w+1;j++){
                if(i==0||j==0){
                    chart[i][j]=0;
                    continue;
                }
                if(j<stuff[i-1][0]){
                chart[i][j]=chart[i-1][j];
                continue;
                }
                k = chart[i-1][j-stuff[i-1][0]]+stuff[i-1][1];
                l = chart[i-1][j];
                if(l<=k)
                chart[i][j]=k;
                else 
                chart[i][j]=l;
            }
        }
        cout<<chart[n][w]<<endl;
        return 0;
    }
     

Measured memory_bytes: 79104
K = int(input())
A, B = map(int,input().split())

count = 0
for i in range (1000):
    K_big = K*i
    if (K_big<=B) & (A<=K_big):
        count +=1
        
        
if count >=1:
    print('OK')
else:
    print('NG')

Measured memory_bytes: 9184
from collections import defaultdict

MOD = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)

for i in a:
    d[i] += 1

for v, c in d.items():
    if N % 2 == 0:
        if v % 2 == 1 and c == 2:
            continue
        else:
            print(0)
            exit()
    else:
        if v % 2 == 0 and c == 2:
            continue
        elif v == 0 and c == 1:
            continue
        else:
            print(0)
            exit()

print(pow(2, N // 2, MOD))

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

using namespace std;

long long fast(long long a, long long b ,long long c){
    long long ret = 1%c;
    for (;b;b >>= 1,a = a*a%c){
        if (b & 1){
            ret = ret*a%c;
        }
    }
    return ret;

}

long long popcount(long long n){
    long long ret = 0;
    while (n>0){
        if (n & 1 ){
            ret++;
        }
        n >>= 1;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);

    int n;
    string s;
    cin >> n >> s;
    int one = 0;
    for (char c : s){
        if (c == '1'){
            one += 1;
        }
    }

    if(one == 1) {
		if(s[n - 1] == '1') {
			for(int i = 0; i < n; ++i) {
				if(i == n - 1) {
					cout << 0 << '\n';
				} else if(i != n - 1) {
					cout << 2 << '\n';
				} 
			}
		} else {
			for(int i = 0; i < n; ++i) {
				if(s[i] == '1') {
					cout << 0 << '\n';
				} else if(i == n - 1) {
					cout << 2 << '\n';
				} else {
					cout << 1 << '\n';
				}
			}
		}
		return 0;
	}

    
    long long sa,sb;
    for(int p=0;p<n;++p){
        sa = (2*sa+s[p]-'0') % (one+1);
        sb = (2*sb+s[p]-'0') % (one-1);
    }

    for (int i=0;i<n;++i){
        if (s[i] == '0'){
            long long tem = (sa + fast(2,n-1-i,one+1)) % (one+1);
            int count = 1;
            while (tem>0){
                long long d = popcount(tem);
                tem = tem%d;
                count += 1;
            }
            cout << count << "\n";
        }
        else{
            long long tem = (sb - fast(2,n-1-i,one-1)+one-1) % (one-1);
            int count = 1;
            while (tem>0){
                long long d = popcount(tem);
                tem = tem%d;
                count += 1;
            }
            cout << count << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 3788
N = int(input())
H = [int(i) for i in input().split()]

# print(N)
# print(H)

mizu_num=0
renzoku= False
while(True):
    #水やりがいらない花を探す
    for i in range(len(H)):
        if H[i]>0:
            H[i]-=1
            renzoku=True
        else:
            if renzoku==True and i!=0:
                mizu_num+=1
            renzoku=False
    # print(renzoku,mizu_num)
    if renzoku==True:
        mizu_num+=1

    # print(H, mizu_num)

    if not any(H):
        break

print(mizu_num)


Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string w;

  std::cin >> w;
  
  std::map<char, int> map;

  for (const auto& c : w)
    map[c] ++;

  bool valid = true;

  for (const auto& kv : map)
    if (kv.second % 2)
      valid = false;

  std::cout << (valid ? "Yes" : "No") << std::endl;

  return 0;
}


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

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	
	string a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	
	string b[m];
	for(int i = 0; i < m; i++)
	{
		cin >> b[i];
	}
	
	for(int i = 0; i < n - m + 1; i++)
	{
		for(int j = 0; j < n - m + 1; j++)
		{
			bool flag = true;
			for(int k = i; k < i + m; k++)
			{
				for(int l = j; l < j + m; l++)
				{
					if(a[k][l] != b[k - i][l - j])
					{
						flag = false;
						break;
					}
				}
			}
			
			if(flag == true)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	
	cout << "No" << endl;
}

Measured memory_bytes: 256
#B - YYMM or MMYY(ABC126)
S=input()
A=S[0]+S[1]
B=S[2]+S[3]
if 0<int(A)<13:
    if 0<int(B)<13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif 0<int(B)<13:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include<iostream>
#include<math.h>

using namespace std;

int main(void){
    int A,B,C;

    cin >> A >> B >> C;

    if((A==B) && (B == C) ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
    }


Measured memory_bytes: 256
#include <cstdio>

int main() {
    int a, b;
    scanf("%d %d", &a,&b);

    int d = a / b;
    int r = a % b;
    double f = (double)a / b;

    printf("%d %d %.5f\n", d, r, f);
    return 0;
}


Measured memory_bytes: 2744
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  int q;
  cin >> q;
  deque<int> v;
  while (q--) {
    int t;
    cin >> t;
    if (t == 0) {
      if (in()) {
        v.emplace_back(in());
      } else {
        v.emplace_front(in());
      }
    }
    if (t == 1) cout << v[in()] << endl;
    if (t == 2) {
      if (in()) {
        v.pop_back();
      } else {
        v.pop_front();
      }
    }
  }
}



Measured memory_bytes: 6288
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline


def main():
    n = int(input())
    s = [None] * n
    for i in range(n):
        s[i] = str(input()).replace("\n", "")

    ans = dict()
    pairs = 0
    for i in s:
        i = ''.join(sorted(list(i)))

        if i in ans:
            pairs += ans[i]
            ans[i] += 1
            continue

        ans[i] = 1

    print(pairs)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24936
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

vector<int> cost = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

/* return true if s>t */
bool strcomp(string s, string t) {
  if (s.size() > t.size()) {
    return true;
  } else if (s.size() < t.size()) {
    return false;
  } else {
    return s > t;
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  typedef pair<int, int> P;
  vector<P> AB(M); /* A:num, B:cost */

  rep(i, M) {
    cin >> AB[i].fi;
    AB[i].se = cost[AB[i].fi];
  }

  vector<int> dp(N + 1, -INF);
  dp[0] = 0;
  rep(i, N) {
    rep(j, M) {
      int ncost = AB[j].se;
      if (i + ncost <= N)
        chmax(dp[i + ncost], dp[i] + 1);
    }
  }

  int keta = dp[N];
  sort(all(AB), greater<P>());
  string ans;

  int itr = N;
  rep(i, keta) {
    rep(j, M) {
      int num = AB[j].fi;
      int cost = AB[j].se;
      if (itr - cost >= 0 && dp[itr] - 1 == dp[itr - cost]) {
        ans += (char)(num + '0');
        itr -= cost;
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] counter = new int[100];
        int maxCnt = 0;
        
        for (int i = 0; i < counter.length; i++) {
            counter[i] = 0;
        }
        
        while (scanner.hasNext()) {
            int n = scanner.nextInt() - 1;
            counter[n]++;
            if (counter[n] > maxCnt) {
                maxCnt = counter[n];
            } 
        }
        
        for (int i = 0; i < counter.length; i++) {
            if (counter[i] == maxCnt) {
                System.out.println(i+1);
            }
        }
    }
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i < (n)i++)
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define re(s) reverse((s).begin(), (s).end())
#define int long long
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

long long x[10000010], y[10000010];
signed main()
{

   cin.tie(0);
   ios::sync_with_stdio(false);

   int a, b, n, cnt = 0, ans = 0;
   string s, v;

   cin >> n >> s;

   if (n % 2 == 1)
   {
      cout << "No" << '\n';
      return 0;
   }
   rep(i, n / 2)
   {
      if (s[i] != s[(n / 2) + i])
      {
         cout << "No" << '\n';
         return 0;
      }
   }
   cout << "Yes" << '\n';
}

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

using namespace std;

const int MAX_N = 10001;

bitset<MAX_N> sieve;
vector<int> primes;
void eratosthenes(){
	sieve[0] = sieve[1] = true;
	for(int i = 2; i < MAX_N; ++i){
		if(sieve[i]){ continue; }
		primes.push_back(i);
		for(int j = i + i; j < MAX_N; j += i){ sieve[j] = true; }
	}
}

int main(){
	eratosthenes();
	int n;
	while(cin >> n){
		int answer = 0;
		for(int i = 1; i <= n; ++i){
			if(!sieve[i] && !sieve[n + 1 - i]){ ++answer; }
		}
		cout << answer << endl;
	}
	return 0;
}

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

using namespace std;

int R,G,B,N;
typedef long long LL;

int main() {
	scanf("%d%d%d%d",&R,&G,&B,&N);
	LL ans = 0;
	for (int r=0;r<=3000;r++) {
		for (int g=0;g<=3000;g++) {
			if (N - r*R - g*G >= 0 && (N - r*R - g*G) % B == 0) {
				ans++;
			}
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()

  a=LI()
  b=LI()

  if n==1 and a[0]!=b[0]:
    return 0

  l1=[]
  l2=[]

  amx=a[0]
  l1.append(1)
  for i in range(1,len(a)):
    x=a[i]
    if amx<x:
      # 矛盾
      if x>b[i]:
        print(0)
        exit()

      l1.append(1)
      amx=x
    elif amx==x:
      l1.append(amx)
    else:
      print(0)
      exit()

  b.reverse()
  l1.reverse()

  bmx=b[0]
  l2.append(1)
  for i in range(1,len(b)):
    x=b[i]
    if bmx<x:
      # 矛盾
      if x>a[n-i-1]:
        print(0)
        exit()

      l2.append(1)
      bmx=x
    elif bmx==x:
      l2.append(min(bmx,l1[i]))
    else:
      print(0)
      exit()

  ans=1
  for x in l2:
    ans*=x
    ans%=mod

  return ans

print(main())


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

using namespace std;

using ll = long long int;

ll calc(ll a, ll b, ll x) { return ((ll)(a * x / b) - (ll)a * (ll)(x / b)); }

int main() {
    // Input
    ll A, B, N;
    cin >> A >> B >> N;

    // Process
    ll ans = calc(A, B, N);
    ll res;

    if (N >= B) {
        res = calc(A, B, B - 1);
        if (res > ans) ans = res;
    }

    // Output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

char island[13][13];

void dfs(int i, int j){
	int di, dj;
	
	island[i][j] = '0';
		
	for (di = -1; di <= 1; di += 2){
		if (0 <= i + di && i + di < 12 && island[i + di][j] == '1'){
			dfs(i + di, j);
		}
	}
	for (dj = -1; dj <= 1; dj += 2){
		if (0 <= j + dj && j + dj < 12 && island[i][j + dj] == '1'){
			dfs(i, j + dj);
		}
	}
}

int main(void)
{
	int i, j;
	int num;
	
	while (1){
		for (i = 0; i < 12; i++){
			if (scanf("%s", island[i]) == EOF){
				return (0);
			}
		}
		
		num = 0;
		for (i = 0; i < 12; i++){
			for (j = 0; j < 12; j++){
				if (island[i][j] == '1'){
					dfs(i, j);
					num++;
				}
			}
		}
		
		printf("%d\n", num);
	}
	
	return (0);
}

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

typedef long long ll;

/* メモリ食い過ぎ注意 */
// #define int ll
#define ALL(v) v.begin(), v.end()
#define _REP(i, n) for (int i = 0; i < n; i++)
#define REP(n) _REP(i, n)

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, m;
    int a[100000], b[100000];
    cin >> n >> m;
    for (int i = 0; i < m; i++)
        cin >> a[i] >> b[i];

    vector<pair<int, int>> v;
    for (int i = 0; i < m; i++)
        v.push_back({b[i], a[i]});

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

    // for (int i = 0; i < v.size(); i++)
    //     cout << v[i].second << "," << v[i].first << endl;
    int idx = 0;
    int cnt = 0;

    while (idx < v.size())
    {
        int tmp = v[idx].first;
        cnt++;
        for (int i = idx + 1; i <= v.size(); i++)
        {
            idx = i;
            if (i == v.size())
                break;
            if (v[i].second >= tmp)
            {
                break;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 2168
from itertools import product, compress

N = int(input())
Ss = input()

Fss = [list(compress(Ss[:N], sels))[::-1] for sels in product([0, 1], repeat=N)]

ans = 0
for iFs in range(2 ** N):
    Fs = Fss[iFs]
    Gs = Fss[2 ** N - 1 - iFs]

    lenF = len(Fs)
    lenG = N - lenF
    dp = [1] + [0] * lenF
    for i, s in enumerate(Ss[N:]):
        dp2 = [0] * (lenF + 1)
        for j in range(lenF + 1):
            if dp[j] == 0: continue
            if j < lenF and s == Fs[j]:
                dp2[j+1] += dp[j]
            if 0 <= i-j < lenG and s == Gs[i-j]:
                dp2[j] += dp[j]
        dp = dp2

    ans += dp[lenF]

print(ans)


Measured memory_bytes: 150096
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

int ctoi(const char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return -1;
	}
}
int keta(int a) {
	return to_string(a).size();
}
int n,a[100010],s[5];
signed main() {
	cin>>n;
	Rep(i,n){
		cin>>a[i];
	}
	int ans=1;
	Rep(i,n){
		int cnt=0,iwa=-1;
		if(a[i]==s[0]){cnt++;iwa=0;}
		if(a[i]==s[1]){cnt++;iwa=1;}
		if(a[i]==s[2]){cnt++;iwa=2;}
		if(iwa==-1){
			cout<<0<<endl;return 0;
		}
		ans*=cnt;s[iwa]++;
		ans%=mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O2")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 

//USE AT YOUR OWN RISK
lli tmod(lli x,lli m=mod){return (x%m+m)%m;}

template <typename T> 
void DEBUG_ARR(vt<T> a,char c)
{
	f(i,0,a.size())cout<<tmod(a[i])<<c;
	cout<<"\n";
}

//make sure x is below mod
lli power(lli x, lli y,lli m=mod) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%m; 
        y = y>>1; 
        x = (x*x)%m;  
    }
    if(res<0)
       res+=m; 
    return res; 
}


// lli fact[2000009];
// lli ncr(lli n,lli r){
//     lli ans=fact[n];
//     if(r>n)return 0;
//     ans=(ans*power(fact[n-r],mod-2))%mod;
//     ans=(ans*power(fact[r],mod-2))%mod;
//     return ans;
// }


int main() 
{ 
    // fact[0]=1;
    // f(i,1,2000001)fact[i]=(i*fact[i-1])%mod;
    
    fastio;
    int t;
    // cin>>t;
    t=1;
    int temp=t;
	while(t--){
        // cout<<"Case #"<<temp-t<<": ";
        lli n,k;cin>>n>>k;
        lli ans[k+1];
        memset(ans,1,sizeof ans);
        lli f[k+1];
        f(i,1,k+1)f[i]=power(k/i,n);
        lli g[k+1];
        fd(i,k,0){
            g[i]=f[i];
            for(lli j=2;j*i<=k;j++)g[i]=(g[i]-g[j*i])%mod;
        }
        lli tans=0;
        f(i,1,k+1)tans=(tans+i*g[i])%mod;
        cout<<tmod(tans);
    }   
    return 0; 	
}

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

int dp[200010];
int main() {
	int N, p;
	cin >> N;
	for(int i=0; i<N; ++i){
	    cin >> p;
	    dp[p]=dp[p-1]+1;
	}
	int mx=0;
	for(int i=1; i<=N; ++i) mx=max(mx, dp[i]);
	cout << N-mx << endl;
	return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int main(){

  char word[8];
  int pre_word=0;
  int age=-1;
  int max_age=0;
  int ans;
  int i;

  i=0;

  while(scanf("%c",&word[i]) != EOF){
    if(word[i] == '\n'){ break; }
    i++;
    word[i]='\0';

    if(strcmp(word,"chicken")==0){

      strcpy(word,"");

      if(pre_word != 1){
	age++;
	if(age > max_age){
	  max_age = age;
	  ans=1;
	}
      }
      else{
	age = 0;
	//cout << "test chi" << endl;
      }
      pre_word=1;
      i=0;
    }


    else if(strcmp(word,"egg")==0){

      strcpy(word,"");

      if(pre_word != 2){
	age++;
	if(age > max_age){
	  max_age = age;
	  ans = 2;
	}
      }
      else{
	age = 0;
	//cout << "test egg" << endl;
      }
      pre_word=2;
      i=0;
    }

  }


  if(ans == 1)
    cout << "chicken" << endl;
  else
    cout << "egg" << endl;

  return 0;
}

Measured memory_bytes: 1148
#include<stdio.h>
int main() {
	long long int a = 100000007, b = 1000000007;
	long long int x, y;
	scanf("%lld %lld", &x, &y);
	if (x%y == 0) printf("-1");
	else if (a % y == 0) printf("%lld", b*y);
	else  printf("%lld", a*x);
	return 0;
}

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

typedef long long ll;

#define rep(var,n) for(int var=0;var<(n);++var)

int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n; cin >> n;
  int a; cin >> a;
  int b; cin >> b;

  cout << min(a*n,b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(b-a==c-b) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main()
{
	int k ;
	cin >> k;
	
	int sum = 0;
	
	rep(i,k){
		rep(j, k){
			rep(h,k){
				sum += gcd(i+1,gcd(j+1,h+1)) ;
			}
		}
	}
	cout <<sum <<endl;
}	


Measured memory_bytes: 3632
n = int(input())
words = [0] * n
ans = 'Yes'
for i in range(n):
    words[i] = input()
    if i == 0:
        continue

    if words[i-1][-1] != words[i][0] or words[i] in words[:i]:
        ans = 'No'
print(ans)

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

int main(void){
    int n;
    cin >> n;
    int a[n],c[n];
    for(int i = 0;i < n;i++)cin >> a[i];
    for(int i = 0;i < n;i++)c[i] = a[i];
    
    long int count = 0,count2 = 0,sum = 0;
    
    for(int i = 0;i < n;i++){
        if(i % 2 == 0){
            if(sum + a[i] <= 0){
                int b = 1-sum;
                count += abs(b-a[i]);
                a[i] = b;
            }
            sum += a[i];
        } else {
            if(sum + a[i] >= 0){
                int b = -1-sum;
                count += abs(b-a[i]);
                a[i] = b;
            }
            sum += a[i];
        }
    }
    
    sum = 0;
    
    for(int i = 0;i < n;i++){
        if(i % 2 == 1){
            if(sum + c[i] <= 0 || c[i] <= 0){
                int b = 1-sum;
                count2 += abs(b-c[i]);
                c[i] = b;
            }
            sum += c[i];
        } else {
            if(sum + c[i] >= 0 || c[i] >= 0){
                int b = -1-sum;
                count2 += abs(b-c[i]);
                c[i] = b;
            }
            sum += c[i];
        }
    }
    cout << min(count,count2) << endl;
}

Measured memory_bytes: 1024
from sys import exit
n=int(input())
z=[]
for i in range(n):
	x,y,h=map(int,input().split())
	z.append((x,y,h))
for i in range(101):
	for j in range(101):
		pp=-1
		ff=True
		for k in range(n):
			if(pp==-1 and z[k][2]>0):
				pp=z[k][2]+abs(z[k][0]-i)+abs(z[k][1]-j)
			else:
				zk=max(pp-abs(z[k][0]-i)-abs(z[k][1]-j),0)
				if(zk!=z[k][2]):
					ff=False
					break
		if(ff):
			for k in range(n):
				zk=max(pp-abs(z[k][0]-i)-abs(z[k][1]-j),0)
				if(zk!=z[k][2]):
					ff=False
					break
			if(ff):
				print(i,j,pp)
				exit(0)

Measured memory_bytes: 3064
n=int(input())
p=[]
for i in range(n):
  p.append(list(map(int,input().split())))
p.sort()

c=[set() for i in range(n)]
for i in range(n):
  for j in range(n):
    c[i].add((p[i][0]-p[j][0],p[i][1]-p[j][1]))
mn=1 if n==1 else 100
for i in range(n):
  for j in range(i+1,n):
    cnt=0
    pq=(p[i][0]-p[j][0],p[i][1]-p[j][1])
    for k in range(n):
      if not(pq in c[k]):
        cnt+=1
    mn=min(mn,cnt)
print(mn)


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

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

	for(int i = 1; i < 50000; ++i){
		if(floor(i*1.08) == N){ cout << i << endl; return 0; }
	}

	cout << ":(" << endl;

	
	return 0;
}


Measured memory_bytes: 256
N = int(input())
Hs = [int(H) for H in input().split(' ')]
cur_num = Hs[0]
impossible = False

for i in range(1, N):
    if cur_num < Hs[i]:
        cur_num = Hs[i] - 1
    elif cur_num > Hs[i]:
        impossible = True
        break

print('No' if impossible else 'Yes')

Measured memory_bytes: 14252
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    int n;
    while(cin>>n&&n){
        vector<vector<int>> fie(30,vector<int>(30,0));
        rep(i,n){
            int x,y;
            cin>>x>>y;
            fie[y][x]++;
        }
        
        
        int tx=10,ty=10;
        int m;
        cin>>m;
        rep(i,m){
            char dir;
            int dist;
            cin>>dir>>dist;
            int dy[]={1,0,-1,0};
            int dx[]={0,1,0,-1};
            map<char,int> mp;
            mp['N']=0;
            mp['E']=1;
            mp['S']=2;
            mp['W']=3;
            
            int d = mp[dir];
            for(int k=1;k<=dist;k++){
                tx+=dx[d];
                ty+=dy[d];
                n-=fie[ty][tx];
                fie[ty][tx]=0;
            }
        }
        if(n==0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3140
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 1000005 ;
using namespace std ;

int n, h[26], f[N][26], r[N] ;
char s[N], t[N] ;
struct poi {
    int x, y ;
} a[N] ;

int main() {
    scanf("%d", &n) ;
    scanf("%s%s", s + 1, t + 1) ;
    bool flg = true ;
    rep(i, 1, n) if (s[i] != t[i]) 
        flg = false ;
    if (flg) {
        printf("0\n") ;
        return 0 ;
    }
    rep(i, 0, 25) h[i] = 0 ;
    rep(i, 1, n) {
        h[s[i] - 'a'] = i ;
        rep(j, 0, 25) f[i][j] = h[j] ;
    }
    int las = n ;
    for (int i = n ; i; -- i) {
        las = min(las, i) ;
        int x = f[las][t[i] - 'a'] ;
        if (!x) {
            printf("-1\n") ;
            return 0 ; 
        }
        r[x] = max(r[x], i) ;
        las = x ;
    }
    int tot = 0, ans = 0 ;
    rep(i, 1, n) if (r[i]) {
        ++ tot ;
        a[tot].x = i, a[tot].y = r[i] ;
    }
    a[tot + 1].x = n + 1 ;
    rep(i, 1, n) {
        int l = i, r = tot + 1, goal = a[i].y - i, ret = r ;
        for ( ; l <= r ; ) {
            int mid = (l + r) / 2 ;
            if (a[mid].x - mid >= goal) ret = mid, r = mid - 1 ;
                else l = mid + 1 ;
        }
        ans = max(ans, ret - i) ;
    }
    printf("%d\n", ans) ;
    return 0 ;
}

Measured memory_bytes: 115456
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
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; }

static const ll mod = 1000000007LL;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


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

  ll ans = modpow(10, n, mod);
  ans = (ans + 3 * mod - modpow(9, n, mod) * 2 + modpow(8, n, mod)) % mod;
  cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    if (((n/100)%10)==(((n/10)%100)%10)){
        if ((n/1000)==((n/100)%10)) {
            cout << "Yes" << endl;
        }
        else if ((n%10)==((n/100)%10)) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 384
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2002 , P = 1e9 + 7;
inline void pp(int &x,int d){if((x+=d)>=P)x-=P;}
int n , m , K , f[N] , g[N];

int main(){
  cin >> n >> m >> K;
  int l = (n + m - 1) / (K - 1);
  f[0] = 1;
  int ans=0 , nmod = n % (K - 1) , mmod = (m - 1) % (K - 1);
  rep(i,1,l+1) {
    rep(j,0,n+1) g[j]=0;
    rep(j,0,n+1) if(f[j]) {
      rep(k,1,K) if(j+k<=n) pp(g[j+k],f[j]);
    }
    rep(j,0,n+1) if(j % (K - 1) == nmod){
      int k = i * (K - 1) - j;
      if(k <= m - 1 && k % (K - 1) == mmod)
        pp(ans , g[j]);
    }
    rep(j,0,n+1) if(f[j]) {
      pp(g[j],f[j]);
    }
    rep(j,0,n+1) f[j]=g[j];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,t=map(int,input().split())
a=list(map(int,input().split()))
b=[]
min_a=a[0]
cnt_min=1
for ai in a[1:]:
  if min_a<ai:
    b.append([ai,ai-min_a,cnt_min])
  elif min_a==ai:
    cnt_min+=1
  elif min_a>ai:
    cnt_min=1
    min_a=ai

b.sort(key=lambda x:x[1])
max_v=b[-1][1]
ans={}
while b and max_v==b[-1][1]:
  d,v,e=b.pop()
  if d in ans:
    if e==ans[d][0]:
      ans[d]=[e,ans[d][1]+1]
    elif e>ans[d][0]:
      ans[d]=[e,1]
    else:
      pass
  else:
    ans[d]=[e,1]
tmp=0
for v in ans.values():
  tmp+=min(v)
print(tmp)


Measured memory_bytes: 74092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define req(i,a,b) for(ll i=(a);i>=(b);--i)
#define name "a"
#define pb push_back
#define sz size()
#define ff first
#define ss second
#define xd '\n'
#define dc " "
#define Truong_Thanh_Minh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair < ll , ll > ii;
const ll maxn = 1e3+7, oo = 1e18, base = 311, mod = 1e9+7;
const double PI = 3.141592654;
ll lt, ls, n, f[maxn][maxn], res;
string s, t;
int main()
{
    Truong_Thanh_Minh
    //freopen(name".inp","r",stdin);
    //freopen(name".out","w",stdout);
    cin >> s >> t;
    ls = s.sz;
    lt = t.sz;
    s = " " + s;
    t = " " + t;
    rep (i, 1, ls - lt + 1)
    {
        ll cur = 0;
        rep (j, 1, lt)
            if (s[i + j - 1] == t[j])
                ++ cur;
        res = max (res, cur);
    }
    cout << lt - res;
}


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

#define PI 3.14159265358979323846
#define int long long int
#define ff first
#define ss second
#define pb push_back

#define N 1010
#define MOD 1000000007

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;

    if (m1 == m2)
    {
    	cout << 0;
    }
    else
    {
    	cout << 1;
    }
   	return 0;	
   		
}

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

typedef pair<int,int> PII;
typedef long long LL;
const int M=2e5+5;
const int MO=2019;

char s[M];
int cnt[MO];

int main()
{
	scanf("%s",s);
	int n=strlen(s);
	cnt[0]=1;
	int now=0;
	int p=1;
	LL ans=0;
	for(int i=n-1;i>=0;i--,p=p*10%MO)
	{
		now=(now+(s[i]-'0')*p)%MO;
		ans+=cnt[now];
		cnt[now]++;
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

using ll = long long;

constexpr ll mod = 1e9 + 7;

ll dp[22][1 << 21];

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

  int n;
  cin >> n;

  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    vector<int> a;
    for (int j = 0; j < n; ++j) {
      int tmp;
      cin >> tmp;
      if (tmp) {
        a.emplace_back(j);
      }
    }
    int mask = (1 << n) - 1;
    for (int j: a) {
      int k = mask ^ (1 << j);
      for (int s = k;; s = (s - 1) & k) {
        dp[i + 1][s | (1 << j)] = (dp[i + 1][s | (1 << j)] + dp[i][s]) % mod;
        if (!s) {
          break;
        }
      }
    }
  }

  cout << dp[n][(1 << n) - 1] << '\n';

  return 0;
}


Measured memory_bytes: 344320
// glory be to the sky
#include<bits/stdc++.h> 


using namespace std;
	
typedef long long ll;  

int main(){

	ios::sync_with_stdio(false);
	cin.tie(0);

	char k;
	cin >> k;
	if (k == 'a' || k == 'e' || k == 'i' || k == 'o' || k == 'u') cout << "vowel\n";
	else cout << "consonant\n";
	return 0;	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long

using namespace std;



int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int n;
    ios::sync_with_stdio(false);
    cin >> n;
    cout << 24 + 24 - n;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	ll ans = 0;
	if( a + b >= 2 * c ) {
		if( x > y ) {
			ans += 2 * c * y;
			
			if( a <= 2 * c ) {
				ans += (x - y) * a;
			} else {
				ans += (x - y) * 2 * c;
			}
		} else if( x < y ) {
			ans += 2 * c * x;
			
			if( b <= 2 * c ) {
				ans += (y - x) * b;
			} else {
				ans += (y - x) * 2 * c;
			}
		} else {
			ans += 2 * c * x;
			cout << ans << endl;
			return 0;
		}
	} else {
		ans = a * x + b * y;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3592
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
A.sort()
ans = 0
P = [0] * (10 ** 6 + 1)
for a in A:
    if P[a] == 0:
        for i in range(10 ** 7):
            x = a * i
            if x > 10 ** 6:
                break
            P[x] = 1
        if cnt[a] == 1:
            ans += 1
print(ans)

Measured memory_bytes: 38824
INF = 10**18

S = '0'+input()
N = len(S)

dp = [[INF,INF] for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(2):
        s = int(S[-1-i])
        s += j

        for a in range(10):
            ni = i+1
            nj = 0
            b = a-s
            if b < 0:
                b += 10
                nj = 1
            dp[ni][nj] = min(dp[ni][nj],dp[i][j]+a+b)

print(dp[N][0])

Measured memory_bytes: 138464
import sys
input=sys.stdin.readline
s=input()
al=set(chr(ord('a')+i) for i in range(26))

def f(s,al):
    if len(s)==0:
        return -1
    t=f(s[1:],al-set([s[0]]))
    if t==(-1):
        larger=[x for x in al if x>s[0]]
        if not larger:
            return -1
        return min(larger)
    return s[0]+t

ans=f(s,al)
print(ans)


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

int main(){
	int A,B;
	cin >> A >> B;
	if(A == B){
		cout << 2*max(A,B) << endl;
	}else{
		cout << 2*max(A,B) - 1<< endl;
	}
	 return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


int main(){
	
	double sp[]={48,51,54,57,60,64,69,75,81,91,1e50};
	string s[]={
		"light fly",
		"fly",
		"bantam",
		"feather",
		"light",
		"light welter",
		"welter",
		"light middle",
		"middle",
		"light heavy",
		"heavy",
	};
	
	double a;
	while(cin>>a){
		rep(i,10000){
			if(sp[i]>=a){
				cout<<s[i]<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int   ll;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
signed main()
{
    fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--)
    {
        double P=3.14159265358979323;
        double A,B;
        ll H,M;
        cin>>A>>B>>H>>M;
        double x=3600*H+M*60;
        double y=12*M*60;
        double ang=abs(x-y)/(120.0);
        double pang=360.0-ang;
        ang*=P;
        ang/=180.0;
        double ans=sqrtl(A*A+B*B-2*A*B*cos(ang));
        cout<<fixed<<setprecision(10)<<ans<<endl;
    }
}

Measured memory_bytes: 4132
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
	int n;

	while(cin >> n){
		if(n == 0){
			break;
		}

		int count = 0;

		while(n > 0){
			n /= 5;
			count += n;
		}

		cout << count << endl;
	}

	return 0;
} 

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  ll N; cin >> N;
  ll ans = 1;
  vector<ll> a(N); rep(i, N) cin >> a[i];
  sort(a.begin(), a.end());
  if (a[0] == 0) {cout << 0 << endl; return 0;}
  sort(a.begin(), a.end(), greater<ll>());
  ll tmp = 1000000000000000000;
  rep(i, N){
    ans *= a[i];
    tmp /= a[i];
    if (tmp == 0) {cout << -1 << endl; return 0;}
  }
  cout << ans << endl;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fprintf(stderr, "\n"), fflush(stderr)

typedef long long ll;

using namespace std;

const ll inf = static_cast<const ll>(1e18);
const int infi = static_cast<const int>(1e9);


void solve() {
    int n;
    cin >> n;
    vector<pair<int, int> > S(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        S[i] = {a, b};
    }
    sort(S.begin(), S.end(), [](pair<int, int> a, pair<int, int> b) {
        return a.first + a.second > b.first + b.second;
    });
    ll res = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) res += S[i].first;
        else res -= S[i].second;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef SIR
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
}

Measured memory_bytes: 1024
from collections import deque

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

A = deque(sorted(A,reverse=True))
B = deque([])
n = 0
for m in range(M):
    if A:
        if B:
            if (A[0] > B[0]):
                B.append(A.popleft()//2)
                continue
        else:
            B.append(A.popleft()//2)
            continue
    # print(m,n)
    n += 1
    b = B.popleft()
    B.append(b//2)

print(sum(A)+sum(B))

Measured memory_bytes: 93392
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> X(N),Y(N);
    rep(i,0,N)cin >> X[i] >> Y[i];
    vector<int> num(N);
    rep(i,0,N)num[i] = i;
    double sum = 0;
    do{
        rep(i,1,N){
            double dx = X[num[i]] - X[num[i-1]];
            double dy = Y[num[i]] - Y[num[i-1]];
            double dist = sqrt(dx * dx + dy * dy);
            sum += dist;
        }
    }while(next_permutation(num.begin(), num.end()));
    double n = 1;
    rep(i,1,N+1)n *= i;
    sum /= n;
    printf("%.9lf\n",sum);
}

Measured memory_bytes: 256
N,M = list(map(int,input().split()))
H = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(M)]
MAX = [0 for _ in range(N)]
for ab in AB:
    MAX[ab[0]-1] = max(MAX[ab[0]-1],H[ab[1]-1])
    MAX[ab[1]-1] = max(MAX[ab[1]-1],H[ab[0]-1])
count = 0
for i,h in enumerate(H):
    if h > MAX[i]:
        count += 1
print(count)

Measured memory_bytes: 31880
#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;

using namespace std;

int main()
{
   string s;
   cin>>s;
   int su = 0;
   rep(i,s.length()){
       su = su + (s[i]-48);
   }
   if((su%9)==0){
       cout<<"Yes"<<endl;
   }
   else{
       cout<<"No"<<endl;
   }
   return 0;
}

Measured memory_bytes: 3732
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }
 
struct  P{
    double x, y;
};
 
int main()
{
    P p[4];
    while(cin >> p[0].x >> p[0].y >> p[1].x >> p[1].y >> p[2].x >> p[2].y >> p[3].x >> p[3].y)
    {
        // y1 / x1 = -x2 / y2;
        // y1 * y2 = -x1 * x2;
        
        double x1 = p[0].x - p[1].x, x2 = p[2].x - p[3].x;
        double y1 = p[0].y - p[1].y, y2 = p[2].y - p[3].y;
        
        if(!x1 && !y2)      cout << "YES" << endl;
        else if(!y1 && !x2) cout << "YES" << endl;
        else if(abs(y1 * y2 + x1 * x2) <= EPS) cout << "YES" << endl;
        else    cout << "NO" << endl;
        
    }
}

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

int main()
{
    long long n,m;
    cin >> n >> m;
    long long ans;
    if(n==2||m==2) ans=0;
    else if(n==1&&m==1) ans=1;
    else if(n==1) ans=m-2;
    else if(m==1) ans=n-2;
    else {
        ans=n*m-2*(n+m)+4;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
len(H)
ANS,TMP = 0,0
for h in range(1,N):
  if H[h-1] >= H[h]:
    TMP += 1
    if ANS <= TMP:
    	ANS = TMP
  else:
    TMP = 0

print(ANS)

Measured memory_bytes: 14224
package main

import "fmt"

func main() {
	var N, X, Y int
	fmt.Scan(&N, &X, &Y)

	m := make(map[int]int)

	for i := 1; i < N; i++ {
		for j := i + 1; j <= N; j++ {
			path := j - i
			pathX := abs(i-X) + 1 + abs(j-Y)
			pathY := abs(i-Y) + 1 + abs(j-X)
			min := path
			if min > pathX {
				min = pathX
			}
			if min > pathY {
				min = pathY
			}
			m[min]++
		}
	}

	for i := 1; i < N; i++ {
		if d, ok := m[i]; ok {
			fmt.Println(d)
		} else {
			fmt.Println(0)
		}
	}

}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


Measured memory_bytes: 2124