akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        if (k % 2 == 0) {
            System.out.println(k * k / 4);
            return;
        }
        System.out.println(k / 2 * (k + 1) / 2);
    }

}


Measured memory_bytes: 23124
#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<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(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())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
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;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

const int W=112345;
const int D=10;
int dp[D+1][W];
pii vw[1<<18];
vector<pii> qs[1<<18];
int re[W];
vector<pii> cur;
int N;

void solve(int i,int d){
	if(i>=N) return;
	if(d<D){
		auto [v,w]=vw[i];
		rep(j,W) dp[d+1][j]=dp[d][j];
		rep(j,W)if(j+w<W) MX(dp[d+1][j+w],dp[d][j]+v);
		reps(j,1,W) MX(dp[d+1][j],dp[d+1][j-1]);
		if(i==8){
			out(i,d,v,w,qs[i],1);
			// rep(j,300) cout<<dp[d][j]<<","; cout NL;
			// rep(j,300) cout<<dp[d+1][j]<<","; cout NL;
		}
		for(auto [l,j]:qs[i]) re[j]=dp[d+1][l];
		solve(i*2+1,d+1);
		solve(i*2+2,d+1);
	}else{
		cur.eb(vw[i]);
		const int m=cur.size();
		for(auto [l,j]:qs[i]){
			rep(i,1<<m){
				int rem=l,s=0;
				rep(j,m)if(i>>j&1){
					rem-=cur[j].Y;
					if(rem<0) break;
					s+=cur[j].X;
				}
				if(j==0) out(cur,i,l,j,rem,s,1);
				if(rem>=0) MX(re[j],s+dp[D][rem]);
			}
		}
		solve(i*2+1,d+1);
		solve(i*2+2,d+1);
		cur.pop_back();
	}
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	int n;
	cin>>n;
	rep(i,n) cin>>vw[i].X>>vw[i].Y;
	int q;
	cin>>q;
	rep(i,q){
		int v,l;
		cin>>v>>l; --v;
		qs[v].eb(l,i);
	}
	N=n;
	solve(0,0);
	rep(i,q) cout<<re[i] NL;
  return 0;
}


Measured memory_bytes: 19660
#include <bits/stdc++.h>
using namespace std;
int n, a[10000], dp[2010][2010], margin = 1e8, allmax = 1e8, rowmax[2010];
void chmax(int &a, int b) { a = max(a, b); }
main() {
    cin >> n;
    for(int i = 0; i < 3 * n; ++i) cin >> a[i];
    dp[a[0]][a[1]] = rowmax[a[0]] = rowmax[a[1]] = margin;
    vector<tuple<int, int, int>> update;
    auto upd = [&](int i, int j, int k) {
        for(int _ = 0; _ < 2; _++) {
            update.emplace_back(i, j, k);
            swap(i, j);
        }
    };
    for(int i = 2; i < 3 * n; i += 3) {
        if(a[i] == a[i + 1] and a[i] == a[i + 2]) {
            margin--;
            continue;
        }
        for(int _ = 0; _ < 3; _++) {
            swap(a[i], a[i + 1]), swap(a[i + 1], a[i + 2]);
            upd(a[i], a[i + 1], max(allmax, dp[a[i + 2]][a[i + 2]] + 1));
            for(int j = 1; j <= n; ++j) {
                if(a[i + 1] == a[i + 2]) upd(j, a[i], dp[j][a[i + 1]] + 1);
                upd(j, a[i], rowmax[j]);
            }
        }
        for(auto [e, f, g] : update) chmax(dp[e][f], g), chmax(rowmax[e], g), chmax(allmax, g);
        update.clear();
    }
    cout << allmax - margin << endl;
}

Measured memory_bytes: 19472
#include<bits/stdc++.h>
using namespace std;
#define RI register int
typedef long long LL;
LL x,y;
int main()
{
    scanf("%lld%lld",&x,&y);
	if(x*y>=0&&y>=x) printf("%lld\n",y-x);
	else if(x*y>=0) printf("%lld\n",min(x-y+2,abs(x+y)+1));
	else printf("%lld\n",min(abs(abs(x)-abs(y))+1,abs(x)+abs(y)));
	return 0;
}

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

const long long INF = 1001001001001001001ll;

int size;
vector<long long> val;
vector<long long> lazy;

void lazy_propagate(int p) {
    if (lazy[p] != -1) {
        val[p] = lazy[p];
        if (p < size-1) {
            lazy[p*2+1] = lazy[p];
            lazy[p*2+2] = lazy[p];
        }
        lazy[p] = -1;
    }
}

void update(int wishl, int wishr, int watchl, int watchr, int k, int x) {
    if (wishr <= watchl || watchr <= wishl) {
        lazy_propagate(k);
        return;
    }
    if (wishl <= watchl && watchr <= wishr) {
        lazy[k] = x;
        lazy_propagate(k);
        return;
    }
    int mid = (watchl+watchr)/2;
    lazy_propagate(k);
    update(wishl, wishr, watchl, mid, k*2+1, x);
    update(wishl, wishr, mid, watchr, k*2+2, x);
    val[k] = min(val[k*2+1], val[k*2+2]);
}
void update(int wishl, int wishr, int x) {
    update(wishl, wishr, 0, size, 0, x);
}

long long getmin(int wishl, int wishr, int watchl, int watchr, int k) {
    if (wishr <= watchl || watchr <= wishl) {
        return INF;
    }
    if (wishl <= watchl && watchr <= wishr) {
        lazy_propagate(k);
        return val[k];
    }
    int mid = (watchl+watchr)/2;
    lazy_propagate(k);
    long long ml = getmin(wishl, wishr, watchl, mid, k*2+1);
    long long mr = getmin(wishl, wishr, mid, watchr, k*2+2);
    return min(ml, mr);
}
long long getmin(int wishl, int wishr) {
    return getmin(wishl, wishr, 0, size, 0);
}

signed main() {
    int n, q;
    cin >> n >> q;
    size = 1;
    while (size < n) size <<= 1;
    val = vector<long long>(size*2, (1ll<<31)-1);
    lazy = vector<long long>(size*2, -1);

    while (q--) {
        int type, l, r;
        cin >> type >> l >> r;
        if(type == 0) {
            int x;
            cin >> x;
            update(l, r+1, x);
        } else {
            cout << getmin(l, r+1) << endl;
        }
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    int idx = 1;
    int ans = 0;
    rep(i,n){
        if(a.at(i) == idx){
            idx++;
            continue;
        }
        ans++;
    }
    if(ans == n) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc = 1; 
    //cin >> tc;
    while(tc--){
        int n,p; cin >> n;
        set<int> ans;
        for(int i = 2; i*i <= n; i++)
        {   
            if(n % i == 0)
            {
                p = n;
                while(p%i == 0)
                    p /= i;
                if(p%i == 1)
                    ans.insert(i);
                p = n;
                while(p%(n/i) == 0)
                    p /= (n/i);
                if(p%(n/i) == 1)
                    ans.insert(n/i);
            }
        }
        ans.insert(n);
        n--;
        for(int i = 2; i*i <= n; i++)
            if(n%i == 0)
            {
                ans.insert(i);
                ans.insert(n/i);
            }
        if(n > 1)
            ans.insert(n);
        cout << ans.size();
    }    
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) 0&&0
#endif
#define rout(i) (cout << i << '\n', 0)
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
template<typename T, typename S>
inline istream& operator >> (istream &in, const pair<T, S> &a){
	return in >> a.first >> a.second;
}
template<typename T, typename S>
inline ostream& operator << (ostream &ou, const pair<T, S> &b){
	return ou << b.first << ' ' << b.second;
}
int n, d[10000];
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	int res = 0;
	for(int i = 0;i < n;++i)cin >> d[i];
	for(int i = 0;i < n;++i)for(int j = i + 1;j < n;++j)res += d[i] * d[j];cout << res << '\n';

}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

int N, A, B;
VI H;

bool check(LL M) {
    double sumx = 0;
    REP(i, N) {
        double x = max(ceil((double)(H[i] - B * M) / (A - B)), 0.0);
        //cout << i << " " << x << " " << M << endl;
        sumx += x;
    }
    return sumx <= M;
}

void solve() {
    LL lo = 0;
    LL hi = 1000000000 + 10;
    int loop = 100;
    for (int i = 0; i < loop; i++) {
        LL md = (lo + hi) / 2;
        //dump(md)
        if (check(md)) {
            hi = md;
        } else {
            lo = md;
        }
    }
    cout << hi << endl;

}

int main(int argc, char const* argv[])
{
    cin >> N >> A >> B;
    REP(i, N) {
        int h; cin >> h; H.PB(h);
    }
    solve();
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

long long n,a[55],cnt=1,t,p;

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    while(cnt){
        cnt=0;
        for(int i=1;i<=n;i++){
            p=a[i]/n;
            a[i]%=n;
            for(int j=1;j<=n;j++){
                if(j!=i) a[j]+=p;
            }
            cnt+=p;
        }
        t+=cnt;
    }
    cout << t;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <string>

using namespace std;

#define MOD 100000007

void solve()
{
	int dp1[100001], dp2[100001];
	memset(dp1,0,sizeof(dp1));
	memset(dp2,0,sizeof(dp2));
	dp1[1] = 1; dp1[2] = 2; dp1[3] = 4; dp1[4] = 8; dp1[5] = 16;
	dp2[1] = 1; dp2[2] = 2; dp2[3] = 4;
	
	for(int i = 6; i < 100001; ++i)
	{
		dp1[i] = (1 + dp1[i - 1] % MOD + dp1[i - 2] % MOD + dp1[i - 3] % MOD + dp1[i - 4] % MOD + dp1[i - 5] % MOD) % MOD;
	}
	for(int i = 4; i < 100001; ++i)
	{
		dp2[i] = (1 + dp2[i - 1] % MOD + dp2[i - 2] % MOD + dp2[i - 3] % MOD) % MOD;
	}
	
	string str;
	while(cin >> str)
	{
		if(str == "#")
		{
			break;
		}
		long long ret = 1;
		char c;
		c = str[0];
		int num;
		num = 1;
		if(str.size() == 1)
		{
			cout << 1 << endl;
		}
		else
		{
			for(int i = 1; i < str.size(); ++i)
			{
				if(str[i] == c)
				{
					++num;
				}
				else
				{
					if(c == '0' || c == '8')
					{
						ret = ((long long)ret * dp2[num]) % MOD;
					}
					else
					{
						ret = ((long long)ret * dp1[num]) % MOD;
					}
					c = str[i];
					num = 1;
				}
			}
			if(c == '0' || c == '8')
			{
				ret = ((long long)ret * dp2[num]) % MOD;
			}
			else
			{
				ret = ((long long)ret * dp1[num]) % MOD;
			}
			cout << ret << endl;
		}
	}
}

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

Measured memory_bytes: 2112
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}

using namespace std;

const int mod=1e9+7;

signed main(){
    int n;
    cin >> n;
    if(n>=1000)
    {
        cout << "ABD" << endl;
        return 0;
    }
    cout << "ABC" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

#define INFTY 1000000000

int count=0;

void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  int *L,*R;

  n1 = mid - left;
  n2 = right - mid;
  /*L[0...n1], R[0...n2] を生成*/
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));
  for( i = 0; i<=n1-1; i++){
    L[i] = A[left + i];
  }

  for (j = 0; j<=n2-1; j++){
    R[j] = A[mid + j];
  }
    L[n1] = INFTY;
    R[n2] = INFTY;
    i = 0;
    j = 0;

  for( k = left; k<=right-1; k++){
      if( L[i] <= R[j]){
        A[k] = L[i];
        i = i + 1;
        count++;
      }

      else{
        A[k] = R[j];
        j = j + 1;
        count++;
      }
    }

    free(L);
    free(R);
  }

void mergeSort(int A[],int left,int right){
        int i,mid;

        if( left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
  mergeSort(A, mid, right);
    merge(A, left, mid, right);
        }
      }

 int main(){

   int A[5000000];
   int n,i;

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

   mergeSort(A,0,n);
   for(i=0; i<n; i++){
     printf("%d",A[i]);
     if(i<n-1) printf(" ");
        }

   printf("\n");
   printf("%d\n",count);
   return 0;
 }



Measured memory_bytes: 5476
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int N;
long long A[200010];
long long T[200010];

bool f(long long X) {
  for (int i=0; i<N; i++) {
    int j = i;
    long long d = 0;

    auto it = lower_bound(T+j, T+i+N, X + (j > 0 ? T[j-1] : 0));
    if (it == T+i+N) continue;
    j = it - T;
    j++;

    it = lower_bound(T+j, T+i+N, X + (j > 0 ? T[j-1] : 0));
    if (it == T+i+N) continue;
    j = it - T;
    j++;

    if (T[i+N-1] - T[j-1] >= X) return true;
  }
  return false;
}

int main() {
  cin >> N;
  for (int i=0; i<N; i++) {
    int a;
    cin >> a;
    A[i] = A[i+N] = a;
  }
  long long t = 0;
  for (int i=0; i<N+N; i++) {
    t += A[i];
    T[i] = t;
  }

  long long lo = 0, hi = 1000000000000000000L;
  long long m;
  while (hi - lo > 1) {
    m = (lo + hi) / 2;
    if (f(m)) lo = m;
    else      hi = m;
  }
  if (f(hi)) m = hi;
  else       m = lo;

  cout << m << "\n";
  return 0;
}

Measured memory_bytes: 6240
#include <bits/stdc++.h>
#define inf (int)1e9
using namespace std;

struct data {
  int x, y, cleaned;
};

int w, h;
int dis[25][25][2000] = {0};
int d[4] = {0, 1, 0, -1};
vector<string> s;
vector<vector<int>> memo;
queue<data> qu;

int solve();
bool ch(data &now);

int main() {
  while(1) {
    cin >> w >> h;
    if(h + w == 0) break;
    s.resize(h);
    for(int i = 0; i < h; ++i) cin >> s[i];
    memo.assign(h, vector<int>(w, -1));
    cout << solve() << endl;
  }
  return 0;
}

int solve() {
  int cnt = 0, ans = inf;
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j) {
      if(s[i][j] == 'o') {
        qu.push({i, j, 0});
        dis[i][j][0] = 0;
        s[i][j] = '.';
      }
      if(s[i][j] == '*') memo[i][j] = cnt++;
    }
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      for(int k = 0; k < (1 << cnt); ++k)
        dis[i][j][k] = inf;
  dis[qu.front().x][qu.front().y][0] = 0;
  while(qu.size() > 0) {
    data now = qu.front();
    qu.pop();
    for(int i = 0; i < 4; ++i) {
      data nextp = now;
      nextp.x += d[i];
      nextp.y += d[1 ^ i];
      if(!ch(nextp)) continue;
      if(s[nextp.x][nextp.y] == '*')
        nextp.cleaned |= (1 << memo[nextp.x][nextp.y]);
      if(dis[nextp.x][nextp.y][nextp.cleaned] >
         dis[now.x][now.y][now.cleaned] + 1) {
        dis[nextp.x][nextp.y][nextp.cleaned] =
            dis[now.x][now.y][now.cleaned] + 1;
        qu.push(nextp);
      }
    }
  }
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      ans = min(ans, dis[i][j][(1 << cnt) - 1]);
  if(ans == inf) return -1;
  return ans;
}

bool ch(data &now) {
  return now.x >= 0 && now.x < h && now.y >= 0 &&
         now.y < w && s[now.x][now.y] != 'x';
}


Measured memory_bytes: 5616
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define num first
#define energy second
#define INF (1<<16)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> P;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int cum[64][64];
int H,W,S,sum;
P dp[40][40][40][40];

int count(int x1,int y1,int x2,int y2){
  return cum[y2-1][x2-1] - cum[y2-1][x1-1] - cum[y1-1][x2-1] + cum[y1-1][x1-1];
}

P dfs(int x1, int y1, int x2, int y2){
  if(~dp[x1][y1][x2][y2].num) return dp[x1][y1][x2][y2];
  if(cum[H][W] - count(x1,y1,x2,y2) > S) return MP(-INF, INF);
  P res = P(1, S-(cum[H][W]-count(x1,y1,x2,y2)));
  for(int i=x1+1;i<x2;i++){
    P a = dfs(x1, y1, i, y2);
    P b = dfs(i, y1, x2, y2);
    P c = P(a.num+b.num, min(a.energy, b.energy));
    res = max(res, c);
  }
  for(int i=y1+1;i<y2;i++){
    P a = dfs(x1, y1, x2, i);
    P b = dfs(x1, i, x2, y2);
    P c = P(a.num+b.num, min(a.energy, b.energy));
    res = max(res, c);
  }
  return dp[x1][y1][x2][y2] = res;
}


int main(){
  while(scanf("%d%d%d",&H,&W,&S) && H||W||S){
    memset(cum, 0, sizeof(cum));
    rep(i,40) rep(j,40) rep(k,40) rep(l,40) dp[i][j][k][l] = MP(-1,-1);
    rep(i,H) rep(j,W) scanf("%d", &cum[i+1][j+1]);
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) cum[i][j] += cum[i][j-1];
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) cum[i][j] += cum[i-1][j];
    sum = cum[H][W];

    P res = dfs(1,1,W+1,H+1);
    printf("%d %d\n", res.first, res.second);
  }
  return 0;
}

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

int main()
{
    int a, b, x;
    cin >> x >> a >> b ;
    if(b <= a){
        cout << "delicious" << endl;
    }else if(b <= a+x){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=1000005,mod=998244353;
int bel[N],A,B,C,n,ans;
char s[N];

int main(){
	scanf("%d%s",&n,s+1);
	ans=1;
	rep(i,1,n)ans=(ll)ans*i%mod;
	rep(i,1,3*n){
		if(s[i]=='R')A++;
		else if(s[i]=='G')B++;
		else C++;
		if(A&&B&&C){
			bel[i]=2;
			A--,B--,C--;
		}
		else{
			if(s[i]=='R'&&A>B&&A>C)bel[i]=1;
			if(s[i]=='G'&&B>A&&B>C)bel[i]=1;
			if(s[i]=='B'&&C>A&&C>B)bel[i]=1;
		}
	}
	int cnt=0;
	rep(i,1,3*n){
		if(bel[i]==1)cnt++;
		if(bel[i]==0)ans=(ll)ans*cnt%mod,cnt--;
	}
	cnt=0;
	per(i,3*n,1){
		if(bel[i]==2)cnt++;
		if(bel[i]==0)ans=(ll)ans*cnt%mod,cnt--;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  LL A,B,C;
  cin>>A>>B>>C;
  cout << min(C, A + B+1) + B << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def dfs(dp,edges,node,visited):
    if node not in visited:
        visited.add(node)
        for kid in edges[node]:
            dfs(dp,edges,kid,visited)
            #print(dp,node,kid)
            dp[node-1] = max(dp[node-1],dp[kid-1])
        if edges[node]:
            dp[node-1] += 1

def solve(edges,n):
    dp = [0]*n
    visited = set()
    for i in range(1,n+1):
        if i not in visited:
            #print(i)
            dfs(dp,edges,i,visited)

    #print(dp)
    print(max(dp))

def main():
    n,m = map(int,input().split())
    edges = {}
    for i in range(1,n+1):
        edges[i] = []

    for i in range(m):
        x,y = map(int,input().split())
        edges[x].append(y)

    solve(edges,n)


main()


Measured memory_bytes: 74336
h = []
w = []
while True:
    h1,w1 = map(int,input().split())
    if (h1 == 0)*(w1 == 0) :
        break
    h.append(int(h1))
    w.append(int(w1))
    

for i in range(len(h)):
    for j in range(h[i]):
        if (j == 0) or (j==h[i]-1):
            print("#"*w[i])
        else:
            print("#"+"."*(w[i]-2)+"#")      
    print()



Measured memory_bytes: 5620
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_ll.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_ll;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

struct range_minimum_query{
  ll fnc(ll a,ll b){
    ll ans = a+b;
    return ans;
  }

  ll n,INF;
  vector<ll> segtree;
  range_minimum_query(ll sz,ll inf=MOD){
    INF=inf;
    for(n = 1; n<sz;) n <<= 1;
    segtree.assign(2*n-1,INF);
  }
  ll find(ll l, ll r){return find(l,r,0,n,0);}
  ll find(ll l, ll r, ll a, ll b, ll k){
    if(b<=l || r<=a) return INF;
    else if(l<=a && b<=r) return segtree[k];
    else return fnc(find(l,r,a,(a+b)/2,2*k+1), find(l,r,(a+b)/2,b,2*k+2));
  }
  void update(ll i, ll x){
    i += n-1;
    segtree[i] += x;
    while(i>0){
      i = (i-1)/2;
      segtree[i] = fnc(segtree[2*i+1], segtree[2*i+2]);
    }
  }
};

int main(){
  ll n,q;
  cin>>n>>q;
  range_minimum_query rmq(n+2,0);
  for(ll i=0;i<q;i++){
    ll a,b,c,d;
    cin>>a>>b;
    if(a==0){
      cin>>c>>d;
      rmq.update(b,d);
      rmq.update(c+1,-d);
    }
    else cout<<rmq.find(0,b+1)<<endl;
  }
}



Measured memory_bytes: 4864
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;



void solve() {
  int N;
  cin>>N;
  cout<<180*N - 360<<endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N, K;
  cin >> N >> K;
  vector<i64> A(N);
  rep(i,0,N) {
    cin >> A[i];
  }

  i64 ok = 1e9;
  i64 ng = 0;
  while(ok - ng > 1) {
    i64 mid = (ok + ng) / 2;
    i64 cnt = 0;
    rep(i,0,N) {
      i64 a = A[i];
      cnt += (a + mid - 1) / mid - 1;
    }
    if(cnt <= K) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"	
	typedef long long LL;
	#define ld long double
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define INFINITE 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)	
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i]; 
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}
	#define precision(a) cout<<fixed<<setprecision(a);
	#define INF (1e18+5)
	#define inf (1e9+5)
	int dx[4] = { 0, 0, 1, -1 };
	int dy[4] = { 1, -1, 0, 0 };
	// 8-directions
	//int dx[]={1,1,1,0,0,-1,-1,-1};
	//int dy[]={-1,0,1,-1,1,-1,0,1};
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	int begtime = clock();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	mt19937_64 rngb(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	ll fpow(ll base, ll power, ll MOD) {
    ll result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	ll modinv(ll x,ll MOD) {return fpow(x, MOD - 2, MOD);}
	void solve()
	{
		ll n;
		cin>>n;
		map<string,ll>pq;
		forn(i,n)
		{
			string x;
			cin>>x;
			pq[x]++;
		}	
		cout<<sz(pq)<<endl;
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
		//cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		#ifndef ONLINE_JUDGE
    		cerr << "Time elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
    		#endif
		return 0;
	}

	
	
	


Measured memory_bytes: 19232
#include <stdio.h>

int main()
{
    int a, b, k;
    scanf("%d %d %d", &a, &b, &k);

    int smaller = a > b ? b : a;

    int n;
    int k_gcd;
    for (n = smaller;; n--)
    {
        if (a % n == 0 && b % n == 0)
            k--;

        if (k <= 0)
        {
            k_gcd = n;
            break;
        }
    }

    printf("%d", k_gcd);

    return 0;
}

Measured memory_bytes: 128
def getval():
    h,w = map(int,input().split())
    a = [input() for i in range(h)]
    return h,w,a 

def main(h,w,a):
    mod = 10**9 + 7
    dp = [[0 for i in range(w+1)] for i in range(h+1)]
    dp[1][1] = 1
    for i in range(1,h+1):
        for j in range(1,w+1):
            if i==1 and j==1:
                continue
            if a[i-1][j-1]=="#":
                continue
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod
    print(dp[h][w])

if __name__=="__main__":
    h,w,a = getval()
    main(h,w,a) 


Measured memory_bytes: 83448
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N; cin >> N;
    vector<int> b(N); rep(i, N) cin >> b[i], --b[i];
    vector<int> ans;
    rep(i, N) {
        bool ok = false;
        for(int j = b.size() - 1; j >= 0; --j) {
            if(j == b[j]) {
                ok = true;
                ans.pb(j + 1);
                b.erase(b.begin() + j);
                break;
            }
        }
        if(!ok){
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(all(ans));
    rep(i, ans.size())cout << ans[i] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool check = false;
  if(s.at(0) != s.at(1)){
    check = true;
  }
  if(s.at(2) != s.at(1)){
    check = true;
  }
  if(s.at(0) != s.at(2)){
    check = true;
  }
  if(check){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, X;
  cin >> N >> X;
  vector<int>L(N);
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }
  int ans = 1, D = 0;
  for (int i = 0; i < N; i++) {
    D = D + L.at(i);
    if (D <= X) {
      ans++;
    }
  }
  cout << ans;
}

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;

int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        mp[a]++;
    }
    
    for (auto x : mp) {
        if (x.second > 1) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 9600
#include <iostream>

using namespace std;

#define MAX 200000

int main(){

    int n, r[MAX];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> r[i];
    }

    int maxv = r[1] - r[0];
    int minv = r[0];
    for(int i = 1; i < n; i++){
        maxv = max(maxv, r[i] - minv);
        minv = min(minv, r[i]);
    }

    cout << maxv << endl;

    return 0;
}



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

#define     MAX             100000 //10^5
#define     ss(a)           scanf("%s",a)
#define     si(a)           scanf("%d",&a)
#define     sii(a,b)        scanf("%d%d",&a,&b)
#define     siii(a,b,c)     scanf("%d%d%d",&a,&b,&c)
#define     sl(a)           scanf("%lld",&a)
#define     sll(a,b)        scanf("%lld%lld",&a,&b)
#define     slll(a,b,c)     scanf("%lld%lld%lld",&a,&b,&c)
#define     sd(a)           scanf("%lf",&a)
#define     sdd(a,b)        scanf("%lf%lf%",&a,&b)
#define     sddd(a,b,c)     scanf("%lf%lf%lf",&a,&b,&c)
#define     deb(a)          printf("## %d ##\n",a)
#define     debb            printf("####\n")
#define     pi(a)           printf("%d",a)
#define     pl(a)           printf("%lld",a)
#define     pd(a)           printf("%lf",a)
#define     pc(a)           printf("%c",a)
#define     bl              printf("\n")
#define     spc             printf(" ")
#define     ll              long long
#define     llu             unsigned long long
#define     pie             2*acos(0.0)
#define     vi              vector<int>
#define     vd              vector<double>
#define     vl              vector<long long>
#define     pb(a)           push_back(a)
#define     pii             pair <int,int>
#define     fl(i,a,n)       for(int i=a; i<n; i++)
#define     rfl(i,n,a)      for(int i=n-1; i>=a; i--)

int t, n, c, T, mn;
int main()
{
    sii(n,T);
    mn = MAX;
    while(n--)
    {
        sii(c,t);
        if(t<=T)
        {
            if(c<mn) mn = c;
        }
    }
    if(mn == MAX) printf("TLE\n");
    else printf("%d\n",mn);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h> 
int main(){
  double r,pai,mennseki,ennsyuu;

  scanf("%lf",&r);
  pai=3.141592653589;
  mennseki=pai*r*r;
  ennsyuu=pai*2*r;
  printf("%f %f\n",mennseki,ennsyuu);
  return 0;
}

Measured memory_bytes: 648
N, M, K = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + a_list[i])
for i in range(M):
    b.append(b[i] + b_list[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)


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

using namespace std;

int main(void)
{
    int n, k;
    cin >> n >> k;
    vector<double> e(n);
    double c = 0, s;

    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        e[i] = (double)(1 + p) / 2;
    }
    for (int i = 0; i < k; i++) c += e[i];
    s = c;

    for (int i = k; i < n; i++) {
        c += e[i] - e[i - k];
        if (s < c) s = c;
    }

    printf("%.12f\n", s);

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int sum(int x){
  int d1,d2,d3,d4,d5;
  d1=x%10;
  x/=10;
  d2=x%10;
  x/=10;
  d3=x%10;
  x/=10;
  d4=x%10;
  x/=10;
  d5=x%10;
  return d1+d2+d3+d4+d5;
}
int main(){
  int N,a,b;
  cin>>N>>a>>b;
  int ans=0;
  for(int i=0;i<=N;i++){
    if(sum(i)>=a&&sum(i)<=b){
      ans+=i;
    }
  }
  cout<<ans<<endl;
}


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

int main() {
    int n;
    cin>>n;
    int m=n;
    int sum;
    while(n>0){
        sum+=n%10;
        n-=n%10;
        n/=10;
    }

    cout << (m%sum==0?"Yes":"No")<<endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
x = [0] * 60
y = [0] * 60
for a in A:
    for i in range(60):
        if a >> i & 1:
            x[i] += 1
        else:
            y[i] += 1
ans = 0
mod = 10**9 + 7
for i in range(60):
    ans += x[i] * y[i] * (1 << i) % mod
    ans %= mod
print(ans)

Measured memory_bytes: 123132
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,y;
  int a[4];
  for(int i=0;i<3;i++)a[i]=-1;
  cin>>n>>y;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n-i;j++){
      if(10000*i+5000*j+1000*(n-i-j)==y){
	a[0]=i;
	a[1]=j;
	a[2]=n-i-j;
      }
    }
  }
  for(int i=0;i<3;i++){
    cout<<a[i];
    if(i==2)cout<<endl;
    else cout<<' ';
  }
  return(0);
}


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

int main(){
    string S;
    cin >> S;
    int N=S.size();
    long long dp_A[100100], dp_AB[100100], dp_ABC[100100];
    const int MOD = pow(10,9)+7;
    dp_A[0]=0; dp_AB[0]=0; dp_ABC[0]=0;
    long long num=1; //文字列の候補数
    for(int i=0; i<N; i++){
        dp_A[i+1]=dp_A[i];
        dp_AB[i+1]=dp_AB[i];
        dp_ABC[i+1]=dp_ABC[i];
        if(S.at(i)=='A'){
            dp_A[i+1] +=num;
        }
        if(S.at(i)=='B'){
            dp_AB[i+1] += dp_A[i];
        }
        if(S.at(i)=='C'){
            dp_ABC[i+1] += dp_AB[i];
        }
        if(S.at(i)=='?'){
            dp_A[i+1] *=3; dp_AB[i+1] *=3; dp_ABC[i+1] *=3;
            dp_A[i+1] += num;
            dp_AB[i+1] += dp_A[i];
            dp_ABC[i+1] += dp_AB[i];
            num *=3;
            num %=MOD;
        }
        dp_A[i+1] %=MOD;
        dp_AB[i+1] %=MOD;
        dp_ABC[i+1] %=MOD;
    }
//    for(int i=0; i<=N; i++){
//        cout << dp_A[i] <<" " << dp_AB[i] << " "<< dp_ABC[i] << endl;
//    }
    cout << dp_ABC[N] << endl;
}

Measured memory_bytes: 2816
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		int c [][] = new int [N][M+1];
		for (int i=0; i<N; i++){
			int K = sc.nextInt();
			
			for (int j=0; j<K; j++){
				int cij=sc.nextInt();
				c[i][cij]=1;
			}
		}
		int ans = 0;
		for (int j=1; j<M+1; j++){
			int temp = 0;
			for  (int i=0; i<N; i++){
			temp+=c[i][j];
			}
			if (temp==N)
				ans++;
		}
		System.out.println(ans);
		sc.close();

	}

}


Measured memory_bytes: 22356
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if((a==1&&b==2)||(a==2&&b==1))
{
    cout<<"3"<<endl;
}
else if((a==1&&b==3)||(a==3&&b==1))
{
    cout<<"2"<<endl;
}
else
{
    cout<<"1"<<endl;
}


    return 0;




}


Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n;
    cin >> n;
    ll tn = 1 << n;
    vl s(tn);
    multiset<ll> alls;
    for (int i = 0; i < tn; ++i) {
        cin >> s[i];
        alls.insert(s[i]);
    }
    sort(s.begin(), s.end(), greater<ll>());
    bool ok = true;
    multiset<ll> sl;
    sl.insert(s[0]);
    alls.erase(s[0]);
    for (int i = 0; i < n; ++i) {
        // for (int j = (1 << i); j < (1 << (i + 1)); ++j) {
        vl temp;
        for (auto its = sl.rbegin(); its != sl.rend(); its = next(its)) {
            auto it = alls.lower_bound(*its);
            if (it == alls.begin()) {
                ok = false;
                break;
            }
            it = prev(it);
            if (*it >= *its) {
                ok = false;
                break;
            } else {
                temp.push_back(*it);
                alls.erase(it);
            }
        }
        for (auto &tt : temp) {
            sl.insert(tt);
        }
    }
    if (ok) {
        cout << "Yes"
             << "\n";
    } else {
        cout << "No"
             << "\n";
    }
    return 0;
}

Measured memory_bytes: 16116
#include <stdio.h>
#include <stdlib.h>
    
typedef struct{
    int k;
    int l;
    int r;
} Node;
    
void insert(Node*, int, int);
void print1(Node*, int);
void print2(Node*, int);
    
int main()
{
    char s[10];
    Node *t;
    int m;
    int a;
    int i;
    
    scanf("%d", &m);
    t=(Node*)malloc(sizeof(Node)*m);
    
    int count=0;
    for(i=0; i<m; i++){
        scanf("%s", &s);
        if(s[0]=='i'){ scanf("%d", &a); insert(t, count, a); count++; }
        if(s[0]=='p'){
            if(count>0) print1(t, 0);
            printf("\n");
            if(count>0) print2(t, 0);
            printf("\n");
        }
    }
        
    return 0;
    
}
    
void print1(Node *t, int p)
{
    if(t[p].l>=0) print1(t, t[p].l);
    printf(" %d", t[p].k);
    if(t[p].r>=0) print1(t, t[p].r);
}
    
void print2(Node *t, int p)
{
    printf(" %d", t[p].k);
    if(t[p].l>=0) print2(t, t[p].l);
    if(t[p].r>=0) print2(t, t[p].r);
}
    
void insert(Node *t, int count, int z)
{
    int x=0, y;
    if(count<1) x=-1;
    
    t[count].k= z;
    t[count].l = -1;
    t[count].r= -1;
    
    while(x>=0){
        y = x; 
        if(z < t[x].k)
            x = t[x].l; 
        else
            x = t[x].r; 
    }
    
    if(count<1){}
    else if(z < t[y].k){
        t[y].l = count; 
    }
    else {
        t[y].r = count;
    }
}

Measured memory_bytes: 8548
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;

const int N=200005;

int n,ans,sum;
int dp[N],a[N],p[N];

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i++) p[a[i]]=i;
	dp[n]=1;
	for (i=n-1;i>=1;i--){
		dp[i]=1;
		if (p[i]<p[i+1]) dp[i]=dp[i+1]+1;
	}
	ans=n-dp[1];
	for (i=1;i<=n;i++){
		if (a[1]==i) sum=i-1;
		else sum=i;
		sum+=n-i-dp[i+1];
		ans=min(ans,sum);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
int a, b, c, d, n, ans;
int ar[234567];
string s;
bool b1, b2;
signed main() {
	cin >> n;
	ans = n;
	for1(i, n) {
		cin >> ar[i];
		if (i > 1 && ar[i] > ar[i - 1])ans--;
	}
	cout << ans << endl << n << endl;
}


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

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

int main() {
  int h,w;
  cin>>h>>w;

  vector<string> c;
  string s;
  rep(i,h){
    cin>>s;
    c.push_back(s);
  }

  rep(i,h*2){
    cout<<c[i/2]<<"\n";
  }
  
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var inp = ReadLine().Split(' ').Select(s => int.Parse(s)).OrderByDescending(i => i).ToArray();
        WriteLine(int.Parse(inp[0].ToString() + inp[1].ToString()) + inp[2]);
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}

Measured memory_bytes: 13396
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

ll h[100010],dp[100010];

int main(void){
	          ll i,j;

	          cin.tie(0);  ios_base::sync_with_stdio(false);

	          ll N,K;
	          cin >> N >> K;
	          for(i=1;i<=N;i++) cin >> h[i];
	          for(i=1;i<=N;i++) dp[i]=1e18;

	          dp[2]=llabs(h[2]-h[1]);
	          dp[1]=0;
	          for(i=2;i<N;i++){
	        	  for(j=max(1LL,i+1-K);j<i+1;j++){
	        		  dp[i+1]=min(dp[i+1],dp[j]+llabs(h[j]-h[i+1]));
	        	  }

	          }

	          cout << dp[N] << endl;

	          return 0;
}


Measured memory_bytes: 1792