akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <math.h>

using namespace std;

int main(){

	int N,base_length,T_length,count;
	char base[26],T[101];
	bool FLG;

	scanf("%d",&N);
	scanf("%s",base);

	for(base_length=0;base[base_length] != '\0';base_length++);

	count = 0;

	for(int loop = 0; loop < N; loop++){
		scanf("%s",T);
		for(T_length=0;T[T_length] != '\0';T_length++);

		for(int k = 0;base_length+k*(base_length-1) <= T_length; k++){
			for(int p = 0; p <= T_length-(base_length+k*(base_length-1));p++){

				FLG = true;
				for(int a = 0; a < base_length; a++){
					if(a == 0){
						if(T[p] != base[0]){
							FLG = false;
							break;
						}
					}else{
						if(T[p+a*(k+1)] != base[a]){
							FLG = false;
							break;
						}
					}
				}
				if(FLG){
					count++;
					break;
				}
			}
			if(FLG)break;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 3200
cardNum,gate = map(int,input().split())
l = []
r = []
for i in range(gate):
  ll,rr = map(int,input().split())
  l.append(ll)
  r.append(rr)

cnum = min(r)-max(l)+1
if cnum < 0:
  print(0)
else:
  print(cnum)

Measured memory_bytes: 10996
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

constexpr ll MOD = 998244353;

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VI as(n);
  FOR(a,as) {
    cin >> a;
  }
  ll sum = accumulate(as.begin(), as.end(), 0ll);
  vector<VL> dp(n + 1, VL(sum + 1, 0ll));
  dp[0][0] = 1;
  REP(i,0,n) {
    REP(j,0,sum + 1) {
      dp[i+1][j] = dp[i][j] * 2 % MOD;
      if (j - as[i] >= 0) {
        dp[i+1][j] = (dp[i+1][j] + dp[i][j - as[i]]) % MOD;
      }
    }
  }
  ll ans = 1;
  REP(i,0,n) {
    ans = ans * 3 % MOD;
  }
  REP(j,(sum+1)/2,sum+1) {
    ans = (ans - (dp[n][j] * 3) % MOD + MOD) % MOD;
  }
  if (sum % 2 == 0) {
    vector<VL> dp_eq(n + 1, VL(sum / 2 + 1, 0ll));
    dp_eq[0][0] = 1;
    REP(i,0,n) {
      REP(j,0,sum / 2 + 1) {
        dp[i+1][j] = dp[i][j];
        if (j - as[i] >= 0) {
          dp[i+1][j] = (dp[i+1][j] + dp[i][j - as[i]]) % MOD;
        }
      }
    }
    ans = (ans + dp[n][sum / 2] * 3) % MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 318016
# まあ探索しましょうや 最低の2でも10回やりゃ1000越えるんだし
ans = 0
x = int(input())
if x == 1:
    print(1)
    exit()
for b in range(2, int(x * 0.5) + 1):
    p = 2
    while True:
        if b ** p > x:
            break
        ans = max(ans, b ** p)
        p += 1
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  int n = s.size();
  vector<int> v[26];
  REP(i, n) v[s[i]-'A'].emplace_back(i+1);
  cout << v[25].back() - v[0][0]+1 << endl;
  return 0;
}

Measured memory_bytes: 1796
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include <string.h>
using namespace std;
typedef long long ll;
ll a[1000005],ma[1000005],c[1000005],v[1000005],p[1000005];
int main()
{
    ll n,j,k,m,h,i,t,hh,x,x2,y1,y2,z1,z2,f,ans,mi;
        scanf("%lld %lld %lld",&n,&x,&t);
        if(n%x==0)
        {
            t=t*(n/x);
        }
        else
        {
            t=t*(n/x+1);
        }
        printf("%lld\n",t);
    return 0;
}


Measured memory_bytes: 3820
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <cstring>
#include <bitset>
#include <stack>
using namespace std;
#define MP make_pair
#define PB push_back
const int INF=1e9;
const long long mod=998244353;

long long n,a,b,k;
long long f[300005],inv[300005],finv[300005],ans;

inline long long C(long long x,long long y)
{
	if (x<y) return 0LL;
	if (y==0) return 1LL;
	return (((f[x]*finv[y])%mod)*finv[x-y])%mod;
}

int main()
{
	cin>>n>>a>>b>>k;
	f[1]=1LL;
	inv[1]=1LL;
	finv[1]=1LL;
	finv[0]=1LL;
	for (long long i=2;i<=300000;i++)
	{
		f[i]=f[i-1]*i%mod;
		inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}

	for (long long i=0;i<=n;i++)
	{
		long long lft=k-(long long)i*a;
		if (lft%b) continue;
		if (lft<0) break;
		long long num=lft/b;
		ans+=(C(n,i)*C(n,num)%mod)%mod;
		ans=ans%mod;
	}
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;


int main(void)
{
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0 ; i < N ; i++){
        cin >> a[i];
    }
    
    int fourx = 0;
    int twox = 0;
    for(int i = 0; i < N; i++){
        if(a[i] % 4 == 0) {
            fourx++;
        } else if(a[i] % 2 == 0){
            twox++;
        }
    }

    int other = N - fourx - twox;


    if(twox != 0) other++;
    
    if(other - fourx <= 1){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


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

using namespace std;
using ll =long long;
using db = double;

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

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const ll mod = 1e9 + 7;
const ll INF = 1LL << 60;


//ここから書き始める
int main()
{
	ll n;
	ll m;
	cin >> n >>m;

	//dpの初期化
	vector<ll> dp(100100,0);
	dp[0] = dp[1] = 1;

	for(int i = 0 ; i<m;i++){
		ll broken_stair;
		cin >> broken_stair;
		dp[broken_stair] = -1;
	}

	//dp[i]=-1のとき、計dp[i] = dp[i-2] + dp[i-1]を行ってはいけない。
	if(dp[1]==-1) dp[1] = 0;
	for(int i = 2 ; i < n + 1 ; i++){
		if(dp[i]==-1){
			dp[i] = 0;
		}else{
			dp[i] = dp[i-1]+dp[i-2];
		}
		dp[i]%=mod;
//		cout<<"dp["<<i<<"] "<<dp[i]<<endl;
	}
	cout <<dp[n]%mod <<endl;
//	cout << mod << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n;
  cin>>n;
  int a[100001]={0};
  for(int i=1;i<=100;i++){
    for(int j=1;j<=100;j++){
      for(int k=1;k<=100;k++){
        a[((i+j)*(i+j)+(j+k)*(j+k)+(k+i)*(k+i))/2]++;
      }
    }
  }
  for(int i=1;i<=n;i++)
    if(a[i])
      cout<<a[i]<<endl;
  else
    cout<<0<<endl;
}

Measured memory_bytes: 3980
n = int(input())
s = list(map(int,input().split()))
A = [i for i in s if i % 2 == 0]

count = 0
for i in range(len(A)):
    while A[i] % 2 == 0:
        A[i] = A[i]//2
        count += 1

print(count)

Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const ll mod = 1e9+7;
const ll INF = 2e9;
const double PI = 3.1415926535;


int main(void){
    int n; cin >> n;
    int a1 = 0, a2 = 0, a4 = 0;
    for(int i = 0;i < n;i++){
        int a; scanf("%d", &a);
        if(a%4 == 0)a4++;
        else if(a%2 == 0)a2++;
        else a1++;
    }
    if(a4 < a1 - 1 || (a4 == a1 - 1 && a2 != 0) || (a4 == 0 && a1 != 0))printf("No\n");
    else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
const int MAXN = 100010;
int n, a[MAXN][3], f[MAXN][3];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
	for(int i=1;i<=n;i++)
	{
		f[i][0] = max(f[i-1][1], f[i-1][2])+a[i][0];
		f[i][1] = max(f[i-1][0], f[i-1][2])+a[i][1];
		f[i][2] = max(f[i-1][1], f[i-1][0])+a[i][2];
	}
	int ans = max(f[n][0], max(f[n][1], f[n][2]));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN = 100000;
const int MAXK = 1000;
int x[MAXN + 5], y[MAXN + 5], c[MAXN + 5];
int y1[10 * MAXK + 5];
int main()
{
	int N,K,Max=0,cnt=0;
	scanf("%d %d",&N,&K);
	for(int i=1;i<=N;i++)
	{
		char ch;
		scanf("%d %d %c",&x[i],&y[i],&ch);
		x[i]=x[i]%(2*K);
		y[i]=y[i]%(2*K);
		if(ch=='W') c[i]=1;
		else c[i]=0;
	}
	for(int i=0;i<=K;i++)
	{
			cnt=0;
			memset(y1,0,sizeof(y1));
		for(int j=1;j<=N;j++) 
		{
			int p=(i<=x[j]&&x[j]<i+K);
			int q=(0<=y[j]&&y[j]<K);
			if(p^q==c[j])
			{
				cnt++;
				y1[y[j]]++;
			}
			else 
			{
				y1[y[j]]--;
			}
		}
		for(int j=0;j<=K;j++) 
		{
			if(cnt>Max) Max=cnt;
			if(N-cnt>Max) Max=N-cnt;
			if(j!=K)
				cnt=cnt-y1[j]-y1[K+j];
		}
	}
	printf("%d\n",Max);
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define pb push_back
typedef pair<ll,ll> pp;

ll mod = 1e9+7;
ll INF = 1e15;

ll powm(ll a , ll b , ll mod)
{
  ll res = 1;
  while(b)
  {
    if(b & 1)
    res = (res *a)%mod;
    a = (a*a)%mod;
    b>>1;
  }
  return res;
}
ll gcd(ll a , ll b);
ll power(ll x , ll y , ll m);

ll modInverse(ll a , ll m)
{
  ll g = gcd(a,m);
  if(g != 1)
  return 1;
  else
  return power(a,m-2,m);

}

ll power(ll x , ll y , ll m)
{
  if(y == 0)
  return 1;
  ll p = power(x , y/2 , m)%m;
  p = (p*p)%m;

  return (y%2 == 0) ? p : (x *p) % m;
}

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





void solve()
{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;

  ll max1 = b;
  ll min1 = a;
  ll max2 = d;
  ll min2 = c;

  while(min2 >=0 and min1>= 0)
  {
    if(min2-max1 <=0)
      {cout<<"Yes\n";return;}
    if(min1-max2 <= 0)
    {
      cout<<"No\n";
      return;
    }
    min2 -= max1;
    min1 -= max2;

  }


}



int main()
{
  int tc;
  // cin>>tc;
  tc = 1;
  while(tc--)
  {
    solve();
  }
}


Measured memory_bytes: 3584
//***Little by little one travels far***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

string s[51];
ll a[51];
int main()
{
    ll n,f=0,ans=0;
    cin>>n;

    forn(i,n){
        cin>>s[i]>>a[i];
    }
    string ss;
    cin>>ss;

    for(ll i=0;i<n;i++){
        if(f==1) ans+=a[i];
        if(s[i]==ss) f=1;
    }
    cout<<ans;
}

Measured memory_bytes: 256
module graph_mod
    use,intrinsic :: iso_fortran_env
    implicit none
    type node
        integer(int32),allocatable:: to(:)
        integer(int32):: l
    contains
        procedure::  init => node_init
        procedure:: regist => node_regist
    end type


    type graph
        type(node),allocatable:: n(:)
    contains
        procedure:: regist => graph_regist
        procedure:: l => graph_elem_num
        procedure:: v => graph_elem_val
    end type
    interface graph
        module procedure graph_init
    end interface
    private
    public:: graph
contains
    function graph_init(n) result(g)
        type(graph):: g
        integer(int32),intent(in):: n
        integer(int32):: i

        allocate(g%n(n))
        do i=1,n
            call g%n(i)%init()
        end do
    end function


    subroutine graph_regist(g,x,y)
        class(graph):: g
        integer(int32):: x,y

        call g%n(x)%regist(y)
        call g%n(y)%regist(x)
    end subroutine


    function graph_elem_num(g,i) result(ret)
        class(graph):: g
        integer(int32):: i,ret

        ret = g%n(i)%l
    end function


    function graph_elem_val(g,i,j) result(ret)
        class(graph):: g
        integer(int32):: i,j,ret

        ret = g%n(i)%to(j)
    end function


    subroutine node_init(n)
        class(node):: n
        allocate(n%to(1))

        n%l = 0
    end subroutine


    subroutine node_regist(n,m)
        class(node):: n
        integer(int32):: m

        if (n%l+1 > size(n%to)) call add_(n)
        n%l=n%l+1
        n%to(n%l) = m
    end subroutine


    subroutine add_(n)
        type(node):: n
        integer(int32),allocatable:: tmp(:)
        integer(int32):: l

        l = size(n%to)
        allocate(tmp(l))
        tmp(:) = n%to(:)
        deallocate(n%to)
        allocate(n%to(l*2))
        n%to(1:l) = tmp(:)
        deallocate(tmp)
    end subroutine
end module

program abc138d
    use,intrinsic :: iso_fortran_env
    use graph_mod
    implicit none
    integer(int32):: n,q,i
    integer(int32):: a,b,p,x
    integer(int32), allocatable:: counter(:)
    logical,allocatable:: passed(:)
    type(graph):: ki

    read*, n,q
    ki = graph(n)
    allocate(counter(n), source=0)
    allocate(passed(n), source=.false.)
    do i=1,n-1
        read*, a,b
        call ki%regist(a,b)
    end do

    do i=1,q
        read*, p,x
        counter(p)=counter(p)+x
    end do

    call dfs(1)

    print'(*(i0,1x))', counter(:)

contains
    recursive subroutine dfs(node)
        integer(int32):: node, next_node
        integer(int32):: i
        passed(node) = .true.
        do i=1,ki%l(node)
            next_node = ki%v(node,i)
            if (.not. passed(next_node)) then
                counter(next_node) = counter(next_node) + counter(node)
                call dfs(next_node)
            end if
        end do
    end subroutine
end program abc138d

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

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var M = input[1];
            var conn = new List<int>[N].Select(l => new List<int>()).ToArray();
            for (int i = 0; i < M; i++)
            {
                input = ReadArrayInt();
                var A = input[0] - 1;
                var B = input[1] - 1;
                conn[B].Add(A);
                conn[A].Add(B);
            }
            var setted = new bool[N];
            var ans = new int[N];
            var que = new Queue<int>();
            que.Enqueue(0);
            while (que.Any())
            {
                var chk = que.Dequeue();
                if (setted[chk]) continue;
                setted[chk] = true;
                foreach (var i in conn[chk])
                {
                    if (ans[i] == 0) ans[i] = chk + 1;
                    que.Enqueue(i);
                }
            }

            Console.WriteLine("Yes");
            for (int i = 1; i < N; i++)
            {
                Console.WriteLine(ans[i]);
            }

            //Console.WriteLine();
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static string[] ReadArrayString() { return Read().Split(' '); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}


Measured memory_bytes: 56096
import numpy as np

num_array = np.ones((3, 3), int)
for row in range(3):
    num_array[row, :] = list(map(int, input().split()))

n = int(input())
b_list = [int(input()) for i in range(n)]

b_set = set(b_list)
flag = False

for i in range(3):
    tate = set(num_array[i, :])
    yoko = set(num_array[:, i])
    if len(tate & b_set) == 3 or len(yoko & b_set) == 3:
        flag = True 

naname_one = set([num_array[0,0], num_array[1,1], num_array[2,2]])
naname_two = set([num_array[0,2], num_array[1,1], num_array[2,0]])
if len(naname_one & b_set) == 3 or len(naname_two & b_set) == 3:
    flag = True

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14280
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int ans = 1999999999;
  vector<int> list(N);
  for (int i = 0; i < N; i++) {
    cin >> list[i];
  }
  sort(all(list));
  dout << "====listの内容====\n";
  for (int i = 0; i < N; i++) dout << list[i] << endl;
  dout << "====ここまで====\n";
  for (int i = 0; i < N-K+1; i++) {
    ans = min(ans,list[i+K-1]-list[i]);
  }
  cout << ans;
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
  //配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define bigger (char)toupper
#define smaller (cjar)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int A,B;
    cin>>A>>B;
    int answer=0;
    for(int i=0; i<1010; i++) {
        if(i*8/100==A&&i/10==B) {
            answer=i;
            break;
        }
        else answer=-1;
    }
    cout<<answer<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){

    
    int n,m;
    cin>>n>>m;
    vector<vector<long int>> set(n,vector<long int>(3,0));
    for(int i=0;i<n;i++){
        cin>>set[i][0]>>set[i][1]>>set[i][2];
    }
    vector<vector<long int>> value(8,vector<long int>(n,0));
    for(int i=0;i<n;i++){
        value[0][i]=set[i][0]+set[i][1]+set[i][2];
        value[1][i]=-set[i][0]+set[i][1]+set[i][2];
        value[2][i]=set[i][0]-set[i][1]+set[i][2];
        value[3][i]=set[i][0]+set[i][1]-set[i][2];
        value[4][i]=-set[i][0]-set[i][1]+set[i][2];
        value[5][i]=-set[i][0]+set[i][1]-set[i][2];
        value[6][i]=set[i][0]-set[i][1]-set[i][2];
        value[7][i]=-set[i][0]-set[i][1]-set[i][2];
    }
    for(int i=0;i<8;i++){
        sort(value[i].begin(),value[i].end(),greater<long>());
    }
    vector<long int> val(8,0);
    long ans=0;
    for(int i=0;i<8;i++){
        for(int j=0;j<m;j++){
            val[i]+=value[i][j];
        }
        if(ans<val[i]){
            ans=val[i];
        }
    }
    cout<<ans;
    return 0;


}

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "YES" : "NO")

typedef pair <int, int> ii;
typedef pair <ii, int> iii;

const int siz = 1e6 + 10;
const int SIZ = 1 << 2;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e12;
const string file = "2";

int n;
int f[siz][SIZ];

int dp(int pos, int mask) {
    if (pos == n + 1) {
        return (mask == (1 << 2) - 1);
    }

    int &res = f[pos][mask];
    if (res != -1) {
        return res;
    }

    res = 0;
    for (int i = 0; i <= 9; i++) {
        int nxt = mask;
        if (i == 0) {
            nxt |= (1 << 0);
        }
        else if (i == 9) {
            nxt |= (1 << 1);
        }

        (res += dp(pos + 1, nxt)) %= mod;
    }

    return res;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    cin >> n;

    memset(f, -1, sizeof(f));

    cout << dp(1, 0) << "\n";

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

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

int N;

void solve()
{
    cin >> N;
    if(N == 1)
    {
        cout << 1 << endl;
        return;
    }

    vi p(N+1, 0);
    while(N > 1)
    {
        int n = N;
        for(int d = 2; d <= n; d++)
        {
           while(n % d == 0)
           {
               n /= d;
               p[d]++;
           } 
        }

        N--;
    }

    ll ans = 1;
    FOR(i, 2, p.size())
    {
        if(p[i] > 0) ans *= p[i] + 1;
        ans %= MOD;
    }

    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<int> > jobs(m);
	int i,a,b;
	for(i=0;i<n;i++){
		cin >> a >> b;
		if(a>m) continue;
		jobs[m-a].push_back(b);
	}
	priority_queue<int> q;
	int ans=0;
	for(i=m-1;i>=0;i--){
		for(int b:jobs[i]){
			q.push(b);
		}
		if(!q.empty()){
			ans+=q.top();
			q.pop();
		}
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 5632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int
	scanner.Scan()
	N, _ = strconv.Atoi(scanner.Text())
	fmt.Println(solve(N))
}
func solve(N int) int {
	allCnt := 0
	for n := 1; n <= N; n += 2 {
		cnt := 0
		for i := 1; i <= N; i += 2 {
			if n%i == 0 {
				cnt++
			}
		}
		if cnt == 8 {
			allCnt++
		}
	}
	return allCnt
}


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

int main() {
    int a, b;
    while(true) {
        cin >> a >> b;
        if(a == 0 && b == 0) break;

        for(int i = 0; i < a; i++) {
            for(int j = 0; j < b; j++) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3096
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	public static int n;
	public static char[] table;
	public static Rect[] rect;
	public static char[][] map;
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int test = in.nextInt();
		for(int t=0; t<test; t++){
			int h = in.nextInt();
			int w = in.nextInt();
//			if(h == 0) break;
			map = new char[h][w];
			int alps = 0;
			for(int i=0; i<h; i++){
				map[i] = in.next().toCharArray();
				for(int j=0; j<w; j++){
					if('A' <= map[i][j] && map[i][j] <= 'Z')
						alps |= 1<<map[i][j]-'A';
				}
			}
			n = Integer.bitCount(alps);
			table = new char[n];
			int idx = 0;
			for(int i=0; i<26; i++){
				if((alps&1<<i)==0) continue;
				table[idx++] = (char)('A'+i);
			}
			rect = new Rect[n];
			for(int i=0; i<n; i++){
				int left = w;
				int right = 0;
				int up = h;
				int down = 0;
				char c = table[i];
				for(int y=0; y<h; y++){
					for(int x=0; x<w; x++){
						if(map[y][x] != c) continue;
						left = Math.min(left, x);
						right = Math.max(right, x);
						up = Math.min(up, y);
						down = Math.max(down, y);
					}
				}
				rect[i] = new Rect(left, right, up, down);
			}
			p = new int[n];
			System.out.println(dfs(0, 0) ? "SAFE" : "SUSPICIOUS");
		}
	}
	
	public static int[] p;
	public static boolean dfs(int idx, int used){
		if(idx == n){
			if(check(p)) return true;
		}
		for(int i=0; i<n; i++){
			if((used&1<<i)>0) continue;
			p[idx] = i;
			if(dfs(idx+1, used|1<<i)) return true;
		}
		return false;
	}
	
	public static boolean check(int[] order){
		int used = 0;
		for(int i=0; i<n; i++){
			char c = table[order[i]];
			used |= 1<<c-'A';
			Rect r = rect[order[i]];
			for(int y=r.up; y<=r.down; y++){
				for(int x=r.left; x<=r.right; x++){
					char p = map[y][x];
					if(p == '.' || (used&1<<p-'A')==0)
						return false;
				}
			}
		}
		return true;
	}
}

class Rect{
	int left, right;
	int up, down;
	public Rect(int l, int r, int u, int d){
		left = l;
		right = r;
		up = u;
		down = d;
	}
}

Measured memory_bytes: 38340
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<int>fri[101010];
vector<int>blo[101010];
int visited[101010],visited2[101010],par[101010],sz[101010];
int cnt;

//親の情報を連結成分の全部に伝搬(それとともに連結成分のサイズ(cnt)もインクリメントしていく)
void dfs(int now, int parent) {
	par[now] = parent;
	visited[now] = 1;
	cnt++;
	fore(x, fri[now]) {
		if (!visited[x]) {
			dfs(x, parent);
		}
	}
}
//↑のdfsで集めたサイズの情報を改めて連結成分全部に伝搬
void dfs2(int now) {
	visited2[now] = 1;
	sz[now] = cnt;
	fore(x, fri[now]) {
		if (!visited2[x]) {
			dfs2(x);
		}
	}
}

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

	int N, M, K;
	cin >> N >> M >> K;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		fri[a].pb(b);
		fri[b].pb(a);
	}
	for (int i = 0; i < K;i++) {
		int c, d;
		cin >> c >> d;
		c--, d--;
		blo[c].pb(d);
		blo[d].pb(c);
	}

	//visited[i]が1の頂点を避けることで、各連結成分について1回だけ探索されるようにする
	for (int i = 0; i < N; i++) {
		if (visited[i])continue;
		cnt = 0;
		dfs(i,i);
		dfs2(i);
	}

	for (int i = 0; i < N; i++) {
		int block = 0;
		//親頂点が同じということは同じ連結成分ということ
		fore(x, blo[i])if (par[i] == par[x])block++;
		int ans = sz[i] - fri[i].size() - block - 1;
		cout << ans << " ";
	}
	puts("");
	return 0;
}


Measured memory_bytes: 13440
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include<vector>
#include<cstring>
#include<set>
#include <cstdio>
#include<queue>
#include<map>
#define WHITE 0
#define GRAY  1
#define BLACK 2
#define endl '\n'
#define forup(i,a,n) for( int i =a; i < n; i++)
#define llforup(i,a,n) for( ll i =a; i < n; i++)
#define fordown(i,a,n) for( int i =a; i >= n; i--)
#define fornot(i,a,n) for( int i=a;!n;i++)
#define mod  (ll)(1e9+7)
#define ifempty(a)  if(!a)
using namespace std;
typedef long long ll;
inline int readnum()
{
	int p, data = 0; char ch = 0;
	while ((ch != ' - ') && ch < '0' || ch>'9') ch = getchar();//相当于正则表达式的搜索，跳过不需要的字符
	if (ch == '- ')p = -1, ch = getchar();
	else p = 1;
	while (ch >= '0' && ch <= '9') data = data * 10 + ch - '0', ch = getchar();//搜索需要的字符
	return data * p;
}
inline int ReadPossitive()
{
	char ch; int data = 0;
	ch = getchar();
	while (ch == ' ' || ch == '\n')ch = getchar();
	while (ch != ' ' && ch != '\n' && ch != EOF)
	{
		data = data * 10 + ch - '0';
		ch = getchar();
	}
	return data;
}
//E-mail 374656045@qq.com
class solve {
private:int x, y, ans;
public:
	solve()
	{
		x = ReadPossitive(); y = ReadPossitive();
		ans = GetDivisor(x, y);
		printf("%d\n", ans);
	}
	int GetDivisor(int a,int b)
	{
		if (x < y)swap(x, y);//细节
		int temp;
		while (a % b != 0)
		{
			temp = b;
			b = a % b;
			a = temp;
		}
		return b;
	}
	
};
int main(void)
{
	ios_base::sync_with_stdio(0); cin.tie(0);//慎用，cin和scanf混用会导致非MSC++WA
#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve solution;
#ifdef DEBUG
	fclose(stdin);//关闭文件 
	fclose(stdout);//关闭文件 
#endif
	return 0;

}




Measured memory_bytes: 3248
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int l, r, d;
	cin >> l >> r >> d;
	cout << (r / d - (l - 1) / d) << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

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

int main(){
    cin >> n;
    ll Out = 1;
    for(int i = 1; i <= n; i++){
        Out = Out * i % MOD;
    }
    cout << Out <<endl;
    return 0;

}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int x,a,b,c,flg=0;
    scanf("%d",&x);
    a = x/100;
    if(a==7){
        flg = 1;
    }
    b = (x - (a*100))/10;
    if(b==7){
        flg = 1;
    }
    c = (x-(a*100)) - b*10;
    if(c==7){
        flg = 1;
    }
    if(flg==1){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 3828
s = input()

abclist = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
abcstr = ''.join(abclist)
if s == abcstr[::-1]:
    print(-1)
    exit()
if len(s) != 26:
    for a in abclist:
        if a not in s:
            print(s+a)
            exit()

else:
    i = 25
    while s[i-1] > s[i]:
        i -= 1
        #print(s[i-1], s[i])
    #print(s[i-1], s[i])
    tt = s[i-1]
    ss = list(s[i-1:])
    ss.sort()
    print(s[:i-1]+ss[ss.index(tt)+1])


Measured memory_bytes: 9096
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n,l = map(int, input().split())
    min_abs = 100
    ans = []
    for i in range(l,(l+n)):
        ans.append(i)
        if abs(i) < min_abs:
            min_abs = abs(i)
    
    for j,v in enumerate(ans):
        if min_abs == abs(v):
            ans.pop(j)
            break
    print(sum(ans))

if __name__ == "__main__":
    main()

Measured memory_bytes: 5116
//....SARANSH GUPTA....\\

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(p,n) for(int i=p;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define endl "\n"
#define mp make_pair
#define pb push_back
#define mod 1000000007
ll n;
vector<ll> v[100001];
vector<pair<ll,ll>> child;

int main()
{
    FIO
    ll k;
    cin>>k;
    string s;
    cin>>s;
    if(s.length()>k)
    cout<<s.substr(0,k)<<"...";
    else
    cout<<s;
    
}

Measured memory_bytes: 5960
import math
N = int(input())


def digit(N):
    d = 0
    while N >= 1:
        N /= 10
        d += 1
    return d


f = []
for i in range(1, int(math.sqrt(N))+1):
    if N % i == 0:
        d1 = digit(i)
        d2 = digit(int(N/i))
        f.append(max(d1, d2))

print(min(f))


Measured memory_bytes: 9184
/*

    author : s@if

*/

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

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			99999999
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    string s1, s2;
    cin>>s1>>s2;

    int ans = 0;

    for(i=0; i<3; i++)
        if(s1[i]==s2[i])
            ans++;
    cout<<ans<<endl;

  //  main();

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


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

int main(){
  long long l, r, i, j, mod, mini=2500, a, b;
  cin >> l >> r;

  if(l%2019==0 || r%2019==0) mini=0;
  else{
    a = l/2019;
    b = r/2019;

    if(b-a>0) mini=0;
    else{
      for(i=l; i<r; i++){
        for(j=i+1; j<=r; j++){
          mod = (i*j)%2019;
          mini = min(mini, mod);
        }
      }
    }
  }


  cout << mini << endl;

  return 0;
}


Measured memory_bytes: 256
from copy import deepcopy
h, w, K = map(int, input().split())
C = [list(input()) for _ in range(h)]
ans = 0
for i in range(2 ** (h + w)):
    pattern = bin(i)[2:].zfill(h + w)
    c = deepcopy(C)
    for j in range(h + w):
        p = pattern[j]
        if p == "1":
            if j < h:
                for k in range(w):
                    c[j][k] = "-"
            else:
                for k in range(h):
                    c[k][j-h] = "-"
    cnt = 0
    for j in range(h):
        for k in range(w):
            cnt += c[j][k] == "#"
    ans += cnt == K

print(ans)


Measured memory_bytes: 9344
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	string a,b;
	cin >> a >> b;
  
  	if(a.length()>b.length()){
		cout << "GREATER" << endl;
    }else if(a.length()<b.length()){
		cout << "LESS" << endl;
    }else{
		if(a<b){
			cout << "LESS" << endl;
        }else if(a>b){
			cout << "GREATER" << endl;
        }else{
			cout << "EQUAL" << endl;
        }
    }

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
ll INF = 1000000007;


/***************/
 #define amin main
/***************/

ll exp(ll x, ll n)
{if(n==0) return 1;if(n==1) return x%INF;if(n%2==0) return exp((x*x)%INF,n/2); else return(x*exp((x*x)%INF,n/2))%INF;}


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j;
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];
	sort(arr,arr+n);
	ll sum =0;
	for(i=0;i<k;i++)
	{

		sum += arr[i];
	}
	
	cout<<sum<<endl;
	


	
	

	
	


	
	return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int maxi=INT_MAX,sum=0;
	for(int i=0;i<k-1;i++)
		sum+=abs(a[i]-a[i+1]); 
	maxi=min(maxi,min(sum+abs(a[0]),sum+abs(a[k-1])));
	//cout<<sum<<"  "<<maxi<<endl;
	for(int i=k-1;i<n-1;i++){
		sum+=abs(a[i]-a[i+1])-abs(a[i-k+1]-a[i-k+2]);
		maxi=min(maxi,min(sum+abs(a[i-k+2]),sum+abs(a[i+1])));
		//cout<<sum<<"  "<<maxi<<endl; 
	}
	cout<<maxi<<endl;
	return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

long double a[105], b;

int main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> a[i];
		b += 1 / a[i];
	}
	cout << fixed << setprecision(10) << 1/b << endl;
	
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
using namespace std;

int main() {
    int H, W, K;
    cin >> H >> W >> K;

    K--;

    using ll = long long;

    const ll mod = 1000000007;

    ll dp[101][9] = {0};

    dp[0][0] = 1;

    for (int i = 0; i < H; i++) {
        for (unsigned j = 0; j < (1 << (W - 1)); j++) {
            bool ok = true;

            for (int k = 0; k < W - 2; k++) {    
                if ((j >> k & 1) && (j >> (k + 1) & 1)) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                for (int k = 0; k < W; k++) {
                    if (k < W - 1 && j >> k & 1) {
                        dp[i + 1][k + 1] = (dp[i + 1][k + 1] + dp[i][k]) % mod;
                    } else if (k > 0 && j >> (k - 1) & 1) {
                        dp[i + 1][k - 1] = (dp[i + 1][k - 1] + dp[i][k]) % mod;
                    } else {
                        dp[i + 1][k] = (dp[i + 1][k] + dp[i][k]) % mod;
                    }
                }
            }
        }
    }

    cout << dp[H][K] << endl;
}


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

int main()
{
  long long n, k;
  cin >> n >> k;
  if(k % 2 == 1)
    cout << (n / k) * (n / k) * (n / k) << endl;
  else{
    cout << (n / k) * (n / k) * (n / k) + ((n + k / 2) / k) * ((n + k / 2) / k) * ((n + k / 2) / k) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> X(n);
  rep(i, n) cin >> X[i];
  ll mn = inf;
  rep(i, 101) {
    ll sum = 0;
    rep(j, n) sum += (X[j]-i)*(X[j]-i);
    chmin(mn, sum);
  }
  cout << mn << endk;
  return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    ll N, M;
    std::cin >> N >> M;

    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }

    std::vector<ll> X(M);
    for (ll i = 0; i < M; ++i) {
        cin >> X[i];
    }
    std::sort(X.begin(), X.end());

    std::vector<ll> L(M, 0);
    for (ll i = 0; i < M - 1; ++i) {
        L[i] = X[i + 1] - X[i];
    }
    std::sort(L.begin(), L.end(), std::greater<>());

    ll ans = X[M - 1] - X[0];
    for (ll i = 0; i < N - 1; ++i) {
        ans -= L[i];
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    map<int,int> m;
    for(int i=0;i<N;i++){
        int A;
        cin >> A;
        m[A] ? m[A]-- : m[A]++;
    }
    int count = 0;
    auto b = m.begin(),e = m.end();
    for(auto itr = b; itr != e; ++itr) {
        count += itr->second;
    }
    cout << count;
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

vector<int> G[100010];
ll L[2][100010];

void dfs(int T, int V, int cost) {
  L[T][V] = cost;
  rep(i, G[V].size()) {
    if(L[T][G[V][i]] != INF) continue;
    dfs(T, G[V][i], cost + 1);
  }
}

signed main() {
  ll n;
  cin >> n;
  rep(i, n - 1) {
    ll a, b;
    cin >> a >> b;
    G[a].pb(b);
    G[b].pb(a);
  }
  rep(i, 2) rep(j, 100010) L[i][j] = INF;

  dfs(0, 1, 0);
  dfs(1, n, 0);
  ll Fennec = 0, Snuke = 0;
  for(int i = 1; i <= n; i++) {
    if(L[0][i] <= L[1][i]) Fennec++;
    else Snuke++;
  }
  if (Fennec > Snuke) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
	return 0;
}

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

#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

using namespace std;


int main()
{
    fastio;

    int n, k;
    cin >> n >> k;
    ll arr[n];
    for (int i = 0; i < n; i++)
    	cin >> arr[i];
    ll dp[n];
    for (auto &x : dp)
    	x = 10000000000;
    dp[0] = 0;
//    for (auto x : dp)
//    	cout << x << " ";
//    cout << endl;
    for (int i = 0; i < n; i++)
    {
    	for (int j = i; j < n and j <= i + k; j++)
    	{
    		ll dif = abs(arr[i] - arr[j]);
    		dp[j] = min(dp[j], dif + dp[i]);

    	}
    }
    cout << dp[n - 1];
    return 0;
}




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

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, x;

            var word = Console.ReadLine().Split(' ');

            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);

            if (n * a <= b)
                Console.WriteLine(n * a);

            else if(n * a >= b)
                Console.WriteLine(b);

            Console.ReadKey();
        }
    }
}


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

# from numba import njit

# input = stdin.readline




def main():
  W,H,M = map(int,input().split())
  x_range = [0,W]
  y_range = [0,H]
  for i in range(M):
    xi,yi,a = map(int,input().split())
    if a == 1:
      x_range[0] = max(x_range[0],xi)
    elif a == 2:
      x_range[1] = min(x_range[1],xi)
    elif a == 3:
      y_range[0] = max(y_range[0],yi)
    elif a == 4:
      y_range[1] = min(y_range[1],yi)
    else:
      raise ValueError
  ans = max(x_range[1] - x_range[0],0)*max(y_range[1] - y_range[0],0)
  print(ans)
  return

if __name__ == '__main__':
  main()



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

ll func(ll A,ll B){
  ll a = A;
  ll b = B;
  ll ca = 0;
  ll cb = 0;
  while(1){
    A = A/10;
    ca++;
    if(A == 0) break;
  }
   while(1){
    B= B/10;
    cb++;
    if(B == 0) break;
  }
  if(ca >= cb) return ca;
  else return cb;
}
  
  
int main(){
  ll N;
  cin >> N;
  vector<ll> d;
  for(ll i = 1;i*i<=N;i++){
    if(N%i == 0){
      d.push_back(i);
      d.push_back(N/i);
    }
  }
  sort(d.begin(),d.end());
  
  ll ans = 10000000000000;
     for(int i = 0;i<(d.size()+1)/2;i++){
      ans = min(ans,func(d[i],N/d[i]));
     }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int getCost(int w){
 int cost = 1150; // ?¬¬?????????
 for (int i = 11; i <= w; i++ ){
 if ( i <= 20 ) cost += 125; // ?¬¬?????????
 else if ( 30 < i ) cost += 160; // ?¬¬?????????
 else cost += 140; // ?¬¬?????????
 }
 return cost;
}
int main(){
 for( int w; cin >> w && w >= 0; ) {
 cout << 4280 - getCost(w) << endl;
 }
 return 0;
}

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

int main() {
   int a,b,c,k;
   cin >> a >> b >> c;
   cin >> k;
   for(int i=0;i<k;i++){
       if(b >= c) c *= 2;
       else if(a >= b) b *= 2;
   }
   if(a < b && b < c) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 3592
from collections import Counter, defaultdict, deque

H, W, K = [int(x) for x in input().split()]
grid = [[int(x) for x in input()] for r in range(H)]


counts1 = Counter()
for cuts in range(2 ** H):
    numCuts = len([r for r in range(H) if (1 << r) & cuts])
    # print("trying", [r for r in range(H) if (1 << r) & cuts], "init", numCuts)

    counts1[cuts] = numCuts
    counts2 = Counter()
    for c in range(W):
        counts3 = {}
        curr = 0
        for r in range(H):
            curr += grid[r][c]
            # Cut ending at (inclusive) r or is last row
            if (1 << r) & cuts or r == H - 1:
                counts3[r] = curr
                curr = 0

        if all(counts2[r] + counts3[r] <= K for r, counts in counts3.items()):

            # print(c, "can add", counts2, counts3)
            for r, counts in counts3.items():
                counts2[r] += counts3[r]
        else:
            # print(c, "must cut", counts2, counts3)

            counts1[cuts] += 1
            if c == W - 1:
                if any(counts3[r] > K for r, counts in counts3.items()):
                    # print('impossible')
                    counts1[cuts] = float("inf")
            counts2 = counts3
    # print("total", counts1[cuts])
    # print()

print(min(counts1.values()))


Measured memory_bytes: 60680