akhauriyash/Code-Regression huggingface dataset:
/*
                            Author: Ankit Kaul
*******Code Belongs to Respective Author Only*************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
/*freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
        {   if(n % 2 ==1)
            result=(result * x)%M;
            x=(x*x)%M;
            n=n/2;
        }
    return result%M;
}
bool isPrime(int n)
    {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
    }
int inv(int a,int m)
{   return power(a,m-2);
}   
int lcm(int a,int b)
{   return a*b/(gcd(a,b));
}
signed main()
{   jaldi   
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int mx=a[0],res=0;
    for(int i=1;i<n;i++)
    {   if(mx<=a[i])
        {   mx=a[i];
            continue;
        }
        else
        res+=mx-a[i];
    }
    cout<<res;
}


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

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

int main(){
    int n,k; std::cin >> n >> k;
    std::vector<int> h(n);
    rep(i,n) std::cin >> h[i];
    std::sort(h.begin(),h.end(),std::greater<int>());

    long ans=0;
    for(int i=k; i<n; ++i)
        ans += h[i];
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
//#define int long long
#define r(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin,v.end()
using namespace std;
typedef pair<int,int>P;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-b)<=d&&abs(b-c)<=d||abs(a-c)<=d)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
for i in range(n-k):
    if t[k+i] == t[i]:
        t[k+i] = 0
x = t.count('r')*p+ t.count('s')*r+t.count('p')*s
print(x)

Measured memory_bytes: 4084
cost = [1,2,4,8].zip(gets.split.map(&:to_i))
n = gets.to_i * 4
cost = cost.sort_by { |a, b| b/a.to_f }
ans = 0
cost.each do |a,b|
  ans += n / a * b
  n = n % a
end
puts ans


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>

using namespace std;
vector<int> v(200001);

int main(){

    int n, k;
    cin >> n >> k;

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

    sort(v.begin(),v.end());
    int ans = 0;
    for(int i = 0; i < v.size() - k; i++){
        ans += v[i];
    }
    cout << ans << endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    string S;
    cin >> S;
    ll min_num = INF;
    for(ll i=0;i<=S.size()-3; i++)
    {
        ll num = stoll(S.substr(i, 3));
        min_num = min(min_num, abs(753 - num));
    }
    cout << min_num << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3580
import math
N = int (input())
x = list(map(int, input().split()))
sum = 0
red = sorted(x)[::-1]
count = math.floor(N/2)
for i in range(count):
    sum += red[i] * 2
sum -= red[0]
desire = N - count*2
sum += desire * red[count]
print(sum)


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

using namespace std;

void printArray(int n, vector<int> &a)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        if (i != n - 1)
            printf(" ");
        else
            printf("\n");
    }
}

void selectionSort(int n, vector<int> &a, int &cnt)
{
    for (int i = 0; i < n; i++)
    {
        int minj = i;
        for (int j = i; j < n; j++)
        {
            if (a[j] < a[minj])
                minj = j;
        }
        if (i < minj)
        {
            swap(a[i], a[minj]);
            cnt++;
        }
    }
}

int main()
{
    int n, cnt = 0;

    scanf("%d", &n);

    vector<int> a(n);

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

    vector<int> &r = a;

    selectionSort(n, r, cnt);
    printArray(n, r);
    printf("%d\n", cnt);

    return 0;
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  int k = s.length();
  for (int i = 0; i < k; i++) {
    cout << "x";
  }
  cout << endl;
}

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

#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define exp2(x)  (1LL<<(x))

using namespace std;
using ll=long long;


int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
  int N; cin >> N;
  int K; cin >> K;
  int num = (N-1)*(N-2)/2;
  if ( num < K) END(-1);

  int M = N-1 + (num-K);
  cout << M << endl;
  rep(i,2,N) cout << 1 << " " << i << endl;
  int c = N-1;
  rep(i,2,N-1)  rep(j,i+1,N){
      if (c >= M) break;
      c++;
      cout << i << " " << j << endl;
  }

}


Measured memory_bytes: 256
import sys
def input():
	return sys.stdin.readline().strip()

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

if K % 2 == 0:
	x = N // (K // 2)
	x2 = x//2
	x = x - x2
	print(x2**3 + x**3)
else:
	x = N // K
	print(x**3)

Measured memory_bytes: 38384
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;
#define rep(i,n) for (int i = 0; i < (n); i++)

int n, a[20], b[20], c[20], ans;
int main(void) {
    cin >> n;
    rep(i,n) {
        cin >> a[i];
        a[i]--;
    }
    rep(i,n) {
        cin >> b[i];
    }
    rep(i,n-1) {
        cin >> c[i];
    }
    rep(i,n) {
        ans += b[a[i]];
        if (i != n-1) {
            if (a[i+1] == a[i]+1) {
                ans += c[a[i]];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

res = 0

res += A.pop(0)

count = 1

for i in range(N):
    for _ in range(2):
        if count < N - 1:
            res += A[i]
            count += 1

print(res)

Measured memory_bytes: 31448
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> a(N);
  long long sum1 = 0;
  rep(i, N) {
    cin >> a[i];
    sum1 += a[i];

    if (a[i] > x) a[i] = x;
  }

  long long sum2 = 0;
  rep(i, N-1) {
    if (a[i] + a[i+1] <= x){
      // do nothing
    } else {
      a[i+1] = x - a[i];
    }

    sum2 += a[i];
  }
  sum2 += a[N-1];

  cout << sum1 - sum2 << endl;

  return 0;
}


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

int main() {

  int dx[4] = { -1,  0,  1,  0 };
  int dy[4] = {  0,  1,  0, -1 };

  long long int n, p, d;

  while( true ) {

    cin >> n;

    if ( n == 0 ) break;

    long long int x0 = 0;
    long long int x1 = 0;
    long long int y0 = 0;
    long long int y1 = 0;

    vector< long long int > x;
    vector< long long int > y;

    x.push_back(0);
    y.push_back(0);

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

      cin >> p >> d;

      x.push_back( x[p] + dx[d] );
      y.push_back( y[p] + dy[d] );
      x0 = min( x0, x[i] );
      x1 = max( x1, x[i] );
      y0 = min( y0, y[i] );
      y1 = max( y1, y[i] );

    }

    cout << x1 - x0 + 1 << " " << y1 - y0 + 1 << endl;

  }

  return 0;

}

Measured memory_bytes: 1220
#include<iostream>

using namespace std;

int dice[6];
//0->top, 1->bottom, 2->north 3->south,4->east, 5->west

void init(){
  dice[0] = 1;
  dice[1] = 6;
  dice[2] = 5;
  dice[3] = 2;
  dice[4] = 3;
  dice[5] = 4;
}

void north(int n){
  while(n--){
    int tmp = dice[0];
    dice[0] = dice[3];
    dice[3] = dice[1];
    dice[1] = dice[2];
    dice[2] = tmp;
  }
}
void east(int n){
  while(n--){
    int tmp = dice[0];
    dice[0] = dice[5];
    dice[5] = dice[1];
    dice[1] = dice[4];
    dice[4] = tmp;
  }
}
void right(int n){
  while(n--){
    int tmp = dice[3];
    dice[3] = dice[4];
    dice[4] = dice[2];
    dice[2] = dice[5];
    dice[5] = tmp;
  }
}

void move(string s){
  if(s[0] == 'N')north(1);
  if(s[0] == 'E')east(1);
  if(s[0] == 'W')east(3);
  if(s[0] == 'S')north(3);
  if(s[0] == 'R')right(1);
  if(s[0] == 'L')right(3);
 

}

int main(){
  int n;
  while(cin >> n && n){
    int sum = 0;
    init();

    for(int i = 0; i < n; i++){
      string s;
      cin >> s;
      move(s);
      sum += dice[0];
    }
    cout << sum+1 << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
const ll inf = 0x3f3f3f3f;
#define case(i) "Case #" << i << ": "
 
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
    out << '(' << p.first << ", " << p.second << ')';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++) out << v[i] << ' ';
    if (l > 0) out << v[l - 1];
    return out;
}

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

    int n, m;
    cin >> n >> m;

    vector<string> v[n+1];

    for(int i = 0; i < m; ++i) {
        int p;
        string s;
        cin >> p >> s;
        v[p].push_back(s);
    }
    ll pen = 0, rt = 0;
    for(int i = 1; i <= n; ++i) {
        bool ok = false;
        int tpen = 0;
        for(string x: v[i]) {
            if(x == "AC") {
                ok = true;
                rt++;
                break;
            }
            else tpen++;
        }
        if(ok) pen += tpen;
    }

    cout << rt << " " << pen << endl;

}

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

using namespace std;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

string s;

int32_t main(){
    migmig
    cin >> s;
    cout << s[0] << s[1] << s[2];
    
    
    
    
    return(0);
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	int x,a,b;
	cin>>x>>a>>b;
	cout<<((abs(a-x)<abs(b-x))?"A":"B")<<endl;
	return 0;
}

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

using namespace std;

vector<int> Change(const vector<int> &vec)
{
    vector<int> res(vec.size());
    size_t start = 0;
    size_t left = 0;
    size_t right = 0;

    if (vec.size() % 2 == 1) {
        res[vec.size() / 2] = vec[0];
        left = vec.size() / 2 - 1;
        right = vec.size() / 2 + 1;
        start = 1;
    } else {
        res[vec.size() / 2] = vec[0];
        res[vec.size() / 2 - 1] = vec[1];
        left = vec.size() / 2 - 2;
        right = vec.size() / 2 + 1;
        start = 2;
    }

    for (auto i = start; i < vec.size(); i += 2) {
        res[right] = vec[i];
        res[left] = vec[i + 1];

        right += 1;
        left -= 1;
    }
    return res;
}

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

    vector<int> vec(n);
    for (auto &num : vec) {
        cin >> num;
    }

    auto res = Change(vec);
    for (const auto &num : res) {
        cout << num << " ";
    }
    cout << "\n";

    return 0;
}


Measured memory_bytes: 3712
#include <iostream>

#define N 16
using namespace std;

long long arr[N][N], mask[1 << N], dp[1 << N];

int main() {

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			scanf("%lld", arr[i] + j);
	// N^2 x 2 ^ N
	for (int i = 0; i < (1 << n); ++i) {
		long long mut = 0;
		for (int j = 0; j < n; ++j)
			for (int k = j + 1; k < n; ++k)
				if ((i & (1 << j)) && (i & (1 << k)))
					mut += arr[j][k];
		mask[i] = mut;
		//cout<<mut<<endl;
	}
	// N x 2 ^ N
	for (int i = 0; i < (1 << n); ++i)
		dp[i] = mask[i];
	for (int i = 0; i < (1 << n); ++i)
		for (int j = i; j > 0; j = (j - 1) & i)
			dp[i] = max(dp[i], dp[i ^ j] + mask[j]); 
	/*
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < (1 << n); ++j) {
			if (j & (1 << i))
				dp[j] = max(dp[], dp[]);
		}
	}
	*/
	printf("%lld\n", dp[(1 << n) - 1]);
	return 0;
}


Measured memory_bytes: 1280
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    ll ans=IINF;
    for(ll i=1;i*i<=n;i++){
        if(n%i!=0)continue;
        ll j=n/i;
        string a=to_string(i);
        string b=to_string(j);
        chmin(ans,mmax(a.length(),b.length()));
    }
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------








































Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int x[3000],y[3000],i,temp;
	
	i=0;
	while(1){
		scanf("%d %d",&x[i],&y[i]);
		if(x[i]==0&&y[i]==0){
			break;
		}
		if(x[i]>y[i]){
			temp=x[i];
			x[i]=y[i];
			y[i]=temp;
		}
		printf("%d %d\n",x[i],y[i]);
		i++;
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  if(s.at(0) == s.at(1)) {
    cout << "Bad" << endl;
  } else if(s.at(1) == s.at(2)) {
    cout << "Bad" << endl;
  } else if(s.at(2) == s.at(3)) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 3576
#include <iostream>

using namespace std;

int main(){
    int n[4];
    cin >> n[0] >> n[1] >> n[2] >> n[3];
    sort(n, n + 4);
    if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define ifr(a, value) insert(a.begin(), value)
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define szz(v) ((int)(v).size())  
#define vi vector<int>
#define vll vector<ll>
#define str string
#define fr(i, j, k) for(i = j; i < k; i++)
#define bk(i, j, k) for(i = j; i >= k; i--)
#define frit(a, it) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)        // use fill() for value other than 0 //
#define rtn return 
#define clk fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC)
#define nl "\n"
#define inf 1LL<<61
#define dbg(x) (cerr << #x << ": " << x << "\n")
const long long mod = 1e9+7;

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }   // no need to swap a, b, it auto. happens after first call //
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, i;
    cin >> n;
    int a[n];
    fr(i, 0, n)
        cin >> a[i];
    if(a[0] != 0)
    {
        cout << -1;
        rtn 0;
    }
    fr(i, 1, n)
    {
        if(a[i] > a[i-1]+1)
        {
            cout << -1;
            rtn 0;
        }
    }
    
    int dif, prev = n;
    ll ans = 0;
    bk(i, n-1, 0)                 // proceeding with back just to add last addition as a[x] = no. of operation 
    {
        dif = i-a[i];
        if(dif != prev)         // dif == prev => of the same operation
        {
            ans += a[i];
            prev = dif;
        }
    }
    cout << ans;
    return 0;
}

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

unsigned GCD(unsigned a, unsigned b) {
	if (a < b)return GCD(b, a);
	if (a % b == 0) return b;
	return GCD(b, a%b);
}

pair<int, int> flip(pair<int, int> s) { return make_pair(s.second, s.first); }

pair<int, int> d(int a, int b) {
	if (a < b) return flip(d(b, a));
	if (b == 1) { return make_pair(0, 1); }
	auto t = d(a%b, b);
	t.second -= t.first * (a / b);
	return t;
}

int main() {
	int a, b; cin >> a >> b;
	int g = GCD(a, b);
	a /= g; b /= g;
	auto k = d(a, b);
	while (abs(b) >= abs(b - a)) { b -= a; }
	while (abs(b) > abs(b + a)) { b += a; }
	while (abs(a) > abs(a + b)) { b += a; }
	while (abs(a) >= abs(a - b)) { b -= a; }
	cout << k.first << " " << k.second << endl;
	return 0;
}





Measured memory_bytes: 3084
n = int(input())
list_A = list(map(int, input().split()))

for i in range(n):
    list_A[i] -= i + 1
list_A.sort()
b = 0
if n % 2 == 1:
    b = list_A[n//2]
else:
    b = (list_A[n//2]+list_A[n//2-1])//2

ans = 0

for num in list_A:
    ans += abs(num-b)

print(ans)

Measured memory_bytes: 26708
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

int dp[100000];

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

    int N, K;
    cin >> N >> K;

    vs32 h(N);
    rep (i, N) cin >> h[i];

    rep (i, N)
    {
        dp[i] = 1e9;
    }
    dp[0] = 0;
    for (int i = 1; i < N; ++i)
    {
        rep (j, K)
        {
            int idx = MAX(0, i - j - 1);
            dp[i] = MIN(dp[i], dp[idx] + abs(h[i] - h[idx]));
        }
    }

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



Measured memory_bytes: 1024
n = int(input())
    
t_num , a_num = 1, 1
for t, a in [map(int, input().split()) for _ in range(n)]:
    pre_t_num, pre_a_num = t_num, a_num
    t_num, a_num = t, a
    if t_num < pre_t_num or a_num < pre_a_num:
        t_k = (pre_t_num + t - 1) // t
        a_k = (pre_a_num + a - 1) // a
        m = max(t_k, a_k)
        t_num, a_num = t * m, a * m

ans = t_num + a_num
print()
print(ans)

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

using namespace std;

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

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

const int N = 100500;



int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	ll n, a, b;
	cin >> n >> a >> b;
	cout << max(0ll, a + (n - 1) * b - (n - 1) * a - b + 1);
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int h,a,cnt=0,flag=1,n;
int main()
{
	cin>>h>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		h=h-a;
	}
	if(h<0||h==0) cout<<"Yes";
	else cout<<"No";
	
/*	while(flag){
		h=h-a;
		if(h==0||h<0){
			flag=0;
		}
		cnt++;
	}
	cout<<cnt;*/
	
	
	return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int used[100100];

int main(){
    int N,M;
    cin >> N >> M;
    UnionFind uf(N);
    rep(i,M){
        int x,y,z;
        cin >> x >> y >> z;
        x--,y--;
        uf.unite(x,y);
    }
    int res = 0;
    rep(i,N){
        if(used[uf.root(i)]==0){
            res++;
            used[uf.root(i)]=1;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main() {
    ll x; cin >> x;
    for(int i=0; i<=200; i++) {
        for(int j=-200; j<=200; j++) {
            ll num = i*i*i*i*i - j*j*j*j*j;
            if(num == x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int N=2000;
char s[N];
int cnt[4];

int main() {
    int i;
    scanf("%s", s);
    for(i=0; s[i]; i++) {
        if(s[i]=='N') cnt[0]++;
        if(s[i]=='E') cnt[1]++;
        if(s[i]=='S') cnt[2]++;
        if(s[i]=='W') cnt[3]++;
    }
    if((cnt[0]==0)+(cnt[2]==0)==1
    || (cnt[1]==0)+(cnt[3]==0)==1)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
dd = [(-1, 0), (-1, -1), (0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1)]
while 1:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    S = [input() for i in range(h)]

    count = {}
    for i in range(h):
        for j in range(w):
            for dx, dy in dd:
                s = S[i][j]
                count[s] = count.get(s, 0) + 1
                x = (j + dx) % w; y = (i + dy) % h
                while x != j or y != i:
                    s += S[y][x]
                    count[s] = count.get(s, 0) + 1
                    x = (x + dx) % w; y = (y + dy) % h
    ans = min(count, key=lambda x: (-len(x)*(count[x]>1), x))
    print(ans*(len(ans)>1)or 0)

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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 2e5 + 5;

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

  int n, m;
  cin >> n >> m;
  vector < int > dp((1 << n), INT_MAX);

  dp[0] = 0;
  for(int i = 0; i < m; i++){
    int cst, sz;
    cin >> cst >> sz;
    int msk = 0;
    for(int i = 0; i < sz; i++){
      int a;
      cin >> a;
      a--;
      msk = msk | (1 << a);
    }
    for(int j = 0; j < (1 << n); j++){
      if(dp[j] != INT_MAX) dp[j | msk] = min(dp[j | msk], dp[j] + cst);
    }
  }

  if(dp[(1 << n) - 1] == INT_MAX) cout << -1 << '\n';
  else cout << dp[(1 << n) - 1] << '\n';
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(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 0;
    }
}
int main()
{
    string s;
   cin>>s;
    for (char i = 'a'; i <= 'z'; i++)
    {
        if (s.find(i) == -1)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
int n,i,x;
std::string s;
char c;
main(){
  for(std::cin>>n>>s;i<n;++i)
    if(c==s[i]&&c=='x')break;
    else c=s[i],x++;
  std::cout<<x<<'\n';
}

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

using namespace std;

vector<int64_t> dp(100010, INT64_MAX);

int64_t dfs(vector<int> &arr, int i) {
    if (dp[i] != INT64_MAX) {
        return dp[i];
    }

    if (i <= 0) {
        return 0;
    } 

    //
    //  i - 1 と、i - 2 への遷移を再帰的に集めてきて
    //  それの min を返り値とする
    //
    //  これは、同じ i であれば、返り値が同じになる
    //  ことがメモ化の鍵となる。
    //

    //  i - 1 からジャンプ
    //  abs(arr[i] - arr[i - 1]) だけコストが増えていく
    int64_t result = INT64_MAX;
    result = min(result, dfs(arr, i - 1) + abs(arr[i] - arr[i - 1]));

    //  i - 2 からジャンプ
    if (i > 1) {
        result = min(result, dfs(arr, i - 2) + abs(arr[i] - arr[i - 2]));
    }

    dp[i] = result;
    return result;
}

int main(int argc, char *argv[]) {
    int N;
    cin >> N;

    vector<int> arr;
    int cur;
    for (int i = 0; i < N; i++) {
        cin >> cur;
        arr.push_back(cur);
    }

    cout << dfs(arr, N - 1) << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  for(char i = 'a'; i <= 'z'; i++) {
    int check = 0;
    for(int j = 0; j < s.size(); j++) {
      if(s[j] == i) {
        check = 1;
        break;
      }
    }
    if(check == 0) {
      cout << i;
      return 0;
    }
  }
  cout << "None";
}

Measured memory_bytes: 512
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

static const int NMAX = 1e5;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;

    map<int,ll> cnts;
    ll ans = 0;
    cnts.insert({0,1});
    ll pre = 0;
    ll prefs[n+1];
    prefs[0] = 0;
    for(int i = 0; i< n; ++i)
    {
		int a; cin >> a; a--;
		pre+= a; pre%=k;
		prefs[i+1] = pre;
		if(i >= k-1)
		{
			cnts[prefs[i-k+1]]--;
		}
		if(cnts.count(pre))
		{
			ans += cnts[pre];
			cnts[pre]++;
		}
		else
		{
			cnts.insert({pre,1});
		}
		
    }
	cout << ans;
	


    return 0;
}

Measured memory_bytes: 14336
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string S;
  cin >> S;
  if (S <= "2019/04/30") cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int x=sc.nextInt();
		int[][] ca=new int[n][m+1];
		for(int i=0; i<n; i++){
			int c=sc.nextInt();
			ca[i][0]=c;
			for(int j=0; j<m; j++){
				int a=sc.nextInt();
				ca[i][j+1]=a;
			}
		}
		long ans=Long.MAX_VALUE;
		for(int i=0; i<1<<n; i++){
			long money=0;
			int[] tmp=new int[m];
			for(int j=0; j<n; j++){
				if((i>>j & 1)==1){
					money+=ca[j][0];
					for(int k=1; k<=m; k++){
						tmp[k-1]+=ca[j][k];
					}
				}
			}
			boolean ch=true;
			for(int j=0; j<m; j++){
				if(tmp[j]<x){
					ch=false;
					break;
				}
			}
			if(ch){
				ans=Math.min(ans,money);
			}
		}
		if(ans==Long.MAX_VALUE){
			System.out.println(-1);
		}else{
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 37432
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

void solve()
{
	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	ll req = (x / d);
	if (req > k)
	{
		cout << x - k*d << endl;
	}
	else
	{
		if ((k - req) & 1)cout << min(abs(x - (req)*d + d), abs(x - (req)*d - d)) << endl;
		else cout << x - (req * d) << endl;
	}
}

int32_t main()
{
	IOS
	ll T = 1;
	// cin >> T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>

int main()
{
	int h, w, i, j;

	while (1){
		scanf("%d %d", &h, &w);

		if (h == 0 && w == 0) return 0;

		for (i = 1; i <= h; i++){
			for (j = 1; j <= w; j++){
				if (((i + j) % 2) == 0)
					printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * @Author: Tard1grad3                                                         *
 * @Last modified time: Sunday, September 20th 2020, 07:40:15 pm (UTC+06:00)   *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include <bits/stdc++.h>
using namespace std;
#define IC ios_base::sync_with_stdio(false); cin.tie(NULL);
#define f(i, a, b) for(int i=a; i<b; i++)
#define ff(i, a, b) for(int i=a-1; i>=b; i--)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mp make_pair
#define sz 1005
#define mod 998244353
#define line "\n"
#define ALL(x) x.begin(), x.end()
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef map<char, int> mci;
const double PI = acos(-1);

// int a[sz];
// string s;
// si st;
// vector<string> vs;
// vector<char> vc;
// mci mm;


void solve()
{
    ll k, a, b, c, d, n, m=0, cnt=0, flg=0, ans=0, pos=0, sum=0, mx=INT_MIN, mn=INT_MAX;
    cin >> a >> b >> c >> d;
    cout << max(max(max(a*c, a*d), b*c), b*d);
}

int main()
{
    int T=1, k=1;
    // cin >> T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n,r;
	while(cin>>n>>r){
		if(n==0 && r==0) break;
		string str(n,0);
		for(int i=0;i<str.length();i++){
			str[i]=n-i;
		}
		for(int j=0;j<r;j++){
			int p,c;
			cin>>p>>c;
			str=str.substr(p-1,c)+str.substr(0,p-1)+str.substr(p+c-1);
		}
		cout<<(int)str[0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int INF = 1e18 + 239;

int n;
vector<int> a;
map<pair<int, int>, int> mem;

int solve(int len, int cnt) {
	if (cnt > (len + 1) / 2) return -INF;
	if (len <= 0) return 0;
	if (!mem.count({len, cnt})) {
		// cerr << len << ' ' << cnt << endl;
		int f = a[len - 1] + solve(len - 2, cnt - 1);
		int s = solve(len - 1, cnt);
		mem[{len, cnt}] = max(f, s);
	}
	return mem[{len, cnt}];
}

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

	cin >> n;
	a.resize(n);
	for (auto &t : a) {
		cin >> t;
		// t = rand();
	}
	cout << solve(n, n / 2) << endl;
}


Measured memory_bytes: 29544
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 1005
#define LL long long
#define mod 1000000007
#define rep(i,j,k) for(i=j;i<=k;++i)
int n,m,i,j;
int mp[N][N];
LL b,K,H,heng;
bool sx,zy;
struct Matrix{
	int n,m,f[2][2];
	Matrix(){ n=m=2; f[0][0]=f[1][1]=1; f[0][1]=f[1][0]=0; }
    Matrix operator * (const Matrix &b)const{
		Matrix c;
		int i,j,k;
		c.n=n; c.m=b.m;
		rep(i,0,c.n-1)
			rep(j,0,c.m-1){
				c.f[i][j]=0;
				rep(k,0,m-1){
					c.f[i][j]+=(f[i][k]*1LL*b.f[k][j])%mod;
					c.f[i][j]%=mod;
				}
			}
		return c;
	}	
}zhuanyi,chushi,ans;
void read(LL &p){
	p=0; char x=getchar();
	while(x<'0' || x>'9') x=getchar();
	while(x>='0'&&x<='9'){ p=p*10+x-'0'; x=getchar();}
}
int quick_mi(LL a,LL b){
	int sum=1;
	for(;b;b>>=1LL){
		if(b&1) sum=(sum*1LL*a)%mod;
		a=(a*1LL*a)%mod;
	}
	return sum;
}
bool check(){
	sx=false; zy=false;
	rep(i,1,m)
	if(mp[1][i]&&mp[n][i]){
		sx=true; break ;
	}
	rep(i,1,n)
	if(mp[i][1]&&mp[i][m]){
		zy=true; break ;
	}
	if(sx && zy) {
		puts("1");
		return true;
	}
	if((!sx)&&(!zy)){
		printf("%d\n",quick_mi(b,K-1LL));
		return true;
	}
	if(zy) {
		rep(i,1,n)
		if(mp[i][1]&&mp[i][m])
			H++;
		rep(i,1,n)
		 rep(j,1,m-1)
		 if(mp[i][j]&&mp[i][j+1])
		 	heng++;
	}else{
		rep(i,1,m)
		if(mp[1][i]&&mp[n][i]) 
			H++;
		rep(i,1,n-1)
		 rep(j,1,m)
		 if(mp[i][j]&&mp[i+1][j])
			heng++;
	}
	return false;
}
Matrix quick_mi(Matrix a,LL b){
	Matrix sum;
	for(;b;b>>=1){
		if(b&1) sum=sum*a;
		a=a*a;
	}
	return sum;
}
int main(){
	scanf("%d%d",&n,&m); read(K);
	rep(i,1,n){
		char x=getchar();
		while((x!='.')&&(x!='#')) x=getchar();
		j=0;
		while((x=='.')||(x=='#')){
			j++; 
			if(x=='.') mp[i][j]=0;
			else {
				mp[i][j]=1;
				b++;
			}
			x=getchar();
		}
	}
	if(K<=1) {
		puts("1");
		return 0;
	}
	if(check()) return 0;
	chushi.n=1; chushi.m=2; chushi.f[0][0]=chushi.f[0][1]=1;
	zhuanyi.f[0][0]=b; zhuanyi.f[1][0]=(mod-heng)%mod; zhuanyi.f[1][1]=H;
	ans=chushi*quick_mi(zhuanyi,K-1);
	printf("%d\n",ans.f[0][0]);
	return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; ++i) cin >> l[i];

  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = 0; i < n - 2; ++i) {
    int k = i + 2;
    for (int j = i + 1; j < n; ++j) {
      while (k < n && l[i] + l[j] > l[k]) ++k;

      if (k > j) ans += k - j - 1;
      
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
import math


def main():
    k: longlong
    result: longlong

    k = int(input())

    result = 0

    for x in range(1, k + 1):
        for y in range(1, k + 1):
            for z in range(1, k + 1):
                temp = math.gcd(math.gcd(x, y), z)
                result += temp
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    int n,m,x,ans=-1;
    cin>>n>>m>>x;
    int ar[n][m],c[n];
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        for(int j=0;j<m;j++)
        cin>>ar[i][j];
    }
    int lim=1 << n;
    for(int i=0;i<lim;i++)
    {
        int cur[m],cost=0;
        fill(cur, 0);
        for(int j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                cost+=c[j];
                for(int k=0;k<m;k++)
                cur[k]+=ar[j][k];
            }
        }
        int f=0;
        for(int i=0;i<m;i++)
        {
            if(cur[i]<x)
            {
                f=1;
                break;
            }
        }
        if(f==0)
        {
            if(ans==-1)
            ans=cost;
            else
            ans=min(ans, cost);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int n, a;
int main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n >> a;
    if (n % 500 <= a) {
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

vector<ll> fact(ll n) {
   vector<ll> res;
   for (int i = 1; (ll)i * i <= n; i++) {
      if (n % i != 0) continue;
      res.push_back(i);
      if ((ll)i * i != n) res.push_back(n / i);
   }
   return res;
}
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   ll n;
   cin >> n;
   int ans = 0;
   for (ll x : fact(n)) {
      if (x == 1) continue;
      ll m = n;
      while (m % x == 0)
         m /= x;
      m %= x;
      if (m == 1) ans++;
   }
   ans += fact(n - 1).size() - 1;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 384
N, K = [int(x) for x in input().split()]
A = sorted([int(x) for x in input().split()])
F = sorted([int(x) for x in input().split()], reverse=True)
lb = 0
ub = 10 ** 12
def isPossible(M):
    cnt = 0
    # a = 4 , f = 5 のとき a*f = 20
    # M = 30 => そのままでOK
    # M = 9 => (20-9+4)//5
    for a, f in zip(A, F):
        if (M >= a*f): continue
        cnt += (a*f - M + (f-1)) // f
    return cnt <= K

for i in range(100):
    mid = (lb + ub) // 2
    if (isPossible(mid)):
        ub = mid
    else:
        lb = mid
print(ub)


Measured memory_bytes: 122828
#coding:utf-8
import bisect
from collections import deque
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True

def index(a,b):
    return str(min(a,b)) + "," +  str(max(a, b))

def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    a = LMIIS()

    if a[0] + a[1] + a[2] >= 22:
        print("bust")
    else:
        print("win")





if __name__ == '__main__':
    main()


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll,ll> P;
template <typename T> std::string tostr(const T& t){std::ostringstream os; os<<t; return os.str();}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
    string s;
    cin>>s;
    int n=s.length();
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            string tmp=s.substr(0,i);
            tmp+=s.substr(j);
            if(tmp=="keyence"){
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back  
#define INF 1000000000000
typedef long long C;
typedef complex<C> P; 
#define X real() 
#define Y imag()


									// nestedcode


 int main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   ll h,n,s = 0,i;
   cin>>h>>n;
   ll a[n+5];
  for(i=0;i<n;i++){
  	cin>>a[i];
  	s+=a[i];
  }
  if(s>= h){
  	cout<<"Yes";
  }else{
  	cout<<"No";
  }
}

Measured memory_bytes: 1024
A, B, C = map(int, input().split())

K = int(input())

c = 0

while True:
    if A >= B:
        B *= 2
        c += 1
    elif B >= C:
        C *= 2
        c += 1
    else:
        break

if c <= K:
    print("Yes")

else:
    print("No")

Measured memory_bytes: 9176
// atcoder/abc133/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

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

  lli l, r;
  while (cin >> l >> r) {
    const lli x = 2019;

    vector<lli> v;
    for (lli i = l; i <= r; ++i) {
      v.push_back(i);
      if (x < v.size()) break;
    }

    lli mn = 1LL << 60;
    for (int i = 0; i < v.size(); ++i) {
      for (int j = i + 1; j < v.size(); ++j) {
        setmin(mn, (v[i] * v[j]) % x);
      }
    }
    cout << mn << endl;
  }

  return 0;
}


Measured memory_bytes: 256