akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//-------------------------------------------MACROS---------------------------------------------
#define 	TIEMPO_CORRIDA		cerr << "tiempo: "<<1.0*clock()/CLOCKS_PER_SEC <<" seg.\n";
#define 	FILES				freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define 	FORIT(it,e)			for(it = e.begin() ; it != e.end() ; it++)
#define 	FOR(i,a,b)			for(i = a ; i < b ; i++)
#define 	RFOR(i,a,b)			for(i = a ; i >= b ;i--)
#define 	FORSW(i,a,b,sw)		for(i = a ; i < b && sw ; i++)
#define 	RFORSW(i,a,b,sw)	for(i = a ; i >= b && sw ; i--)
#define 	fast 				ios::sync_with_stdio(false),cin.tie(),cout.tie();
#define 	to_int(x) 			atoi(x.data())
#define 	to_long(x) 			atoll(x.data())
#define 	ALL(x) 				x.begin(),x.end()
#define 	RALL(x) 			x.rbegin(),x.rend()
typedef 	long long 			ll;
typedef 	pair<int,int> 		pi;
typedef 	pair<ll,ll> 		pl;
const		int 				modN = 1e9+7;
const		double 				PI = 3.1415926535897932384626433832795028841;
//---------------------------------------------------------------------------------------------
const int tam = 6e5;
const int oo=1e9;
int ar[tam],memo[tam];
int n,k;

int f(int x){
	if (memo[x]!=-1) return memo[x];
	if(x == n-1) return memo[x]=0;
	int ans=oo, i;
	FOR(i,1,k+1)
		if(x+i<n)
			ans = min(ans,f(x+i) + abs(ar[x+i]-ar[x]));
	return memo[x]=ans;
}

int main(){
	int i;
	while(scanf("%d%d",&n,&k)==2){
		memset(memo,-1,sizeof memo);
		FOR(i,0,n) scanf("%d",&ar[i]);
		printf("%d\n",f(0));
	}
	return 0;
}

Measured memory_bytes: 14256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> vec;
  int six = 6;
  while(six <= 100000){
    vec.push_back(six);
    six *= 6;
  }
  int nine = 9;
  while(nine <= 100000){
    vec.push_back(nine);
    nine *= 9;
  }
  vec.push_back(1);
  sort(all(vec));
  vector<int> dp(100001);
  dp[0] = 0;
  for(int i=1; i<=100000; i++){
    int smallest = 1000000000;
    rep(j, vec.size()){
      if(vec[j]<=i) smallest = min(smallest, dp[i-vec[j]]+1);
    }
    dp[i] = smallest;
  }
  cout << dp[n] << endl;
  return 0;
}
  

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if (n % 2 == 0)
        print(n / 2 - 1);
    else
        print(n / 2);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
#define int long long
#define All(v) (v.begin(),v.end())
int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
int lcm(int a, int b) {
	return a / gcd(a, b)*b;
}
int modpow(int a,int b){
    if(!b)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int fac(int a){
    int Ans=1;
    for(int i=1;i<=a;i++){
        Ans*=i;
        Ans%=MOD;
    }
    return Ans;
}//kaijo
int comb(int a,int b){
    return fac(a)*modpow(fac(a-b),MOD-2)%MOD*modpow(fac(b),MOD-2)%MOD;
}
signed main(){
	int n;
	int a[110];
	cin>>n;
	int sum=0;
	int mi=1000;
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
		if(a[i]%2==1)mi=min(mi,a[i]);
	}
	if(sum%2==0){
		cout<<sum/2<<endl;
		return 0;
	}
	cout<<(sum-mi)/2<<endl;
	return 0;
}




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

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

    int counter = 0;
    for (int i = 0; i < N - 2; ++i)
    {
        string s = { S[i], S[i + 1], S[i + 2] };
        if (s == "ABC")
        {
            counter++;
        }
    }
    cout << counter << endl;
}

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

int main(int argc, char const *argv[]){
    string s;
    cin >> s;
    vector<string> weather;
    weather = {"Sunny", "Cloudy", "Rainy"};

    for (int i = 0; i < 3; i++)
    {
        if(s == weather[i]) {
            cout << weather[(i+1)%3] << endl;
            break;
        }
    }
    

    return 0;
}


Measured memory_bytes: 256
#![allow(unused)]

use std::io::{Read, Stdin, StdinLock};
use std::iter::{FromIterator, Iterator};
use std::str::{FromStr};
use std::string::String;

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

struct TokenReader<'a> {
    lock: StdinLock<'a>,
}

impl<'a> TokenReader<'a> {
    fn new(s: &'a Stdin) -> TokenReader<'a> {
        TokenReader { lock: s.lock() }
    }

    fn read_chars<T: FromIterator<char>>(&mut self) -> T {
        self.lock
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<T>()
    }

    fn read_str(&mut self) -> String {
        self.read_chars::<String>()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read_str().parse().ok().unwrap()
    }
}

//==============================================================================
//
// Problem specific code
//
//==============================================================================

fn main() {
    let sin = std::io::stdin();
    let mut tr = TokenReader::new(&sin);

    let n: usize = tr.read();
    let avec: Vec<usize> = (1..n).map(|_| tr.read()).collect();

    let mut cs = vec![0; n];
    for i in avec {
        cs[i - 1] += 1;
    }

    for i in 0..n {
        println!("{}", cs[i]);
    }
}

Measured memory_bytes: 4344
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
using namespace std;

#define rep(i, e) for (int i = 0; i < e; i++)
#define repp(i, s, e) for (int i = s; i < e; i++)
#define N_Max 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long

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

const long long INF = 1LL << 60;

int main()
{
    int n;
    cin>>n;
    cout<<n*n*n<<endl;

}

Measured memory_bytes: 256
n = int(input())
ans = [0]*(n+1)
for x in range(1, 103):
    for y in range(1, 103):
        for z in range(1, 103):
            k = x**2+y**2+z**2+x*y+y*z+z*x
            if k<=n: ans[k]+=1
for i in range(1, n+1):
    print(ans[i])


Measured memory_bytes: 9252
/*
     _              ,_,
    / \   _ __, ___,| |__   __ _,_ __
   / ^ \ | '_ \/ _ \| '_ \ / _` | /_/
  /-/-\-\|-| |--| |-|-|_)-|-(_|-|-|
 /_/   \_\_| |__| |_|_.__/ \__,_|_|
 
*/
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(a)       (a).begin(),(a).end()
#define rep(i,a,n)   for(int i=a ; i<n ; i++)
 
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<ll,ll> mii;
typedef map<char,ll> mci;
 
ll gcd(ll a, ll b){
	if(b==0)return a;
	else return gcd(b, a%b);
}

signed main(){
    ios_base :: sync_with_stdio (false);
	cin.tie(NULL);
	// cout << fixed << setprecision(15);
 
	ll TESTS=1; 
	// cin>>TESTS;
	while(TESTS--){
		string s, t; cin>>s>>t;
		ll n=s.size(), m=t.size();
		ll mat[n+1][m+1];
		memset(mat, 0, sizeof(mat));
		for(int i=1; i<=n; i++){
			for(int j=1; j<=m; j++){
				if(s[i-1]==t[j-1])mat[i][j]=mat[i-1][j-1]+1;
				else mat[i][j]=max(mat[i-1][j], mat[i][j-1]);
			}
		}
		ll i=n, j=m;
		string ans="";
		while(i>0 && j>0){
			if(s[i-1]==t[j-1]){
				ans+=s[i-1];
				i--; j--;
			}
			else if(mat[i][j-1]<mat[i-1][j]) i--;
			else j--;
		}
		reverse(all(ans));
		cout<<ans<<endl;

	}
    return(0);
}

Measured memory_bytes: 73988
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    for(int i = 10;i <= 10000;i++){
          if(i * 8 / 100 == a && i / 10 == b){
                cout << i << endl;
                return 0;
                
          }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
#coding=UTF-8
hou=1000000007

N=int(input())

Sone=input()
Stwo=input()

tateyoko=[]
idx=0
owari=len(Sone)
while idx < owari:
    if Sone[idx] == Stwo[idx]:
        #tate
        tateyoko.append(1)
        idx=idx+1
    else:
        #yoko
        tateyoko.append(2)
        idx=idx+2

ans=1
mae=None
for mono in tateyoko:
    if mono==1:
        #tate
        if mae==None:
            kake=3
        elif mae==1:
            kake=2
        else:
            kake=1
    else:
        #yoko
        if mae==None:
            kake=6
        elif mae==1:
            kake=2*1
        else:
            kake=1+2

    mae=mono
    ans=(ans*kake)%hou

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
int dx[2] = {1,-1};
int dy[2] = {-1,1};
int main(){
  int n;
  int casenum = 0;
  while(cin>>n,n){
    int ans[11][11] = {};
    int x = 0, y = 0;
    int r = 1;
    int cnt = 0;
    if(n == 1){
      ans[0][0] = 1;
      goto OUTPUT;
    }
    ans[y][x++] = ++cnt;
    while(true){
      //printf("%d,%d\n",x+1,y+1);
      ans[y][x] = ++cnt;
      if(y==n-1&&x==n-1) break;
      if(x+dx[r]>=n){
        y++;
        r = 1;
      }else if(y+dy[r]>=n){
        x++;
        r = 0;
      }else if(x+dx[r]<0){
        y++;
        r = 0;
      }else if(y+dy[r]<0){
        x++;
        r = 1;
      }else{
        x += dx[r];
        y += dy[r];
      }
    }
OUTPUT:
    printf("Case %d:\n",++casenum);
    REP(y,n){
      REP(x,n)printf("%3d",ans[y][x]);
      putchar('\n');
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stack>
using namespace std;

int n, m;
string s;

int cnt;
vector<int> v;
void insertionSort(int n, int h) {
	for (int i = h; i < n; ++i) {
		int w = v[i];
		int j = i - h;
		while (j >= 0 && v[j] > w) {
			v[j + h] = v[j];
			j = j - h;
			cnt++;
		}
		v[j + h] = w;
	}
}
int main() {
	cin >> n;
	
	for (int i = 0; i < n; ++i) {
		int a; cin >> a;
		v.push_back(a);
	}
	int m = 0;
	vector<int> h;
    int i=0;
	while(i<n){
        i=3*i+1;
        if(i>n) break;
        h.push_back(i);
        m++;
    }
	reverse(h.begin(), h.end());
	cout << m << endl;
	for (int i = 0; i < m; ++i) {
		if (i == m - 1) {
			cout << h[i] << endl;
			break;
		}
		cout << h[i] << " ";
	}
	
	for (int i = 0; i < m; ++i) {
		insertionSort(n, h[i]);
	}
	cout << cnt << endl;
	for (int i = 0; i < n; ++i) {
		cout << v[i] << endl;
	}
}



Measured memory_bytes: 6948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int n, x; cin >> n >> x;
    vector<int> d(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> d[i];
        sum += d[i];
    }
    int MIN = *min_element(d.begin(), d.end());
    cout << (x - sum) / MIN + n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

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

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int n, l;
    cin>>n>>l;
    multiset<string> a;
    for (int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        a.insert(s);
    }
    for (auto x:a)
    {
        cout<<x;
    }
    return 0;
}

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

long long t[2], a[2], b[2];

void solve();

int main() {
  cin >> t[0] >> t[1] >> a[0] >> a[1] >> b[0] >> b[1];
  solve();
  return 0;
}

void solve() {
  long long x = (a[0] - b[0]) * t[0],
            y = (b[1] - a[1]) * t[1];
  if(x == y) {
    cout << "infinity" << endl;
    return;
  }
  if((x < 0 && y > 0) || (x > 0 && y < 0) ||
     abs(x) - abs(y) > 0) {
    cout << 0 << endl;
    return;
  }
  if(x < 0) {
    x *= -1;
    y *= -1;
  }
  y -= x;
  cout << (x % y != 0) + 2 * (x / y) << endl;
}

Measured memory_bytes: 256
#include<map>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
map<string,int> a;
int fn(string s){
  int i,j,k;
  int ln=s.length();
  int sm=0;
  s+=' ';
  for(i=0;i<ln;){
    if(s[i]>='A'&&s[i]<='Z'){
      if(s[i+1]>='a'&&s[i+1]<='z'){
	if(a[s.substr(i,2)]==0)
	  return -1;
	if(s[i+2]>='0'&&s[i+2]<='9'){
	  for(j=i+2;s[j]>='0'&&s[j]<='9';j++);
	  sm+=a[s.substr(i,2)]*atoi(s.substr(i+2,j-i-2).c_str());
	  i=j;
	}else{
	  sm+=a[s.substr(i,2)];
	  i+=2;
	}
      }else{
	if(a[s.substr(i,1)]==0)
	  return -1;
	if(s[i+1]>='0'&&s[i+1]<='9'){
	  for(j=i+1;s[j]>='0'&&s[j]<='9';j++);
	  sm+=a[s.substr(i,1)]*atoi(s.substr(i+1,j-i-1).c_str());
	  i=j;
	}else{
	  sm+=a[s.substr(i,1)];
	  i++;
	}
      }
    }else{
      k=1;
      for(j=i+1;k;j++){
	if(0){
	}else if(s[j]=='('){
	  k++;
	}else if(s[j]==')'){
	  k--;
	}
      }
      for(k=j+1;s[k]>='0'&&s[k]<='9';k++);
      int tm=fn(s.substr(i+1,j-i-2));
      if(tm==-1)
	return -1;
      sm+=tm*atoi(s.substr(j,k-j).c_str());
      i=k;
    }
  }
  return sm;
}
int main(){
  string s;
  while(cin>>s&&s!="END_OF_FIRST_PART"){
    int p;
    cin>>p;
    a[s]=p;
  }
  while(cin>>s&&s[0]!='0'){
    int tm=fn(s);
    if(tm==-1)
      cout<<"UNKNOWN"<<endl;
    else
      cout<<tm<<endl;
  }
  return 0;
}

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

int main(){
    int k,s;
    cin >> k >> s;
    int cnt=0;
    for(int i=0;i<=s;i++){
        for(int j=0;j<=s;j++){
            if(s-i-j>=0&&s-i-j<=k&&i<=k&&j<=k){
                int l = s-i-j;
                if(i+j+l==s){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
S = input()

C = [chr(i) for i in range(97, 97+13)]
D = [chr(i) for i in range(97+13, 97+26)]
A = [chr(i) for i in range(65, 65+13)]
B = [chr(i) for i in range(65+13, 65+26)]

X = [0] * 2
for s in S:
    if s in A:
        X[0] += 1
    elif s in B:
        X[0] -= 1
    elif s in C:
        X[1] += 1
    elif s in D:
        X[1] -= 1

ans = ""
if X[0] < 0:
    ans += 'N' * abs(X[0])
else:
    ans += 'A' * X[0]

if X[1] < 0:
    ans += 'n' * abs(X[1])
else:
    ans += 'a' * X[1]

print(len(ans))
print(ans)


Measured memory_bytes: 5744
# coding: utf-8
# Task: https://arc061.contest.atcoder.jp/tasks/arc061_a#

def calc(num):
    backup = num
    ans = 0
    bit = 0b0
    
    while not(0b1 & (bit >> len(num)-1)):
        bit += 0b1
        # print(bin(bit))
        count = 0
        for i in range(len(num)-1):
            if 0b1 & (bit >> i):
                num = num[:len(num)-i-count-1] + "," + num[len(num)-i-count-1:]
                count += 1
        # print(num)
        li = num.split(',')
        for n in li:
            ans += int(n)
        num = backup
    return ans

num_input = input()

if len(num_input) == 1:
    print(num_input)
else:
    ans = calc(num_input)
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int a[100000+10];
	int x;
	scanf("%d",&x);
	int ans=10000000;
	for(int i=1;i<x;i++){
		int t1=i,sum=0;
		while(t1){
			sum+=(t1%10);
			t1/=10;
		}
		int t=x-i;
		while(t){
			sum+=(t%10);
			t/=10;
		}
		ans=min(sum,ans);
	}
	printf("%d",ans);
	return 0;
} 

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

int main() {
  int n;
  cin >> n;
  vector<int> light(n);
  int a = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    light.at(i) = a - 1;
    a = 0;
    //cout << light.at(i) << endl;
  }
  int tmp = 0;
  int count = 1;
  for (int i = 0; i < 100000000; i++) {
    tmp = light.at(tmp);
    if (tmp == 1) {
      cout << count << endl;
      break;
    }
    count++;
  }
  if (count == 100000001) {
    cout << -1 << endl;
  }    
}
    
  



Measured memory_bytes: 640
#include <iostream>
#include <map>

using namespace std;

int main()
{
	int N;
	cin >> N;
	map<int, int> m;
	for (int i = 1; i <= N; i++) {
		int tmp;
		cin >> tmp;
		m[tmp] = i;
	}

	for(auto itr = m.begin(); itr != m.end(); itr++) {
		cout << itr->second << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 8256
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int N,K;
  	cin>>N>>K;
  	vector<int> v(N);
  	priority_queue<int,vector<int>,greater<int>> pq;
  	for(int i=0;i<N;i++){
  		cin>>v[i];
  		pq.push(v[i]);
  	}
  	int sum=0;
  	while(K--){
  		// cout<<pq.top();
  		sum+=pq.top();
  		pq.pop();
  	}
  	cout<<sum;
}

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

namespace 競プロ_Csharp {
    class Program {
        static void Main(string[] args) {

            while (true) {

                String[] a = NextStrings();
                if (a[1].Equals("?")) return;

                int ans = 0;
                int b = int.Parse(a[0]), c = int.Parse(a[2]);

                switch (a[1]) {
                    case "+":
                        ans = b + c;
                        break;
                    case "-":
                        ans = b - c;
                        break;
                    case "*":
                        ans = b * c;
                        break;
                    case "/":
                        ans = b / c;
                        break;
                }

                Println(ans);

            }

        }

        public static void Println (Object o) {
            Console.WriteLine(o);
        }

        public static string NextString() {
            return Console.ReadLine();
        }

        public static string[] NextStrings () {
            return Console.ReadLine().Split();
        }

        public static int NextInt () {
            return int.Parse(Console.ReadLine());
        }

        public static int[] NextInts () {
            string[] a = Console.ReadLine().Split();
            int[] b = new int[a.Length];
            for (int i = 0; i < a.Length; i++) {
                b[i] = int.Parse(a[i]);
            }
            return b;
        }

        public static double NextDouble () {
            return double.Parse(Console.ReadLine());
        }

    }
}



Measured memory_bytes: 15944
def main():
    N = int(input())

    dp = [0] * 3
    n_dp = [0] * 3

    for _ in range(N):
        a = list(map(int, input().split()))
        for j in range(3):
            n_dp[j] = max(dp[j-2] + a[j], dp[j-1] + a[j])
        dp = n_dp.copy()

    print(max(dp))


main()


Measured memory_bytes: 3060
a,b=map(int,input().split())

def calc(x):
      
    a = x%4

    if a == 0:
        return x
    elif a == 1:
        return 1
    elif a == 2:
       return x|1
    else:
        return 0
 
print(calc(b) ^ calc(a-1))

Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

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

    string s;
    cin >> s;
    int ret = 0;
    for(size_t i=0; i<s.length(); ++i)
    {
        if(s[i] == '+')
        {
            ret++;
        }
        else
        {
            ret--;
        }
    }

    cout << ret << endl;
}

Measured memory_bytes: 256
n, *D,  = [list(map(int, s.split())) for s in open(0)]
n, D = n[0], D[0]

D = sorted(D, reverse=True)
m = D[0]
length = 0
for i in range(1, len(D)):
    length += D[i]
if length > m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i=0; i < int(n); i++)
typedef vector<int> VI;


int main() {
	int n;
  cin >> n;
  VI a(n);
  rep(i, n) cin >> a[i];

  int q;
  cin >> q;

  const int M_MAX = 2001;
  VI canMake(M_MAX);
  rep(st, 1 << n) {
    int val = 0;
    rep(i, n) if (st & (1 << i)) val += a[i];
    if (val < M_MAX) canMake[val] = true;
  }

  rep (qi, q) {
    int m;
    cin >> m;
    if (canMake[m]) cout << "yes\n";
    else cout << "no\n";
  }
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void)
{
	int cnt = 0,a,b,c;
	scanf("%d%d%d", &a,&b,&c);
	for (int i = a; i<= b; i++)
	{
		if (c%i == 0)
		{
				cnt++;
	    }
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 2724
#include <bits/stdc++.h>
#define forn(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;




int main()
{
      ll n,k,diff ;
      cin >>n >>k ;


        diff = n % k ;
        cout<< min(diff , abs(diff-k));


  return 0 ;
}


Measured memory_bytes: 256
N = int(input())
w = list(map(int, input().split()))
ans_list=[]
for t in range(2,N):
    s1 =0
    s2 =0
    for j in range(t):
        s1 += w[j]
    for k in range(t,N):
        s2 += w[k]
    ans_list.append(abs(s1-s2))
print(min(ans_list))

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

def main():
    N,K =  map(int, input().split())
    S = input()
    K = K-1 #indexに置換
    lower = S[K].lower()
    if K == 0:
        result = lower + S[K+1:]
    else:
        result = S[:K] + lower + S[K+1:]
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}



int main(){
    ll n;
    cin>>n;
    vector<ll> A(n);
    cin>>A;
    ll sum=0,sum2=0;
    for(auto &I:A){sum+=I;}
    ll ans=sum;
    for(int i=0;i<n;i++){
        sum2+=A[i];
        ans=min(ans,abs(sum-2*sum2));
    }
    cout<<ans<<endl;
    
    return 0;
}


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


int main(void) {
    using namespace std;

    long n, x;
    cin >> n >> x;

    long r = 0;
    for(int i=0; i<n; i++) {
        long y;
        cin >> y;
        r = __gcd(r, y-x);
    }
    cout << abs(r) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<vector<int>> abc(n,vector<int>(3));
    REP(i,n) cin >> abc[i][0]>> abc[i][1]>> abc[i][2];

    vector<vector<int>> dp(n+1,vector<int>(3));

    REP(i,n) {
        dp[i+1][0] = max(dp[i][1]+abc[i][0],dp[i][2]+abc[i][0]);
        dp[i+1][1] = max(dp[i][0]+abc[i][1],dp[i][2]+abc[i][1]);
        dp[i+1][2] = max(dp[i][0]+abc[i][2],dp[i][1]+abc[i][2]);
    }

    int ans = 0;
    REP(i,3) ans = max(ans,dp[n][i]);
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 11136
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

const lint MOD = pow(10, 9) + 7;

lint gcd(lint a, lint b) {
	//aとbの最大公約数を返す
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}

lint lcm(lint a, lint b) {
	//aとbの最小公倍数を返す
	return a / gcd(a, b) * b;
}

lint sgm(lint n) {
	//0からの総和を返す
	return n * (n + 1) / 2;
}

lint fact(lint n) {
	//n!を返す
	if (n == 0) return 1;
	else return n * fact(n - 1);
}

lint power(lint x, lint n, lint m) {
	//(x^n)%mを返す
	lint res = 1;
	x %= m;
	while (n > 0) {
		if (n % 2 == 1) {
			res = res * x % m;
		}
		x = x * x % m;
		n /= 2;
	}
	return res;
}

/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/


int main() {
	lint A, B, K;
	cin >> A >> B >> K;
	if (A > K) {
		cout << A - K << ' ' << B << endl;
	}
	else {
		if (B - (K - A) > 0) {
			cout << 0 << ' ' << B - (K - A) << endl;
		}
		else {
			cout << 0 << ' ' << 0 << endl;
		}
	}
}


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

using namespace std;
typedef long long ll;

int n, m;
int head[100100], frm[100100], to[100100], nxt[100100];
int edgeCount;

void addEdge(int x, int y)
{
    frm[edgeCount] = x;
    to[edgeCount] = y;
    nxt[edgeCount] = head[x];
    head[x] = edgeCount;
    ++edgeCount;
}

int dp[100100];
int f(int u)
{
    if (dp[u] != -1) return dp[u];
    dp[u] = 0;
    for (int j = head[u]; ~j; j = nxt[j])
    {
        dp[u] = max(dp[u], f(to[j]) + 1);
    }
    return dp[u];
}

int main()
{
    memset(head, -1, sizeof head);
    memset(dp, -1, sizeof dp);

    scanf("%d%d", &n, &m);
    for (int i = 0, x, y; i < m; ++i)
    {
        scanf("%d%d", &x, &y);
        --x; --y;
        addEdge(x, y);
    }
    for (int i = 0; i < n; ++i)
        f(i);
    printf("%d\n", *max_element(dp, dp + 100100));

    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int search(int h[], int a, int b, int n, int hmax) {
    int left = 0;
    int right = hmax + 1;
    while (left < right) {
        int mid = (left + right) / 2;
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] > b * mid) {
                if ((h[i] - b * mid) % (a - b) == 0) count += (h[i] - b * mid) / (a - b);
                else count += (h[i] - b * mid) / (a - b) + 1;
            }
        }

        if (count <= mid) right = mid;
        else left = mid + 1;
    }

    return right;
}

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

    int hmax = h[0];
    for (int i = 1; i < n; i++) {
        hmax = max(hmax, h[i]);
    }

    int ans = search(h, a, b, n, hmax);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
import sys


def IN_I(): return int(sys.stdin.readline().rstrip())
def IN_LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def IN_S(): return sys.stdin.readline().rstrip()
def IN_LS(): return list(sys.stdin.readline().rstrip().split())


N = IN_I()
a = [0] + IN_LI()
b = [0] * (N + 1)
ans = []

for i in range(N, 0, -1):
    tmp = 0
    for j in range(2 * i, N + 1, i):
        tmp += b[j]
    if tmp % 2 != a[i]:
        b[i] = 1
        ans.append(i)
if len(ans) == 0:
    print(0)
else:
    print(len(ans))
    print(' '.join(map(str, ans)))


Measured memory_bytes: 26596
parseint(x) = parse(Int, x)
parseintmap(x::Array{SubString{String},1}) = map(parseint, x)

function solve(a::Int, b::Int)::Int
    if a >= 13
        return b
    elseif a >= 6
        return b ÷ 2
    else
        return 0
    end
end

function main()
    a, b = readline() |> split |> parseintmap
    println(solve(a, b))
end

main()


Measured memory_bytes: 167372
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
 int a[6]={0};
  int b[4]={0};
  int i=0;
  int j=0;
  int o,t;
  o=0;
  for(i=0;i<6;i++){
  cin>>a[i];
    for(j=1;j<5;j++){
  if(a[i]==j){
  b[j-1]++;
  }  
    }
  }
for(i=0;i<4;i++){
if(b[i]>2){
 o++;
}
   if(b[i]<1){
o++;
  }
  
}
 if(o>0){
 cout<<"NO"<<endl;
 }else{
 cout<<"YES"<<endl;
 }
}

Measured memory_bytes: 256
h,w,k=map(int,input().split())
C=[[0]*w for i in range(h)]
for i in range(h):
    c=input()
    for j in range(w):
        if c[j]=="#":
            C[i][j]=1

ans=0
for i in range(2**h):
    for j in range(2**w):
        R=[]
        for p in range(h):
            if i>>p&1:
                R.append([1]*w)
            else:
                R.append([0]*w)
        for q in range(w):
            if j>>q&1:
                for p in range(h):
                    R[p][q]=1
        cnt=0
        for p in range(h):
            for q in range(w):
                if C[p][q]==1 and R[p][q]==0:
                    cnt+=1
        if cnt==k:
            ans+=1
print(ans)

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

using namespace std;

using ll = long long;

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

    ll L, R;
    cin >> L >> R;

    ll min_v = 2018;
    R = min(L + 2018, R);
    for (ll i = L; i < R; ++i)
        for (ll j = i + 1; j <= R; ++j)
            min_v = min(min_v, (i * j) % 2019);

    cout << min_v << endl;

    return 0;
}


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

using namespace std;

int main() {
    int n, a, b;
    int first = 0, second = 0, third = 0, count = 0;
    vector<int> p;

    cin >> n;
    cin >> a >> b;
    p.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    for (int j = 0;j < p.size(); j++) {
        if (p[j] <= a) {
            first++;
        }
        else if(p[j] > b) {
            third++;
        }
        else {
            second++;
        }
    }

    while (first != 0 && second != 0 && third != 0) {
        count++;
        first--;
        second--;
        third--;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
N=int(input())
ans=0
if N<=9:
  ans=N
elif 10<=N<=99:
  ans=9
elif 100<=N<=999:
  ans=9+(N-99)
elif 1000<=N<=9999:
  ans=909
elif 10000<=N<=99999:
  ans=909+(N-9999)
else:
  ans=90909
print(ans)


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

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

int main() {
    int n,m;
    ll k;
    cin >> n >> k;
    vector<ll> a,b;
    ll c = 0;
    for (int i = 0;i < n;++i) {
        ll d;
        cin >> d;
        if (d < 0) b.push_back(-d);
        else if (d > 0) a.push_back(d);
        else c++;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    n = a.size();
    m = b.size();
    ll mn = -1e18-10,mx = 1e18+10;
    while (mx-mn > 1) {
        ll mid = (mn+mx)/2;
        ll cnt = 0;
        for (int i = 0;i < n;++i) {
            if (mid < 0) cnt += m-(lower_bound(b.begin(),b.end(),(-mid+a[i]-1)/a[i])-b.begin());
            else cnt += upper_bound(a.begin(),a.begin()+i,mid/a[i])-a.begin()+m+c;
        }
        for (int i = 0;i < m;++i) {
            if (mid < 0) ;
            else cnt += upper_bound(b.begin(),b.begin()+i,mid/b[i])-b.begin();
        }
        if (mid >= 0) cnt += c*(c-1)/2+c*m;
        (cnt < k ? mn : mx) = mid;
    }
    cout << mx << endl;
}

Measured memory_bytes: 2420
#include<stdio.h>
int main(int argc, char* argv[])
{
  int a, b;
  scanf("%d %d", &a, &b);
  if(a < b){
    printf("a < b\n");
  }else if(b < a){
    printf("a > b\n");
  }else{
    printf("a == b\n");
  }
  return(0);
}

Measured memory_bytes: 580
class Dijkstra():
    """ ダイクストラ法
    重み付きグラフにおける単一始点最短路アルゴリズム

    * 使用条件
        - 負のコストがないこと
        - 有向グラフ、無向グラフともにOK

    * 計算量はO(E*log(V))

    * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい
    """
    class Edge():
        """ 重み付き有向辺 """
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        """ 重み付き有向辺
        無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい

        Args:
            V(int): 頂点の数
        """
        self.G = [[] for i in range(V)]  # 隣接リストG[u][i] := 頂点uのi個目の隣接辺
        self._E = 0  # 辺の数
        self._V = V  # 頂点の数

    @property
    def E(self):
        """ 辺数
        無向グラフのときは、辺数は有向グラフの倍になる
        """
        return self._E

    @property
    def V(self):
        """ 頂点数 """
        return self._V

    def add(self, _from, _to, _cost):
        """ 2頂点と、辺のコストを追加する """
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1

    def shortest_path(self, s):
        """ 始点sから頂点iまでの最短路を格納したリストを返す
        Args:
            s(int): 始点s
        Returns:
            d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。
                     到達不可の場合、値はfloat("inf")
        """
        import heapq
        que = []  # プライオリティキュー（ヒープ木）
        d = [10**15] * self.V
        d[s] = 0
        heapq.heappush(que, (0, s))  # 始点の(最短距離, 頂点番号)をヒープに追加する

        while len(que) != 0:
            cost, v = heapq.heappop(que)
            # キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ
            if d[v] < cost: continue

            for i in range(len(self.G[v])):
                # 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する
                e = self.G[v][i]  # vのi個目の隣接辺e
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost  # dの更新
                    heapq.heappush(que, (d[e.to], e.to))  # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush
        return d

n,m,s,t=map(int,input().split())
yen=Dijkstra(n)
snuke=Dijkstra(n)
for i in range(0,m):
    u,v,a,b=map(int,input().split())
    u-=1
    v-=1
    yen.add(u,v,a)
    yen.add(v,u,a)
    snuke.add(u,v,b)
    snuke.add(v,u,b)

s-=1
t-=1
answer=[]
ye=yen.shortest_path(s)
sn=snuke.shortest_path(t)
cost=float("inf")
for i in range(n-1,-1,-1):
    cost=min(cost,sn[i]+ye[i])
    answer.append(cost)

for i in range(0,len(answer)):
    print(10**15-answer[-i-1])

Measured memory_bytes: 128216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int N, K;
  cin >> N >> K;
  vector<int> dice(N);
  for (int i = 0; i < N; i++) {
    cin >> dice.at(i);
  }
  long double sum = 0, max = 0;
  for (int i = 0; i < N; i++) {
    sum += dice.at(i);
    if(i >= K) {
        sum -= dice.at(i - K);
    }
    if(max < sum) {
      max = sum;
    }
  }
  cout << fixed << setprecision(7) << (max + K) / 2 << endl;
}

Measured memory_bytes: 1024
N,S=map(int,input().split())
A=list(map(int,input().split()))
import numpy as np
d=np.zeros((N+1,S+1),dtype=np.int64)
d[0,0]=1
m=998244353
for i in range(N):
    d[i+1]=d[i]*2%m
    d[i+1,A[i]:]=(d[i+1,A[i]:]+d[i,:-A[i]])%m
print(d[-1,-1])

Measured memory_bytes: 96940
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    def sieve_of_eratosthenes(upper_bound):
        upper_bound += 1
        P = [True] * upper_bound
        P[0] = P[1] = False
        for i in range(4,upper_bound,2):
            P[i] = False
        for i in range(3,int(upper_bound**0.5),2):
            if P[i]:
                for j in range(i**2,upper_bound,i):
                    P[j] = False
        res = []
        for i in range(upper_bound):
            if P[i]:
                res.append(i)
        return res






    N = II()
    primes = deque()
    p_counts = deque()
    tmp = N
    if tmp % 2 == 0:
        c = 0
        while tmp % 2 == 0:
            tmp //= 2
            c += 1
        primes.append(2)
        p_counts.append(c)
        
    for i in range(3,int(N**0.5)+1,2):
        c = 0
        if tmp % i == 0:
            while tmp % i == 0:
                tmp //= i
                c += 1
            primes.append(i)
            p_counts.append(c)

    if tmp != 1:
        primes.append(tmp)
        p_counts.append(1)



    ans = 0



    for i in p_counts:
        max_num = 1
        while (1+max_num)*max_num//2 <= i:
            max_num += 1

        ans += max_num-1
    print(ans)
            



    
main()

Measured memory_bytes: 68328
/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	ll n;
	cin>>n;
	vl a(n),b(n+1);
	for(ll i=0;i<n;i++)
	cin>>b[i];
	a[n-1]=b[n-2];
	for(ll i=n-2;i>0;i--)
	a[i]=min(b[i],b[i-1]);
	a[0]=b[0];
	ll ans=0;
	for(ll i=0;i<n;i++)
	ans+=a[i];
	cout<<ans<<nl;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

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

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int grid[52][52];
    rep(i, 52) rep(j, 52) grid[i][j] = 0;
    int H, W; cin >> H >> W;
    rep(i, H){
        string S; cin >> S;
        rep(j, W){
            if(S[j] == '.') grid[i+1][j+1] = 0;
            else grid[i+1][j+1] = 1;
        }
    }
    int ans[H+2][W+2];
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            int res = 0;
            rep(k, 8){
                int ni = i+dx[k];
                int nj = j+dy[k];
                if(grid[ni][nj] == 1) res++;
            }
            ans[i][j] = res;
        }
    }

    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            if(grid[i][j] == 1) cout << "#";
            else cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

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

int main()

{

    vector<ll > v;
    for(ll i = 0; i < 3; i++)
    {

        ll x;
        cin >> x;
        v.pb(x);
    }
    sort(all(v));
    ll a=v[0], b =v[1] , c=v[2];
    ll d1 = c-a, d2 = c-b;
    if(d1%2==0 && d2%2==0)
    {

        cout << (d1/2)+(d2/2);
    }
    else if(d1%2 && d2%2)
    {

        cout << (d1-1)/2 + (d2-1)/2 + 1;
    }
    else
    {

        if(d1%2) d1++;
        else d2++;
        cout << (d2/2)+(d1/2)+1;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
}









Measured memory_bytes: 256
S = input()
char = len(S)

even, odd = [], []

Yes = True

for i in range(char):
  if (i+1)%2 == 0: even.append(S[i])
  else: odd.append(S[i])
    
for i in odd:
  if not(i == 'R' or i == 'U' or i == 'D'): 
    Yes = False
    
for i in even:
  if not(i == 'L' or i == 'U' or i == 'D'): 
    Yes = False
  
if Yes == True: 
  print('Yes') 
else: 
  print('No')  

Measured memory_bytes: 3064