akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int sumdigit(int n){
    int sum =0;
    while(n>0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
int main() {
    int N,A,B,count=0;
    cin >> N >> A >> B;
    for(int i=1; i<=N; i++){
        int sum = sumdigit(i);
        if(sum >= A && sum <= B){
            count += i;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
R,C,K = map(int, input().split())

d = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp = [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]

for i in range(K):
    r, c, v = map(int, input().split())
    d[r-1][c-1] = v
for i in range(R):
    for j in range(C):
        # kが大きい方からやらないとダメ。01ナップサックと同じ考え方。書き換えられた値を見ないように。
        for k in range(2, -1, -1):
            # 拾う遷移。d[i][j]を取るかどうかという判定
            dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + d[i][j])
        for k in range(4):
            dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
            dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j])
ans = 0

for k in range(4):
    ans = max(ans, dp[k][R-1][C-1])
print(ans)    

Measured memory_bytes: 463732
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<51)
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define all(c) (c).begin(),(c).end()
#define N 3000
int n,k;
int a[100];
int dp[100001][2];

int rec(int i,int ch)
{

    if(dp[i][ch] == -1)
    {
        int ans = 0;
        for(int j = 0;j < n;j++)
        {
            if(a[j] <= i)
            {
                ans |= (!rec(i-a[j],!ch));
            }
        }
        dp[i][ch] = ans;
        return ans;
    }
    else
        return dp[i][ch];
}

int32_t main()
{                
    IOS;
    
    
    memset(dp,-1,sizeof(dp));
    cin>>n>>k;
    for(int i = 0;i < n;i++)
        cin>>a[i];
    if(rec(k,0))
        cout<<"First";
    else
        cout<<"Second";
    return 0;

}

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

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t,u;
    cin >> s >> t >> u;
    cout << s[0] << t[1] << u[2] << "\n";

    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    size_t n;
    cin >> n;
    vector<string> s(n);
    for (size_t i = 0; i < n; ++i)
        cin >> s[i];
    for (auto& e : s)
        sort(begin(e), end(e));
    sort(begin(s), end(s));
    size_t c = 0;
    size_t d = 0;
    for (size_t i = 1; i < n; ++i) {
        const auto& p = s[i - 1];
        const auto& n = s[i];
        if (p == n) {
            c += ++d;
        } else
            d = 0;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
VI a,b;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n;
  a=b=VI(n);
  forn(z,n){
    cin>>a[z]>>b[z];
  }
  in sm=0;
  for(in i=n-1;i>=0;--i){
    a[i]+=sm;
    a[i]%=b[i];
    if(a[i])
      sm+=b[i]-a[i];
  }
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 1792
Scanf.scanf "%d %d %d" (fun h w n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let mat = Array.make_matrix h w 0 in
    let rec loop y x i r =
        if r > 0 then (
            mat.(y).(x) <- i;
            let vx = if y mod 2 = 0 then 1 else -1 in
            let x = x + vx in
            let y, x = if x >=0 && x < w then y, x else y + 1, x - vx in
            loop y x i (r - 1)
        ) else (
            if i = n then () else loop y x (i + 1) a.(i)
        )
    in
    loop 0 0 0 0;
    Array.iter (fun a ->
        Array.iter (Printf.printf "%d ") a;
        print_newline ()
    ) mat
)

Measured memory_bytes: 5864
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;


struct SegmentTreemin{
private:
    int n;
    vector<int> node;

public:
    SegmentTreemin(vector<int> v){
        int sz = v.size();
        n = 1;
        while(n < sz) n *= 2;
        node.resize(2*n-1,INF);
        for (int i = 0; i < sz; i++) node[i+n-1] = v[i];
        for (int i = n-2; i >= 0; i--) node[i] = min(node[2*i+1],node[2*i+2]);
    }

    void update(int x,int val){
        x += n-1;
        node[x] = val;
        while(x > 0){
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1],node[2*x+2]);
        }
    }

    int getmin(int a, int b, int k=0, int l=0, int r=-1){
        if (r < 0) r = n;
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return node[k];
        int vl = getmin(a, b, 2*k+1, l , (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2,r);
        return min(vl, vr);
    }
};


struct SegmentTreemax{
private:
    int n;
    vector<int> node;

public:
    SegmentTreemax(vector<int> v){
        int sz = v.size();
        n = 1;
        while(n < sz) n *= 2;
        node.resize(2*n-1,-INF);
        for (int i = 0; i < sz; i++) node[i+n-1] = v[i];
        for (int i = n-2; i >= 0; i--) node[i] = max(node[2*i+1],node[2*i+2]);
    }

    void update(int x,int val){
        x += n-1;
        node[x] = val;
        while(x > 0){
            x = (x - 1) / 2;
            node[x] = max(node[2*x+1],node[2*x+2]);
        }
    }

    int getmax(int a, int b, int k=0, int l=0, int r=-1){
        if (r < 0) r = n;
        if(r <= a || b <= l) return -INF;
        if(a <= l && r <= b) return node[k];
        int vl = getmax(a, b, 2*k+1, l , (l+r)/2);
        int vr = getmax(a, b, 2*k+2, (l+r)/2,r);
        return max(vl, vr);
    }
};


int main(){
    int n,k;cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    SegmentTreemin smin(p);
    SegmentTreemax smax(p);
    int ans = 0;
    set<int> st;
    for (int i = 0; i < k; i++) {
        st.insert(p[i]);
    }
    vector<int> cum(n+1,0);
    for (int i = 0; i < n-1; i++) {
        cum[i+1] = cum[i] + (p[i] < p[i+1]);
    }
    vector<bool> f(n,true);
    bool c = false;
    for (int i = 0; i <= n-k; i++) {
        if(cum[i+k-1] - cum[i] == k - 1){
            f[i] = false;
            c = true;
        }
    }
    if(c) ans = 1;
    if(f[0]) ans++;
    for (int i = 1; i <= n-k; i++) {
        if(p[i-1] == smin.getmin(i-1,i-1+k) && p[i-1+k] == smax.getmax(i,i+k)){
        }
        else{
            ans += f[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15344
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <numeric>
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define Brep(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define INF 999999999
using namespace std;

int main(){
    string row1, row2; cin >> row1 >> row2;
    int tp = (int)row1.size()-1;
    int flag = 0;
    Rep(i, 0, (int)row1.size()){
        if(row1[i] != row2[tp]) flag = 1;
        tp -= 1;
    }

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

    return 0;
}


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

int xdp[8005][16004];
int ydp[8005][16004];

int main() {
    string s; cin >> s;
    int x, y; cin >> x >> y;
    vector<int> xz;
    vector<int> yz;
    int n = s.size();
    int xycheck = 0;
    int cnt = 0;
    rep(i, n){
        if(s[i] == 'F'){
            cnt++;
            if(i == n-1){
                if(xycheck % 2 == 0){
                    xz.push_back(cnt);
                } else {
                    yz.push_back(cnt);
                }
            }
        } else {
            if(xycheck % 2 == 0){
                xz.push_back(cnt);
            } else {
                yz.push_back(cnt);
            }
            cnt = 0;
            xycheck++;
        }
    }

    int xs = xz.size();
    xdp[0][8000] = 1;
    rep(k, xs){
        for (int i = 0; i < 16001; i++){
            int p = i + xz[k];
            if(p >= 0 && p <= 16000){
                if(xdp[k+1][p] == 0){
                    xdp[k+1][p] = xdp[k][i];
                }
            }
            if(k == 0)continue;
            int m = i - xz[k];
            if(m >= 0 && m <= 16000){
                if(xdp[k+1][m] == 0){
                    xdp[k+1][m] = xdp[k][i];
                }
            }
        }
    }

    int ys = yz.size();
    ydp[0][8000] = 1;
    rep(k, ys){
        for (int i = 0; i < 16001; i++){
            int p = i + yz[k];
            if(p >= 0 && p <= 16000){
                if(ydp[k+1][p] == 0){
                    ydp[k+1][p] = ydp[k][i];
                }
            }
            int m = i - yz[k];
            if(m >= 0 && m <= 16000){
                if(ydp[k+1][m] == 0){
                    ydp[k+1][m] = ydp[k][i];
                }
            }
        }
    }

    //cout << "x " << xdp[xs][8000+x] << "y " << ydp[ys][8000+y] << endl;
    bool ok = xdp[xs][8000+x] == 1 && ydp[ys][8000+y] == 1;
    if(ok){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 499676
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

//---------------------------------------------------------------
// ------ graph ------ //
using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
struct Graph {
    vector<Edges> adj;
    Graph(int n) : adj(n) { }
    int size() { return adj.size(); }
    Edges operator [] (int v) { return adj[v]; }
    void add_edge(int a, int b, Weight w = 1) { // graph
        adj[a].emplace_back(a, b, w);
        adj[b].emplace_back(b, a, w);
    }
    void add_arc(int a, int b, Weight w = 1) {  // digraph
        adj[a].emplace_back(a, b, w);
    }
};
using Array = vector<Weight>;
using Matrix = vector<Array>;

// ------ Topological Sort (Kahn) ------ //
vector<int> tsort(Graph &g) {
    int n = g.size(), k = 0;
    vector<int> ord(n), in(n);
    for (int i = 0; i < n; i++) for (Edge &e : g[i]) in[e.dst]++;
    queue<int> q;
    for (int i = 0; i < n; i++) if (in[i] == 0) q.push(i);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        ord[k++] = v;
        for (Edge &e : g[v]) if (--in[e.dst] == 0) q.push(e.dst);
    }
    return *max_element(in.begin(), in.end()) == 0 ? ord : vector<int>();
}
//---------------------------------------------------------------

int main() {
    int V, E; cin >> V >> E;
    Graph g(V);
    for (int i = 0; i < E; i++) {
        int s, t; cin >> s >> t;
        g.add_arc(s, t);
    }
    vector<int> ord = tsort(g);
    for (int i = 0; i < V; i++) cout << ord[i] << endl;
    return 0;
}


Measured memory_bytes: 4424
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

class RMQ{
public:
  ll n,dat[555555];
  void init(ll _n){
    n=1;
    while(n<_n)n*=2;
    fill(dat,dat+2*n-1,-MAXL);
  }
  void update(ll k,ll a){
    k+=n-1;dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=max(dat[k*2+1],dat[k*2+2]);
    }
  }
  ll query(ll a,ll b){return query(a,b,0,0,n);}
  ll query(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||b<=l) return -MAXL;
    if(a<=l&&r<=b) return dat[k];
    ll vl=query(a,b,k*2+1,l,(l+r)/2);
    ll vr=query(a,b,k*2+2,(l+r)/2,r);
    return max(vl,vr);
  }
};

RMQ t;
void Main() {
  ll n,m;
  cin >> n >> m;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  ll d[2][n+1],c[2][n+1];
  mem(d),mem(c);
  rep(i,n) {
    d[0][i+1]=a[i].F;
    c[0][i+1]+=c[0][i]+a[i].S;
  }
  rrep(i,n) {
    d[1][i]=m-a[i].F;
    c[1][i]+=c[1][i+1]+a[i].S;
  }
  ll ans=0;
  rep(k,2) {
    t.init(n+1);
    rep(i,n+1) t.update(i,c[k^1][i]-d[k^1][i]);
    rep(i,n+1) {
      ans=max(ans,c[k][i]-d[k][i]);
      if(!k) ans=max(ans,c[k][i]-d[k][i]*2+max(0LL,t.query(i,n+1)));
      else ans=max(ans,c[k][i]-d[k][i]*2+max(0LL,t.query(0,i+1)));
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 8960
import java.util.ArrayList;
import java.util.Scanner;
import java.io.PrintWriter;

public class Main {
	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args){
		while(true){
			int n = si();
			if(n==0) break;
			ListArray[] lista = new ListArray[30];
			for(int i=0;i<30;i++) lista[i] = new ListArray();
			long[] map = new long[n];
			int res = -1;
			for (int i = 0; i < n; i++) {
				int m = si();
				map[i]=1L<<i;
				for (int j = 0 ;j < m ; j++)
					lista[si()-1].list.add(i);
			}
			for (int i = 0; i < 30; i++) {
				long tmp = 0;
				for (Integer e : lista[i].list)
					tmp |= map[e];
				for (Integer e : lista[i].list)
					map[e]=tmp;
				if(tmp==(1L<<n)-1){
					res = i+1;
					break;
				}
			}
			out.println(res);
		}
		out.flush();
	}
	static int si(){
		return Integer.parseInt(scan.next());
	}
}

class ListArray{
	ArrayList<Integer> list = new ArrayList<Integer>();
}

Measured memory_bytes: 75564
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
string a;
int b;
signed main()
{
	cin>>a;
	rep(i,4){
		if(a[i]=='2'){
			b++;
		}
	}
	cout<<b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N, M, Q;
vector<int> a, b, c, d;
vector<int> Aseq;
ll ans = 0;

void dfs(int k) {
    if (k == N + 1) {
        ll sum = 0;
        rep(i, Q) {
            if (Aseq[b[i]] - Aseq[a[i]] == c[i]) sum += d[i];
        }
        ans = max(ans, sum);
        return;
    }

    rep(n, Aseq[k - 1], M + 1) {
        Aseq[k] = n;
        dfs(k + 1);
    }
}

int main() {
    cin >> N >> M >> Q;
    a.resize(Q), b.resize(Q), c.resize(Q), d.resize(Q);
    rep(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    Aseq.resize(N + 1);
    Aseq[0] = 1;
    dfs(1);
    write(ans);
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<bitset>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long 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 {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return 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 {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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

bool judge(vector<ll> &A) {
	ll N = A.size();

	bool fin = 1;
	rep(i, N)if (A[i] != 1) { fin = 0; }
	if (fin) { return 0; }

	ll e = 0, o = 0;

	ll oid;
	rep(i, N) {
		if (A[i] % 2 == 1) { o++; oid = i; }
		else { e++; }
	}

	if (e % 2 == 1) { return 1; }
	else if (o > 1) { return 0; }
	if (A[oid] == 1) { return 0; }
	A[oid]--;

	ll g = A[0];
	rep(i, N) g = gcd(g, A[i]);
	rep(i, N) A[i] /= g;

	bool b = judge(A);
	return !b;

}

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	rep(i, N) cin >> A[i];

	
	if (judge(A)) { cout << "First" << endl; }
	else { cout << "Second" << endl; }
	
	system("PAUSE");
}

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

int main(){
	int x, y, tmp;
	cin>>x>>y;
	while(x || y){
		if(x>y){
			tmp=x;
			x=y;
			y=tmp;
		}
		cout << x << ' ' << y << endl;
		cin>>x>>y;
	}
	return 0;
}

Measured memory_bytes: 1160
from collections import deque
S = deque(input())
Q = int(input())
s = 1
for _ in range(Q):
    q = input()
    if q!='1':
        if (q[2]=='1' and s==1) or (q[2]!='1' and s!=1):
            S.extendleft(q[4])
        else:
            S.extend(q[4])
    else:
        s *= -1
S = ''.join(list(S))
if s==1:
    print(S)
else:
    print(S[::-1])

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

a, b, ba = 0, 0, 0
ret = 0
for _ in range(N):
    s = input()

    ret += s.count('AB')

    cond_a = s[-1] == 'A'
    cond_b = s[0] == 'B'
    if cond_a:
        if cond_b:
            ba += 1
        else:
            a += 1
    else:
        if cond_b:
            b += 1

if ba:
    ret += ba - 1
    if a:
        ret += 1
        a -= 1
    if b:
        ret += 1
        b -= 1
ret += min(a, b)

print(ret)

# ...A
# B...
# B...A
# ... -> 無視


Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class CStrangeBank {
public:
	void solve(istream& in, ostream& out) {
        int n; in >> n;
	    int dp[100005];
        rep(i,100005) dp[i] = 1e6;
        vector<int> a;
        rep(i,5) a.push_back(pow(9,i+1));
        rep(i,6) a.push_back(pow(6,i+1));
        a.push_back(1);

        dp[0] = 0;
        for(int i = 1; i < n + 1;i++){
            for(int j = 0;j < a.size();j++){
                if(i >= a[j]) {
                    dp[i] = min(dp[i], dp[i - a[j]] + 1);
                }
            }
        }
        out << dp[n] << endl;
	}
};

int main() {
	CStrangeBank solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 640
#include"bits/stdc++.h"

using namespace std;

typedef long long LL;

vector<LL> A;

int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		LL B;
		cin >> B;
		A.push_back(B);
	}
	sort(A.begin(), A.begin() + A.size());
	LL Ans = 0;
	LL ans = 0;
	LL now = -1;
	for (int i = 0; i < A.size(); i++)
	{
		if (now == A[i])
		{
			ans++;
		}
		else
		{
			Ans += (ans % 2);
			now = A[i];
			ans = 1;
		}
	}
	Ans += (ans % 2);
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 1400
#[allow(unused_imports)]
use {
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::ops::*,
};

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        ab: [(Usize1, Usize1); h]
    }

    let mut s = BTreeSet::<(usize, usize)>::new();
    let mut v = BTreeSet::<(usize, usize)>::new();
    for i in 0..w {
        s.insert((i, i));
        v.insert((0, i));
    }

    for (i, &(a, b)) in ab.iter().enumerate() {
        let update = s
            .range((a, 0)..(b, w))
            .map(|&(i, j)| (i, j))
            .collect::<Vec<(usize, usize)>>(); // total: O(w)log w
        if !update.is_empty() {
            let mut x = 0;
            for (end, start) in update {
                s.remove(&(end, start));
                v.remove(&(end - start, start));
                x = max(x, start);
            }
            if b + 1 != w {
                s.insert((b + 1, x));
                v.insert((b + 1 - x, x));
            }
        }
        if let Some((m, _)) = v.iter().next() {
            println!("{}", m + i + 1);
        } else {
            println!("-1");
        }
    }
}


Measured memory_bytes: 22192
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N, M, INF = 1000000000;
  while(cin >> N >> M, N||M){
    int S[N], D[M];
    for(int i = 0; i < N; ++i) cin >> S[i];
    for(int i = 0; i < M; ++i) cin >> D[i];
    vector<int> init(M+1);
    init[0] = 0;
    for(int i = 0; i < M; ++i) init[i+1] = D[i];
    vector< vector<int> > dp((1<<N), init);
    for(int i = 0; i < (1<<N); ++i){
      int t = INF;
      for(int j = 0; j < N; ++j){
	if(i & (1<<j)){
	  int s = 0;
	  vector<int> v = dp[i - (1<<j)];
	  v[0] += S[j];
	  for(int k = 0; k < M; ++k){
	    v[k+1] = min(v[k+1],abs(v[0]-D[k]));
	    s += v[k+1];
	  }
	  if(s < t){
	    dp[i] = v;
	    t = s;
	  }
	}
      }
    }
    int ans = 0;
    for(int i = 0; i < M; ++i){
      ans += dp[(1<<N)-1][i+1];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 16768
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
#define ll long long
#define mod 1000000007
#define test int t; cin>>t; while(t--)
#define f for(int i=0;i<n;i++)
#define f1 for(int i=1;i<n-1;i++)
#define read(x) ll x; cin>>x;
#define TIME  cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

using namespace std;
/*ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
int combi(int n, int k)
{
    int C[k+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (int i = 1; i <= n; i++)
    {
        for (int j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}
int factorial(int n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll power(ll x,ll n)
{
    if(n==0) return 1;
    if(n&1) return x*power(x,n/2)*power(x,n/2);
    else
        return power(x,n/2)*power(x,n/2);
}*/
/*int gcd(int a, int b){
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

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

   ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
   // static const auto _ = []() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); return 0; }();

   ll n,x,t; cin>>n>>x>>t;

   int t1=ceil(n*1.0/x);
   int tt=t*t1;
   cout<<tt<<endl;


//TIME
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  int h[n];
  rep(i,n)cin >> h[i];
  rep(i,n){
    if(i==0){
      h[i]--;continue;
    }
    if(h[i-1]<h[i])h[i]--;
    else if(h[i-1]==h[i])continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main(){
    ll n, i, j, k, mn, count = 0, flag = 0, res = 0;
    cin >> n;
    ll a[n][n] = {};
    for(i=0; i<n; i++){
        for(j=0; j<n; j++){
            cin >> a[i][j];
        }
    }
    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            mn = a[i][j];
            for(k=0; k<n; k++){
                if(k == i || k == j) continue;
                if(a[i][j] > a[i][k] + a[k][j]){
                    flag = 1;
                    i = j = k = n;
                }else if(a[i][j] == a[i][k] + a[k][j]){
                    mn = 0;
                    k = n;
                }
            }
            res += mn;
        }
    }
    if(flag){
        cout << "-1\n";
    }else{
        cout << res << "\n";
    }    
    return 0;
}

Measured memory_bytes: 896
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    print(A*B)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


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

int main(){
  int h, w, n;
  cin >> h >> w >> n;
  cout << ceil((double)n / (double)max(h, w)) << endl;
  return 0;
}


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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> ac(n), wa(n);

  for (int i = 0; i < m; i++)
  {
    int p;
    string s;
    cin >> p >> s;

    if (ac[p - 1])
    {
      continue;
    }

    if (s == "WA")
    {
      wa[p - 1]++;
    }
    else
    {
      ac[p - 1] = 1;
    }
  }
  int AC = 0;
  int WA = 0;
  for (int i = 0; i < n; i++)
  {
    AC += ac[i];
    if (ac[i])
    {
      WA += wa[i];
    }
  }
  cout << AC << " " << WA << endl;
}


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

int main() {
	int a, n, m, ans = 0;
	cin >> a >> n >> m;
	for (int y = 0; y <= 9*8; y++) {
		long long int ypa = 1;
		for (int i = 0; i < n; i++)
			ypa *= y+a;
		if (ypa > m || ypa == 0) continue;
		int tmpx = ypa, yfx = 0;
		while (tmpx > 0) {
			yfx += tmpx%10;
			tmpx /= 10;
		}
		if (yfx == y)
			ans++;
	}
	cout << ans << endl;
} 


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int N = 405;
const int MOD = 998244353;

template <typename T> inline void read(T &AKNOI) {
    T x = 0, flag = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') flag = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    AKNOI = flag * x;
}

namespace ModCalculator {
	inline void Inc(int &x, int y) {
		x += y; if (x >= MOD) x -= MOD;
	}
	inline void Dec(int &x, int y) {
		x -= y; if (x < 0) x += MOD;
	}
	inline int Add(int x, int y) {
		Inc(x, y); return x;
	}
	inline int Sub(int x, int y) {
		Dec(x, y); return x;
	}
	inline int Mul(int x, int y) {
		return 1LL * x * y % MOD;
	}
}
using namespace ModCalculator;

int n, m, a[N], b[N], as, bs;
int fac[N], inv[N], finv[N], pw[N][N], pinv[N][N];
int dp[2][N][N];

void init() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(a[i]); read(b[i]);
		as += a[i];
		bs += b[i];
	}
	m = max(as, bs);
	fac[0] = fac[1] = inv[0] = inv[1] = finv[0] = finv[1] = 1;
	for (int i = 2; i <= m; ++i) {
		fac[i] = Mul(fac[i - 1], i);
		inv[i] = Mul(MOD - MOD / i, inv[MOD % i]);
		finv[i] = Mul(finv[i - 1], inv[i]);
	}
	for (int i = 0; i <= m; ++i) {
		pw[i][0] = pinv[i][0] = 1;
		for (int j = 1; j <= m; ++j) {
			pw[i][j] = Mul(pw[i][j - 1], i);
			pinv[i][j] = Mul(pinv[i][j - 1], inv[i]);
		}
	}
}

void solve() {
	dp[0][0][0] = MOD - 1;
	int pre = 0, cur = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= as; ++j) {
			for (int k = 0; k <= bs; ++k) {
				dp[cur][j][k] = dp[pre][j][k];
			}
		}
		for (int c = 0; c < b[i]; ++c) {
			for (int j = a[i]; j <= as; ++j) {
				for (int k = c; k <= bs; ++k) {
					Dec(dp[cur][j][k], Mul(dp[pre][j - a[i]][k - c], Mul(pw[a[i]][c], finv[c])));
				}
			}
		}
		swap(pre, cur);
	}
	int ans = 0;
	for (int j = 1; j <= as; ++j) {
		int tmp = Mul(as, inv[j]);
		for (int k = 0; k <= bs; ++k) {
			Inc(ans, Mul(dp[pre][j][k], Mul(tmp, Mul(fac[k], pinv[j][k]))));
		}
	}
	printf("%d\n", ans);
}

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


Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int k, a, b;
    cin >> k >> a >> b;
    for (int q = a; q <= b; q++){
        if (q % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


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

int main(void)
{
    vector<int> dish(5);
    int modmin=11,num;
    for (int i = 0; i < 5; i++){
        cin >> dish.at(i);
        if(modmin>((dish.at(i)-1)%10)){
            modmin = (dish.at(i) - 1) % 10;
            num = i;
        }
    }
    int sum = 0,x;
    for (int i = 0; i < 5;i++){
        if(i !=num){
            int temp = (dish.at(i) + 9) / 10;
            sum += temp * 10;
        }
        else
            x = dish.at(i);
    }
    cout << sum + x << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 500005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, x;
    cin >> n >> m >> x;
    int ans = 1e9;
    int c[n];
    int ag[n][m];
    f(n) {
        cin >> c[i];
        fr(j,0,m) {
            cin >> ag[i][j];
        }
    }
    f(1<<n) {
        int cc = 0;
        int s[m] = {};
        fr(j,0,n) {
            if (i & (1<<j)) {
                cc += c[j];
                fr (k, 0, m) {
                    s[k] += ag[j][k];
                }
            }
        }
        int f = 0;
        fr (j, 0, m) {
            if (s[j] < x) {
                f = 1;
            }
        }
        if (!f) {
            ans = min(ans, cc);
        }
    }
    if (ans == 1e9) {
        ans = -1;
    }
    cout << ans << '\n';
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int x, y;
  std::cin >> x >> y;
  set<int> g1{1, 3, 5, 7, 8, 10, 12};
  set<int> g2{4, 6, 9, 11};
  if ((g1.count(x) && g1.count(y)) || (g2.count(x) && g2.count(y)))
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include<climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

int i,j,k,l,m,n;
/////////////////////////////////////////////////////


ll N,M;

int main(){
    scanf("%lld%lld",&N,&M);
    if(N==1){
        printf("%lld\n",M);
        return 0;
    }
    ll ans;
    for(ans=M/N;true;ans--){
        if(M%ans==0&&N<=M/ans){
            break;
        }
    }
    printf("%lld\n",ans);
    
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
typedef long double ld;

using namespace std;

void solve(ll N){
	int ans_last = 99;
	int len_N = to_string(N).length();
    ld NN = (ld)N;
    int hoge = to_string((int)sqrt(NN)).length();
	for (int i = hoge; i >= 1; i--) {
        int start = 1;
		int end = 10;
        rep(j, i - 1) {
            start *= 10;
			end *= 10;
		}
		for (int j = start; j < end; j++) {
            if (N % j == 0) {
				int p = to_string(N/j).length();
				int ans = max(p, i);
				if (ans_last > ans) {
					ans_last = ans;
				}
			}
		}
        if (ans_last < 95) {
			cout << ans_last << endl;
			return;
		}
	}
	cout << len_N << endl;
	return;
}

int main(){
    // 提出時は削除 //////////////////////////////
//	FILE* fp_in = freopen("/Users/kokinakamura/git/ToolsForAtCoder/workspace/abc057/C/in_C_3.txt", "r", stdin);
    ////////////////////////////////////////////

	ll N;
	scanf("%lld",&N);
	solve(N);

    // 提出時は削除 //////////////////////////////
//    fclose(fp_in);
    ////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int N;
    int max = 0;
    int num = 0;
    
    scanf("%d",&N);
    
    for(int i = 0;i<N;i++){
        char ch;
        scanf(" %c ",&ch);
        if(ch == 'I'){
            num++;
        }
        else{
            num--;
        }
        if(max < num){
            max = num;
        }
    }
    
    printf("%d",max);
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
  int n, a, b, c, d;
  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  b *= (n + a - 1) / a;
  d *= (n + c - 1) / c;
  printf("%d\n", b < d ? b : d);
  return 0;
}


Measured memory_bytes: 2740
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

s = str(input())
obj_x, obj_y = list(map(int, input().split()))


x = []
y = []
flag = 0
num = 0
for i in range(len(s)):
    if s[i] == "T":
        if flag % 2 == 0:
            x.append(num)
        else:
            y.append(num)
        flag += 1
        num = 0
    else:
        num += 1

if num > 0:
    if flag % 2 == 0:
        x.append(num)
    else:
        y.append(num)


if x == []:
    x = [0]
if y == []:
    y = [0]


num_x = sum(x)
num_y = sum(y)

max_x = num_x*2+1
max_y = num_y*2+1

dp_x = [[0]*((len(x)+1)) for i in range(max_x)]
dp_y = [[0]*((len(y)+1)) for i in range(max_y)]

dp_x[num_x][0] = 1
dp_y[num_y][0] = 1

# print(x)
dp_x[num_x+x[0]][1]=1

# print(dp_x)

for i in range(1, len(x)):
    num = x[i]
    for j in range(0, len(dp_x)):
        if j+num < max_x:
            dp_x[j+num][i+1] = max(dp_x[j+num][i+1], dp_x[j][i]*1)
        if j-num >= 0:
            dp_x[j-num][i+1] = max(dp_x[j-num][i+1], dp_x[j][i]*1)
        # if dp_x[j][i] == 1:
        #     print(j+num, j-num)
for i in range(0, len(y)):
    num = y[i]
    for j in range(0, len(dp_y)):
        if j+num < max_y:
            dp_y[j+num][i+1] = max(dp_y[j+num][i+1], dp_y[j][i]*1)
        if j-num >= 0:
            dp_y[j-num][i+1] = max(dp_y[j-num][i+1], dp_y[j][i]*1)
        # if dp_y[j][i] == 1:
        #     print(j+num, j-num)


if (num_x+obj_x)<len(dp_x) and (num_x+obj_x)>=0:
    ans_x = dp_x[num_x+obj_x][-1]
else:
    print("No")
    exit()
if (num_y+obj_y)<len(dp_y) and (num_y+obj_y)>=0:
    ans_y = dp_y[num_y+obj_y][-1]
else:
    print("No")
    exit()

# print(dp_x)
if ans_x*ans_y == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 200356
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
    int q,x;
    char op[20];
    list<int> v;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>op;
        if(op[0]=='i')
        {
            cin>>x;
            v.push_front(x);
        }
        else if(op[6]=='L')
            v.pop_back();
        else if(op[6]=='F')
            v.pop_front();
        else if(op[0]=='d')
        {
            cin>>x;
            for(list<int>::iterator it=v.begin();it!=v.end();it++)
                if(*it==x)
                {
                    v.erase(it);
                    break;
                }
        }
    }
    int i=0;
    for(list<int>::iterator it=v.begin();it!=v.end();it++)
    {
        if(i++)
            cout<<" ";
        cout<<*it;
    }
    cout<<endl;
    return 0;
}


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

string s[10] = { "0111111", "0000110", "1011011", "1001111", "1100110",
		"1101101", "1111101", "0100111", "1111111", "1101111", };

int main(void) {
	int n;
	while (cin >> n, (n != -1)) {
		string now = "0000000";
		for (int i = 0; i < n; i++) {
			int x;
			cin >> x;
			string change = "0000000";
			for (int i = 0; i < 7; i++) {
				if (s[x][i] != now[i]) {
					change[i] = '1';
				}
			}
			cout << change << endl;
			now = s[x];
		}
	}

	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h> 
using namespace std; 
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(void) {
    io;
    int k,y; cin >> k >> y;
    if ((k * 500) >= y) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3600
using System;
using System.Numerics;
using System.Linq;

namespace AtCoder.Abc171
{
    class B
    {
        public static void Main()
        {
            var nk = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int n = nk[0];
            int k = nk[1];
            var p = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).OrderBy(x => x);
            Console.WriteLine(p.Take(k).Sum());
        }
    }
}


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

int main(){
   int n;
   std::cin>>n;
   std::vector<int> an(n,0);
   for (int i = 0; i < n; i++)
   {
       std::cin>>an[i];
   }

   int    q,beg,mid,end;
   std::cin>>q;
   for(int i=0;i<q;i++){
       std::cin>>beg>>mid>>end;
       std::rotate(&an[beg],&an[mid],&an[end]);
   }

   for(int i=0;i<n;i++){std::cout<<(i? " ":"")<<an[i];}
   std::cout<<std::endl;
   return 0;    

}


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

int N;
int A[210];

int main(){
  cin >> N;
  for(int i=0;i<N;++i){cin >> A[i];
                      }
  int count = 0;
  
  while(true){
    bool exist_odd =false;
    for(int i=0;i<N;++i){
      if(A[i] % 2 != 0)
        exist_odd =true;
      }
      if(exist_odd)break;
      
      for(int i=0;i<N;i++){
        A[i] /= 2;
      }
      count++;
    }
    
    cout << count <<endl;
  }
      


Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp0 = [[0] * (k + 1)] * n
dp1 = [0] * n
for i in range(1, n):
    for j in range(k + 1):
        if j <= i and j != 0:
            dp0[i][j] = dp1[i - j] + abs(h[i] - h[i - j])
        else:
            dp0[i][j] = 10 ** 9
    dp1[i] = min(dp0[i])
print(dp1[n - 1])

Measured memory_bytes: 52856
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define MOD 1000000007
typedef long long LL;
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	int A, B;
	cin >> A >> B;

	map<int, int> strength;
	REP(i, 2, 14) strength[i] = i;
	strength[1] = 14;

	if (strength[A] > strength[B]) {
		cout << "Alice" << endl;
	}
	else if (strength[A] < strength[B]) {
		cout << "Bob" << endl;
	}
	else {
		cout << "Draw" << endl;
	}
	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 D = scanner.nextInt();
      	int difference = 25 - D;
      	System.out.print("Christmas");
      	for (int i = 0; i < difference; i++){
          	System.out.print(" Eve");
        }
    }
}

Measured memory_bytes: 35520
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <set>
#include <string>
using namespace std;
int n,k,t,m,x,y,x1,y1,t1;
int main()
{
    scanf("%d",&n);
    x=0; y=0;t=0;
    for(int i=1;i<=n;++i)
    {
        scanf("%d%d%d",&t1,&x1,&y1);
        m=abs(x-x1)+abs(y-y1);
        if(t1-t<m||(t1-t-m)%2==1)
        {
            printf("No\n");
            return 0;
        }
        x=x1;
        y=y1;
        t=t1;
    }
    printf("Yes\n");
    return 0;
}


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

int main(){
	
	int pasta[3], juice[2];
	
	for(int i=0; i<3; i++){
		cin >> pasta[i];
	}
	for(int i=0; i<2; i++){
		cin >> juice[i];
	}
	
	sort(pasta, pasta+3);
	sort(juice, juice+2);
	
	cout << pasta[0] + juice[0] - 50 << endl;
	
	return 0;

}

Measured memory_bytes: 1176
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("avx") 
#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define j0 j5743892
#define j1 j542893
                         
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> T gcd(T a, T b) { re a ? gcd (b % a, a) : b; }
template<class T> T sqr(T a) { re a * a; }
template<class T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }

const double pi = acos(-1.0);

#define filename ""

int n;
int m;

int main () {
//  freopen (filename".in", "r", stdin);
//  freopen (filename".out", "w", stdout);
    cin >> n;
    vi a(n + 1);
    for (int i = 0; i <= n; i++) cin >> a[i];
    ll l = 0, r = 1;
    vector <ll> L(n + 1), R(n + 1);
    for (int i = 0; i < n; i++) {
        l -= a[i];
        r -= a[i];
        if (r < 0) {
            cout << -1 << endl;
            re 0;
        }
        l = max(l, 0ll);
        r = max(r, 0ll);
        L[i] = l;
        R[i] = r;
        //cout << i << " " << l << " " << r << endl;
        r = min(r * 2, (ll)1e18);
    }
    if (0 < a[n] && a[n] <= r) {
        ll cur = a[n];
        ll ans = 0;
        //cout << endl;
        for (int i = n - 1; i >= 0; i--) {
            ans += cur;
            //cout << cur << " " << R[i] << " " << a[i] << endl;
            cur = min(cur, R[i]) + a[i];
        }
        //cout << endl;
        ans++;
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 5108