akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int &x:a)
    {
        cin>>x;
    }
    vector<int> dp (n,inf);
    dp[0] = 0;

    for(int i = 0;i<n;i++)
    {
        for(int j:{i+1, i+2})
        {
            if(j<n)
            {
                dp[j] = min(dp[j], dp[i] + abs(a[j]-a[i]));
            }
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
//in the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
     int n,k;
     cin>>n>>k;
     int a[n];
     for(int i=0;i<n;i++)
        cin>>a[i];
     sort(a,a+n);
     ll s=0;
     for(int i=0;i<k;i++)
        s+=a[i];
        cout<<s<<endl;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  ll n, k;
  cin >> n >> k;
  mint ans = 0;
  rep2(i, k, n + 2) {
    ll l = i * (i - 1) / 2;
    ll r = i * (n - i + n + 1) / 2;
    ans += r - l + 1;
  }
  cout << ans << endl;
}

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

N = 100
board = [['.#'[row >= N//2] for _ in range(N)] for row in range(N)]
for i in range(B-1):
    r, c = i // 25 * 2, (i % 25) * 2
    board[r][c] = "#"
for i in range(A-1):
    r, c = i // 25 * 2, (i % 25) * 2
    board[-r-1][c] = "."
print(N, N)
print("\n".join(''.join(row) for row in board))


Measured memory_bytes: 3188
N=int(input())
S=input()
i=0
hidari=str()
migi=str()
a=0
while i<N:
  if S[i]==")":
    hidari+="("
    i+=1
  else:
    break
while i<N:
  if S[i]=="(":
    a+=1
  else:
    a-=1
  i+=1
if a<0:
  hidari+=abs(a)*"("
elif a>0:
  migi+=a*")"
s=hidari+S+migi


i=0
hidari=str()
migi=str()
a=0
while i<N:
  if S[i]==")":
    hidari+="("
    i+=1
  else:
    break
while i<N:
  if S[i]=="(":
    if a<0:
      a=0
    a+=1
    mina=0
  else:
    a-=1
    if a<0:
      if mina>a:
        hidari+="("
  i+=1
if a>0:
  migi+=a*")"
t=hidari+S+migi
if len(s)==len(t):
  print(s)
elif len(s)>len(t):
  print(s)
else:
  print(t)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int X, Y;
    cin >> X >> Y;

    /*
    int x = (4*X-Y) % 2;
    int y = (Y-2*X) % 2;
    if (x || y  || Y > 4*X) no;
    else yes;
    */

   REP(i,X+1) {
       if (Y == 2*i + (X-i)*4) ans = 1;
   }

   yn(ans);
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc170/abc170_b && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc170/abc170_b && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc170/abc170_b && sh shellscripts/submit_cpp.sh
*/


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

using namespace std;
typedef long long ll;

ll mod=1e9+7;
ll B=1999;

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n){
    if(n%2) res=res*x%mod;
    x=x*x%mod;
    n/=2;
  }
  return res;
}

int main(){
  string s;
  int n,m;
  set<pair<ll,ll> > st;
  
  cin>>n>>m>>s;
  ll d=mod_pow(B,mod-2),dv=1,l=0,r=0,h=s[0];
  
  string q;
  while(m--){
    cin>>q;
    
    if(q=="L++"){
      h+=(mod-s[l])*dv;
      h%=mod;
      dv= (dv*d) %mod;
      l++;
    }
    
    else if(q=="L--"){
      l--;
      dv= (dv*B) %mod;
      h+=s[l]*dv;
      h%=mod;
    }
    
    else if(q=="R++"){
      r++;
      h=(h*B+s[r])%mod;
      dv=(dv*B)%mod;
    }
    
    else{
      h=(h-s[r]+mod)%mod;
      h=h*d%mod;
      dv=dv*d%mod;
      r--;
    }
    st.insert(make_pair(h,r-l));
  }
  cout<<st.size()<<endl;
  return 0;
}

Measured memory_bytes: 21908
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 998244353
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 100003
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
	long long a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k&1){
		cout<<b-a<<endl;
	}
	else cout<<a-b<<endl;
}




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

using namespace std;

int main() {

	long n;
	cin >> n;
	vector<long long> a(n );
	for (long i = 0; i < n; i++) {

		cin >> a[i];
	}
	sort(a.begin(), a.end());

	long long maxx = 0;
	long long resi=0, resj=0;
	double center = 0;
	for (long i = 1; i < n; i++) {
		
		center = (double)a[i] / 2;
		long l,r,m;
		l = 0;
		r = i-1;
		m = (l + r) / 2;

		

		while (l + 1 < r) {

			if (center > a[r] || center<a[l]) {
				break;
			}

			if (center > a[m]) {
				l = m;
				m = (l + r) / 2;
			}
			else if (center < a[m]) {
				r = m;
				m = (l + r) / 2;
			}
			else {
				l = m;
				r = m;
				break;
			}
		}
		if (abs(a[l] - center) >= abs(a[r] - center)) {
//			if (maxx < comb(a[i], a[r])) {
//				maxx = comb(a[i], a[r]);
				resi = a[i];
				resj = a[r];
//			}
		}
		else {
//			if (maxx < comb(a[i], a[l])) {
//				maxx = comb(a[i], a[l]);
				resi = a[i];
				resj = a[l];
//			}
		}

	}
	cout << resi << " " << resj << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        StringBuilder h = new StringBuilder();
        for(int i = 0; i < W + 2; i++) {
            h.append("#");
        }
        String header = h.toString();
        System.out.println(header);
        for(int i = 0; i < H; i++) {
            String s = scan.next();
            System.out.println("#" + s + "#");
        }
        System.out.println(header);
    }
}

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

int main() {
    int N,count,minl=101,last;
    cin >> N;
    vector<int> length(N),flag(N-1);
    
    

    for (int i = 0; i < N; ++i){
        cin >> length.at(i);
        minl = min(minl,length.at(i));
    }

    count = minl;
    
    for (int i = 0; i < N; ++i){
        length.at(i) -= minl;
    }

    count += length.at(0);

    for (int i = 1; i <N; ++i ){
        count += max(0,length.at(i)-length.at(i-1));
    }
    cout << count << endl;
        
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

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

    int b[N], c, s, sum=0;
    for(i=N-1; i>-1; i--) {
        if((i+1)>(N/2)) {
            b[i] = a[i];
            if(b[i]==1) sum += 1;
        }
        else {
            c = 2;
            s = 0;
            // cout << i << endl;
            while((i+1)*c<=N) {
                s += b[(i+1)*c-1];
                c += 1;
                // cout << s << endl;
            }
            // cout << endl;
            if(s%2==a[i]) b[i] = 0;
            else {
                b[i] = 1;
                // cout << i << s << endl;
                sum += 1;
            }
        }
    }

    cout << sum << endl;

    int count=1;
    for(i=0; i<N; i++) {
        if(b[i]==1 && count!=sum) {
            cout << i+1 << ' ';
            count += 1;
        } else if(b[i]==1 && count==sum) {
            cout << i+1 << endl;
        }
    }

    return 0;

}

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

int main(){
    int n;
    long long sum = 0;
    cin >> n;
    for (int i = 1; i < n + 1; i++){
        if (i % 3 != 0 && i % 5 != 0){
            sum = sum + i;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.util.*;
 
class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        System.out.println(c-(a-b) <= 0 ? 0 : c-a+b);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int n;
    cin >> n;
    ll z[n],w[n];
    for(int i=0;i<n;i++){
        ll x,y;
        cin >> x >> y;
        z[i]=x+y;
        w[i]=x-y;
    }

    //cout << 2*M << endl;

    ll zmax=INT64_MIN,wmax=INT64_MIN,wmin=INT64_MAX,zmin=INT64_MAX;
    for(int i=0;i<n;i++){
        zmax=max(zmax,z[i]);
        zmin=min(zmin,z[i]);
        wmax=max(wmax,w[i]);
        wmin=min(wmin,w[i]);
    }

    ll ans=max(zmax-zmin,wmax-wmin);
    cout << ans << endl;
}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
typedef pair<ll,ll> Pair;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }

const ll INF=99999999999999;
const ll MOD=1000000007;

vector<bool> IsPrime(1);

void sieve(ll x){
     if(x+1 > IsPrime.size()){
         IsPrime.resize(x+1,true);
     }
     IsPrime[0] = false;
     IsPrime[1] = false;

     for(ll i=2; i*i<=x; ++i){
         if(IsPrime[i]){
            for(ll j=2; i*j<=x; ++j){
                IsPrime[i*j] = false;
            }
         }
     }
}
 
int main() {
  ll n;
  cin >> n;
  sieve(55556);
  ll c = 11;
  ll count = 0;
  rep(i,50000){
    if(IsPrime[c]){
      cout << c << " ";
      count++;
    }
    if(count == n) break;
    c += 10;
  }
  
    
 return 0;
}

Measured memory_bytes: 256
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 110
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int n;
int a[N],num[N];
inline void L(){printf("Impossible\n");exit(0);}
inline void W(){printf("Possible\n");exit(0);}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(register int i=1;i<=n;i++)num[read()]++;
	for(register int i=1;i<=n;i++)
	{
		if(num[i])
		{
			if(num[i]>2){L();}
			int x;
			if(num[i]==1)x=2*i;
			else x=2*i-1;
			for(register int j=i+1;j<=x;j++){if(num[j]<2)L();}
			for(register int j=x+1;j<=n;j++){if(num[j])L();}
			W();
		}
	}
	return 0;
}


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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

  vector<int> dp(n + 1, 100010);
  dp.at(0) = 0;
  for (int i = 1; i <= n; i++) {
    dp.at(i) = dp.at(i - 1) + 1;
    for (int j = 6; j <= i; j *= 6) {
      chmin(dp.at(i), dp.at(i - j) + 1);
    }
    for (int j = 9; j <= i; j *= 9) {
      chmin(dp.at(i), dp.at(i - j) + 1);
    }
  }

  cout << dp.at(n) << endl;
  return 0;
}

Measured memory_bytes: 3728
/**
 * Author: Martin Leshko (leshko.martin@gmail.com)
 */

#include <bits/stdc++.h>
#define F0R(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, n) for (int i = 1; i <= (int)(n); i++)
#define trav(i, a) for (auto& i: a)
#define sz(x) (int)x.size()
#define psb push_back
template<class T> void re(T& x) { std::cin >> x; }
template<class T, class... Ts> void re(T& t, Ts&... ts) { re(t); re(ts...); }
void pr(int x) { std::cout << x; }
void pr(long long x) { std::cout << x; }
void pr(float x) { std::cout << x; }
void pr(double x) { std::cout << x; }
void pr(char x) { std::cout << x; }
void pr(const char* x) { std::cout << x; }
void pr(const std::string& x) { std::cout << x; }
template<class T> void pr(const T& x);
template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {  pr(t); pr(ts...); }
void ps() { std::cout << "\n"; }

using namespace std;
using ll = long long;
using vi = vector<int>;

const int N = 100001;

int main() {
  string s; re(s);
  vector<int> ans(sz(s)+1,0);
  F0R(i, sz(s)) if (s[i] == '<') {
    ans[i+1] = ans[i]+1;
  }
  for (int i = sz(s)-1; i >= 0; i--) if (s[i] == '>') {
    ans[i] = max(ans[i], ans[i+1]+1);
  }
  ll sum = 0;
  F0R(i,sz(s)+1) sum += ans[i];
  pr(sum);
  return 0;
}

Measured memory_bytes: 2820
#include <stdio.h>
#include <stdlib.h>

int *s;
int *m;
int n, q;

int solve(int i, int m){
  int res;

  if (m==0) {
    return 1;
  }
  if (i >= n) {
    return 0;
  }else{
    res = solve(i + 1, m) || solve(i + 1, m - s[i]);
    return res;
  }
}
int main(){
  int i,j;
  //要素数と要素の読み込み
  scanf("%d",&n);
  s = (int*)malloc(sizeof(int) * n);
  for(i=0; i<n; i++){
    //printf("s[%d]: ",i);
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  m = (int*)malloc(sizeof(int) * q);
  for(i=0; i<q; i++){
    //printf("m[%d]: ",i);
    scanf("%d",&m[i]);
    if(1==solve(0,m[i])){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }
  return 0;
}



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

int main()
{
	int n,m;
	cin >> n >> m;
	bool edges[n][n];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			edges[i][j] = false;
		}
	}
	for(int i = 0; i < m; i++){
		int a,b;
		cin >> a >> b;
		edges[a-1][b-1] = true;
		edges[b-1][a-1] = true;
	}

	vector<int> perm;
	for(int i = 1; i < n; i++)
		perm.push_back(i);

	int ans = 0;
	do{
		bool able = edges[0][perm[0]];
		for(int i = 0; i < n-2; i++){
			if(!edges[perm[i]][perm[i+1]])
				able = false;
		}
		if(able){
		/*	cout << 0 << " ";
			for(int i = 0; i < n-1; i++)
				cout << perm[i] << " ";
			cout << "\n";*/
			ans++;
		}
	}while(next_permutation(perm.begin(), perm.end()));

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
A = []
for _ in range(3):
  A.append(list(map(int, input().split())))

B = []
while True:
    try:
        B.append(int(input()))
    except:
        break;

for i in range(3):
  if (A[0][i] in B and A[1][i] in B and A[2][i] in B) or (A[i][0] in B and A[i][1] in B and A[i][2] in B):
    print("Yes")
    import sys; sys.exit()

if (A[0][0] in B and A[1][1] in B and A[2][2] in B) or (A[0][2] in B and A[1][1] in B and A[2][0] in B):
  print("Yes")
  import sys; sys.exit()

print("No")

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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define MOD 1000000007

const int MAX_M = 100000;


int main(){
  ll n, k;
  //string s, t;
  cin >> n >> k;

  vector<ll> a(n);
  //map<string,ll> m;

  rep(i,0,n){
    cin >> a[i];
  }

  ll i = 1;
  vector<ll> q;
  ll cnt = 0;
  vector<ll> seen(n+1, -1);

  while(seen[i] == -1){

    seen[i] = cnt;
    cnt++;
    q.push_back(i);

    i = a[i-1];
  }
  //cout << seen[i] << endl;

  if(k <= seen[i]){
    cout << q[k] << endl;
  }
  else{
    cnt -= seen[i]; //周期
    k -= seen[i];
    k %= cnt;
    cout << q[seen[i]+k] << endl;
  }


  /*rep(i,0,q.size()){
    cout << q[i] << endl;
  }*/



  //cout << fixed << setprecision(10);
  //cout << q.at(k-1) << endl;
  //cout << ((ok)? "Yes" : "No") << endl;

}


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

int main() {
    ll l, k;
    cin >> l >> k;
    vector<vector<ll> > dp(l+1, vector<ll>(2));
    dp[0][0] = 1;
    for(int i=0;i<l;i++){
        dp[i+1][0] += dp[i][1];
        dp[i+1][1] += dp[i][0];
        if(i+k<=l)dp[i+k][1] += dp[i][0];
    }
    ll ans = 0;
    for(int i=1;i<=l;i++){
        ans += dp[i][1];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    string S;
    cin >> S;
    S[0] += 1;
    cout << S << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int H, N; cin >> H >> N;
    vector<pair<int, int>> M(N);
    int ma = 0;
    for (int i = 0; i < N; i++)
    {
        int a, b; cin >> a >> b;
        M[i] = make_pair(a, b);
    }

    vector<vector<long long>> dp(N+1, vector<long long>(H+1, 1e9));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j <= H; j++)
        {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][min(H, j + M[i].first)] = min(dp[i+1][min(H, j + M[i].first)], dp[i+1][j] + M[i].second);
        }
    }

    cout << dp[N][H] << endl;
    return 0;
}

Measured memory_bytes: 78592
IN = list(raw_input())
N = 0
S = 0
E = 0
W = 0

for i in range(len(IN)):
    if IN[i] == 'N':
        N += 1
    elif IN[i] == 'S':
        S += 1
    elif IN[i] == 'E':
        E += 1
    elif IN[i] == 'W':
        W += 1

if (N>0 and S>0):
    if (E==0 and W==0)or(E>0 and W>0):
        print 'Yes'
    else:
        print 'No'
elif N==0 and S ==0:
    if (E==0 and W==0)or(E>0 and W>0):
        print 'Yes'
    else:
        print 'No'
else:
    print 'No'


Measured memory_bytes: 2692
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(n * a < b) System.out.println(n * a);
        else System.out.println(b);
    }
}


Measured memory_bytes: 22100
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
#define int long long int

void solve() {
  int N, K;
  cin >> N >> K;

  int M = (N - 1) * (N - 2) / 2;

  if (K > M) {
    cout << -1 << endl;
    return;
  }

  vector<pair<int, int>> v;
  for (int i = 2; i <= N; i++) {
    v.emplace_back(1, i);
  }

  int cnt = M - K;
  for (int i = 2; i <= N && cnt != 0; i++) {
    for (int j = i + 1; j <= N && cnt != 0; j++) {
      v.emplace_back(i, j);
      cnt--;
    }
  }

  cout << v.size() << endl;
  for (auto &p : v) {
    cout << p.first << " " << p.second << endl;
  }

  // int x;
  // cout << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 512
N,M = gets.split.map(&:to_i)
path = [0]
M.times do
  a,b = gets.split.map(&:to_i)
  (path[a]||=[]) << b
  (path[b]||=[]) << a
end
mark = [0,'Yes']
np = [1]
while np.size > 0
  nx = []
  np.each do |t|
    path[t].map do |f| 
      (mark[f]=t; nx << f) if !mark[f]
    end
  end
  np = nx
end
puts mark[1..-1]


Measured memory_bytes: 33128
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  

  int x, y;
  cin>>x>>y;
  if (x % y) {
    cout<<x<<endl;
  } else {
    cout<<"-1"<<endl;
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = 0;
		int n = 0;

		k = sc.nextInt();
		n = sc.nextInt();

		int array[] = new int [n];

		for(int i = 0;i<n;i++){
			array[i] = sc.nextInt();
		}

		int ans = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++){
			int  tmp = 0;
			int index = i -1;
			if(index < 0){
				index += n;
			}
			tmp = array[index] - array[i];
			if(tmp <= 0){
				tmp += k;
			}
			ans = Math.min(ans, tmp);
		}
			System.out.println(ans);
	}
}

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

int main(){
  int N,i=1,a[200000],l,j=0,s[200000],k=0;
  cin >> N;
  while(j<N){
    s[j]=0;
    j++;
  }
  while(cin>>l){
    a[i] = l;
    s[a[i]-1]=s[a[i]-1]+1;
    i++;
  }
  while(k<N){
    cout << s[k] <<endl;
    k++;
  }
}

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a = sorted(LI())
    r = 0
    while a[0] != a[2]:
        r += 1
        if a[1] == a[0]:
            a[0] += 1
            a[1] += 1
        else:
            a[0] += 2
        a.sort()

    return r

print(main())





Measured memory_bytes: 6600
S = input()
T = input()

length = len(T)
index = 0
minimum = 1000
count = 0
for i in range(len(S)):
    if length+index > len(S):
        break
    bubun = S[index:length+index]
    for s, t in zip(bubun, T):
        if s != t:
            count += 1
    minimum = min(minimum, count)
    index += 1
    count = 0

print(minimum)

Measured memory_bytes: 9124
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(W, H, x, y):
    if W/2 == x and H/2 == y:
        return (W*H)/2, 1

    return (W*H)/2, 0


def main():
    W, H, x, y = read_int_n()
    print('%f %d' % slv(W, H, x, y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		int s = Integer.parseInt(str);
		int answer = 0;

		for(int i=s; i>0; i--){
			answer = answer + i;
		}

		System.out.println(answer);
	}

}


Measured memory_bytes: 21588
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
typedef pair<int,int>pii;
int dp[3001];
int main(){
    int n,t,s;
    cin>>n>>t>>s;
    vector<pii>V(n);
    for(int i=0;i<n;i++)
        cin>>V[i].first>>V[i].second;

    for(int i=1;i<=n;i++){
        int a=V[i-1].first,b=V[i-1].second;
        for(int j=t;j>=0;j--){
            if(j-b>=0&&(!(j-b<s&&j>s))){
                    dp[j]=max(dp[j],dp[j-b]+a);
            }
        }
    }

    cout<<*max_element(dp,dp+t+1)<<endl;
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }




int main(){
  long n,k;
  vl p(6000);
  vl c(6000);
  cin >> n >> k;
  rep(i,n){
    cin >> p.at(i);
    p.at(i)--;
  }
  rep(i,n) cin >> c.at(i);
  long ans = -1e16;
  rep(i,n){
    long okane = 0;
    vl o;
    long pv = p.at(i);
    okane += c.at(pv);
    o.push_back(okane);
    long maxi = c.at(pv);
    long cnt = 1;
    while(pv != i){
      pv = p.at(pv);
      okane += c.at(pv);
      o.push_back(okane);
      cnt++;
    }
    if(okane <= 0){
      rep(i,min(cnt,k)) chmax(maxi, o.at(i));
    }else{
      if(k <= cnt){
        rep(i, min(k,cnt)) chmax(maxi, o.at(i));
      }else{
        long ddd = 0;
        rep(i, cnt) chmax(ddd, o.at(i));
        maxi = (k-cnt) / cnt * okane;
        long fa = k % cnt + cnt;
        long mm = 0;
        
        rep(i, fa){
          chmax(mm, o.at(i%cnt) + (i/cnt * okane));
        }
        maxi += mm;
      }
      
    }
    chmax(ans, maxi);
  }

  cout << ans << endl;
}

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

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forrn(i, a, b) for (int i = (a); i < (int)(b); i++)
#define PYMOD(A, M) ((((A) % (M)) + (M)) % (M))
typedef long long ll;

using namespace std;

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

    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    forn(i, n)
        cin >> a[i];
    forn(i, n)
        cin >> b[i];

    if (accumulate(all(a), 0ll) < accumulate(all(b), 0ll)) {
        cout << -1 << endl;
        return 0;
    }

    vector<ll> extra;
    ll insufficient = 0;
    forn(i, n) {
        if (a[i] < b[i])
            insufficient += b[i] - a[i];
        else 
            extra.pb(a[i] - b[i]);
    }

    sort(rall(extra));

    int j = 0;
    while (insufficient > 0) {
        insufficient -= extra[j++];
    }

    cout << j + n - extra.size() << endl;

    return 0;
}

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

using namespace std;
char field[1001][1001];
typedef pair<int, int> P;

class white
{
public:
	int x;
	int y;
	char c;
};

void solve()
{
	int M, N;
	cin >> M >> N;
	for (int i = 0; i < M; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			cin >> field[i][j];
		}
	}
	char flag[2][2];
	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < 2; ++j)
		{
			cin >> flag[i][j];
		}
	}
	int ans = 0;
	vector<white> threePointOK;
	for (int i = 0; i < M - 1; ++i)
	{
		for (int j = 0; j < N - 1; ++j)
		{
			if (field[i][j] == flag[0][0] && field[i][j + 1] == flag[0][1] && field[i + 1][j] == flag[1][0] && field[i + 1][j + 1] == flag[1][1])
			{
				++ans;
			}
			else if (field[i][j] != flag[0][0] && field[i][j + 1] == flag[0][1] && field[i + 1][j] == flag[1][0] && field[i + 1][j + 1] == flag[1][1])
			{
				white w;
				w.x = j;
				w.y = i;
				w.c = flag[0][0];
				threePointOK.push_back(w);
			}
			else if (field[i][j] == flag[0][0] && field[i][j + 1] != flag[0][1] && field[i + 1][j] == flag[1][0] && field[i + 1][j + 1] == flag[1][1])
			{
				white w;
				w.x = j + 1;
				w.y = i;
				w.c = flag[0][1];
				threePointOK.push_back(w);
			}
			else if (field[i][j] == flag[0][0] && field[i][j + 1] == flag[0][1] && field[i + 1][j] != flag[1][0] && field[i + 1][j + 1] == flag[1][1])
			{
				white w;
				w.x = j;
				w.y = i + 1;
				w.c = flag[1][0];
				threePointOK.push_back(w);
			}
			else if (field[i][j] == flag[0][0] && field[i][j + 1] == flag[0][1] && field[i + 1][j] == flag[1][0] && field[i + 1][j + 1] != flag[1][1])
			{
				white w;
				w.x = j + 1;
				w.y = i + 1;
				w.c = flag[1][1];
				threePointOK.push_back(w);
			}
		}
	}
	int additional = 0;
	for (int i = 0; i < threePointOK.size(); ++i)
	{
		int plus = 0;
		white w = threePointOK[i];
		char c_back = field[w.y][w.x];
		field[w.y][w.x] = w.c;
		if (w.x != 0 && w.y != 0)
		{
			if (field[w.y - 1][w.x - 1] == flag[0][0] && field[w.y - 1][w.x] == flag[0][1] && field[w.y][w.x - 1] == flag[1][0] && field[w.y][w.x] == flag[1][1])
			{
				++plus;
			}
		}
		if (w.x != N - 1 && w.y != 0)
		{
			if (field[w.y - 1][w.x] == flag[0][0] && field[w.y - 1][w.x + 1] == flag[0][1] && field[w.y][w.x] == flag[1][0] && field[w.y][w.x + 1] == flag[1][1])
			{
				++plus;
			}
		}
		if (w.x != 0 && w.y != M - 1)
		{
			if (field[w.y][w.x - 1] == flag[0][0] && field[w.y][w.x] == flag[0][1] && field[w.y + 1][w.x - 1] == flag[1][0] && field[w.y + 1][w.x] == flag[1][1])
			{
				++plus;
			}
		}
		if (w.x != N - 1 && w.y != M - 1)
		{
			if (field[w.y][w.x] == flag[0][0] && field[w.y][w.x + 1] == flag[0][1] && field[w.y + 1][w.x] == flag[1][0] && field[w.y + 1][w.x + 1] == flag[1][1])
			{
				++plus;
			}
		}
		field[w.y][w.x] = c_back;
		additional = max(additional, plus);
	}
	ans += additional;
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 5864
#include <stdio.h>

int main(void)
{
int a,b,c,n,i;

scanf("%d %d",&a,&b);

while(a!=0&&b!=0){
for(i=0;i<a;i++)
{
	
	
		if(i==0||i==a-1){
			for(c=0;c<b;c++)
			printf("#");
		}
		else 
		{
			printf("#");
			for(c=0;c<b-2;c++)
			{
				printf(".");
			}
			printf("#");
		}

		printf("\n");
	}
printf("\n");
scanf("%d %d",&a,&b);
}
return 0;

}

Measured memory_bytes: 572
#include <stdio.h>

int main(void)
{
	int w, h, n;
	int bex, bey, mapx, mapy,x;
	int sum = 0;
	
	scanf("%d %d %d", &w, &h, &n);
	
	for (x = 0; x < n; x++) {
		scanf("%d %d", &mapx, &mapy);
		if (x != 0) {
			while (1) {
				if (mapx == bex && mapy == bey) {
					break;
				}
				if (mapx > bex && mapy > bey) {
					bex++;
					bey++;
				}
				else if (mapx < bex && mapy < bey) {
					bex--;
					bey--;
				}
				else if (mapx > bex) {
					bex++;
				}
				else if (mapx < bex) {
					bex--;
				}
				else if (mapy > bey) {
					bey++;
				}
				else if (mapy < bey) {
					bey--;
				}
				sum++;
			}
		}
		bex = mapx;
		bey = mapy;
	}
	printf("%d\n", sum);
	
	return (0);
}

Measured memory_bytes: 596
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(len(a)):
    a[i] = a[i] * (-1)
heapq.heapify(a)
for i in range(m):
    t = heapq.heappop(a)
    t = t * (-1)
    t = t // 2
    t = t * (-1)
    heapq.heappush(a, t)
ans = 0
for i in range(n):
    t = heapq.heappop(a)
    t = t * (-1)
    ans = ans + t
print(ans)

Measured memory_bytes: 75244
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        w: usize,
        mut weval: [(usize, usize); n],
    }

    const V_MAX: usize = 100_001;

    weval.insert(0, (0, 0));
    let mut dp = vec![vec![1_000_000_001; V_MAX]; n+1];
    let mut ans = 0;

    dp[0][0] = 0;

    for i in 1..=n {
        for j in 0..V_MAX {
            if weval[i].1 <= j {
                dp[i][j] = dp[i-1][j].min(dp[i-1][j-weval[i].1] + weval[i].0);
            } else {
                dp[i][j] = dp[i-1][j];
            }

            if dp[i][j] <= w {
                ans = j;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 81160
#include<stdio.h>
int main(void) {
	int s,a[100000];
	int ans, flag = 0;
	int i, j, k;

	scanf("%d", &s);
	a[0] = s;
	//printf("%d ", a[0]);
	for (i = 1;; i++) {
		if (a[i - 1] % 2 == 0) {
			a[i] = a[i - 1] / 2;
		}
		else {
			a[i] = 3 * a[i - 1] + 1;
		}
		for (j = 0; j < i / 2; j++) {
			for (k = 0; k < i; k++) {
				if (j == k) {
					continue;
				}
				else {
					if (a[j] == a[k]) {
						//printf("k==%d\n", k);
						ans = k + 1;
						flag = 1;
						break;
					}
				}
			}
		}
		if (flag) {
			break;
		}
		else {
			//printf("%d ", a[i]);
			continue;
		}
	}

	printf("%d\n", ans);
	return 0;

}

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

using namespace std;

int64_t burger_len[51];

int64_t calc_burger_len(int lv) {
    if (lv == 0) return burger_len[lv] = 1;
    int64_t prev_burger_len = calc_burger_len(lv - 1);
    return burger_len[lv] = 1 + prev_burger_len + 1 + prev_burger_len + 1;
}

map<pair<pair<int, int>, int>, int64_t> memo;

int64_t count_patti(int lv, int64_t start, int64_t end) { // count patti from [start, end) of level lv
    if (memo[make_pair(make_pair(lv, start), end)]) return memo[make_pair(make_pair(lv, start), end)];
    if (lv == 0) return memo[make_pair(make_pair(lv, start), end)] = 1;
    if (start == end) return memo[make_pair(make_pair(lv, start), end)] = 0;
    if (start == 0) return memo[make_pair(make_pair(lv, start), end)] = count_patti(lv, start + 1, end);
    if (start == burger_len[lv] / 2)
        return memo[make_pair(make_pair(lv, start), end)] = 1 + count_patti(lv, start + 1, end);
    if (end == burger_len[lv] / 2 + 1)
        return memo[make_pair(make_pair(lv, start), end)] = count_patti(lv, start, end - 1) + 1;
    if (end == burger_len[lv]) return memo[make_pair(make_pair(lv, start), end)] = count_patti(lv, start, end - 1);
    if (start < burger_len[lv] / 2 && end <= burger_len[lv] / 2)
        return memo[make_pair(make_pair(lv, start), end)] = count_patti(lv - 1, start - 1, end - 1);
    if (start > burger_len[lv] / 2 && end < burger_len[lv])
        return memo[make_pair(make_pair(lv, start), end)] = count_patti(lv - 1, start - burger_len[lv],
                                                                        end - burger_len[lv]);
    return memo[make_pair(make_pair(lv, start), end)] = count_patti(lv - 1, start - 1, burger_len[lv] / 2 - 1) + 1 +
                                                        count_patti(lv - 1, 0, end - burger_len[lv] / 2 - 1);
};

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

    calc_burger_len(50);
    cout << count_patti(N, 0, X);
}

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

int main(){
    int h,m,s;
    while(1){
    	cin >> h >> m >> s;
    	if(h == -1 && m == -1 && s == -1)break;
    	int sum = h * 3600 + m * 60 + s;
    	int ans = 7200 - sum;
    	h = ans / 3600;
    	m = ans % 3600 / 60;
    	s = ans % 60;
    	cout << "0" << h << ":";
    	if(m < 10)cout << "0" << m << ":";
    	else cout << m << ":";

    	if(s < 10)cout << "0" << s << endl;
    	else cout << s << endl;

    	ans *= 3;
    	h = ans / 3600;
    	m = ans % 3600 / 60;
    	s = ans % 60;
    	cout << "0" << h << ":";
    	if(m < 10)cout << "0" << m << ":";
    	else cout << m << ":";

    	if(s < 10)cout << "0" << s << endl;
    	else cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
using namespace std;
 
int main(){
 
	//あられの個数
	int N;
	cin >> N;
 
	bool bYellowFound = false;
	char S;
	for(int i = 0; i < N; ++i){
		cin >> S;
		if('Y' == S){
			bYellowFound = true;
        	break;  
		}
	}
 
	if(bYellowFound){
		cout << "Four" << endl;
	}
	else{
		cout << "Three" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static int ans = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        boolean[][] con = new boolean[M][N];
        for (int i = 0; i < M; i++) {
            int len = scanner.nextInt();
            for (int j = 0; j < len; j++) {
                con[i][scanner.nextInt() - 1] = true;
            }
        }
        int[] p = new int[M];
        for (int i = 0; i < M; i++) {
            p[i] = scanner.nextInt();
        }
        dfs(0, 0, N, M, con, p);
        System.out.println(ans);

    }

    public static void dfs(int i, int s, int N, int M, boolean[][] con, int[] p) {
        if (i == N) {
            boolean flag = true;
            for (int l = 0; l < M; l++) {
                int cnt = 0;
                for (int j = 0; j < N; j++) {
                    if ((s >> j & 1) == 1 && con[l][j]) {
                        cnt++;
                    }
                }
                if (cnt % 2 != p[l]) {
                    flag = false;
                }
            }
            if (flag) {
                ans++;
            }
        } else {
            dfs(i + 1, s | 1 << i, N, M, con, p);
            dfs(i + 1, s, N, M, con, p);
        }
    }

}


Measured memory_bytes: 23764
N = int(input())
L = list(map(int, input().split()))

cnt = 0
for i in range(N):
  for j in range(i + 1, N):
    if L[i] == L[j]:
      continue
    for k in range(j + 1, N):
      if L[i] == L[k] or L[j] == L[k]:
        continue
      a = L[i]
      b = L[j]
      c = L[k]
      if a + b > c and b + c > a and c + a > b:
        cnt += 1


print(cnt)

Measured memory_bytes: 9108
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

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

    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
    }

    cout << (N-1 + (K-2))/(K-1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll cost(string hoge){
  ll cnt=0;
  ll ret=0;
  for(int i=0;i<hoge.size();i++){
    if(hoge[i]=='A'){
      cnt++;
    }else{
      ret+=cnt;
    }
  }
  return ret;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  string hoge="";
  ll ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='B'){
      if(i!=s.size()-1){
	if(s[i]=='B'&&s[i+1]=='C'){
	  hoge+='D';
	  i++;
	}else{
	  ans+=cost(hoge);
	  hoge="";
	}
      }else{
	ans+=cost(hoge);
	hoge="";
      }
    }else{
      if(s[i]=='A')hoge+='A';
      else{ans+=cost(hoge);hoge="";}
    }
  }
  ans+=cost(hoge);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 916
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,i,x,ans,ans2;
	vector<int> a,p,up;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	if(a[0]>=0)
	{
		ans=a[0];
		for(i=1;i<n-1;i++)
		{
			ans-=a[i];
		}
		cout<<a[n-1]-ans<<endl;
		ans=a[0];
		for(i=1;i<n-1;i++)
		{
			cout<<ans<<' '<<a[i]<<endl;
			ans-=a[i];
		}
		cout<<a[n-1]<<' '<<ans<<endl;
		return 0;
	}
	else if(a[n-1]<=0)
	{
		ans=a[n-1];
		for(i=1;i<n-1;i++)
		{
			ans-=a[i];
		}
		cout<<ans-a[0]<<endl;
		ans=a[n-1];
		for(i=1;i<n-1;i++)
		{
			cout<<ans<<' '<<a[i]<<endl;
			ans-=a[i];
		}
		cout<<ans<<' '<<a[0]<<endl;
		return 0;
	}
	else
	{
		for(i=0;i<n;i++)
		{
			if(a[i]>=0)
				p.push_back(a[i]);
			else
				up.push_back(a[i]);
		}
		ans=p[0];
		ans2=up[0];
		for(i=1;i<up.size();i++)
			ans-=up[i];
		for(i=1;i<p.size();i++)
			ans2-=p[i];
		cout<<ans-ans2<<endl;
		ans=p[0];
		ans2=up[0];
		for(i=1;i<up.size();i++){
			cout<<ans<<' '<<up[i]<<endl;
			ans-=up[i];
		}
		for(i=1;i<p.size();i++){
			cout<<ans2<<' '<<p[i]<<endl;
			ans2-=p[i];
		}
		cout<<ans<<' '<<ans2<<endl;
	}
	return 0;
}


Measured memory_bytes: 2808
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val vv = readLine()!!.split(" ").map { it.toInt() }
    val vCnts = vv.groupBy { it }.entries.sortedByDescending { it.value.count() }

    if (vCnts.size == 1) {
        println(n/2)
        return
    }

    val v1 = vCnts[0].key
    val v2 = vCnts[1].key

    var cnt1 = 0
    var cnt2 = 0
    vv.forEachIndexed { idx, v ->
        if (idx % 2 == 1) {
            if (v != v1) cnt1++
            if (v != v2) cnt2++
        } else {
            if (v != v2) cnt1++
            if (v != v1) cnt2++
        }
    }

    println(Math.min(cnt1, cnt2))
}

Measured memory_bytes: 61852
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N, M, C;
    cin >> N >> M >> C;
    int B[M];
    int ans = 0;
    for( int i = 0; i < M; i++) {
        cin >> B[i];
    }
    for( int i = 0; i < N; i++) {
        int A[M];
        int sum = 0;
        for( int j = 0; j < M; j++ ) {
            cin >> A[j];
            sum += A[j] * B[j];
        }
        if (sum + C > 0) {
            ans += 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256