akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int             long long
#define gcd(a, b)       __gcd(a, b)
#define here            cout<<"here";
#define lcm(a, b)       ((a)*1ll * (b)) / gcd(a, b)
#define pb              push_back
#define mp              make_pair
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define nl              "\n"
#define vi              vector<int>
#define vd              vector<double>
#define vc              vector<char>
#define vs              vector<string>
#define vvi             vector<vector<int> >
#define F               first
#define S               second
#define pii             pair<int,int>
#define w(x)            int x; cin>>x; while(x--)
#define fre(i,a,n)      for (int i = a; i <= n; ++i)
#define fr(i,n)         for (int i = 0; i < n; ++i)
#define rf(i,n,a)       for (int i = n; i >=a; --i)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int pow(int a, int b, int m)
{
        int ans = 1;
        while (b)
        {
                if (b & 1)
                        ans = (ans * a) % m;
                b /= 2;
                a = (a * a) % m;
        }
        return ans;
}
int modInv(int a, int m)
{
        a = a % m;
        for (int x = 1; x < m; x++)
                if ((a * x) % m == 1)
                        return x;
}
//when m is prime
int modinv(int a, int m)
{
        return pow(a, m - 2, m);
}


////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
const int N = 1005;

void solve()
{

        int h,w;cin>>h>>w;
        char a[h][w];
        int dp[h][w];
        memset(dp,0,sizeof dp);
        fr(i,h) fr(j,w) cin>>a[i][j];

        fr(i,h){
                fr(j,w){
                        if(i==0 and j==0){
                                if(a[i][j]=='.') dp[i][j]=1;
                                else dp[i][j]=0;
                        }
                        else if(i==0){
                                if(dp[i][j-1]>0 and a[i][j]=='.') dp[i][j]=1;
                                else dp[i][j]=0; 
                        }
                        else if(j==0){
                                if(dp[i-1][j]>0 and a[i][j]=='.') dp[i][j]=1;
                                else dp[i][j]=0;
                        }
                        else{
                                if(a[i][j]=='#')dp[i][j]=0;
                                else dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
                        }
                }
        }

        cout<<dp[h-1][w-1];


}


////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////


int32_t main()
{


        solve();
        // w(x)    {solve();}
#ifndef ONLINE_JUDGE
        cerr << "\nTime Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
}


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

using namespace std;

const int N = 200000;

int n, m, k, a[N], b[N], ans, total, p, q;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> m >> k;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < m; ++i)
		cin >> b[i];

	while (p < n) {
		total += a[p];
		++p;

		if (total > k) {
			--p;
			total -= a[p];
			break;
		}
		else
			++ans;
	}

	int maybeAns = ans;
	while (p >= 0) {
		while (q < m) {
			total += b[q];
			++q;

			if (total > k) {
				--q;
				total -= b[q];
				break;
			}
			else
				++maybeAns;
		}

		ans = max(ans, maybeAns);

		--p;
		if (p >= 0)
			total -= a[p];
		--maybeAns;
	}

	cout << ans << endl;
}


Measured memory_bytes: 5192
N,T = map(int, input().split())
As = list(map(int, input().split()))
AsR = As[::-1]
mxs = []
mx = 0
ind = 0
for i, a in enumerate(AsR):
    if a > mx:
        mx = a
        ind = N-i-1
    mxs.append((mx,ind))
pairs = []
for a,mx in zip(As,mxs[::-1]):
    # print(mx[0]-a,mx[1])
    pairs.append((mx[0]-a,mx[1]))
pairs.sort(reverse=True)
mx = pairs[0][0]
from collections import defaultdict
ans = set()
for x, i in pairs:
    if x != mx:break
    ans.add(i)
print(len(ans))

Measured memory_bytes: 28260
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0 ;i<n; i++){
        cin >> d[i];
    }
    int ans = 0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            if(i!=j){
                ans += d[i]*d[j];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// failed to generate code

#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
//
// 1234567894848 * 10
// 1234567891011
// 1234567900000
// 3800/10 = 380
//
// 7 * 3 = 21
// 27
//
// K * N
//
// N - (N-1) * K
// 50 - 49
// 50*10^16 -
//
// 1000+193+256+777+0+1+1192+1234567891011+48+425

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}
ll K;
ll MAX = 1e16 + 1000L;

bool solve(ll N) {
  if (K == 0) {
    cout << "2" << endl;
    cout << "1 1" << endl;
    return true;
  } else if (K == 1) {
    cout << "2" << endl;
    cout << "3 0" << endl;
    return true;
  }

  ll sum = K * N;
  vll v(N, 0);

  if (K <= 50) {
    REP(i, N) { v[i] = i + 1; }
  } else {
    REP(i, N) v[i] = i + K / N;
    REP(i, K % N) {
      v[i % N] += N;
      REP(j, N) if (i % N != j) { v[j]--; }
    }
    REP(i, N) {
      if (v[i]<0 | v[i]> MAX)
        return false;
    }
  }

  cout << N << endl;
  REP(i, N) {
    cout << v[i];
    if (i != N - 1)
      cout << " ";
  }
  cout << endl;
  return true;
}
int main() {
  ios::sync_with_stdio(false);

  cin >> K;

  if (K <= 50) {
    solve(K);
  } else {
    FOR(i, 2, 51) if (solve(i)) return 0;
  }
}


Measured memory_bytes: 256
import sys
import math
import itertools

input = sys.stdin.readline


def main():
    l, r = [int(i) for i in input().split()]

    if r - l >= 2019:
        print(0)
        return
    else:
        num = [i for i in range(l, min(l + 2019, r + 1))]
        min_ = 2019
        for i, n in enumerate(num):
            for j in num[i + 1 :]:
                min_ = min([n * j % 2019, min_])
    print(min_)


if __name__ == "__main__":
    main()


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

int main() {
	string s;
	bool chk=true;
	cin>>s;
	
	for(int i=0; i<s.length(); ++i){
		
		if(i%2==0){
			if(s[i]=='L')	chk=false;
		}
		else{
			if(s[i]=='R')	chk=false;
		}
	}
	if(chk==false)	cout<<"No";
	else	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int d;
  cin>>d;

  vector<ll> p(26);
  rep(i,26) cin>>p[i];

  vector<vector<ll>> q(d,vector<ll>(26));
  rep(i,d) {
    rep(j,26) {
      cin>>q[i][j];
    }
  }

  ll pre=0;
  vector<int> r(26,0);
  rep(i,d){
    ll ans=-INF;
    ll memo;
    rep(j,26){
      ll sum=pre;
      auto last=r;
      sum+=q[i][j];
      last[j]=i+1;
      rep(k,26){
        sum-=p[k]*(i+1-last[k]);
      }
      if(sum>ans) {
        memo=j;
        chmax(ans,sum);
      }
    }
    cout << memo+1 << endl;
    pre=ans;
    r[memo]=i+1;
  }


}

Measured memory_bytes: 3756
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i=1; i<=n; i++) {
        ans += (ll)i * (n - i + 1);
    }
    for (int i=0, ui, vi; i<n-1; i++) {
        cin >> ui >> vi;
        if (vi < ui) swap(ui, vi);
        ans -= (ll) (ui) * (n - vi + 1);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#define N 1000000

int main(void) {

    int i, j, k;
    int n, H[N], W[N];

    for (i = 0; i < N; i++) {
        H[i] = 0;
        W[i] = 0;
    }

    i = 0;
    while (1) {
        scanf("%d%d", &H[i], &W[i]);
        if ((H[i] == 0) && (W[i] == 0)) {
            break;
        }
        i++;
    }
    n = i;

    for (i = 0; i < n; i++) {
        for (j = 1; j <= H[i]; j++) {
            for (k = 1; k <= W[i]; k++) {
                if ((j + k) % 2 == 0) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;

}

Measured memory_bytes: 8384
import sys
sys.setrecursionlimit(10**7)

def find(x):#xの親を見つける
  if par[x] < 0:
    return x
  else:
    par[x] = find(par[x])
    return par[x]

def unite(x,y):#要素xとｙを併合させる
  x,y=find(x),find(y)#xとyの親の検索
  if x!=y:#親が異なる場合併合させる
    if x>y:
        x,y=y,x#小さい方をxとする. これにより要素の値が小さいものを優先して木の根とする. 
    par[x]+=par[y] #値を無向木の要素数の和にする.
    par[y]=x #枝側は根の位置を格納

def same(x, y):#要素xと要素yが同じ無向木に所属しているかを判定する
  return find(x) == find(y)#同じ値を持つか否か

def size(x):#要素xが所属する無向木の大きさを返す
  return-par[find(x)]

n, m = map(int, input().split()) #要素の数
par = [-1] * n #
path = []
for i in range(m):
  a, b = map(int, input().split())
  path.append([a-1, b-1])
ans_l = [n*(n-1)//2]
for i in range(m-1, 0, -1):
  if same(path[i][0], path[i][1]):
    ans_l.append(ans_l[-1])
    unite(path[i][0], path[i][1])
  else:
    ans_l.append(ans_l[-1] - size(path[i][0])*size(path[i][1]))
    unite(path[i][0], path[i][1])
for i in range(m-1, -1, -1):
  print(ans_l[i])

Measured memory_bytes: 25600
// ALDS1_13_B.cpp
// Heuristic Search - 8 Puzzle
// AC
// ??????????????????????????????????????????AC??????????????????
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

const int N = 3;
const int N2 = 9;
const int INF = 40;
struct Puzzle {
    int f[N2];
    //int space;
    string path;

    bool operator < (const Puzzle &p) const {
        for (int i = 0; i < N2; i++) {
            if (f[i] == p.f[i]) continue;
            return f[i] > p.f[i];
        }
        return false;
    }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};
map<Puzzle, bool> ms;
Puzzle in;
int ministep = INF;
int sx = 0;
int sy = 0;
int limit;

void swap(int& a, int& b)
{
    int t = a;
    a = b;
    b = t;
}

bool isTarget(Puzzle p)
{
    for (int i = 0; i < N2; i++) {
        if (p.f[i] != i + 1)
            return false;
    }
    return true;
}

int getAllMD(Puzzle p)
{
    int dist = 0;
    int x, y;
    int ux, uy;
    for (int i = 0; i < N2; i++) {
        if (p.f[i] == N2) continue; // ??????0??????
        x = (p.f[i] - 1) / N;
        y = (p.f[i] - 1) % N;
        ux = i / N;
        uy = i % N;
        dist += abs(x - ux) + abs(y - uy);
    }
    return dist;
}

bool bfs(int i)
{
    if (isTarget(in)) {
        ministep = min(ministep, i);
//        cout << "ministep = " << ministep << endl;
        return true;
    }
    if (ms[in] || limit < i + getAllMD(in)) {
        return false;
    }

    ms[in] = true;
    for (int u = 0; u < 4; u++) {
        int tx = sx + dx[u];
        int ty = sy + dy[u];
        if (tx < 0 || tx >= N || ty < 0 || ty >= N)
            continue;
        swap(in.f[sx * N + sy], in.f[tx * N + ty]);
        sx = tx;
        sy = ty;
        in.path += dir[u];
        /* test */
//    cout << "(i = " << i << ") " << in.path << endl;
//    for (int j = 0; j < N2; j++)
//        cout << " " << in.f[j];
//    cout << endl;
//    cout << "MD: " << getAllMD(in) << endl;
        if(bfs(i+1)) return true;
        sx = sx - dx[u];
        sy = sy - dy[u];
        swap(in.f[sx * N + sy], in.f[tx * N + ty]);
        in.path.pop_back();
    }
    ms[in] = false;
    return false;
}

string iterative_deepening()
{
    limit = getAllMD(in);
    for ( ; limit <= INF; limit++) {
        if (bfs(0)) {
            return in.path;
        }
    }
}

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

    for (int i = 0; i < N2; i++) {
        cin >> in.f[i];
        if (in.f[i] == 0) {
            sx = i / N;
            sy = i % N;
            in.f[i] = 9; // ??????isTarget?????????
        }
    }
    string ans = iterative_deepening();
    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 5264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
	int n,i;
	cin>>n;
	vi a(n);
	loop(i,0,n){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	cout<<a[n-1]-a[0]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int solve(int N, vector<int> T, vector<int> C) {
	vector<int> remaining_lap = C;

	vector<pair<int, int>> D[2];
	for (int i = 0; i < N; i++) D[0].push_back(make_pair(i, 0));

	for (int t = 0; t <= 150000; t++) {
		for (int i = 0; i < 2; i++) {
			vector<pair<int, int>> S;
			vector<bool> VV(D[i].size(), false);
			
			for (int j = 0; j < D[i].size(); j++) {
				if (D[i][j].second == t) {
					int pos = D[i][j].first;
					remaining_lap[pos]--; VV[j] = true;
					if (remaining_lap[pos] == 0) continue;
					S.push_back(make_pair(T[pos], pos));
				}
			}
			sort(S.begin(), S.end());
			
			vector<pair<int, int>> new_D;
			for (int j = 0; j < D[i].size(); j++) { if (VV[j] == false) new_D.push_back(D[i][j]); }
			D[i] = new_D;

			for (int j = 0; j < S.size(); j++) {
				int pos = S[j].second;
				D[i ^ 1].push_back(make_pair(pos, t + T[pos]));
			}
		}
		for (int i = 0; i < 2; i++) {
			for (int j = 1; j < D[i].size(); j++) {
				D[i][j].second = max(D[i][j].second, D[i][j - 1].second);
			}
		}

		if (D[0].size() == 0 && D[1].size() == 0) return t;
	}
	return -1;
}

int main() {
	while (true) {
		int N; cin >> N; if (N == 0) break;
		vector<int> T(N, 0), C(N, 0);
		for (int i = 0; i < N; i++) { cin >> T[i] >> C[i]; C[i] *= 2; C[i]++; }

		cout << solve(N, T, C) << endl;
	}
	return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second

signed main(){
    int n;
    cin>>n;
    int a[n];
    int l[n],r[n];
    r(i,n)cin>>a[i];
    r(i,n)l[i]=r[i]=a[i];

    for(int i=1;i<n;i++){
        l[i]=__gcd(l[i],l[i-1]);
    }
    for(int i=n-2;i>=0;i--){
        r[i]=__gcd(r[i],r[i+1]);
    }
    int ans=0;

    for(int i=0;i<n;i++){
        if(!i){
            ans=max(ans,r[i+1]);
        }
        else if(i==n-1){
            ans=max(ans,l[i-1]);
        }
        else{
           ans=max(ans,__gcd(l[i-1],r[i+1])); 
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
fun main() {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    val hList = readLine()!!.split(" ").map(String::toLong)
    val array = Array(n) { mutableListOf<Int>() }
    (0 until m).map {
        val (a, b) = readLine()!!.split(" ").map(String::toInt)
        array[a - 1].add(b - 1)
        array[b - 1].add(a - 1)
    }

    var count = n
    array.forEachIndexed { index, mutableList ->
        if (mutableList.isEmpty()) return@forEachIndexed

        val base = hList[index]
        mutableList.forEach {
            val height = hList[it]
            if (height >= base) {
                count -= 1
                return@forEachIndexed
            }
        }
    }

    println(count)
}

Measured memory_bytes: 74828
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    k = ni()
    a = na()
    a.reverse()

    min_num = 2
    max_num = 2

    for ai in a:
        min_num = int(math.ceil(min_num / ai) * ai)
        max_num = int(math.floor(max_num / ai + 1) * ai) - 1

    if min_num <= max_num:
        print(min_num, max_num)
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20744
# coding: utf-8
# Here your code !
import numpy as np
n,m = [int(x) for x in input().split(' ')]
chil = []
check = []
minlist = []
for i in range(n):
    chil.append([int(x) for x in input().split(' ')])
for i in range(m):
    check.append([int(x) for x in input().split(' ')])
for c in chil:
    min = 10**12
    index = 0
    for inde,ch in enumerate(check):
        if abs(ch[1]-c[1]) + abs(ch[0]-c[0]) < min:
            min = abs(ch[1]-c[1]) + abs(ch[0]-c[0])
            index = inde
    minlist.append(index + 1)
for i in minlist:
    print(i)
    


Measured memory_bytes: 20380
#x, y, a, b, c = gets.split.map(&:to_i)

s = gets.chomp
n = s.size

stat = 0
cnt = 0
arrR = []
arrL = []
for i in 0..n-1
    if stat == 0
        if s[i] == 'R'
            cnt += 1
        else
            arrR << cnt
            cnt = 1
            stat = 1
        end
    else # stat == 1
        if s[i] == 'L'
            cnt += 1
        else
            arrL << cnt
            cnt = 1
            stat = 0
        end
    end
end
arrL << cnt

raise 'fail' if arrL.size != arrR.size

ansarr = []
nn = arrR.size
for i in 0..nn-1
    mm = arrR[i]
    for j in 0..mm-2
        ansarr << 0
    end
    lc = mm/2
    rc = (mm + 1)/2

    kk = arrL[i]
    lc += (kk + 1)/2
    rc += kk/2
    ansarr << rc
    ansarr << lc
    for j in 0..kk-2
        ansarr << 0
    end
end

puts ansarr.join(" ")


Measured memory_bytes: 16280
# -*- coding: utf-8 -*-
import sys


S_list=list(input().strip())
sub_S = S_list[2:-1]

if S_list[0] != "A"  or  sub_S.count("C") != 1:
    print("WA")
    sys.exit()

check_S = S_list[:]
del check_S[ 2 + sub_S.index("C") ]
del check_S[0]

if ("".join(check_S)).islower():
    print("AC")
else:
    print("WA")
    sys.exit()


Measured memory_bytes: 3060
//   //  /////       ///      
//  //   //  //     // //     
// //    //   //   //   //    
////     //   //  //     //   
// //    //   //  /////////    
//  //   //  //   //     //    
//   //  /////    //     //    

#include <bits/stdc++.h>
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define iter(it,a,b) for(a::iterator it=b.begin(); it!=b.end();++it)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll)
#define ln "\n"
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end() 
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef vector<bool> vbool;
typedef priority_queue<p32> pq32;
typedef priority_queue<p32, vector<p32>, greater<p32> > pq32l;

#pragma GCC optimize ("-O2")
const ll LIM = 2e5+5;
const ll MOD = 1e9+7;
const ll inf = 1e10;



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

	int n;
	cin >> n;

	ll a[n];
	forn(i,n) cin >> a[i];

	ll dp[n][n];

	forn(i,n){
		forn(j,n-i){
			if(i == 0) dp[j][j] = a[j];
			else{
				dp[j][i+j] = max(a[i+j] - dp[j][i+j-1], a[j] - dp[j+1][i+j]);
			}
		}
	}

	cout << setprecision(20) << dp[0][n-1];

}


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

using namespace std;

typedef long long int ll;

const ll MAXN = 1e5 + 5;

vector < ll > parent(MAXN), sz(MAXN);

void make_set(ll u){
  parent[u] = u;
  sz[u] = 1;
}

ll find_set(ll u){
  if(u == parent[u]) return u;
  return parent[u] = find_set(parent[u]);
}

void union_sets(ll u, ll v){
  u = find_set(u);
  v = find_set(v);
  if(u != v){
    if(sz[u] > sz[v]) swap(u, v);
    parent[u] = v;
    sz[v] += sz[u];
  }
}

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

  ll n, m;
  cin >> n >> m;
  vector < ll > p(n + 1), pos(n + 1);
  for(int i = 1; i <= n; i++){
    cin >> p[i];
    pos[p[i]] = i;
    make_set(i);
  }
  for(int i = 0; i < m; i++){
    ll u, v;
    cin >> u >> v;
    union_sets(u, v);
  }

  ll ans = 0;
  for(int i = 1; i <= n; i++){
    if(find_set(i) == find_set(pos[i])){
      pos[p[i]] = pos[i];
      pos[i] = i;
      swap(p[i], p[pos[i]]);
      ans++;
    }
  }

  cout << ans << '\n';
}


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

int main() {
long int W,H;
  cin >> W>>H;
  
  if(W==1||H==1){
    cout<<1<<endl;
    
    return 0;
  }
  
  if(W*H%2==0){
cout<<W*H/2<<endl;

}
  if(W*H%2>0){
cout<<W*H/2+1<<endl;

}
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>

#define for0(i, N)    for (int i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (int i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (int i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (int i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (int i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (int i = (x), a = 0; a < (N);  \
                              i = (i + 1) % (N), ++a)

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;


int main(void){
    cin.tie(0); ios::sync_with_stdio(false);
    string s, t, u;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    cin >> u;

    if (s == u) --a;
    else --b;

    cout << a << " " << b;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int first = n % 10;
        switch(first){
            case 0:
                System.out.println("pon");
                break;
            case 1:
                System.out.println("pon");
                break;
            case 2:
                System.out.println("hon");
                break;
            case 3:
                System.out.println("bon");
                break;
            case 4:
                System.out.println("hon");
                break;
            case 5:
                System.out.println("hon");
                break;
            case 6:
                System.out.println("pon");
                break;
            case 7:
                System.out.println("hon");
                break;
            case 8:
                System.out.println("pon");
                break;
            case 9:
                System.out.println("hon");
                break;
            default:
                break;
        }
    }
}


Measured memory_bytes: 35544
#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456;
int f[maxn], v[maxn];
int main(){
  int n; cin >> n;
  for(int i = 1; i <= n; i++) cin >> f[i];
  int now = 1;
  v[2] = 1;
  int ans = 0;
  while(!v[now]){
  	v[now] = 1;
    now = f[now];
    ans++;
  }
  if(now == 2) cout << ans << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s.at(k - 1) = tolower(s.at(k - 1));
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<queue>
#include<cstdio>

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

using namespace std;

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

int h,w;
char B[10][10];

int ub;
bool dfs(int t){
	bool end=true;
	rep(i,h) rep(j,w) if(B[i][j]!=B[0][0]) { end=false; break; }
	if(end) return true;

	if(t==ub) return false;

	char B0[10][10],c0=B[0][0];
	rep(i,h) rep(j,w) B0[i][j]=B[i][j];

	queue< pair<int,int> > Q;
	rep(ic,3){
		char c="RGB"[ic];
		if(c==c0) continue;

		B[0][0]=c;
		Q.push(make_pair(0,0));
		while(!Q.empty()){
			int y=Q.front().first,x=Q.front().second; Q.pop();
			rep(k,4){
				int yy=y+dy[k],xx=x+dx[k];
				if(0<=yy && yy<h && 0<=xx && xx<w && B[yy][xx]==c0){
					B[yy][xx]=c;
					Q.push(make_pair(yy,xx));
				}
			}
		}

		if(dfs(t+1)) return true;

		rep(i,h) rep(j,w) B[i][j]=B0[i][j];
	}

	return false;
}

int main(){
	for(;scanf("%d%d",&w,&h),w;){
		rep(i,h) rep(j,w) scanf(" %c",B[i]+j);

		for(ub=0;!dfs(0);ub++);

		printf("%d\n",ub);
	}

	return 0;
}

Measured memory_bytes: 824
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> istream& operator>>(istream& is, vector<T>& v);
template<class T> ostream& operator<<(ostream& os, vector<T> const& v);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream&, const tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream& os, const tuple<T...>& t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream& operator<<(ostream& os, const tuple<T...>& t){ _ot<0>(os, t); return os; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _it(istream&, tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _it(istream& is, tuple<T...>& t){ is >> get<n>(t); _it<n+1>(is, t); }
template<class...T> istream& operator>>(istream& is, tuple<T...>& t){ _it<0>(is, t); return is; }
template<class T> istream& operator>>(istream& is, vector<T>& v){ rep(i,v.size()) is >> v[i]; return is; }
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif

int K;
double R,L,P,E,T;

double eps = 1e-10;
double solve(double l, double r, double k){
    if(T-E < l+eps && r < T+E+eps) return 1.0;
    if(r < T-E || T+E < l) return 0.0;
    double h=(l+r)/2;
    if(k==K){
        if(T-E < h+eps && h < T+E+eps) return 1.0;
        else return 0.0;
    }
    if(h+eps > T){
        return P*solve(h,r,k+1) + (1.0-P)*solve(l,h,k+1);
    } else {
        return P*solve(l,h,k+1) + (1.0-P)*solve(h,r,k+1);
    }
}

int main(){
    while(cin>>K>>R>>L){
        cin >> P >> E >> T;
        auto ans = solve(R,L,0);
        printf("%.10lf\n", ans);
    }
}

Measured memory_bytes: 1240
hog1=list(map(int,input().split()))
hog2=list(map(int,input().split()))
hog3=list(map(int,input().split()))

for i in range(100):
  if(hog1[0]!=0 and hog1[1]!=0 and hog1[2]!=0):
    hog1[0]-=1
    hog1[1]-=1
    hog1[2]-=1
  if(hog2[0]!=0 and hog2[1]!=0 and hog2[2]!=0):
    hog2[0]-=1
    hog2[1]-=1
    hog2[2]-=1
  if(hog3[0]!=0 and hog3[1]!=0 and hog3[2]!=0):
    hog3[0]-=1
    hog3[1]-=1
    hog3[2]-=1
  if(hog1[0]!=0 and hog2[0]!=0 and hog3[0]!=0):
    hog1[0]-=1
    hog2[0]-=1
    hog3[0]-=1
  if(hog1[1]!=0 and hog2[1]!=0 and hog3[1]!=0):
    hog1[1]-=1
    hog2[1]-=1
    hog3[1]-=1
  if(hog1[2]!=0 and hog2[2]!=0 and hog3[2]!=0):
    hog1[2]-=1
    hog2[2]-=1
    hog3[2]-=1

ans=sum(hog1)+sum(hog2)+sum(hog3)
if(ans==0):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

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

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
    ins(A, B);

    if (A.size() < B.size())
        out("LESS");
    else if (A.size() > B.size())
        out("GREATER");
    else if (A < B)
        out("LESS");
    else if (A == B)
        out("EQUAL");
    else
        out("GREATER");
}


Measured memory_bytes: 3652
import sys

input = sys.stdin.readline

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

a = {int(input()) for _ in range(m)}

count = 0

stair = [0] * (n + 1)

for index, value in enumerate(stair):
    if index == 0:
        stair[index] = 1
        continue
    if index == 1:
        if index - 1 not in a:
            stair[index] += stair[index-1]
        continue

    if index - 1 not in a:
        stair[index] += stair[index - 1]
        stair[index] %= 1000000007
    if index - 2 not in a:
        stair[index] += stair[index - 2]
        stair[index] %= 1000000007

print(stair[len(stair) - 1])


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

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

  cout << N*N-A << endl;
  return 0;
}

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

using namespace std;

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void milkshake() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int x = a[0];
  for(int i = 1; i <= n; i++) {
    if(x == 2) drop(i);
    x = a[x-1];
  }
  cout << -1 << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt=1;
  //cin >> tt;
  while(tt--) milkshake();

  return 0;
}


Measured memory_bytes: 4012
#include <iostream>
#include <string>
#include <set>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    string str;
    cin >> str;
    int ans = 0;
    for(int i = 1; i < n; i++){
        string f = str.substr(0, i);
        string s = str.substr(i);
        set<char> cnt;
        for(auto&& i : f){
            if(count(begin(s), end(s), i)){
                cnt.insert(i);
            }
        }
        ans = max<int>(ans, cnt.size());
    }
    cout << ans << "\n";
}

Measured memory_bytes: 384
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*, fastout};
use superslice::*;


fn main() {
    input! {
        k: usize, s: String,
    }
    if s.len() <= k {
        println!("{}", s);
    } else {
        let ss = &s[..k];
        println!("{}...", ss);
    }
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
typedef long long ll;
#define matrix vector<vector<ll>>
using namespace std;
const ll mod=1e9+7;
void matexp(matrix graph,matrix &ans,ll k);
void multiply(matrix &a,matrix b);

int main()
{
    ll n,k;
    cin>>n>>k;
    matrix graph(n,vector<ll>(n));
    for(ll i=0;i<n;i++)
        for(ll j=0;j<n;j++)
            cin>>graph[i][j];
    
    matrix ans(n,vector<ll>(n,0));
    for(ll i=0;i<n;i++)
        ans[i][i]=1;

    //ans=graph^k
    matexp(graph,ans,k);

    ll answer=0;
    for(ll i=0;i<n;i++)
        for(ll j=0;j<n;j++)
            answer=(answer+ans[i][j])%mod;
        
    cout<<answer<<endl;

}
void matexp(matrix graph,matrix &ans,ll k)
{
    //set ans=Identity matrix when k=0
    if(k==0)
        return;
    //ans=graph^(k/2)
    matexp(graph,ans,k/2);
    //ans=graph^k if k is even otherwise ans=graph^(k-1)
    multiply(ans,ans);
    if(k%2!=0)
        multiply(ans,graph);
}
void multiply(matrix &a,matrix b)
{
    ll n=a.size();
    matrix ans(n,vector<ll>(n));
    for(ll i=0;i<n;i++)
        for(ll j=0;j<n;j++)
            for(ll k=0;k<n;k++)
                ans[i][j]=(ans[i][j]+(a[i][k]*b[k][j])%mod)%mod;

    for(ll i=0;i<n;i++)
        for(ll j=0;j<n;j++)
            a[i][j]=ans[i][j];
    
}



Measured memory_bytes: 4796
n=int(input())
A=list(int(i) for i in input().split())
# n=6
# A=[30,10,60,10,60,50]
dpmincost=[0 for i in range(n)]
dpmincost[0]=0
dpmincost[1]=abs(A[1]-A[0])
for i in range(2,n):
    dpmincost[i]=min(dpmincost[i-1]+abs(A[i]-A[i-1]),dpmincost[i-2]+abs(A[i]-A[i-2]))
print(dpmincost[-1])


Measured memory_bytes: 53448
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  double ans;
  double anseven;
  cin >> N;
  ans = ((N+1.0)/2.0)/(1.0*N);
  anseven = (N/2)/(1.0*N);
  if(N%2==1){
    cout << fixed << setprecision(8);
    cout << ans << endl;
  }
  else{
    cout << fixed << setprecision(8);
    cout << anseven << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

int main()
{
    int a,n;
    cin >> n >> a;
    if (a - (n % 500) >= 0) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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




int main(){
    int AB,BC,CA;
    cin >> AB >> BC >> CA;
    cout << (AB * BC / 2) << endl;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
ls = []
yside = {-1,-1,-1,0,0,1,1,1}
xside = {-1,0,1,-1,1,-1,0,1}
side = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
for i in range(h):
  ls.append(list(input()))
for i in range(h):
  ans2 = ""
  for j in range(w):
    ans = 0
    if ls[i][j] == "#":
      ans2 += "#"
    else:
      for k in range(8):
        if i+side[k][0] < 0 or j+side[k][1] < 0 or h <=i+side[k][0] or w <= j+side[k][1]:
          continue
        else:
          ans += (1 if ls[i+side[k][0]][j+side[k][1]] == "#" else 0)
      ans2 += str(ans)
  print(ans2)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef complex<int> cli;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr> PQ;

int main(){
	int now=0;
	string s;
	cin >> s;
	REP(i,s.size()){
		if(now==0 && s[i]=='C') now++;
		if(now==1 && s[i]=='F') now++;
	}
	cout << ((now==2)?"Yes":"No") << endl;

	return 0;
}

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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

LL dp[3005][3005];
const LL p = 998244353;

LL binpow(LL n, LL k) {
  if (k == 0) {
    return 1;
  }

  if (k & 1) {
    return (n * binpow(n, k - 1)) % p;
  }

  LL tmp = binpow(n, k / 2);
  return (tmp * tmp) % p;
}

LL inv(LL n) { return binpow(n, p - 2); }

int main() {
  _upgrade;
  int n, s;
  cin >> n >> s;
  vector<int> A(n);
  for (auto &a : A) {
    cin >> a;
  }

  LL inv_of_two = inv(2);

  dp[0][0] = binpow(2, n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % p;

      if (j + A[i] <= s) {
        dp[i + 1][j + A[i]] = (dp[i + 1][j + A[i]] + dp[i][j] * inv_of_two) % p;
      }
    }
  }
  cout << dp[n][s] << "\n";
  return 0;
}

Measured memory_bytes: 74060
#include <bits/stdc++.h>
#define X 5010
#define O 1000000007
#define L long long
using namespace std;
int e[X],o[X<<1],K[X<<1],t=0;inline void $(int u,int v){
K[t]=e[u],o[t]=v,e[u]=t++;K[t]=e[v],o[t]=u,e[v]=t++;}int n,z[X],q[X],r,s;void G(int x,int fa){z[x]=1;
for(int i=e[x];~i;i=K[i]){if(o[i]==fa)continue;G(o[i],x);z[x]+=z[o[i]];q[x]=max(q[x],z[o[i]]);}q[x]=max(q[x],n-z[x]);
if(q[x] < q[r])r=x,s=1;else if(q[x]==q[r])s=2;}L F[X],V[X],f[2][X];inline L fpow(L x,int p){L r=1;while(p){
if(p & 1)(r*=x)%=O;(x*=x)%=O;p>>=1;}return r;}inline L C(int n,int m){return F[n]*V[m]%O*V[n-m]%O;}int main(){F[0]=1;
for(int i=1;i < X;i++)F[i]=F[i-1]*i%O;V[X-1]=fpow(F[X-1],O-2);for(int i=X-1;i;i--)V[i-1]=V[i]*i%O;cin>> n;memset(e,-1,sizeof(e));for(int i=1;i < n;i++){
int u,v;cin>>u>>v;$(u,v);}q[r=0]=n+ 1;G(1,0);if(s>1){cout<<F[z[1]>> 1]*F[z[1]>> 1]%O<<endl;return 0;}G(r,0);
int now=0,pre=1;f[pre][0]=1;for(int i=e[r];~i;i=K[i]){memset(f[now],0,sizeof(f[now]));for(int j=0;j <=n;j++){
for(int k=0;k <=z[o[i]];k++)(f[now][j+ k]+=f[pre][j]*C(z[o[i]],k)%O*C(z[o[i]],k)% O*F[k]%O)%=O;}swap(pre,now);}L ans=0;
for(int i=0;i <=n;i++)(ans -=f[pre][i]*(i & 1 ? 1 : -1)*F[n-i])%=O;cout<<((ans+=O)%=O)<<endl;return 0;}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,H,N,a,b;
  cin>>H>>N;
  vec v(H+1,inf);
  v[0]=0;
  rep(i,N){
    cin>>a>>b;
    rep(j,H+1){
      chmin(v[min(j+a,H)],v[j]+b);
    }
  }
  print(v[H]);
  return 0;
}

Measured memory_bytes: 384
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n;
  cin >> n;

  cout << (800 * n) - ((n / 15) * 200);



  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

Measured memory_bytes: 256
//P : Independent Set (Atcoder)
#pragma GCC target("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>

#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>

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

const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;
const int N = 1e5 + 100;
vi adj[N];
ll dp[N][2];
void dfs(int src = 0 ,int par = 0){
    dp[src][0] = dp[src][1] = 1;
    for(int i : adj[src]){
        if(i == par) continue;
        dfs(i , src);
        dp[src][1] *= (dp[i][0] % MOD);
        dp[src][0] *= (dp[i][1] + dp[i][0]) % MOD;
        dp[src][1] %= MOD;
        dp[src][0] %= MOD;
    }
    
    return ;
}

signed main(){

#ifndef ONLINE_JUDGE
	//freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    int n;
    cin >> n;
    
    fo(i , n - 1){
        int u , v;
        cin >> u >> v;
        u--;--v;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    
    dfs();

    cout << (dp[0][0] + dp[0][1]) % MOD << '\n';


    return 0;

}



Measured memory_bytes: 18884
#include<iostream>
using namespace std ;
typedef long long ll ;
ll dp[105][100005],weight[105],value[105],n,cap;
ll knap(ll idx,ll w)
{
  if(idx>n){return 0;}
  if(dp[idx][w]!=0){return dp[idx][w];}
  ll p1=0,p2=0;
  if(w+weight[idx]<=cap)
  {
      p1 = value[idx]+knap(idx+1,w+weight[idx]);
  }
  p2=knap(idx+1,w);
  return dp[idx][w]=max(p1,p2);
}
int main()
{
    cin >> n >> cap ;
    for(int i=1;i<=n;i++){ll x,y ; cin >> x >> y ; weight[i]=x;value[i]=y;}
    ll ans = knap(1,0);
    cout << ans << endl;
}


Measured memory_bytes: 78080