akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}


int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, a0, b0;
  cin >> n >> a0 >> b0;
  ll l = a0, r = a0;
  ll c = 0;
  priority_queue<ll> neg;
  neg.push(0);
  priority_queue<ll, vector<ll>, greater<ll>> pos;
  pos.push(0);
  while (--n) {
    int a1, b1;
    cin >> a1 >> b1;
    l -= b1 - a1;
    r += b0 - a0;
    a0 = a1;
    b0 = b1;
    if (l <= a0 && a0 <= r) {
      neg.push(neg.top() + a0 - l);
      pos.push(pos.top() + a0 - r);
      l = r = a0;
    } else if (a0 < l) {
      neg.push(neg.top() + a0 - l);
      neg.push(neg.top() + a0 - l);
      pos.push(pos.top() + l - r);
      c += l - a0;
      r = l;
      l -= neg.top();
      neg.pop();
      l += neg.top();
    } else {
      pos.push(pos.top() + a0 - r);
      pos.push(pos.top() + a0 - r);
      neg.push(neg.top() + r - l);
      c += a0 - r;
      l = r;
      r -= pos.top();
      pos.pop();
      r += pos.top();
    }
  }
  cout << c;

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;


int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> v;
    int i, elm;
    for (i=0; i<n; i++) {
        scanf("%d", &elm);
        v.push_back(elm);
    }

    make_heap(v.begin(), v.end());


    for (i=0; i<m; i++) {
        pop_heap(v.begin(), v.end());
        v[n-1] /= 2;
        push_heap(v.begin(), v.end()); 
    }

    long long int ans = 0;
    for (i=0; i<n; i++) {
        ans += v[i];
    } 
    
    cout << ans << endl;
}

Measured memory_bytes: 892
#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>

using namespace std;

int main(int argc, char *argv[]) {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int t;
		cin >> t;
		n -= t;
	}
	cout << max(-1, n) << endl;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<iostream>
using namespace std;
int main() {
    int Q;
    scanf("%d",&Q);
    for(int i = 0; i < Q; i++) {
        int c,a,n;
        scanf("%d%d%d",&c,&a,&n);
        int ans = 0;
        while(c > 0 && a > 0 && n > 0) {
            c--; a--; n--;
            ans++;
        }
        while(c > 1 && a > 0) {
            c -= 2; a--;
            ans++;
        }
        while(c > 2) {
            c -= 3;
            ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1188
#include <cstdio>
#include <vector>
#include <string>
using namespace std;

int m, n;
vector<string> v;
vector<string> w;
int c;
char x[4] = "JOI";
int ans;

int count(int p, int q){
	int z = 0;
	for(int i=0; i<2; i++){
		for(int j=0; j<2; j++){
			if(0 <= p+i && p+i+1 <= m-1 && 0 <= q+j && q+j+1 <= n-1){
				bool b = true;
				for(int k=0; k<2; k++)
					for(int l=0; l<2; l++)
						if(v[p+i+k][q+j+l] != w[k][l]) b = false;
				if(b) z++;
			}
		}
	}
	return z;
}

int main(){
	scanf("%d %d", &m, &n);
	for(int i=0; i<m; i++){
		char t[n+1];
		scanf("%s", t);
		v.push_back(t);
	}
	for(int i=0; i<2; i++){
		char t[3];
		scanf("%s", t);
		w.push_back(t);
	}

	for(int i=0; i<m-1; i++){
		for(int j=0; j<n-1; j++){
			bool b = true;
			for(int k=0; k<2; k++)
				for(int l=0; l<2; l++)
					if(v[i+k][j+l] != w[k][l]) b = false;
			if(b) c++;
		}
	}

//	printf("%d\n", ans);

	for(int i=0; i<m; i++){
		for(int j=0; j<n; j++){
			int a = count(i-1, j-1);
			for(int k=0; k<3; k++){
				char y[2];
				y[0] = v[i][j];
				v[i][j] = x[k];
				int b = count(i-1, j-1);
				ans = max(ans, c + b - a);
				v[i][j] = y[0];
			}
		}
	}

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

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int n,m,q;
vector<ll> a,b,c,d;

ll dfs(int i, vector<int> A) {
  if (i == n) {
    ll res = 0;
    rep(k,q) { //check
      if (A[b[k]] - A[a[k]] == c[k]) res += d[k];
    }
    return res;
  }
  ll res = 0;
  for (int j = A[i-1]; j <= m; ++j) {
    A[i] = j;
    chmax(res, dfs(i+1, A));
  }
  return res;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  cin >> n >> m >> q;
  a = vector<ll>(q);
  b = vector<ll>(q);
  c = vector<ll>(q);
  d = vector<ll>(q);
  rep(i,q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--; b[i]--;
  }
  ll ans = 0;
  for (int i = 1; i <= m; ++i) {
    vector<int> A(n);
    A[0] = i;
    chmax(ans, dfs(1, A));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3660
#include <iostream>

using namespace std;

int main(){
    int a, b, n=0, i, j;
    cin >> a >> b;
    for (i=1; i<=a; i++){
        for (j=1; j<=12; j++){
            if (i==a){
                if (j > b) break;
            }
            if (i==j) n++;
        }
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
using namespace std;
int main()
{
  int N,count=0;
  vector<int> A(111111),Z(111111);
  cin>>N;
  rep(i,N){cin>>A.at(i);Z.at(A.at(i)-1)=i+1;}
  rep(i,N){cout<<Z.at(i)<<endl;}
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
const int N=533333;
int n,V,vs[20],vp=0,mx,xs[N],f1[N],f2[N],ls[20][N],rs[20][N],ml[N];
void maxs(int&a,int b){if(a<b)a=b;}
void mins(int&a,int b){if(a>b)a=b;}
int main(){
	scanf("%d%d",&n,&V);
	for(int i=1;i<=n;++i)scanf("%d",xs+i);
	for(int a=V>>1;vs[vp++]=a;a>>=1);
	mx=1<<vp,vs[vp]=V;
	for(int z=0;z<=vp;++z){
		rs[z][n+1]=n,ls[z][0]=1;
		for(int i=1,j=1,x=vs[z];i<=n;i=j){
			for(++j;j<=n&&xs[j]-xs[j-1]<=x;++j);
			for(int k=i;k<j;++k)ls[z][k]=i,rs[z][k]=j-1;
		}
	}
	for(int i=0;i<mx;++i)f2[i]=n+1;
	for(int i=1;i<mx;++i){
		for(int j=0;j<vp;++j)if(i>>j&1){
			maxs(f1[i],rs[j][f1[i-(1<<j)]+1]);
			mins(f2[i],ls[j][f2[i-(1<<j)]-1]);
		}
	}
	for(int i=0;i<mx;++i)maxs(ml[f2[mx-1-i]-1],f1[i]+1);
	for(int i=0;i<=n;++i)maxs(ml[i+1],ml[i]);
	for(int i=1;i<=n;++i)puts(ml[rs[vp][i]]>=ls[vp][i]?"Possible":"Impossible");
	return 0;
}

Measured memory_bytes: 89472
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N);
    REP(i,N) cin>>A[i];
    sort(ALL(A));
    ll l=0;
    ll r=INF;
    while(r-l>1){
        ll x=(l+r)/2;
        ll cnt=0;
        REP(i,N){
            cnt+=(A[i]-1)/x;
        }
        if(cnt>K){
            l=x;
        }else{
            r=x;
        }
    }
    cout<<r<<endl;
}

Measured memory_bytes: 4744
N = int(input())
s = []
t = []
for i in range(N):
    stmp, ttmp = input().split(' ')
    s.append(stmp)
    t.append(int(ttmp))
X = input()

sumtime = 0
found = False
for i in range(N):
    if found == True:
        sumtime += t[i]
    if s[i] == X:
        found = True
print(sumtime)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    if(y % 2== 0 && y >= 2 * x && y <= 4 * x){
    	cout<< "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    map<string, int> ans;
    ans["SUN"] = 7;
    ans["MON"] = 6;
    ans["TUE"] = 5;
    ans["WED"] = 4;
    ans["THU"] = 3;
    ans["FRI"] = 2;
    ans["SAT"] = 1;

    string s;
    cin >> s;

    cout << ans[s] << endl;

    return 0;
}


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

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

using namespace std;

const int INF=1<<29;

int n;
bool adj[50][50];

int dp[50][50][150];
int dfs(int a,int b,int t){
	if(a==b)   return 0;
	if(t==3*n) return INF;

	if(~dp[a][b][t]) return dp[a][b][t];

	int res;
	if(t%2==0){
		res=0;
		rep(u,n) if(adj[a][u]) res=max(res,dfs(u,b,t+1));
	}
	else{
		res=INF;
		rep(u,n) if(adj[b][u]) res=min(res,dfs(a,u,t+1)+1);
	}
	return dp[a][b][t]=res;
}

int main(){
	int T; scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		rep(u,n) rep(v,n) {
			int b; scanf("%d",&b);
			adj[u][v]=(u==v?true:b);
		}
		int a0,b0; scanf("%d%d",&a0,&b0);

		rep(u,n) rep(v,n) rep(t,3*n) dp[u][v][t]=-1;

		int ans=dfs(a0,b0,0);
		if(ans<INF) printf("%d\n",ans);
		else        puts("infinity");
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <list>
#include <string>
#include <map>
#include <numeric>
#include<unordered_map>
#include<queue>
#include <set>
#include<unordered_set>
#include <bitset>
#include <cmath>
#include <functional>
using namespace std;
int main() {
	ifstream fin("input.txt");
	int A, B, C;
	cin >> A >> B >> C;
	if (A != B && A != C)
	{
		cout << A << endl;
		return 0;

	}
	if (B != A && B != C)
	{
		cout << B << endl;
		return 0;
	}
	if (C != A && C != B)
	{
		cout << C << endl;
		return 0;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;
template< typename T = long long >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}
template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

int main(){
  int x;
  cin>>x;
  cout<<10-x/200<<endl;
}


Measured memory_bytes: 3572
import collections
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
count = collections.Counter(A)
count = count.most_common()
ans = 0
for i in range(len(count)):
    if count[i][1] % 2 == 1:
        ans += 1

print(ans)


Measured memory_bytes: 21244
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
int a[3][3];

int main(){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    int p=a[0][1]-a[0][0];
    int q=a[0][2]-a[0][1];
    if(p!=a[1][1]-a[1][0] || p!=a[2][1]-a[2][0] || q!=a[1][2]-a[1][1] || q!=a[2][2]-a[2][1]){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int x; cin>>x;
    int ans=1;
    for(int i=2;i*i<=x;i++){
        int cnt=i;
        while(cnt*i<=x){
            cnt*=i;
            ans=max(ans,cnt);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	int n;
	std::cin >> n;
	int pown = std::pow(2,n);
	std::vector<int> a(pown);
	rep(i,pown) std::cin >> a[i];
	for(int i=0;i*2<a.size();i++) {
		if(i*2+1>a.size()-1) break;
		a.emplace_back(std::abs(a[2*i]-a[2*i+1]));
	}
	print(a.back());
	return 0;
}


Measured memory_bytes: 6016
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // min, max, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define rep(i,n) rep1(i,0,n)
#define rep1(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
const double PI = acos(-1);
int main(){
    int n, m;
    cin >> n >> m;
    int d[1000000];
    rep(i,m){
        int l,r;
        cin >> l >> r;
        l--;
        d[l]++;
        d[r]--;
    }
    rep1(i, 1, n + 10) d[i] += d[i - 1];
    int cnt = 0;
    rep(i,n+10){
        if(d[i]==m)
            cnt++;
    }
    cout << cnt << endl;
}

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

int main (){
    int N, M, K;
    cin >> N >> M >> K;
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= M; j++)
        {
            int sum = N * j + M * i - 2 * i * j;
            if (sum == K)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
        
    }
    cout << "No" << endl;
 
    return 0;
    
}

Measured memory_bytes: 256
x, n = map(int, input().split())
p = list(map(int, input().split()))

l = [i - x for i in p]
m = [0]
for i in range(1, 101):
    m.append(-i)
    m.append(i)
for i in range(201):
    if (m[i] in l) == True:
        continue
    if (m[i] in l) == False:
        print(x + m[i])
        break

Measured memory_bytes: 9100
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
const ll MOD = 1000000007;

int main(){
    //input
    int n;
    scanf("%d", &n);
    char c[202020];
    scanf("%s", c);

    //solve
    ll ans = MOD;
    ll tmp = 0;
    rep(i, n) if(c[i] == 'W') tmp++;
    ans = min(tmp, ans);
    //printf("%lld\n", tmp);
    tmp = 0;
    rep(i, n) if(c[i] == 'R') tmp++;
    ans = min(tmp, ans);
    //printf("%lld\n", tmp);
    tmp = 0;
    int left = 0, right = n-1;
    while(right - left > 0){
        while(left < n && c[left] != 'W') left++;
        while(right >= 0 && c[right] != 'R') right--;
        if(right > left) tmp++;
        right--;
        left++;
    }
    ans = min(tmp, ans);
    //printf("%lld\n", tmp);

    //output
    printf("%lld\n", ans);
}

Measured memory_bytes: 1928
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

VL mul(const VL &a, const VL &b) {
  int n = a.size();
  VL ret(2 * n - 1);
  REP(i, 0, n) {
    REP(j, 0, n) {
      ret[i + j] += a[i] * b[j];
      ret[i + j] %= mod;
    }
  }
  for (int i = n - 2; i >= 0; --i) {
    ret[i] += ret[i + n];
    ret[i] %= mod;
  }
  return VL(ret.begin(), ret.begin() + n);
}


int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  VL a(n, 0);
  VL sum(n, 0);
  a[0] = 1;
  sum[0] = 1;
  REP(et, 0, m) {
    int p;
    cin >> p;
    a[p % n] += 1;
  }
  VL cur(a);
  while (k > 0) {
    if (k % 2) {
      sum = mul(sum, cur);
    }
    cur = mul(cur, cur);
    k /= 2;
  }
  REP(i, 0, n) {
    cout << sum[i] << "\n";
  }
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) (find(all(v),x)!=v.end())
#define incls(s,c) (s.find(c)!=string::npos)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; cin >> x; return x;}
inline ll lin() { ll x; cin >> x; return x;}
inline char chin() { char x; cin >> x; return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n = in();
  vi a(n);
  rep(i,n) cin >> a[i];
  vector<bool> c(40001);
  rep(b,1<<n) {
    int sum = 0;
    rep(i,n) if (bit(b,i)) {
      sum += a[i];
    }
    c[sum] = true;
  }
  int q = in();
  while (q--) {
    int m = in();
    if (c[m]) puts("yes");
    else puts("no");
  }
  return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>
#define N 3
int sum[N][N] =
{
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 0}
};
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };

int num(int gum[N][N]) {
    for (int a = 0; a < N; ++a) {
        for (int b = 0; b < N; ++b) {
            if (gum[a][b] != sum[a][b])
                return 0;
        }
    }
    return 1;
}

int xu(int gum[N][N], int x, int y, int v, int d, int e) {
    if (num(gum))
        return d;
    if (d > e)
        return -1;
    for (int i = 0, fan; i < 4; ++i) {
        int x2 = x + dx[i];
        int y2 = y + dy[i];
        if (x2 < 0 || x2 > 2 || y2 < 0 || y2 > 2 || (i + 2) % 4 == v)
            continue;
        gum[y][x] = gum[y2][x2];
        gum[y2][x2] = 0;
        if ((fan = xu(gum, x2, y2, i, d + 1, e)) > 0)
            return fan;
        gum[y2][x2] = gum[y][x];
        gum[y][x] = 0;
    }
    return -1;
}

int main() {
    int gum[N][N], x, y;
    for (int a = 0; a < N; ++a) {
        for (int b = 0; b < N; ++b) {
            scanf("%d", &gum[a][b]);
            if (gum[a][b] == 0) {
                y = a;
                x = b;
            }
        }
    }

    int fan;
    for (int a = 1; a < 50; ++a) {
        if ((fan = xu(gum, x, y, -1, 0, a)) >= 0) {
            break;
        }
    }
    printf("%d\n", fan);

    return 0;
}



Measured memory_bytes: 2112
n = int(input())

xu = [0]*n

for i in range(n):
  xu[i] = input().split()
  
ans = []
#print(xu)
for i in range(n):
  if(xu[i][1] == "BTC"):
    ans.append(float(xu[i][0])*380000.0)
  else:
    ans.append(int(xu[i][0]))
print(sum(ans))

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>
#include <chrono>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const double EPS = 1e-9;

const int MAX = 1e5 + 10;
int N;
vector<int> a;

int main() {
    cin >> N;
    int pre = -1;
    for (int i = 0; i < N; ++i) {
        int buf; cin >> buf;
        if (buf != pre) {
            a.emplace_back(buf);
            pre = buf;
        }
    }
    N = a.size();
    int ans = 1;
    bool up = false, start = true;
    for (int i = 1; i < N; ++i) {
        if (start) {
            up = a[i - 1] < a[i];
            start = false;
        } else {
            if (up ^ a[i - 1] < a[i]) {
                ++ans;
                start = true;
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;

int n, a[200005], siz[200005], cnt[400005];
long long ans[200005];
vector <int> edge[200005];
stack <int> stk[200005];

long long f(int x) {
	return 1LL * x * (x + 1) / 2;
}

void calc(int id, int p) {
	siz[id] = 1;
	for (int i = 0; i < edge[id].size(); i++) {
		int to = edge[id][i];
		if (to == p) continue;
		calc(to, id);
		siz[id] += siz[to];
	}
}

void dfs(int id, int p) {
	int before = stk[a[id]].top();
	cnt[before] -= siz[id];
	
	stk[a[id]].push(id);
	
	for (int i = 0; i < edge[id].size(); i++) {
		int to = edge[id][i];
		if (to == p) continue;
		cnt[id] = siz[to];
		dfs(to, id);
		ans[a[id]] += f(cnt[id]);
	}
	
	stk[a[id]].pop();
}

int main() {
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	
	for (int i = 1; i <= n; i++) {
		cnt[n - 1 + i] = n;
		stk[i].push(n - 1 + i);
	}
	
	calc(0, -1);
	dfs(0, -1);
	
	for (int i = 1; i <= n; i++) {
		ans[i] += f(cnt[n - 1 + i]);
		printf("%lld\n", f(n) - ans[i]);
	}
}


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

using namespace std;

typedef vector<int> vi;

#define PB push_back
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define all(a) a.begin(),a.end()

int P[1001];

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

	int N, M;
	
	while (cin >> N >> M, N || M) {
		rep1(i, N) cin >> P[i];

		vi A;

		A.PB(0);

		rep(i, N + 1) rep(j, N + 1) A.PB(P[i] + P[j]);

		sort(all(A));

		int ma = 0;

		rep(i, A.size()) {
			int tmp;

			int pos = upper_bound(all(A), M - A[i]) - A.begin();

			if (pos == A.size()) {
				tmp = A.back();
			} else if (pos - 1 == -1) {
				tmp = 0;
			} else {
				tmp = A[pos - 1];
			}

			if (A[i] + tmp <= M) {
				ma = max(ma, A[i] + tmp);
			}
		}

		cout << ma << endl;
	}
}

Measured memory_bytes: 9204
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		boolean[] isPrime = new boolean[10001];
		Arrays.fill(isPrime, true);
		isPrime[0]=isPrime[1]=false;
		for(int i = 2; i < isPrime.length; i++){
			if(isPrime[i]){
				for(int j = i+i; j < isPrime.length; j+=i){
					isPrime[j]=false;
				}
			}
		}
		while(true){
			int n = cin.nextInt();
			if(n==0){
				break;
			}
			for(int i = n; i >= 0; i--){
				if(isPrime[i] && isPrime[i-2]){
					System.out.println((i-2)+" " + i);
					break;
				}
			}
		}

	}

}

Measured memory_bytes: 12000
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int a, b;
	while (true) {
		cin >> a>>b;
		if (a == 0&&b==0) { return 0; }
		cout << min(a, b) << " " << max(a, b) << endl;
	}
    return 0;
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)

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

    reverse(b.begin(), b.end());
    int l = -1, r = N;
    for (int i = 0; i < N && l == -1; i++)
    {
        if (a[i] == b[i])
            l = i;
    }

    for (int i = N - 1; i >= 0 && r == N; i--)
    {
        if (a[i] == b[i])
            r = i;
    }

    if (!(l == -1 && r == N))
    {
        int next = 0;
        for (int i = l; i <= r; i++)
        {
            while (next < N && (a[i] == b[next] || a[next] == b[i]))
                next++;
            if (next == N)
            {
                cout << "No\n";
                return 0;
            }
            swap(b[i], b[next]);
            next++;
        }
    }

    cout << "Yes\n";
    for (int i = 0; i < N; i++)
        cout << b[i] << "\n";
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

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

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

  ll N;
  cin >> N;

  cout << N * (N-1)/ 2 << endl;

  return 0;
}



Measured memory_bytes: 256
/*
 *  Created on: 22-December-2019
 *      Author: ankur314
 */
#include <bits/stdc++.h>
#define lli long long int
#define li long int
#define db double
#define ldb long double
#define vr vector
#define it iterator
#define fi(i,a,n) for(int i=a;i<n;i++)
#define fli(i,a,n) for(long int i=a;i<n;i++)
#define flli(i,a,n) for(long long int i=a;i<n;i++)
#define pb(n) push_back(n)
#define ppf() pop_front()
#define pii pair<int,int>
#define MOD 1000000007
#define INF 1000000005
 
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define debug4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"
 
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    int n; cin>>n;
    string s, t;
    cin>>s>>t;
    string ans = "";
    fi(i,0,n) 
    {
    	ans += s[i];
    	ans += t[i];
    }
    cout<<ans;
    return 0;
}   

Measured memory_bytes: 256
//Author- Vaibhav singh
//will be expert soon 
// *#####################################################################################*
#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define re return 0;
// *#######################################################################################*
// *#########################################################################################*
    //      ll ans=0,b[5000005]={0},a[5000005],i,n,x=0;                
   //ll k,n,i;

    int main()
    {
          
          
          
    string s;
    cin>>s;
    ll i;
    string z;
    
    f(i,s.size())
    {
          if(s[i]!='B')
          {
                z+=s[i];
          }
          else
          {     if(z.size()>=1)
                {z.erase(z.size()-1);}
          }
    }


o(z)
    re
}

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

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main(int argc, const char * argv[]) {
    ll N; cin >> N;
    vector<ll> d(N);
    for(ll i=0;i<N;i++){
        cin >> d[i];
    }
    
    ll sum=0;
    for(ll i=0;i<N;i++){
        for(ll j=i+1;j<N;j++){
            sum += d[i]*d[j];
        }
    }
    
    cout << sum << endl;
    
    return 0;
    
}




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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int n, l;
    cin >> n >> l;
    vector<Int> a(n + 1);
    for (Int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    Int index = -1;
    for (Int i = 1; i <= n - 1; i++) {
        if (a[i] + a[i + 1] >= l) {
            index = i;
        }
    }
    if (index == -1) {
        dump("Impossible");
        return 0;
    }
    dump("Possible");
    for (Int i = 1; i < index; i++) {
        dump(i);
    }
    for (Int i = n - 1; i >= index; i--) {
        dump(i);
    }
    return 0;
}

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

using namespace std;

const int mod=998244353;

long long qpow(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}

long long inv(long long x)
{
	return qpow(x,mod-2);
}

long long fac[1000010];
long long invf[1000010];

void init(int n)
{
    fac[0]=1;
    for(int i=1;i<=n;i++)    
    {
        fac[i]=fac[i-1]*i%mod;
    }
    invf[n]=inv(fac[n]);
    for(int i=n-1;i>=0;i--)
    {
        invf[i]=invf[i+1]*(i+1)%mod;
    }
}

long long C(long long n,long long m)
{
    return fac[n]*invf[m]%mod*invf[n-m]%mod;
}

int main()
{
	int n,m;
	cin>>n>>m;
    if(n>m)
    {
        swap(n,m);
    }
    init(n+m);
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        ans+=C(2*i,i)*C(n-i+m-i,n-i)%mod;
        ans%=mod;
    }
    cout<<(ans*inv(C(n+m,n))%mod*inv(2)%mod+m)%mod<<endl;
}

Measured memory_bytes: 15872
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main(string[] _)
    {
        _ = Console.ReadLine().Split(' ');
        int a = int.Parse(_[0]);
        int b = int.Parse(_[1]);
        int c = int.Parse(_[2]);

        Console.WriteLine(b - a == c - b ? "YES" : "NO");
    }
}

Measured memory_bytes: 11092
from itertools import product
N = int(input())
ans = 0
for l in range(1, 11):
    for p in product("357", repeat=l):#product関数はlistを返す
        v = "".join(p)
        if "3" in v and "5" in v and "7" in v and int(v) <= N:#文字列のリストをjoinで結合
            ans += 1
print(ans)

#直積集合，集合の集まり（集合族）に対して各集合から1つずつ元を取り出して組にしたものを元としてもつ新たな集合

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N;
    cin >> N;
    vector<int> cnt(N, 0);
    REP (i, N - 1) {
        int A;
        cin >> A;
        cnt[A - 1]++;
    }
    REP (i, N) cout << cnt[i] << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const int N = 3e3+5;
long long dp[N][N][2] , in[N] , pre[N];
int main()
{
	#ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	int n ; cin >> n ;
	for(int i = 1 ; i <= n ; ++i)
		cin >> in[i] , pre[i] = pre[i-1] + in[i]; 
	for(int dif = 0 ; dif < n ; ++dif)
	{
		for(int i = 1 ; i <= n - dif ; ++i)
		{
			dp[i][i+dif][1] = max(dp[i+1][i+dif][2]+in[i] , dp[i][i+dif-1][2] + in[i+dif]);
			dp[i][i+dif][2] = pre[i+dif] - pre[i-1] - dp[i][i+dif][1];
			// cerr << i << " "<< i+dif << " "<<dp[i][i+dif][1] << " "<< dp[i][i+dif][2] << endl;
		}
	}

	cout << dp[1][n][1] - (pre[n] - dp[1][n][1]);

	return 0;
}

Measured memory_bytes: 139648
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int,int> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N]  ;
bool visited[N]={};
int main()
{
 
 int n;
 cin>>n;
 for(int i=0; i<=n ; i+=4)
 {
     if((n-i)%7==0)
     {
         cout<<"Yes";
         go;
     }
 }
cout<<"No";
 go;
}


Measured memory_bytes: 256
#include <stdio.h>

int left[40];
int right[40];
int pre[40];
int in[40];
int post[40];
int posthead;

void push(int node){
    post[posthead++] = node;
}

void postorder(int node){
    if(node == -1) return;
    postorder(left[node]);
    postorder(right[node]);
    push(node);
}

int find(int a[], int v, int b, int c){
    for(int i=b; i<c; i++)
        if(a[i] == v)
            return i;
    return -1;
}

int recon(int pa, int pb, int ia, int ib){
    int root = pre[pa];
    int i = find(in, root, ia, ib);
    int nl = i - ia;
    if(nl == 0)
        left[root] = -1;
    else
        left[root] = recon(pa + 1, pa + nl + 1, ia, ia + nl);
    int nr = ib - i - 1;
    if(nr == 0)
        right[root] = -1;
    else
        right[root] = recon(pa + nl + 1, pb, i + 1, ib);
    return root;
}

int main(void){
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &pre[i]);
        pre[i]--;
    }
    for(int i=0; i<n; i++){
        scanf("%d", &in[i]);
        in[i]--;
    }
    int root = recon(0, n, 0, n);
    postorder(root);
    for(int i=0; i<n; i++){
        printf("%d", post[i]+1);
        putchar(i<n-1?' ':'\n');
    }
}



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

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#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>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

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

  ll a,b;
  cin >> a >> b;

  ll ans = 0;
  if(a <= 0 && 0 <= b)
  {
    ans = 0;
  }
  else if(a > 0 && b > 0)
  {
    ans = 1;    
  }
  else
  {
    ll diff = abs(b - a) + 1;
    if(diff % 2)
    {
      ans = -1;
    }
    else
    {
      ans = 1;
    }
  }

  switch(ans)
  {
    case 1:
      cout << "Positive" << endl;
      break;
    case 0:
      cout << "Zero" << endl;
      break;
    case -1:
      cout << "Negative" << endl;
      break;
  }
  
  



  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
// ABC152のB問題
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        if(a >= b) {
            for(int i = 0; i < a; ++i) {
                System.out.printf("%d", b);
            }
        }
        else {
            for(int i = 0; i < b; ++i) {
                System.out.printf("%d", a);
            }
        }

    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=1;i<=1000000;++i){
		if((a&1)||(b&1)||(c&1))return printf("%d",i-1),0;
		int _a=(a+b)/2,_b=(b+c)/2,_c=(a+c)/2;
		a=_a,b=_b,c=_c;
	}
	printf("-1");
}

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

using namespace std;

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

  int n, m;
  cin >> n >> m;
  vector<string> A(n);
  for (auto &a : A) cin >> a;
  vector<string> B(m);
  for (auto &b : B) cin >> b;
  bool ok = true;
  for (int i = 0; i+m < n; ++i) {
    for (int j = 0; j+m < n; ++j) {
      ok = true;
      for (int k = 0; k < m; ++k) {
        for (int l = 0; l < m; ++l) {
          if (A[i+k][j+l] != B[k][l]) {
            ok = false;
            break;
          }
        }
        if (!ok) break;
      }
      if (ok) break; 
    }
    if (ok) break;
  }
  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <stdio.h>
//#include <string>
//#include <vector>
//#include <algorithm>

using namespace std;

int main() {

	int n, l, eatenapple;
	scanf("%d%d", &n, &l);

	if (l > 0) eatenapple = l;
	else if (n + l - 1 > 0) eatenapple = 0;
	else eatenapple = n + l - 1;

	printf("%d\n", (l + l + n - 1) * n / 2 - eatenapple);

	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#define M 1000000000
using namespace std;
int dp[501][10001];
int main(void)
{
	int i,j,m,n,sum,x,xx,max;
	int man[10001],hako[10001],jo[10001];
	int wa[10001];
	scanf("%d %d",&m,&n);
	for(i=0;i<m;i++) scanf("%d",&man[i]);
	for(i=0;i<n;i++) scanf("%d %d",&jo[i],&hako[i]);
	for(i=0;i<=n;i++) {
		for(j=0;j<=m;j++) {
			dp[i][j]=M;
		}
	}
	dp[0][0]=0;
	for(i=0;i<n;i++) {
		for(j=0;j<=m;j++) {
			if(dp[i][j]!=M) {
				x=jo[i];
				if(dp[i+1][j]>dp[i][j]) dp[i+1][j]=dp[i][j];
				if(x+j>m)	xx=m;
				else xx=x+j;
				if(dp[i+1][xx]>dp[i][j]+hako[i]) {
					dp[i+1][xx]=dp[i][j]+hako[i];	
				}
//				if(dp[i+1][m]>dp[i][j]+hako[i] && x+j>m) {
//					dp[i+1][m]=dp[i][j]+hako[i];
//				}
//				else if(dp[i+1][j+x]>dp[i][j]+hako[i] && x+j<=m) {
//					dp[i+1][j+x]=dp[i][j]+hako[i];
//				}
			}
		}
	}
//	for(i=0;i<=n;i++) {
//		for(j=0;j<=m;j++) {
//			printf("%5d ",dp[i][j]);
//		}
//		printf("\n");
//	}
	sort(man,man+m,greater<int>());
	sum=0;
	wa[0]=0;
	for(i=1;i<=m;i++) {
		sum+=man[i-1];
		wa[i]=sum;
	}
	max=-1;
	for(i=0;i<=m;i++) if(wa[i]-dp[n][i]>max) max=wa[i]-dp[n][i];
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 20704
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String line = br.readLine();
		int n = Integer.parseInt(line);
		for(int i = 1; i <= n; i++){
			int x = i;
			if( x % 3 == 0 ){
				sb.append(" ").append(i);
			}else{
				do{
					if( x % 10 == 3 ){
						sb.append(" ").append(i);
                                                x = 0;
					}
					x /= 10;
				}while( x != 0 );
			}
		}
		sb.append("\n");
		System.out.print(sb);
	}
}

Measured memory_bytes: 25284