akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

template<typename T>
struct is_vector : false_type{};

template<typename T>
struct is_vector<vector<T>> : true_type{};

template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) {
    return ostr;
  }
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    if (is_vector<T>()) ostr << "\n" << *itr;
    else ostr << ' ' << *itr;
  }
  return ostr;
}

vector<int> Zalgorithm(const string &str) {
  vector<int> ret(str.size());
  ret[0] = str.size();
  int i = 1, j = 0;
  while (i < str.size()) {
    while (i+j < str.size() && str[j] == str[i+j]) ++j;
    ret[i] = j;
    if (j == 0) {
      ++i;
      continue;
    }
    int k = 1;
    while (i+k < str.size() && k+ret[k] < j) {
      ret[i+k] = ret[k];
      ++k;
    }
    i += k; j -= k;
  }
  return ret;
}

bool eternity;
vb seen, visited;

void dfs(vi &ans, const vb &portion, string &s, string &t, int v) {
  seen[v] = true;
  if (portion[v]) {
    int nv = (v + t.size()) % s.size();
    if (seen[nv] && !visited[nv]) {
      eternity = true;
      return;
    }
    if (!visited[nv]) {
      dfs(ans, portion, s, t, nv);
      if (eternity) return;
    }
    ans[v] = ans[nv] + 1;
  }
  visited[v] = true;
}

void solve() {
  string s, t; cin >> s >> t;

  vi Zt = Zalgorithm(t);

  vb portion(s.size(), false);
  int idx = 0, cnt = 0;
  while (idx < s.size()) {
    while (cnt < t.size() && s[(idx+cnt)%s.size()] == t[cnt]) {
      ++cnt;
    }
    if (cnt == 0) {
      ++idx;
      continue;
    }
    if (cnt == t.size()) {
      portion[idx] = true;
    }
    int move = 1;
    while (idx+move < s.size() && move+Zt[move] < cnt) {
      ++move;
    }
    idx += move; cnt -= move;
  }

  vi ans(s.size(), 0);
  eternity = false;
  seen.assign(s.size(), false);
  visited.assign(s.size(), false);

  rep(i,s.size()) {
    if (seen[i]) continue;
    dfs(ans, portion, s, t, i);
    if (eternity) {
      cout << -1 << endl;
      return;
    }
  }

  cout << *max_element(all(ans)) << endl;
  return;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int a, b, c, ans = 0;
    cin >> a >> b >> c;

    for (int i = a; i <= b; i++) {
        if(c%i == 0) {
            ++ans;
        }
    }

    cout << ans << endl;

}


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

signed main() {
    int a, b;
    cin >> a >> b;
    
    if ( abs(a-b)%2 == 0 ) {
        cout << (a+b) / 2 << "\n";
    } else {
        cout << "IMPOSSIBLE\n";
    }
    
    return (0);
}

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

const int mod = 1e9+7;
const int INF = 2000000;
const double PI = acos(-1.0);

int main() {
    string s;
    cin >> s;
    int c[2019] = {};
    c[0]++;
    int a = 0;
    int multiply = 1;
    for(int i = 1; i <= s.size(); ++i) {
        int n = s[s.size()-i] - '0';
        a = (n * multiply + a) % 2019;
        multiply = multiply * 10 % 2019;
        c[a]++;
    } 

    int ans = 0;
    for (int i = 0;i < 2019; i++) {
        ans += c[i]*(c[i]-1)/2;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3748
from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
q = deque()
q.append(0)

ans = [-1 for _ in range(n)]
ans[0] = 0

visited = set({})

while q:
    start = q.popleft()
    visited.add(start)
    for i in graph[start]:
        if ans[i] == -1:
            q.append(i)
            ans[i] = start
                
if -1 not in ans:
    print('Yes')
    for i in range(1, n):
        print(ans[i] + 1)
else:
    print('No')



Measured memory_bytes: 107092
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

ans = 0
memo = {}

1.upto(n) do |j|
  target = j - a[j-1]

  i_target = j + a[j-1]
  if memo[i_target]
    memo[i_target] += 1
  else
    memo[i_target] = 1
  end
  ans += memo[target].to_i
end
p ans


Measured memory_bytes: 38676
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();
        int n = sc.nextInt();
        int sum = 0;

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

        System.out.println(sum >= h ? "Yes" : "No");
    }
}

Measured memory_bytes: 48328
//----------ACCIDENTAL COMPETITIVE PROGRAMMER---------------------

#include<bits/stdc++.h>

/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
using namespace std;

#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair


const LL MOD = (1e9) + 7 ;
const LD EPS = 0.0000001 ;
const int N = 100000 + 10;
LL dp[N];

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  	for (int i = 0; i < N; i++)
  		dp[i] = 1e18;

  	dp[0] = 0;
  	LL n, w; cin >> n >> w;
  	LL weight[n];
  	LL value[n];
  	for (int i = 0; i < n ; i++){
  		cin >> weight[i] >> value[i];
  	}

  	for (int i = 0; i < n; i++){
  		for (int j = N-1; j > 0; j--){
  			if (value[i] > j)
  				continue;
  			dp[j] = min (dp[j - value[i]] + weight[i], dp[j]);
  		}
  	}
    
  	LL ans = 0;
  	for (int i = 0; i < N; i++){
  		if (dp[i] <= w)
  			ans = i;
  	  /*  if (dp[i] != 1e18)
  	        cout << i << " " << dp[i] << endl; */
  	}
  	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#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") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;


int main(void)
{
    IOS
    int n; cin >> n;
    vector<string> v(n);
    map<string,ll> m;
    REP(i,n)  {
        cin >> v[i];
        sort(ALL(v[i]));
    }
    
    sort(ALL(v));
    
    ll ans = 0;

    REP(i,n) {
        if (m.find(v[i]) == m.end()) {
            m[v[i]] = 0;
        } else {
            m[v[i]]++;
            ans += m[v[i]];
        }

    }


    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 12032
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS
int xorxx(int num) {
    int rem = num%4;
    if(rem ==0 ) return num;
    if(rem == 1) return 1;
    if(rem == 2) return num+1;
    if(rem == 3) return 0;
}
vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int a,b;
cin>>a>>b;
int x = xorxx(b);
int y = xorxx(a-1);
cout<<(x^y);
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで


using namespace std;
int r,g,b,n;
lint ans;

int main(){
  cin >> r >> g >> b >> n;
  for(int i=0;i<=3000;i++){
    for(int j = 0;j<=3000;j++){
      if((n-(r*i+g*j))%b==0&&(n-(r*i+g*j))>=0){
        ans ++;

      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main()
{
	int a,b,k;
    cin>>a>>b>>k;
    int g=__gcd(a,b);
    for(int i=g;i>=1&&k>0;i--)
    {
        if(g%i==0) k--;
        if(k==0) cout<<i<<'\n';
    }
}


Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
ll dp[800][2010];

ll getDp(ll len/*長さ*/, ll remain /*残りの数*/ )
{
    //
    auto& v = dp[len][remain];
    if (v != 0)
    {
        return v;
    }
    if (len <= 1)
    {
        v = 1;
        return 1;
    }
    ll total = 0;
    for (ll r=0;r<=remain;++r)
    {
        total += getDp(len - 1, r);
    }
    total %= BIGP;
    v = total;
    return v;
}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll S;
    cin >> S;
    rep(i, 800) rep(j, 2010) dp[i][j] = 0;

    //
    ll maxLen = S / 3;
    ll total = 0;
    for (int32_t i = 1; i <= maxLen; ++i)
    {
        ll remain = S - i * 3;
        total += getDp(i,remain);
    }
    total %= BIGP;
    cout << total;
    return 0;
}

Measured memory_bytes: 15748
#include<stdio.h>
int main(void)
{
	int N,K,P,i;
	scanf ("%d",&N);
	for (i=0;i<N;i++)
	{
		scanf ("%d%d",&K,&P);
		if (K%P==0)
		printf ("%d\n",P);
		else
		printf ("%d\n",K%P);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 200010
#define maxm 100010
#define inf 1000000007
#define mod 1000000007
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m;
char s[maxn];
int a[maxn];
bool check()
{
    for(int i=1;i<=m;i++)  if(a[i])  return false;
    return true;
}
int g[maxn],f[maxn],sum[maxn][2];
int L=inf;
int main()
{
    n=read();m=read();
    scanf("%s",s+1);
    for(int i=1;i<=m;i++)  a[i]=(s[i]=='B');
    if(a[1])  for(int i=1;i<=m;i++)  a[i]^=1;
    if(check())
    {
        if(n==2) return puts("3"),0;
        g[0]=1;g[1]=2;
        for(int i=2;i<=n;i++)  g[i]=(g[i-1]+g[i-2])%mod;
        return printf("%d\n",(g[n-1]+g[n-3])%mod),0;
    }
    for(int i=1;i<=m;i++)
    {
        if(a[i])  continue;
        int R=i;
        while(R<m&&!a[R+1])  R++;
        if(R==m)  break;
        if(i==1)  L=min(L,R-i+2);
        if((R-i+1)&1)  L=min(L,R-i+1);
        i=R;
    }
    f[0]=1;sum[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        if(i>=2)
        {
            f[i]=sum[i-2][i&1];
            if(i>=L+2)  f[i]=(f[i]-sum[i-L-2][i&1]+mod)%mod;
        }
        sum[i][0]=sum[i-1][0];sum[i][1]=sum[i-1][1];
        sum[i][i&1]=(sum[i][i&1]+f[i])%mod;
    }
    int ans=f[n];
    for(int i=1;i<=L;i+=2)  ans=(ans+1ll*i*f[n-i-1])%mod;
    cout<<ans<<endl;
    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            var result = 0;

            foreach(var i in Enumerable.Range(1, N-1))
            {
                var head = S.Take(i).Distinct();
                var tail = S.Reverse().Take(N - i).Distinct();
                var sum = head.Intersect(tail).Count();

                if (sum > result)
                {
                    result = sum;
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13396
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

struct CombMod{
    fac: Vec<u64>,
    inv: Vec<u64>,
    finv: Vec<u64>,
    mmod: u64,
}

impl CombMod{
    pub fn new(max: u64, m: u64) -> CombMod{
        let max: usize = max as usize;
        let mut fac: Vec<u64> = vec![0;max+1];
        let mut finv: Vec<u64> = vec![0;max+1];
        let mut inv: Vec<u64> = vec![0;max+1];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..max+1{
            fac[i] = fac[i-1] * i as u64 % m;
            inv[i] = m - inv[m as usize %i] * (m/(i as u64)) % m;
            finv[i] = finv[i-1] * inv[i] % m;
        }

        CombMod{
            fac: fac,
            finv: finv,
            inv: inv,
            mmod: m,
        }
    }

    fn get(&self, n: u64, m: u64) -> u64{
        assert!(n >= m && n != 0 && m != 0);
        self.fac[n as usize] * self.finv[m as usize] % self.mmod
            * self.finv[(n-m) as usize] % self.mmod
    }
}

fn main(){
    let n: u64 = read_as_vec()[0];

    println!("{}", (n-1)/2);
}


Measured memory_bytes: 4352
n = int(input())
array = list(map(int, input().split()))

bt = 0 #break times
i = 0  
j = 0  #iterator

while i < n:
  while j < n:
    if array[j] == i+1:
      bt += 1
      break
      
    else:
      if j == n-1:
        if i == 0:
          bt = -1
          i = n+1
          j = n+1
          break
        else:
          i = n+1
          j = n+1
          break
          
    j += 1
  i +=1
  
if bt != -1:
  bt = n - bt
  
print(bt)

Measured memory_bytes: 25716
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	
	sort(a, a + n);
	int ans{};
	for (int i = 0; i < k; i++) ans += a[i];
	cout << ans;
}

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

namespace ABC085A
{
    class Program
    {
        static void Main(string[] args)
        {
            String S;
            S = Console.ReadLine();
            char[] cs = S.ToCharArray();
            cs[3] = '8';
            Console.WriteLine(cs);
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
a=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
b=[int(input()) for _ in range(n)]
flag=0

for i in b:
    for j in range(3):
        for k in range(3):
            if a[j][k]==i:
                a[j][k]=0

for i in range(3):
    if a[i][0]==a[i][1]==a[i][2]:
        flag=1                    
    if a[0][i]==a[1][i]==a[2][i]:
        flag=1
if a[0][0]==a[1][1]==a[2][2] or a[0][2]==a[1][1]==a[2][0]:
    flag=1
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>


using namespace std;
typedef long long ll;

int H, W, h, w = 0;

int main(){

    cin >> H >> W >> h >> w;

    int total = H * W;

    total = total - (h * W + w * H - w * h);

    cout << total << endl;
    
}

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

using namespace std;

#define ll  long long
#define ld  double

#define all(x)  x.begin(),x.end()
#define sz(x)   (int)x.size()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 5005;
const ll    inf = 1e18;

typedef pair<int,int>   ii;

int p[N];
ll  f[N];

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

    int n;  cin >> n;
    int A;  cin >> A;
    int B;  cin >> B;

    p[++n] = n;

    for(int i = 1 ; i <  n ; ++i)   cin >> p[i];
    for(int i = 1 ; i <= n ; ++i)   {
        f[i] = inf;
        int cnt = 0;

        for(int j = i - 1 ; j >= 0 ; --j)   {
            if (p[j] > p[i])
                cnt++;
            else    {
                ll  nxt = f[j] + 1ll * A * cnt + 1ll * B * (i - j - 1 - cnt);

                if (f[i] > nxt)
                    f[i] = nxt;
            }
        }
    }
    cout << f[n] << endl;
}

Measured memory_bytes: 384
n, k, q = (int(i) for i in input().split())
a = [int(input()) for i in range(q)]
score = [k] * n
if k > q:
    for i in range(n):
      print("Yes")

else:
    for i in a:
        score[i-1] += 1
    for i in score:
        if i - q > 0:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 9160
import java.io.*;

public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String buf;
        double weight;
        String cup ="A";
        while((buf = br.readLine())!=null){
            String[] str=buf.split(",");
            if(cup.equals(str[0])){
                cup = str[1];
            }else if(cup.equals(str[1])){
                cup = str[0];
            }
        }
        System.out.println(cup);
    }
}

Measured memory_bytes: 9360
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
using namespace std;
long long ans,pre;
const int mod = 1e9+7;
int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    int n,t;
    scanf("%d",&n);
    for(int i=0; i<n; ++i){
        scanf("%d",&t);
        ans = (ans + (pre*t))%mod;
        pre = (pre+t)%mod;
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 3736
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7),n;
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		String s = sc.next();
		switch(s){
			case "Sunny" : out.print("Cloudy"); break;
			case "Cloudy" : out.print("Rainy"); break;
			case "Rainy" : out.print("Sunny");
		}
		out.close();
	}
	
	
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  sort(a.begin(),a.end());
  a.erase(unique(a.begin(),a.end()),a.end());

  bool flag = true;
  if(n!=a.size()) flag = false;

  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
  return 0;
}


Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

bool d[10];

bool f(int n) {
  while (n != 0) {
    int x = n%10;
    if (!d[x]) return false;
    n /= 10;
  }
  return true;
}

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < 10; i++) d[i] = true;
  for (int i = 0; i < k; i++) {
    int t;
    cin >> t;
    d[t] = false;
  }
  while (1) {
    if (f(n)) break;
    n++;
  }
  dump(n);
  return 0;
}


Measured memory_bytes: 256
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void solve()
{
	int h, w;
	cin >> h >> w;
	vector<string> ans;
	string str(w + 2, '#');
	ans.push_back(str);
	for (int i = 0; i < h; i++)
	{
		cin >> str;
		str = "#" + str;
		str += "#";
		ans.push_back(str);
	}
	string temp(w + 2, '#');
	ans.push_back(temp);
	for (auto s : ans)
		cout << s << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int res = 0;
    for (int n = 1; n <= N; n += 2) {
        int cnt = 0;
        for (int i = 1; i <= n; ++i) if (n % i == 0) ++cnt;
        if (cnt == 8) ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
/*SorooshH*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> tpi;
typedef pair<pii,pii> qpi;
const int MAX = 2000;
const int MV = 1e5;
const int MOD = 1e9 + 7;
const int INF = 2e9;

int n , y;

int32_t main()
{
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n >> y;
    y /= 1000;
    for(int i=0 ; i*10<=y && i<=n ; i++)
    {
        for(int j=0 ; j*5 + i*10 <= y && i+j <= n ; j++)
        {
           if(n-(i+j) == y - (j*5 + i*10 ) )
                    return cout << i << " " << j << " " << n-(i+j) << "\n" , 0;
        }
    }

    cout << "-1 -1 -1\n";

    return 0;
}


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

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

    string num;
    num = to_string(N);

    for(int i = 0;i < num.length();i++)
    {
        if(num[i] == '7')
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3724
import copy
import itertools
h,w,k2 = list(map(int,input().split()))
c = []
res = 0
temp = 0
hc = []
wc = []
a2 = []

hl = [i for i in range(h)]
wl = [i for i in range(w)]

for i in range(h):
    c.append(list(str(input())))

for i2 in range(h+1):
    for i in list(itertools.combinations(hl, i2)):
        a = copy.deepcopy(c)
        for j in i:
            for k in range(w):
                a[j][k] = "."
        for i3 in range(w+1):
            for l in list(itertools.combinations(wl, i3)):
                a2 = copy.deepcopy(a)
                for m in l:
                    for n in range(h):
                        a2[n][m] = "."
                temp = 0
                for o in a2:
                    temp += o.count("#")
                if temp == k2:
                    res += 1

print(res)

Measured memory_bytes: 9360
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(0LL, min(b, d) - max(a, c)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long int LL;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int b[200001] = {};
  int w[200001] = {};
  for(int i=1; i<=N; ++i) {
    if(S[i-1] == '.') {
      b[i] = b[i-1];
      w[i] = w[i-1] + 1;
    } else {
      b[i] = b[i-1] + 1;
      w[i] = w[i-1];
    }
  }
  int ret = 9999999;
  REP(i, N+1) {
    int tmp = b[i] + (w[N] - w[i]);
    if(tmp < ret) ret = tmp;
  }
  cout << ret << endl;
}

Measured memory_bytes: 2180
from collections import deque

n,x = map(int, input().split())
a = list(map(int, input().split()))

def slide(a, k):
  q = deque()
  ans = 0
  for i in range(-k,0):
    while q and a[q[-1]] > a[i]: q.pop()
    q.append(i)
  for i in range(n):
    if q[0] <= i-k: q.popleft()
    while q and a[q[-1]] > a[i]: q.pop()
    q.append(i)
    ans += a[q[0]]
  return ans

print(min(slide(a,k+1) + x*k for k in range(n)))

Measured memory_bytes: 51292
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)
	N := readInt()
	A := make([]int, N)
	for i := range A {
		A[i] = readInt()
	}
	x1 := 0
	for i, a := range A {
		if i%2 == 0 {
			x1 += a
		} else {
			x1 -= a
		}
	}
	ans := make([]int, N)
	ans[0] = x1
	for i := 1; i < N; i++ {
		ans[i] = (A[i-1] - ans[i-1]/2) * 2
	}
	for _, a := range ans {
		fmt.Println(a)
	}
}

/*-----------------------------------------*/

func checkError(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func read() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	res, err := strconv.Atoi(read())
	checkError(err)
	return res
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a int, b int) int {
	return -min(-a, -b)
}

func pow(a int, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func sqrt(a int) float64 {
	return math.Sqrt(float64(a))
}


Measured memory_bytes: 5760
#include <iostream>


#include <vector>

using namespace std;
using ll =long long;

int main()
{
	ll way,count;
	cin >> way>>count;

	vector<ll> house_pos;
	house_pos.resize(count * 2);
	vector<ll> house_pos_dif;
	house_pos_dif.resize(count * 2);
	vector<ll> house_pos_sum;
	house_pos_sum.resize(count * 2+1);
	house_pos_sum[0] = 0;


	for (ll i = 0; i < count; i++)
	{
		cin >> house_pos[i];
	}


	for (ll i = count; i < count*2; i++)
	{
		house_pos[i] = house_pos[i - count] + way;
	}

	house_pos_dif[0] = (way - house_pos[count - 1]) + house_pos[0];

	for (ll i = 1; i < count * 2; i++)
	{
		house_pos_dif[i] = house_pos[i] - house_pos[i-1];
	}

	auto GetLoopedIndex = [](ll index, ll i_max)
	{
		return (index < i_max ? index : index-i_max);
	};

	for (ll i = 0; i < count * 2; i++)
	{
		house_pos_sum[i + 1] = house_pos_dif[GetLoopedIndex(i,count)] + house_pos_sum[i];
	}




	auto Max = [](ll a, ll b)
	{
		return a >= b ? a : b;
	};

	auto Min = [](ll a, ll b)
	{
		return a <= b ? a : b;
	};
	int min_len = house_pos_sum[count] - house_pos_sum[0];
	for (ll i = 0; i < count; i++)
	{
		ll len = house_pos_sum[i + count-1] - house_pos_sum[i];
		min_len = Min(len, min_len);

	}

	cout << min_len;

	
    return 0;
}



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

int A[3], K;

int main() {
    rep(i, 3) cin >> A[i];
    cin >> K;

    rep(i, K) {
        sort(A, A + 3);
        A[2] *= 2;
        // cout << A[2] << endl;
    }

    // rep(i, 3) {
    //     cout << A[i] << endl;
    // }

    cout << accumulate(A, A + 3, 0) << endl;
}

Measured memory_bytes: 256
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x:]
q=sorted(list(map(int,input().split())))[-y:]
r=sorted(list(map(int,input().split())))
s=sorted(p+q+r)[-x-y:]
print(sum(s))

Measured memory_bytes: 22616
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int x[200010]={0},y[200010]={0};
int main(){
	int i,j,k,m,n;
	scanf("%d%d",&m,&n);
	for (i=1;i<=n;i++){	
		int a,b;
		scanf("%d%d",&a,&b);
		if (a==1) x[b]++;
		if (b==m) y[a]++;
	}	
	for (i=1;i<=n;i++)
		if (x[i] && y[i]){
			printf("POSSIBLE\n");
			return 0;
	}	
	printf("IMPOSSIBLE\n");
	return 0;
}

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

int main(void) {
  string S;
  cin >> S;
  int y, m, d;
  y = stoi(S.substr(0,4));
  m = stoi(S.substr(5,2));
  d = stoi(S.substr(8,2));

  if ( y < 2019 || ( y == 2019 && m < 4 ) || ( y == 2019 && m == 4 && d <= 30 ) )
    cout << "Heisei" << endl;
  else
    cout << "TBD" << endl;

  return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
A = [int(input()) for i in range(m)]
if m == 0:
  Fib = [1,2]
  for i in range(2,n):
    Fib.append(Fib[i-2]+Fib[i-1])
  print(Fib[n-1]%1000000007)
  exit()

B = [A[i+1]- A[i] for i in range(m-1)]
B.insert(0,A[0]+1)
B.append(n+1-A[m-1])

M = max(A)

Fib = [0,1]
for i in range(2,M+10):
  Fib.append(Fib[i-2]+Fib[i-1])

ans = 1
for i in range(len(B)):
  ans = (ans * Fib[B[i]-1])%1000000007
  
print(ans)


Measured memory_bytes: 464816
#include<stdio.h>

 int main()
 {
	 int A, C, B, D;
	 int sum = 0;
	 
	 scanf("%d",&A);
	 scanf("%d",&B);
	 scanf("%d",&C);
	 scanf("%d",&D);
	 
	 if(A >= B) sum += B;
	 else sum += A;
	 
	 if(C >= D) sum += D;
	 else sum += C;
	 
	 printf("%d",sum);
	 
	 return 0;
 }

Measured memory_bytes: 128
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {

    int n;
    cin >> n;

    int a[n];
    a[1] = 0; //社員番号#1(a[1])は一番偉いから上司はいない
    
    for(int i=2; i<=n; i++) cin >> a[i]; //社員番号#2〜#Nの上司の人数を入力
    
    int ans[n];
    for(int i=1; i<=n; i++) ans[i] = 0; //配列の初期化
    
    
    int tmp;
    
    for(int i=1; i<=n; i++){
        tmp = a[i];
        ans[tmp]++; //社員番号#iの上司である人の社員番号a[i]をカウント
    }
    
    for(int i=1; i<=n; i++) cout << ans[i] << endl;
    
    return 0;
    
}

Measured memory_bytes: 5204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    A.push_back(0);
   
    ll ans = 0;
    rep(i,N){
        
        if(A[i] == 0) continue;
        if(A[i]%2==0) ans += ll(A[i]/2);
        else{
            if(A[i+1] > 0){
                A[i+1]--;
                ans += ll((A[i]+1)/2);
            }
            else ans += ll(A[i]/2);
        }
        
        
    }
    cout << ans << endl;
    
    
    return 0;
}



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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    vector<ll> left;
    vector<ll> right;
    left.push_back(0);
    right.push_back(0);


    rep(i,N)
    {
        if(s[i] == 'E' )
        {
            left.push_back(left[left.size()-1]+1);
            right.push_back(right[right.size()-1]);
        }
        else
        {
            left.push_back(left[left.size()-1]);
            right.push_back(right[right.size()-1]+1);
        }
    }

    ll ans = INF;
    rep(i,N)
    {
        ll tmp = (left[left.size()-1] - left[i+1] ) + right[i];
        //cout << left[left.size()-1] - left[i+1] << " " <<  right[i] << endl;
        if( tmp < ans ) ans = tmp;
    }
    
    /*
    for(ll i = 0;i < left.size();i++) cout << left[i] << " ";
    cout << endl;
    for(ll i = 0;i < right.size();i++) cout << right[i] << " ";
    cout << endl;
    */

    cout << ans << endl;
}


Measured memory_bytes: 10860
#include <iostream>
#include <vector>
#include<string>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<string> x(n);
    vector<string> u(n);
    for(int i=0;i<n;i++){
        cin >> x[i];
        cin >> u[i];
    }
    double ans =0;
    for(int i =0;i<n;i++){
        if(u[i] == "JPY"){
            ans += stol(x[i]);
        }
        else if(u[i] == "BTC"){ 
            ans += (stod(x[i])*380000);
        }
        
    }
    cout << ans;
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}
//最終奥義
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

signed main(void){
  int n;cin >> n;
  vint h(n);vin(h);
  int cnt=0,ans=0;
  rep(i,n-1){
    if(h[i]>=h[i+1]){
      cnt++;
      chmax(ans,cnt);
    }
    else cnt=0;
  }
  cout << ans << endl;

}


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

int main() {
  string s;
  getline(cin, s);

  rep (i, s.size()) {
    if (s.at(i) == ' ') {
      cout << "A" << s.at(i+1) << "C" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3600
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, m = map(int, input().split())

a = list( map(int, input().split()))

from itertools import accumulate
b = [0] + a
b = list(accumulate(b))

count_mod = defaultdict(int)

for i in range(n+1):
    bi_modm = b[i]%m
    if count_mod[bi_modm] is None: count_mod[bi_modm]=1
    else: count_mod[bi_modm] += 1

ans = 0
for count in count_mod.values():
    ans += count*(count-1)//2
print(ans)


Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;


int main() {string a;
cin >> a;
if(a.size() == 3){
    char b = a[2];
    a[2] = a[0];
    a[0] = b;
}
show(a);








 return 0;
 
}



Measured memory_bytes: 256
import           Data.Array.IArray
import           Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set

modN = 1000000007 :: Integer

main :: IO ()
main = do
    [n,_] <- map read . words <$> getLine :: IO [Int]
    a <- Set.fromList . map (fst . fromJust . BS.readInt) . BS.lines <$> BS.getContents
    print $ solve n a `mod` modN

solve :: Int -> Set.Set Int -> Integer
solve n a = dp!n
  where
    dp = listArray (0,n) (map f [0..n]) :: Array Int Integer
    f k
      | Set.member k a = 0
      | k == 0 = 1
      | k == 1 = 1
      | otherwise = dp!(k-1) + dp!(k-2)


Measured memory_bytes: 605564
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int n,k;

void divisor_enum(int x, vector<int> &div) {
    for (int i = 1; i*i <= x; ++i) {
        if (x%i==0) {
            div.push_back(i);
            if ((x/i)!=i) div.push_back((x/i));
        }
    }
}

bool check(int x, vector<ll> a) {
    // printf("x = %d\n",x);
    rep(i,n) a[i]%=x;
    sort(a.begin(), a.end());

    vector<ll> sl(n), sr(n);
    sl[0]=a[0];

    // 累積和
    for (int i = 1; i < n; ++i) sl[i]+=(sl[i-1]+a[i]);
    rep(i,n) a[i]=x-a[i];
    sr[n-1]=a[n-1];
    for (int i = n-2; i >= 0; --i) sr[i]+=(sr[i+1]+a[i]);

    /*
    rep(i,n) {
        printf("sl[%d] = %lld, sr[%d] = %lld\n", i,sl[i],i,sr[i]);
    }
    */

    // 判定パート
    ll times = LINF;
    rep(i,n-1) {
        ll tmp = max(sl[i],sr[i+1]);
        times = min(times, tmp);
    }

    if (times > k) return false;
    return true;
}

int main(int argc, char const *argv[]) {
    cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll x = accumulate(a.begin(), a.end(), 0ll);
    vector<int> div;
    divisor_enum(x,div);
    sort(div.begin(), div.end());

    int ans = 1;

    for (auto &&e: div) if (check(e,a)) ans = e;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int N, X;
    int L[200];
    int i, j, k;
    int sum = 0;
    
    scanf("%d %d", &N, &X);

    for(i=0; i<N; i++){
        scanf("%d", &L[i]);
    }

    for(i=0; i<N; i++){
        sum = sum + L[i];
        if(sum>X){
            break;
        }
    }

    printf("%d", i+1);

    return 0;
}

Measured memory_bytes: 128
N = int(input())

def sum_of(num): 
    list_b = []
    k = 0
    while num > 0:
        list_b.append(num%10)
        num //= 10
    for i in range(len(list_b)):
        k += list_b[i]
    return k 

list_a =[]
if N == 2:
    print(str(2))
if N == 3:
    print(str(3))
if N >= 4:
    for i in range(2,N-1):
        A = i
        B = N - i
        list_a.append(sum_of(A) + sum_of(B))
    print(min(list_a))


Measured memory_bytes: 9852
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int days(int y,int m,int d) {
	int sum=d;
	for(int i=1;i<y;i++) {
		if(i%3==0) {
			sum+=200;
		}else {
			sum+=195;
		}
	}
	for(int i=1;i<m;i++) {
		if(y%3==0||i%2==1) {
			sum+=20;
		}else {
			sum+=19;
		}
	}
	return sum;
}
int main() {
	int n;
	scanf("%d",&n);
	int x=days(1000,1,1);
	for(int i=0;i<n;i++) {
		int y,m,d;
		scanf("%d %d %d",&y,&m,&d);
		printf("%d\n",x-days(y,m,d));
	}
}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main()
{
    int m1,m2,d1,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m1!=m2){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;


int main(){
    int n;
    cin >> n;
    if(n < 3 || n > 10000) return -1;
    for(int i = 1 ;i <= n ; i ++){
        int x = i;
        if(x % 3 == 0){
            cout << " " << i ;
            continue;
        }else if(x % 10 == 3){
            cout << " " << i ;
            continue;
        }else{
            while(x > 0){
                x = round(x/10);
                if(x % 10 == 3){
                    cout << " " << i ;
                    break;
                }
            }
            continue;
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3188
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int h = sc.nextInt();
        int w = sc.nextInt();
        boolean[][] b = new boolean[h][w];
        
        for(int i=0; i<h; i++){
            String line = sc.next();
            for(int j=0; j<w; j++){
                if(line.charAt(j) == '.'){
                    b[i][j] = true;
                }
            }
        }
        
        UnionFind[] huf = new UnionFind[2002];
        UnionFind[] vuf = new UnionFind[2002];
        
        for(int i=0; i<2002; i++){
            huf[i] = new UnionFind(2002);
            vuf[i] = new UnionFind(2002);
        }
        
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(b[i][j]){
                    //hrz
                    if(i<h-1 && b[i+1][j]){
                        huf[j].unite(i,i+1);
                    }
                    //vrt
                    if(j<w-1 && b[i][j+1]){
                        vuf[i].unite(j,j+1);
                    }
                }
            }
        }
        
        long ans = 0;
        
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(b[i][j]){
                    int c = huf[j].size(i);
                    int d = vuf[i].size(j);
                    
                    //System.out.println("h :" + c + " , v : " + d);
                    ans = Math.max(ans, c+d-1);
                }
            }
        }
        
        System.out.println(ans);
        
    }
    
}


class UnionFind{
    int[] par;
    int[] size;
    
    public UnionFind(int n){
        par = new int[n];
        for(int i=0; i<n; i++){
            par[i] = i;
        }
        size = new int[n];
        Arrays.fill(size, 1);
    }
    
    public int find(int x){
        if(par[x] == x){
            return x;
        }else{
            par[x] = find(par[x]);
            return par[x];
        }
    }
    
    public boolean unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return false;
        
        if(size[x]<size[y]){
            int tmp = x;
            x = y;
            y = tmp;
        }
        size[x] += size[y];
        par[y] = x;
        return true;
    }
    
    public boolean same(int x, int y){
        return find(x)==find(y);
    }
    
    public int size(int x){
        return size[find(x)];
    }
}


Measured memory_bytes: 131884
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int N;
    cin >> N;
    int t[] = {ceil(N / 1.08), floor(N / 1.08)};
    if ((int)(1.08* t[0]) == N) cout << t[0] << endl;
    else if (int(1.08 * t[1]) == N) cout << t[1] << endl;
    else cout << ":(" << endl;
}


Measured memory_bytes: 256