akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#define put(x) \
    int x;     \
    cin >> x;
using namespace std;
using ll = long long;
using pii = pair<int, int>;
constexpr int mod = 1e9 + 7;

int main()
{
    ll ans = 0LL;
    int cnt = 0;
    put(n);
    put(m);
    auto comp = [](pii x, pii y) {
        return x.first > y.first;
    };
    priority_queue<pii, vector<pii>, decltype(comp)>
        s(comp);
    for (int i = 0; i < n; i++)
    {
        put(a);
        put(b);
        s.push({a, b});
    }
    while (!s.empty())
    {
        pii tmp = s.top();
        // cout << tmp.first << ' ' << tmp.second << endl;
        if (tmp.second + cnt <= m)
        {
            ans += 1LL * tmp.first * tmp.second;
            cnt += tmp.second;
        }
        else
        {
            ans += 1LL * tmp.first * (m - cnt);
            break;
        }
        s.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

int main(){
    int N;cin>>N;
    int a,odd=0,eve2=0,eve4=0;
    for(int i=0;i<N;i++){
        cin>>a;
        if(a%4==0)eve4++;
        else if(a%2==0)eve2++;
        else odd++;
    }
    
    if(eve2==0){
        if(eve4>=N/2)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else{
        N-=eve2;
        if(eve4>=(N+1)/2)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = 0;
    int N,M; cin >> N >> M;
    vector<vector<char>> masu(N+2,vector<char>(M+2,'#'));
    vector<vector<int>> flag(N+2,vector<int>(M+2,0));
    int dy[4] = {1,0,-1,0};
    int dx[4] = {0,-1,0,1};
    map<char,int> mp;
    mp['v'] = 0; mp['<'] = 1; mp['^'] = 2; mp['>'] = 3;
    pii S;
    int dir = 0;
    for(int i = 1; i <= N;i++){
        for(int j = 1; j <= M; j++){
            cin >> masu[i][j];
            if(mp.count(masu[i][j])){
                dir = mp[masu[i][j]];
                masu[i][j] = '.';
                S = {i,j};
            }
        }
    }
    int y = S.first, x = S.second;
    int from_dir = dir;
    bool f = false;
    while(true){
        if(y == S.first && x == S.second && dir == from_dir && f) return -1;
       // cout << y << " " << x << " " << dir << endl;
        f = true;
        flag[y][x] = 1;
        if(masu[y][x] == 'G') break;
        
        int migi = (dir+1)%4;
        int migiy = y + dy[migi],migix = x + dx[migi];
        int maey = y + dy[dir],maex = x + dx[dir];
        
        if(masu[migiy][migix] != '#'){
            dir = migi;
            y = migiy; x = migix;
        }else if(masu[maey][maex] != '#'){
            y = maey; x = maex;
        }else {
            dir = (dir +3)%4;
        }
    }
    for(auto vec:flag) res += accumulate(vec.begin(),vec.end(),0);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



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

int main()
{
	int N,flag,change,count;
	int A[100];
	count = 0;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	flag = 1;
	int i = 0;
	while(flag)
	{
		flag = 0;
		for (int j = N-1; j > i ; --j)
		{
			if (A[j] < A[j-1])
			{
				change = A[j];
				A[j] = A[j-1];
				A[j-1] = change;
				flag = 1;
				count += 1;
			}
		}
		++i;
	}
	for (int i = 0; i < N; ++i)
	{
		if (i != N-1)
		{
			cout << A[i] << " ";
		}
		else
		{
			cout << A[i] << "\n";
		}
	}
	cout << count << "\n";
	return 0;
}


Measured memory_bytes: 3076
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		String s = scan.nextLine();
		
		int[] number = new int[s.length()];
		for(int i = 0; i < s.length(); i++)
			number[number.length-1-i] = s.charAt(i) - '0';
		
		dfs(number,0,0);
		System.out.println(sum);
	}
	
	static long sum = 0;
	
	static void dfs(int[] number, int digit, int i) {
		sum += Math.pow(2,number.length-i-1) * number[i] * Math.pow(10, digit);
		i += 1;
		if(i == number.length) return;
		
		dfs(number,digit+1,i);
		dfs(number,0,i);
		return;
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const int mod = 2019;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = sz(s);
    reverse(s.begin(), s.end());
    vi modsum(n+1);
    int now = 1;
    rep(i, n) {
        modsum[i+1] = (modsum[i] + (s[i] - '0') * now) % mod;
        now = (now * 10) % mod;
    }
    map<int, int> mp;
    ll ans = 0;
    rep(i, n+1) mp[modsum[i]]++;
    for (auto p : mp) {
        ans += (ll)p.se * (p.se - 1) / 2; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 4428
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

ll fun(ll n,ll x){//cout<<pii(n,x)<<endl;
  ll a=x,b=n-x;
  if(!a || !b) return 0;
  if(a>b){
    return a+b+a/b*2*b+a%b+fun(b,b-a%b)-(b-a%b);
  }else{
    return a+b+b/a*2*a+fun(b%a+a,b%a)-a-b%a;
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  ll n,x;
  cin>>n>>x;
  cout<<fun(n,x)<<endl;
  return 0;
}


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

int n;

int main() {
  cin >> n;
  int ans = 1;
  if (n >= 2) ans = 2;
  if (n >= 4) ans = 4;
  if (n >= 8) ans = 8;
  if (n >= 16) ans = 16;
  if (n >= 32) ans = 32;
  if (n >= 64) ans = 64;
  cout << ans << endl;
  return 0;
}


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

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

  string s;
  string ss;
  cin>>s>>ss;


  if(ss.substr(0, (int)ss.size()-1)==s) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 3612
#include<iostream>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

ll n, a, b;
ll ans, x, y, z;

int main() {
	cin >> n >> a >> b;

	x = n / (a + b);
	y = n % (a + b);
	if (y >= a) {
		z = a;
	}
	else z = y;

	ans = x * a + z;

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    k = int(args[0])

    ret = 1
    a = 7 % k
    while(a):
        a = (a*10+7) % k
        ret += 1
        if k < ret:
            ret = -1
            break

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 9144
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>

using namespace std;

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

typedef long long ll;

#define MAX_T 1260
#define MAX_N 1000

int N,M;
int tb[MAX_N+1][MAX_T+1];

void solve(){
}

int main(){
  while(true){
    cin >> N >> M;
    if(N == 0 && M == 0) break;
    
    memset(tb, false, sizeof(tb));
    
    int r, q;
    
    cin >> r;
    rep(i,r){
      int t,n,m,s;
      cin >> t >> n >> m >> s;
      for(int j=t;j<=MAX_T;j++) {
        tb[n][j] = (s == 1 ? m : 0);
      }
    }

    cin >> q;
    rep(i,q){
      int ts, te, m;
      cin >> ts >> te >> m;
      //      cout << "q: " << ts << " " << te << " " << m << endl;
      int cnt = 0;
      for(int i=ts;i<te;i++){
        for(int j=0;j<=N;j++){
          if(tb[j][i] == m){ cnt++; break; }
        }
      }
      cout << cnt << endl;
    }
  }
}

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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("C.in", "r", stdin);
	freopen ("C.out", "w", stdout);
#endif
}

int main () {

	File();

	int n = read(); 
	
	long double a = read(), x = read(), ans = .0;

	for (int m = n * 2; m; m -= 2) {
		ans += a + x * (m - 1) / 2;
		a = (a * (m + 2) + 5 * x) / m;
		x = (m + 4) * x / m;
	}
	printf ("%.15Lf\n", ans);

    return 0;

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7
from collections import Counter
ctr = Counter(A)
dup = ctr.most_common()[0][0]
i = A.index(dup)
j = A[::-1].index(dup)
l = i+j

MAXN = N+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

ans = []
for k in range(1,N+2):
    ans.append(comb(N+1,k))
for k in range(l+1):
    ans[k] -= comb(l,k)
    ans[k] %= MOD
print(*ans, sep='\n')

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

using namespace std;

vector<int> dp(100001,0);

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   dp.assign(100001,0);
   int n; cin>>n;
   vector<int> arr(n);
   for(int i=0; i<n; ++i) cin>>arr[i];
   
    dp[2] = abs(arr[1]-arr[0]);
   for(int i=3; i<=n; ++i){
       dp[i] = min( dp[i-1] + abs(arr[i-1]-arr[i-2]), dp[i-2] + abs(arr[i-1] - arr[i-3]) );
      
   }
   
   cout<<dp[n]<<'\n';
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
  int n;
  cin>>n;
  bool ans=false;
  vector<int> data(n);
   rep(i,n)cin>>data.at(i);
   sort(data.begin(),data.end());
   rep(i,n-1){
   if(data.at(i)==data.at(i+1))
     ans=true;
   }
   if(ans)cout<<"NO"<<endl;
   else cout<<"YES"<<endl;
    
}


Measured memory_bytes: 1024
import math

N,A,B = map(int, input().split())

H = [int(input()) for _ in range(N)]
H.sort(reverse=True)

# mid回の攻撃で全撃破できるか確認。
hi = math.ceil(H[0] / B)
lo = 1


while hi - lo > 1:
    can_defeat_all_enemies = True
    mid = (hi+lo) // 2
    cnt_extra_attack = 0

    for i in range(N):
        if H[i] > mid * B:
            cnt_extra_attack += math.ceil((H[i] - mid * B) / (A - B))
        # 降順に並べてあるので、あるモンスターで追加攻撃が必要なければそれ以降も必要ない
        else:
            break
    
    # mid以下しか追加攻撃が必要ないので倒しきれる
    if cnt_extra_attack <= mid:
        hi = mid
    else:
        lo = mid

print(hi)


Measured memory_bytes: 7512
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll ans = 0;
    ll n; cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    rep(i,0,n){
        if(i % 2 == 0 && (a[i] & 1))ans++;
    }   

    cout << ans <<"\n";
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define REP(i,a) for(int i=0;i<(a);i++)
#define REPR(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<long long>;
using vvl = vector<vl>;
using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

int main() {
  string S=ss();
  int ans=0;
  int c=0;
  REP(i,S.size()){
    if(S[i]=='A'||S[i]=='C'||S[i]=='G'||S[i]=='T')c++;
    else c=0;
    ans=max(ans,c);
  }
  pi(ans);br();
}


Measured memory_bytes: 256
//37
#include<iostream>
#include<algorithm>

using namespace std;

#define INF (1<<29)

int main(){
  for(int n,m,c,s,g;cin>>n>>m>>c>>s>>g,n|m|c|s|g;){
    int dc[21][101][101];
    fill(dc[0][0],dc[21][0],INF);
    while(m--){
      int x,y,d,c;
      cin>>x>>y>>d>>c;
      dc[c][x][y]=dc[c][y][x]=min(dc[c][x][y],d);
    }
    for(int i=1;i<=c;i++){
      for(int j=1;j<=n;j++){
	for(int k=1;k<=n;k++){
	  for(int l=1;l<=n;l++){
	    dc[i][k][l]=min(dc[i][k][l],dc[i][k][j]+dc[i][j][l]);
	  }
	}
      }
    }
    int p[21];
    for(int i=1;i<=c;i++){
      cin>>p[i];
    }
    int q[21][50],r[21][50];
    for(int i=1;i<=c;i++){
      for(int j=0;j<p[i]-1;j++){
	cin>>q[i][j];
      }
      for(int j=0;j<p[i];j++){
	cin>>r[i][j];
      }
    }
    int op[101][101];
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
	int f=INF;
	for(int k=1;k<=c;k++){
	  if(dc[k][i][j]<INF){
	    int x=0,c=0;
	    for(int l=0;l<dc[k][i][j];l++){
	      c+=r[k][x];
	      if(x<p[k]-1&&q[k][x]-1==l){
		x++;
	      }
	    }
	    f=min(f,c);
	  }
	}
	op[i][j]=f;
      }
    }
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
	for(int k=1;k<=n;k++){
	  op[j][k]=min(op[j][k],op[j][i]+op[i][k]);
	}
      }
    }
    cout<<((op[s][g]==INF)?-1:op[s][g])<<endl;
  }
  return 0;
}

Measured memory_bytes: 2044
s = gets.chomp

aa = s[0..1]
bb = s[2..3]

if aa.to_i >= 1 && bb.to_i >=1 && aa.to_i <= 12 && bb.to_i <= 12
  puts 'AMBIGUOUS'
elsif aa.to_i >= 1 && aa.to_i <= 12
  puts 'MMYY'
elsif bb.to_i >= 1 && bb.to_i <= 12
  puts 'YYMM'
else
  puts 'NA'
end

Measured memory_bytes: 1788
/*
Created by Rishu Sahu @ covid 20-20
*/
/*
*****************************************************************
*/

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define pai pair<int,int>
#define pal pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,a,b) for(int i=a;i<=b;i++)
#define ff first 
#define ss second
#define sz(x) (int)x.size()
#define vi vector<int>
#define vl vector<ll>
#define mpl map<ll,ll>
#define mpi map<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()

const int mod = 1e9+7;
const int INF = INT_MAX;
const int mxm = 500000;

int dp[mxm][3],arr[mxm];

void solve(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        if(i==0){
            dp[i][0]=a;
            dp[i][1]=b;
            dp[i][2]=c;
        }else{
            dp[i][0]=a+max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=b+max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=c+max(dp[i-1][0],dp[i-1][1]);
        }
    }
    int mx=-1;
    rep(i,3) mx=max(mx,dp[n-1][i]);
    cout<<mx<<endl;
}

int main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 4780
a, b = [int(item) for item in input().split()]

if a >= 2 and b >= 2:
  print((a-2) * (b-2))
else:
  if a == 1 and b == 1:
    print(1)
  elif a == 1:
    print(b-2)
  elif b == 1:
    print(a-2)

Measured memory_bytes: 3060
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }


int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	int a[n];

	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	 } 
	 sort(a,a+n);
	 for(int i=0;i<n-1;i++)
	 {
	 	if(a[i]==a[i+1])
	 	{
	 		cout<<"NO"<<endl;
	 		return 0;
		 }
	 }
	 cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 1024
N, K = list(map(int, input().split()))
S = input()

S = S + 'E'   # 終端処理
ans = -1    # 答えの初期値（十分に小さい値）

# 立った人の連続の数
if (S[0] == '0'):
    stand = 1
else:
    stand = 0

L = 0
R = 0

# 尺取り法
while (R < N):
    # 右端を進めることが可能（立った人の連続の数がK以下）なら、右端を進める
    if (stand <= K):
        # 立った人の連続の数が増えるなら1足す
        if (S[R] == '1' and S[R + 1] == '0'):
            stand += 1
        # 答えの更新
        ans = max(ans, R - L + 1)
        R += 1
    # 進められない場合、左端と右端が同じなら両者を進める
    # 左端が右端を追い越さないための処理
    elif (L == R):
        L += 1
        R += 1
    # それ以外は左端のみを進める
    else:
        # 立った人の連続の数が減るなら1減らす
        if (S[L] == '0' and S[L + 1] == '1'):
            stand -= 1
        L += 1
        # 左端のみを進めた場合は答えを更新し得ない

print(ans)

Measured memory_bytes: 9236
#include<stdio.h>

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

int main() {
	int X, K;
	scanf("%d", &X);
	K = 360 / gcd(360, X);
	printf("%d", K);

	return 0;
}

Measured memory_bytes: 2136
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
using std::string;
using std::cin;
using std::cout;
using std::endl;
typedef long long ll;
using std::vector;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

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



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

int main() {
    
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        int h;
        cin >> h;
        H[i] = h;
    }
    vector<int> cnt(N);
    int ans = 0;
    int migi = H[N-1];
    cnt[N-1] = 0;
    for (int i = N-2; i >= 0; i--) {
        if (H[i] >= migi) {
            cnt[i] = cnt[i+1]+1;
        } else {
            cnt[i] = 0;
        }
        migi = H[i];
        ans = std::max(ans, cnt[i]);
    }
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

int main(){

        int hour, minute, second, time[2];

        while(cin >> hour >> minute >> second){

                if(hour == -1 && minute == -1 && second == -1) break;

                time[0] = 120 * 60 - (hour * 3600 + minute * 60 + second);
                time[1] = time[0] * 3;

                for(int i = 0; i < 2; ++i)  printf("%02d:%02d:%02d\n", time[i] / 3600, time[i] % 3600 / 60, time[i] % 3600 % 60);

        }

}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int a[1010][1010],b[1010][1010];
int s1[1010][1010],s2[1010][1010];
int n,m;
char c[10];
int dfs(int x,int y)
{
    int i=0,j=0;
	i=s1[m][m]-s1[x][m]-s1[m][y]+s1[x][y]+s1[x][y];
	i+=s2[x][m]+s2[m][y]-s2[x][y]-s2[x][y];
	j+=s2[m][m]-s2[x][m]-s2[m][y]+s2[x][y]+s2[x][y];
	j+=s1[x][m]+s1[m][y]-s1[x][y]-s1[x][y];
	return max(i,j);
}
int main()
{
    int i,j,k,x,y,ans;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d%s",&x,&y,c);
        j=x%m;
        k=y%m;
        if(j==0)
            j=m;
        if(k==0)
            k=m;
        if(((abs(x-j)+abs(y-k))/m)%2==1)
        {
            if(c[0]=='W')
                c[0]='B';
            else
                c[0]='W';
        }
        if(c[0]=='W')
            b[j][k]++;
        else
            a[j][k]++;
    }
    for(i=1;i<=m;i++)
    for(j=1;j<=m;j++)
    {
        s1[i][j]=s1[i-1][j]+s1[i][j-1]-s1[i-1][j-1]+a[i][j];
        s2[i][j]=s2[i-1][j]+s2[i][j-1]-s2[i-1][j-1]+b[i][j];
    }
    ans=0;
    for(i=0;i<=m+1;i++)
    for(j=0;j<=m+1;j++)
    ans=max(ans,dfs(i,j));
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 16128
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define sc second
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define sp(n) cout << fixed << setprecision(n)
#define ma(n, o) map<n, o>
#define pr(n, o) pair<n, o>
#define so(n) sort(n.begin(), n.end())
#pragma endregion
// abs 絶対値, rtsq ルート, pow(a, n) aのn乗

int main() {
  int N;
  ci(N);
  vector<tuple<st, int, int>> SP(N);
  st S;
  int P;
  rep(i, N) {
    ci(S, P);
    SP.at(i) = mt(S, - P, i + 1);
  }
  so(SP);
  rep(i, N) {
    cout << get<2>(SP.at(i)) << endl;
  }
} 


Measured memory_bytes: 256
from functools import lru_cache
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


N = int(input())
A = tuple(tuple(map(int, input().split())) for _ in range(N))

score = [0] * (1 << N)
for bit in range(1 << N):
    for i in range(N-1):
        if (bit >> i) & 1:
            for j in range(i + 1, N):
                if (bit >> j) & 1:
                    score[bit] += A[i][j]


dp = [0] * (1 << N)
for bit in range(1 << N):
    sub = bit
    while True:
        dp[bit] = max(dp[bit], dp[sub] + score[bit & ~sub])
        sub = (sub - 1) & bit
        if bit == sub:
            break

print(dp[(1 << N) - 1])

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


struct UnionFind{
    vector<int> dat;

    UnionFind(int sz){
        dat.assign(sz, -1);
    }

    bool unite(int x, int y){
        x = root(x), y = root(y);
        if(x == y) return false;
        if(dat[x] > dat[y]) swap(x, y);
        dat[x] += dat[y];
        dat[y] = x;
        return true;
    }
    int root(int k){
        if(dat[k] < 0) return k;
        return dat[k] = root(dat[k]);
    }

    int size(int k){
        return -dat[root(k)];
    }
};

struct BipartiteMatching{
    using Graph = vector<vector<int>>;
    Graph G;
    vector<int> match, alive, used;
    int ts;

    BipartiteMatching(int n) : G(n), alive(n, 1),
                               used(n, 0), match(n, -1), ts(0) {}

    void add_edge(int u, int v){
        G[u].push_back(v);
        G[v].push_back(u);
    }

    int dfs(int idx){
        used[idx] = ts;
        for(auto &&to: G[idx]){
            int w = match[to];
            if(alive[to] == 0) continue;
            if(w < 0 || (used[w] != ts && dfs(w))){
                match[idx] = to;
                match[to] = idx;
                return 1;
            }
        }
        return 0;
    }

    int bimatch(){
        int res = 0;
        for(int i=0; i<G.size(); i++){
            if(alive[i] == 0) continue;
            if(match[i] == -1){
                ++ts;
                res += dfs(i);
            }
        }
        return res;
    }
};


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(m), y(m);
    BipartiteMatching BM(2*n);
    for(int i=0; i<m; i++){
         cin >> x[i] >> y[i];
         x[i]--; y[i]--;
         BM.add_edge(x[i], y[i]+n);
     }
         

    UnionFind UF(m);
    for(int i=0; i<m; i++){
        for(int j=0; j<m; j++){
            if(x[i] == x[j] || y[i] == y[j]){
                UF.unite(i, j);
            }
        }
    }
    int ansmx = 0;
    for(int i=0; i<m; i++){
        if(UF.root(i) == i) ansmx += UF.size(i) - 1;
    }

    int ansmn = BM.bimatch();
    cout << m-ansmn << " " << ansmx << endl;

}



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

typedef pair<int,int> Pos;

int h,w,c;
int ans;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

vector< vector<int> > change(vector< vector<int> > panel, int pre, int after)
{
  vector< vector<int> > visited(h+2,vector<int>(w+2,0));
  queue<Pos> q;
  q.push(Pos(1,1));
  visited[1][1]=1;
  while(!q.empty()){
    Pos p=q.front();q.pop();
    panel[p.first][p.second]=after;
    for(int i=0;i<4;i++){
      Pos next=p;
      next.first+=dy[i];
      next.second+=dx[i];
      if(visited[next.first][next.second])continue;
      if(panel[next.first][next.second]!=pre)continue;
      q.push(next);
      visited[next.first][next.second]=1;
    }
  }
  return panel;
}

int count(vector< vector<int> > panel){
  int cnt=1,color=panel[1][1];
  vector< vector<int> > visited(h+2,vector<int>(w+2,0));
  queue<Pos> q;
  q.push(Pos(1,1));
  visited[1][1]=1;
  while(!q.empty()){
    Pos p=q.front();q.pop();
    for(int i=0;i<4;i++){
      Pos next=p;
      next.first+=dy[i];
      next.second+=dx[i];
      if(visited[next.first][next.second])continue;
      if(panel[next.first][next.second]!=color)continue;
      q.push(next);
      visited[next.first][next.second]=1;
      cnt++;
    }
  }
  return cnt;
}

void solve(vector< vector<int> > panel, int depth)
{
  if(depth==4){
    ans=max(ans,count(change(panel,panel[1][1],c)));
    return;
  }
  for(int i=1;i<=6;i++){
    if(panel[1][1]==i)solve(panel,depth+1);
    else solve(change(panel,panel[1][1],i),depth+1);
  }
  return;
}

int main()
{
  while(cin>>h>>w>>c,h|w|c){
    vector< vector<int> > panel(h+2,vector<int>(w+2,-1));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>panel[i+1][j+1];
      }
    }
    ans=0;
    solve(panel,0);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
import bisect

shrines_many, temples_many, x_many = map(int, input().split())
shrine_positions = [int(input()) for _ in range(shrines_many)]
temple_positions = [int(input()) for _ in range(temples_many)]

inf = int(1e20)
shrine_positions = [-inf] + sorted(shrine_positions) + [inf]
temple_positions = [-inf] + sorted(temple_positions) + [inf]

# s_a, s_b, t_c, t_dを求める。
for _ in range(x_many):
    x = int(input())
    b = bisect.bisect_right(shrine_positions, x)
    d = bisect.bisect_right(temple_positions, x)
    min_distance = inf
    for shrine_position in [shrine_positions[b-1], shrine_positions[b]]:
        for temple_position in [temple_positions[d-1], temple_positions[d]]:
            distance1 = abs(x - shrine_position) + abs(shrine_position - temple_position)
            distance2 = abs(x - temple_position) + abs(shrine_position - temple_position)
            min_distance = min(min_distance, distance1, distance2)

    print(min_distance)


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

using ll = long long;
ll n, m, k;

int main(){
    std::cin >> n >> m >> k;
    std::vector<ll> a(n + 1), b(m + 1);
    a[0] = 0; b[0] = 0;
    for(int i = 0; i < n; i++){
        ll tmp;
        std::cin >> tmp;
        a[i + 1] = a[i] + tmp;
    }
    for(int i = 0; i < m; i++){
        ll tmp;
        std::cin >> tmp;
        b[i + 1] = b[i] + tmp;
    }

    ll cnt = 0;
    for(ll i = 0; i < n + 1; i++){
        ll time = a[i];
        if(time > k) break;
        auto iter = std::lower_bound(b.begin(), b.end(), k - time);
        ll dist = std::distance(b.begin(), iter);
        if(iter == b.end()) dist--;
        if(b[dist] + time > k){
            while(dist != 0 && b[dist] + time > k){
                dist--;
            }
        }
        cnt = std::max(cnt, i + dist);
    }
    std::cout << cnt << std::endl;
    return 0;
}


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

bool isPrime(int x){
  int i;
  if(x < 2) return 0;
  else if(x == 2) return 1;
  if(x % 2 == 0) return 0;
  for(i = 3; i*i <= x; i += 2)
    if(x % i == 0) return 0;
    return 1;

}

int main(){
  int X;
  int i;
  cin >> X ;

  for(i = X; i < X*2; i += 1){
    if(isPrime(i)){
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

vector<long long> w, d;
long long n, k;

bool C(long long mid){
	long long f = 0;

	rep(i,n){
		if(mid - w[i] >= 0){
			f++;
			f+=(mid - w[i]) / d[i];
		}
	}

	return k <= f;
}

int main(){
	cin >> n >> k;

	w = vector<long long>(n);
	d = vector<long long>(n);
	rep(i,n){
		cin >> w[i] >> d[i];
	}

	long long right = (1LL << 61), left = 0;
	rep(i,100){
		long long mid = (right + left ) / 2;
		if(C(mid)) right = mid;
		else left = mid;
	}
	cout << right << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int h,w,pa[12],PA[12];
string dat[12];
bool equiv[12][12];

bool ok(int a, int b) {
    F0R(i,h) if (dat[i][a] != dat[pa[i]][b]) return 0;
    return 1;
}

void match2(bool b = 0) {
    int rem = 0, lst = -1;
    F0R(i,w) if (PA[i] == -1) rem ++, lst = i;
    if (rem == 0) {
        cout << "YES";
        exit(0);
    }
    if (b == 0 && w % 2 == 1) {
        if (equiv[lst][lst]) {
            PA[lst] = lst;
            match2(1);
            PA[lst] = -1;
        }
    }
    F0Rd(i,lst) if (PA[i] == -1 && equiv[i][lst]) {
        PA[i] = lst, PA[lst] = i;
        match2(b);
        PA[i] = -1, PA[lst] = -1;
    }
}

void solve() {
    F0R(i,w) FOR(j,i,w) equiv[i][j] = equiv[j][i] = ok(i,j);
    F0R(i,w) PA[i] = -1;
    match2();
}

void match(bool b = 0) {
    int rem = 0, lst = -1;
    F0R(i,h) if (pa[i] == -1) rem ++, lst = i;
    if (rem == 0) {
        solve();
        return;
    }
    if (b == 0 && h % 2 == 1) {
        pa[lst] = lst;
        match(1);
        pa[lst] = -1;
    }
    F0Rd(i,lst) if (pa[i] == -1) {
        pa[i] = lst, pa[lst] = i;
        match(b);
        pa[i] = -1, pa[lst] = -1;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    F0R(i,h) cin >> dat[i];
    F0R(i,h) pa[i] = -1;
    match();
    cout << "NO";
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 256
import java.io.*;

class Main{
  public static void main(String[] args)throws java.io.IOException{
	  BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

	  String hoge = input.readLine();
	  int x = Integer.parseInt(hoge);

      System.out.println(x*x*x);
  }
}

Measured memory_bytes: 24248
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define M 1000000007
typedef long long ll;

ll ruijo(int i) {
  ll ans = 1;
  for (int j = 0; j < i; j++) {
    ans = ans*2%M;
  }
  return ans;
}

int main() {
  int N;
  ll A[300005];
  int i, j;
  ll ans = 0;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A+N);
  ll temp = A[N-1];
  int cnt = 0;
  while (temp > 0) {
    temp /= 2;
    cnt++;
  }
  for (i = 0; i < cnt; i++) {
    ll sum1 = 0;
    ll sum2 = 0;
    for (j = 0; j < N; j++) {
      if (A[j] % 2 == 0)
        sum1++;
      else
        sum2++;
      A[j] /= 2;
    }
    ans += ((sum1 * sum2)%M * (ruijo(i) % M)) % M;
  }
  cout << ans%M << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
ll cnt = 0;

int main(){
  int R,G,B,N;  cin >> R >> G >> B >> N;
  ll ans = 0;
  for(int i=0;i<=N;i++){
      for(int j=0;j<=N;j++){
          if( (N-G*i-B*j)%R == 0 && (N-G*i-B*j)>=0){
              ans++;
          }
      }
  }
  cout << ans << endl;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 998244353;

const int MAXN = 2e3 + 5;

ll dp[MAXN][MAXN][2];

ll c[2 * MAXN][2 * MAXN];

ll ans[2 * MAXN];

ll get_ans(int n, int k, int lim) {
	/*if (k == 1) {
		printf("%d %d %d %lld\n", n, k, lim, c[n + lim - k - 1][lim - k - 1]);
		return c[n + lim - 2][lim - 2];
	}*/
	ll ans = 0ll;
	REPN(i, 0, n) {
		ll mul = 0ll;
		if (k <= lim) {
			mul = c[n - i + lim - k][lim - k];
		} else {
			if (i == n) {
				mul = 1;
			} else {
				mul = 0;
			}
		}
		ll mul2 = (dp[i][k / 2][0] + dp[i][k / 2][1]) % MOD;
		ans = (ans + mul * mul2) % MOD;
		
		/*if (k == 5) {
			printf("n = %d, k = %d, lim = %d, i = %d: %lld %lld %lld\n", n, k, lim,i,  mul, mul2, ans);
		}*/
	}
	return ans;
}

void solve(){
	int lim = 2001;
	REPN(i, 0, lim) {
		dp[0][i][0] = 1;
	}
	dp[0][1][0] = 1;
	REPN(i, 0, lim) {
		REPN(j, 1, lim) {
			dp[i + 1][j][1] = (dp[i + 1][j][1] + 2 * dp[i][j][0] + dp[i][j][1]) % MOD;
			if (i) {
				dp[i][j + 1][0] = (dp[i][j + 1][0] + dp[i][j][0] + dp[i][j][1]) % MOD;
			}
		}
	}
	
	/*REPN(i, 1, lim) {
		REPN(j, 1, lim) {
			printf("%d %d %lld %lld\n", i, j, dp[i][j][0], dp[i][j][1]);
		}
	}*/
	
	REPN(i, 0, 2 * lim) {
		c[i][0] = c[i][i] = 1;
		REP(j, 1, i) {
			c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
		}
		
		/*REPN(j, 0, i) {
			printf("%ld ", c[i][j]);
		}
		putchar('\n');*/
	}
	
	int n, k;
	cin >> k >> n;
	REPN(i, 2, 2 * k) {
		if (i <= k + 1) {
			if (i % 2 == 1) {
				ans[i] = get_ans(n, i, k);
				//ans[i - 1] = ans[i];
			} else {
				ans[i] = (get_ans(n, i - 1, k - 1) + get_ans(n - 1, i - 1, k - 1)) % MOD;
				//ans[i + 1] = ans[i];
			}
		} else {
			ans[i] = ans[2 * k + 2 - i];
		}
		cout << ans[i] << endl;
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

#define reb(i,b,n) for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n) reb(i,0,n)
#define rreb(i,b,n) for(int i = b-1; i >= n; i--)
#define rrep(i,n) reb(i,n,0)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v) for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vall(x) (x).begin(), (x).end()
#define rvall(x) (x).rbegin(), (x).rend()
#define vsort(v) sort(vall(v))
#define rvsort(v) sort(rvall(v))
#define len(array) (sizeof (array) / sizeof *(array))
#define aall(x) x, x+len(x)
#define asort(x) sort(aall(x))
#define rasort(a, type) sort(aall(a), greater<type>())
#define afill(a, v) fill(aall(a), v)
#define afill2(a, v, type) fill((type *)a, (type *)(a + len(a)), v)
#define sz(x) (int)(x).size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define pb push_back
#define _USE_MATH_DEFINES
#define priArr(table, n) rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define priAr2(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;

using namespace std;
using std::stringstream;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class F, class T> inline void convert(const F &f, T &t){stringstream ss;ss<<f;ss>>t;}
template<class T> inline T sqr(T x) {return x*x;}

typedef long long ll; typedef unsigned long long ull;
typedef pair <int, int> P; typedef pair <int, P> PP;
typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<string> vs;
typedef vector<ll> vl; typedef vector<P > vP; typedef vector<char> vc;
typedef long double ld;

const static int INF = 0x3f3f3f3f;
const static ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const static double EPS = 1e-9;
const static ll MOD = 1000000007LL;

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

int main(int argc, char *argv[])
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    while (true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            break;
        }

        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3620
H, W, K = map(int, input().split())

S = []
for _ in range(H):
    S.append(input())

ans = H * W

for c in range(2**(H-1)):
    num_lines = 0

    g = {}
    tmp = c
    g_index = 0
    for h in range(H):
        g[h] = g_index 
        num_groups = g_index 
        if tmp & 1 == 1:
            g_index += 1
        tmp >>= 1

    num_groups += 1
    num_lines = num_groups - 1 
    g_sum = [0] * num_groups

    for w in range(W):
        tmp = g_sum[:]

        ok = True
        ok2 = True
        for h in range(H):
            tmp[g[h]] += int(S[h][w])
        
            if tmp[g[h]] > K :
                # modoru
                ok = False
                if g_sum[g[h]] == 0:
                    ok2 = False

        if ok :
            g_sum = tmp
        else:
            if ok2:
                g_sum = [tmp[gi] - g_sum[gi] for gi in range(num_groups)]
                num_lines += 1
            else:
                break

    if not ok2:
        continue

    if ans > num_lines:
        ans = num_lines


print(ans)


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

int F(long long a, long long b) {
	int ans = log10(a) < log10(b) ? (int)log10(b)+1 : (int)log10(a)+1;
	return ans;
}

int main() {
	long long N;
	cin >> N;
	double sqrtN = sqrt(N)+1;
	int min = (int)log10(N)+1;
	for (long long i = 1; i < sqrtN; i++) {
		if (N % i == 0) {
			int f = F(i, N / i);
			min = min > f ? f : min;
		}
	}
	cout << min;
}

Measured memory_bytes: 640
n, k = list(map(int, input().split()))
c = {}
cnts = []

for i in range(n):
    a, b = list(map(int, input().split()))
    if a in c:
        cnts[c[a]][1] += b
    else:
        c[a] = len(cnts)
        cnts.append([a, b])

cnts = sorted(cnts, reverse=True)

s = 0
while True:
    si = cnts.pop()
    s += si[1]

    if s >= k:
        print(si[0])
        break

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

typedef long long ll;
typedef long double ld;

using namespace std;

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

int main(){
  string X;
  cin >> X;

  int open = 0;
  int cnt = 0;
  rep(i,X.size()){
    if(X[i] == 'S'){
      ++open;
    }else{
      if(open>0){
        --open;
        cnt+=2;
      }
    }
  }

  cout << X.size() - cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}












const int limit = 51;
int n,m;
bool vec[limit][limit];
bool vis[limit];

void DFS(int x){
    if(vis[x]) return;

    vis[x] = true;

    REP(i,n){
        if(vec[i][x]){
            DFS(i);
        }
    }
}
using namespace std;
int main(){
    string s;
    cin >> s;

    REP(i,s.size()-1){
        if(s[i] == s[i+1]){
            cout << "Bad" <<endl;
            return 0;
        }
    }

    cout << "Good" <<endl;
}

Measured memory_bytes: 256