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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class T> ostream& operator<<(ostream &os, set<T> S){os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}";}
#ifdef np
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "<<arg1<<endl;}
template<typename Arg1, typename ... Args>void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,','); cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif


const int N = 1e5+10;
vector<int>g[N];
vector<int> vis;
void dfs(int in , int out , vi &h){
	h[in] = out ;
	vis[in] = true;
	for(auto u : g[in]){
		if(!vis[u]) dfs(u,out+1,h);
	}
}


int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
	
	
    int n; cin >> n;
    int u , v ; 
    cin >> u >> v; --u;--v;
    vis.resize(n);
    
    for(int i =0 ; i+1<n ;++i){
		int a , b;
		cin >> a >> b; --a;--b;
		g[a].pb(b);
		g[b].pb(a); 
	}
	int ans = 0 ;
	vi va(n) ,vb(n);
	dfs(u,0,va);
	fill(all(vis),false);
	dfs(v,0,vb);
	rep(i,0,n){
		if(vb[i]>va[i]) ans = max(ans,vb[i]-va[i]+va[i]-1);
	}    
	cout<<ans<<endl;

#ifdef np
    cerr <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
 return 0; 
 }


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

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

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

inline tuple<ll, ll> rotate45(tuple<ll, ll> p) { ll x = get<0>(p), y = get<1>(p); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	string s; cin >> s;
	ll sum1 = 0;
	REP(i, s.size()) sum1 += s[i] - '0';
	ll sum2 = (s.size() - 1) * 9 + s[0] - '0' - 1;
	cout << max(sum1, sum2) << endl;

	return 0;
}


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

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long, long> pll;

const int INF = 1 << 29;
const double EPS = 1e-9;
const int MOD = 100000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_HW = 1500;
int H, W;
int board[MAX_HW][MAX_HW];
int dp[MAX_HW][MAX_HW];
int main() {
  scanf("%d %d", &H, &W);
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      scanf("%d", &board[i][j]);
    }
  }
  for (int j = 1; j <= W; j++) {
    for (int i = 1; i <= H; i++) {
      if (board[i][j] == 1) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = dp[i - 1][j] + 1;
      }
    }
  }
  int res = 0;
  for (int i = 1; i <= H; i++) {
    stack<pii> st;
    for (int j = 1; j <= W + 1; j++) {
      if (st.empty()) {
        st.push(mp(dp[i][j], j));
      } else if (st.top().first < dp[i][j]) {
        st.push(mp(dp[i][j], j));
      } else if (st.top().first > dp[i][j]){
        int target = i;
        while (!st.empty() && st.top().first >= dp[i][j]) {
          pii pre = st.top();
          st.pop();
          int area = pre.first * (j - pre.second);
          res = max(res, area);
          target = pre.second;
        }
        st.push(mp(dp[i][j], target));
      }
    }
  }
  cout << res << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define mod 1000000007
queue<pair<int,int> >  q;
int n,m,mas[1000][1000];
char a[1000][1000];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    if(a[i][j]=='#')mas[i][j]=1,q.push(mp(i,j));
while(!q.empty())
    {
        pair<int,int> g;
        g=q.front();
        q.pop();
       int x=g.fr;
       int y=g.sc;
        if(x+1<n)
            if(!mas[x+1][y])mas[x+1][y]=mas[x][y]+1,q.push(mp(x+1,y));
        if(y+1<m)
            if(!mas[x][y+1])mas[x][y+1]=mas[x][y]+1,q.push(mp(x,y+1));
        if(x>0)
            if(!mas[x-1][y])mas[x-1][y]=mas[x][y]+1,q.push(mp(x-1,y));
        if(y>0)
            if(!mas[x][y-1])mas[x][y-1]=mas[x][y]+1,q.push(mp(x,y-1));
    }
    int ans=1;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
    ans=max(mas[i][j],ans);
    cout<<ans-1<<endl;
    return 0;
}


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

int main()
{
    long a[3];
    for(auto& e: a) cin>>e;

    long res=1LL<<60;
    for(int i=0; i<3; ++i) {
        long v=a[i]*a[(i+1)%3];
        long t=a[(i+2)%3];
        res=min(res, v*(t-t/2*2));
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<stack>
#define ll long long
#define inf 20021225
#define mid (l+r>>1)
#define M 1000100
#define N 400010
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
struct node{int x,y,id;}a[M],b[M];
struct edge{int to,lt;}e[M];
int poi,ls[N],rs[N],in[N],cnt,n,tot;
void add(int x,int y){e[++cnt].to=y; e[cnt].lt=in[x]; in[x]=cnt;}
void build(int &x,int l,int r,int tag)
{
	if(l==r)	return void(x=tag?a[l].id+n:b[l].id); if(!x) x=++poi;
	build(ls[x],l,mid,tag),build(rs[x],mid+1,r,tag); add(x,ls[x]),add(x,rs[x]);
}
void link(int x,int l,int r,int LL,int RR,int fr)
{
	if(LL>RR)	return;
	if(LL<=l&&RR>=r)	return void(add(fr,x));
	if(LL<=mid)	link(ls[x],l,mid,LL,RR,fr);
	if(RR>mid)	link(rs[x],mid+1,r,LL,RR,fr);
}
stack<int> stk;
int dfn[N],low[N],tms,col[N],cl; bool is[N];
void tarjan(int x)
{
	stk.push(x); dfn[x]=low[x]=++tms; is[x]=1;
	for(int i=in[x];i;i=e[i].lt)
	{
		int y=e[i].to;
		if(!dfn[y])	tarjan(y),low[x]=min(low[x],low[y]);
		else if(is[y])	low[x]=min(low[x],dfn[y]);
	}
	if(low[x]==dfn[x])
	{
		int w=0; cl++;
		do
		{
			w=stk.top(); stk.pop(); col[w]=cl; is[w]=0;
		}while(w!=x);
	}
}
int rem[N],rem_cnt,rtx,rty;
bool check(int val)
{
	int lx,rx;
	for(int i=1;i<=poi;i++)	in[i]=rem[i]; cnt=rem_cnt;
	lx=1,rx=1;
	for(int i=1;i<=n;i++)
	{
		while(lx<i&&a[i].x-a[lx].x>=val)	lx++;
		while(rx<=n&&a[rx].x-a[i].x<val)	rx++;
		link(rtx,1,n,lx,i-1,a[i].id),link(rtx,1,n,i+1,rx-1,a[i].id);
	}
	lx=1,rx=1;
	for(int i=1;i<=n;i++)
	{
		while(lx<=n&&a[i].x-b[lx].y>=val)	lx++;
		while(rx<=n&&b[rx].y-a[i].x<val)	rx++;
		link(rty,1,n,lx,rx-1,a[i].id);
	}
	lx=1,rx=1;
	for(int i=1;i<=n;i++)
	{
		while(lx<=n&&b[i].y-a[lx].x>=val)	lx++;
		while(rx<=n&&a[rx].x-b[i].y<val)	rx++;
		link(rtx,1,n,lx,rx-1,b[i].id+n);
	}
	lx=1,rx=1;
	for(int i=1;i<=n;i++)
	{
		while(lx<i&&b[i].y-b[lx].y>=val)	lx++;
		while(rx<=n&&b[rx].y-b[i].y<val)	rx++;
		link(rty,1,n,lx,i-1,b[i].id+n),link(rty,1,n,i+1,rx-1,b[i].id+n);
	}
	
	while(!stk.empty())	stk.pop(); tms=0;
	for(int i=1;i<=poi;i++)	dfn[i]=low[i]=is[i]=col[i]=0;
	for(int i=1;i<=poi;i++)	if(!dfn[i])	tarjan(i);
	for(int i=1;i<=n;i++)	if(col[i]==col[i+n])	return 0;
	return 1;
}
void get()
{
	int l=0,r=1e9,ans=0;
	while(l<=r)
	{
		int val=l+r>>1;
		if(check(val))	ans=val,l=val+1;
		else	r=val-1;
	}
	printf("%d\n",ans);
}
bool cmpx(node x,node y){return x.x<y.x;}
bool cmpy(node x,node y){return x.y<y.y;}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)	a[i].x=b[i].x=read(),a[i].y=b[i].y=read(),a[i].id=b[i].id=i; poi=2*n;
	sort(a+1,a+n+1,cmpx); sort(b+1,b+n+1,cmpy);
	build(rtx,1,n,1); build(rty,1,n,0);
	for(int i=1;i<=poi;i++)	rem[i]=in[i];
	rem_cnt=cnt; get();
	return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n,m; cin >> n >> m;
    vb a(n),b(n);
    rep(i,m){
      int c,d; cin >> c >> d;
      c--;d--;
      if(c == 0)a[d]=true;
      if(d==n-1)b[c]=true;
    }
    rep(i,n){
      if(a[i] && b[i]){
        out("POSSIBLE");
        return 0;
      }
    }
    out("IMPOSSIBLE");
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <cstdio>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  
  int ans = a > b ? a - 1 : a;
  printf("%d\n", ans);
  
  return 0;
}


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

const int MAX = 200000;

// 隣接リストを用いた深さ優先探索（再帰ver.） O(|V|+|E|)
vector<int> G[MAX], color(MAX, 0);
// main関数からこれらを削除すること

void dfs(int u) {
  color[u] = 1; // GRAY
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (color[v] == 0) dfs(v);
  }
  color[u] = 2; // BLACK
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p.at(i);
  
  set<int> s;
  for (int i = 0; i < k; i++) s.insert(p.at(i));
  
  //vector<int> G[n - k + 1];
  
  for (int i = k; i < n; i++) {
    auto fin = s.end();
    fin--;
    if (*s.begin() == p.at(i - k) && *fin < p.at(i)) {
      G[i - k].emplace_back(i - k + 1);
      G[i - k + 1].emplace_back(i - k);
    }
    s.erase(p.at(i - k));
    s.insert(p.at(i));
  }
  
  vector<int> x;
  int count = 0;
  for (int i = 1; i < n; i++) {
    if (p.at(i - 1) < p.at(i)) count++;
    else count = 0;
    if (count >= k - 1) {
      x.emplace_back(i - k + 1);
    }
  }
  
  for (int i = 1; i < x.size(); i++) {
    G[x[i - 1]].emplace_back(x[i]);
    G[x[i]].emplace_back(x[i - 1]);
  }
  
  int ans = 0;
  for (int i = 0; i < n - k + 1; i++) {
    if (color[i] == 0) {
      dfs(i);
      ans++;
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 23032
#include <stdio.h>
#define MAX 600

int f(int x){
	return x*x;
}

int main(void){
	int i,d;
	int s;
	while(1){
		if(scanf("%d",&d) == EOF){break;}
		s = 0;
		for(i = d; i <= MAX-d; i+=d){
			s += f(i) * d;
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int n = N;
		int fx = 0;
		
		while(true){
			if(n == 0) break;
			fx += n % 10;
			n /= 10;
		}
		
		System.out.println((N % fx == 0) ? "Yes" : "No");
	}
}

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

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		int a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	int alice = 0, bob = 0, idx = 0;
	while(idx < N)
	{
		if (idx < N)
		{
			alice += A[idx];
			idx++;
		}
		if (idx < N)
		{
			bob += A[idx];
			idx++;
		}
	}
	cout << alice - bob << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
	int n;
	cin >> n;
	int acout=0, waout=0, tleout=0, reout=0;

	rep(i, n) {
		string s;
		cin >> s;
		if (s == "AC") acout++;
		else if (s == "WA") waout++;
		else if (s == "TLE") tleout++;
		else if (s == "RE") reout++;
	}

	cout << "AC" << " " << "x " << acout<< " " <<endl;
	cout << "WA" << " " << "x " << waout << " " << endl;
	cout << "TLE" << " " << "x " << tleout << " " <<endl;
	cout << "RE" << " " << "x " << reout << " " << endl;
}

Measured memory_bytes: 3632
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    N, M, K = map(int, input().split())

    g = tuple(set() for _ in range(N))
    direct_friend = [0] * N
    for _ in range(M):
        a, b = (int(x) - 1 for x in input().split())

        g[a].add(b)
        g[b].add(a)

        direct_friend[a] += 1
        direct_friend[b] += 1

    bk = tuple(set() for _ in range(N))
    for _ in range(K):
        c, d = (int(x) - 1 for x in input().split())
        bk[c].add(d)
        bk[d].add(c)

    dq = deque()
    checked = [-1] * N
    for v in range(N):
        if ~checked[v]: continue

        dq.append(v)  # v
        checked[v] = v
        root = v
        while dq:
            v = dq.pop()
            for u in g[v]:
                if ~checked[u]: continue
                checked[u] = root
                dq.append(u)

    ctr = [0] * N
    for v in range(N):
        root = checked[v]
        ctr[root] += 1

    ret = []
    for v in range(N):
        root = checked[v]
        t = ctr[root] - direct_friend[v] - 1 - sum(checked[u] == root for u in bk[v])
        ret.append(t)

    print(*ret)


if __name__ == '__main__':
    main()


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	vector<int> ans = {abs(a-b)+abs(a-c),abs(c - b) + abs(b - a) ,abs(c - b) + abs(a - c) };
	sort(ans.begin(), ans.end());
	cout << ans[0] << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();

        int t[] = new int[N + 1];
        t[0] = 0;
        for (int i = 1; i <= N; i++) {
            t[i] = L + i - 1;
        }

        int index = -1;
        int min = 10000;
        for (int i = 1; i <= N; i++) {
            if (min > Math.abs(t[i])) {
                min = Math.abs(t[i]);
                index = i;
            }
        }

        int res = 0;
        for (int i = 1; i <= N; i++) {
            if (i == index) continue;
            res += t[i];
        }

        System.out.println(res);
    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<" "<<endl;
int main(){
  int A,B;cin>>A>>B;
  int ans=-1;
  rep(i,10000){
    if(i*8/100==A && i*10/100==B){ans=i;break;}
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct Node{
  int p;
  int l;
  int r;
};

struct Node T[MAX];
int n,D[MAX];

void print(int u){
  int i,c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p , D[u]);
  if(T[u].p == NIL)printf("root, ");
  else if(T[u].l == NIL)printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  for(i = 0 , c = T[u].l ; c != NIL ; i++ , c = T[c].r){
    if(i)printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

int rec(int u,int p){
  D[u]=p;
  if(T[u].r != NIL)rec(T[u].r , p);
  if(T[u].l != NIL)rec(T[u].l , p+1);
  return 0;
}

int main(){
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].p = T[i].l = T[i].r = NIL;

  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j = 0 ; j < d ; j++){
      scanf("%d",&c);
      if(j==0)T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i = 0 ; i < n ; i++){
    if(T[i].p == NIL)r = i;
  }
  rec(r,0);
  for(i = 0 ; i < n ; i++)print(i);
  return 0;
}



Measured memory_bytes: 6400
#include <iostream>

using namespace std;

int main()
{
    int N,Tmax;
    int custo,tempo;
    int melhorc = 1000,melhort;
    ios::sync_with_stdio(false);
    cin >> N >> Tmax;
    melhort = Tmax + 1;
    for (int i = 0 ; i < N ; i++)
    {
        cin >> custo >> tempo;
        if(custo<=melhorc && tempo<=Tmax)
        {
            if(custo <= melhorc)
            {
                melhorc = custo;
                //cout << "melhorc: " << melhorc << endl;
                melhort = tempo;
            }
        }
    }
    if (melhort <= Tmax)
    {
        cout << melhorc << endl;
    }
    else
    {
        cout << "TLE" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Payment
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  printf("%d\n", (n + 999) / 1000 * 1000 - n);
  return 0;
}


Measured memory_bytes: 3228
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  t,a=LI()
  l=[LI() for _ in range(n-1)]

  # t<=nt' and a<=na'
  # t/t'<=n and a/a'<=n
  for _t,_a in l:
    _n=max(-(-t//_t),-(-a//_a))
    t=_n*_t
    a=_n*_a

  return t+a

# main()
print(main())


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

int main() {
    int X, G_500 = 1000, G_5 = 5, C_500, C_5;
    cin >> X;
    C_500 = X / 500;
    C_5 = (X - (int)(X / 500) * 500) / 5;
    cout << G_500 * C_500 + G_5 * C_5 << 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++)
#define N 41
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n;
    ll k;
    cin>>n>>k;
    vector<ll>a(n);
    REP(i,n)IN(a[i]);
    ll x=0;
    vector<int>t(N,0);
    REP(i,N){
        REP(j,n){
            if(a[j]&(ll)(1LL<<i))t[i]++;
        }
    }
    for(int i=N-1;i>=0;i--){
        if(t[i]<=n/2&&(ll)((1LL<<i)|x)<=k){
            x|=(ll)(1LL<<i);
        }
        //cout<<t[i]<<" "<<x<<endl;
    }
    ll ans=0;
    REP(i,n){
        ans+=(ll)(x^a[i]);
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        String T = scanner.next();

        scanner.close();

        int ans = Integer.MAX_VALUE;
        if (S.contains(T)) {
            System.out.println(0);
            return;
        }

        int i = 0;
        while (true) {
            int temp = 0;
            for (int j = 0; j < T.length(); j++) {
                if (S.charAt(i + j) != T.charAt(j)) {
                    temp++;
                }
            }
            if (temp < ans) {
                ans = temp;
            }

            if (i >= S.length() - T.length()) {
                break;
            } else {
                i++;
            }
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 35984
def div2(n):
  count = 0
  while True:
    if n%2!=0: break
    n /= 2
    count += 1
  return count

N=int(input())
a=list(map(int, input().split()))

count = 0
for i in range(N):
  count += div2(a[i])
print(count)

Measured memory_bytes: 4148
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl '\n'
#define PI acos(-1)
typedef long long ll;
//	Table is the complete reverse of dp
//	Always think of the pattern (LCM, GCD)
//	Be careful of unsigned
//	double epsilon = FLT_EPSILON;
//	Think of a solution that gets TLE and optimize it
int n;
ll **dp, *x;

int main()
{
    cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);
    cin >> n;
    x = new ll[n];
    dp = new ll *[n];
    for(int i = 0; i < n; i++)
    {
    	cin >> x[i];
    	dp[i] = new ll[n];
    	dp[i][i] = 0;
    	if(i)
    	{
			x[i] += x[i - 1];
    		dp[i - 1][i] = x[i] - (i - 1? x[i - 2]: 0);
    	}
    }
    for(int sz = 2; sz < n; sz++)
    	for(int i = 0; i < n - sz; i++)
    	{
    		ll &ret = dp[i][i + sz];
    		ret = 1e16;
    		for(int j = i; j < i + sz; j++)
    			ret = min(ret, dp[i][j] + dp[j + 1][i + sz]);
    		ret += x[i + sz] - (i? x[i - 1]: 0);
    	}
    cout << dp[0][n - 1];
}


Measured memory_bytes: 1536
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    string s_,t; cin >> s_ >> t;
    int ns = s_.size(), nt = t.size();

    vector<string> ans;
    REP(i,ns-nt+1){
        bool flag=true;
        REP(j,nt){
            if(s_[i+j] == '?') continue;
            if(s_[i+j] != t[j]){flag=false; break;}
        }
        if(flag){
            string ans1="";
            REP(j,i){
                if(s_[j] == '?') ans1 += "a";
                else ans1 += s_[j];
            }
            ans1 += t;
            int n = ans1.size();
            REP(j,ns-nt-i){
                if(s_[n+j] == '?') ans1 += "a";
                else ans1 += s_[n+j];
            }
            ans.push_back(ans1);
        }
    }
    if(ans.size()==0){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    SORT(ans);
    cout << ans[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
#define sz(x) (ll)x.size()
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> osSet;

using pll = pair<ll, ll>;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

ll func(ll x){
	return (x*(x+1))/2;
}

ll _pow(ll b, ll p){
	if(p == 0) return 1;
	if(p == 1) return b;
	ll exB = b*b;
	if(p&1) return b*_pow(exB, p/2);
	return _pow(exB, p/2);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	ll ar[a];
	for(ll i=0; i<a; i++){
		cin >> ar[i];
		if(i >= b){
			if(ar[i] > ar[i-b])
				cout << "Yes\n";
			else
				cout << "No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 5216
#include <iostream>

using namespace std;

int main()
{
    int n;
    long long int a,b,d;
    cin >> n >> d;
    int cn{0};
    for(int i=0;i<n;i++)
    {
        cin >> a >> b;
        if((a*a)+(b*b)<=d*d)
            cn++;
    }
    cout << cn << '\n';
    return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

int main() {
  ll n;
  cin >> n;
  vector< pair<ll, ll> > a;
  for (int i=0;i<n;i++){
    ll tmp;
    cin >> tmp;
    a.push_back(pair<ll, ll>(tmp, i));
  }
  sort(a.begin(),a.end());
  ll max1 = a[n-1].first;
  ll max_idx = a[n-1].second;
  ll max2 = a[n-2].first;
  
  for (int i=0;i<n;i++){
    if (i == max_idx) cout << max2 << endl;
    else cout << max1 << endl;
  }
}

Measured memory_bytes: 6256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 1000010
#define MAX_V 900010
using namespace std;
struct edge{
    int from,to,cost;
};
int m;
edge e[61];
void ins(int x,int y,int c){
    e[m]={x,y,c};
    m++;
}
main(){
    int n;cin>>n;
    
    int temp=20;
    while(temp>1){
        if(n==1){
            ins(1,temp,0);break;
        }
        else if(temp==2){
            rep(i,n)ins(1,2,i);
            temp--;
        }
        else if(n%2==0){
            ins(temp-1,temp,n/2);
            ins(temp-1,temp,0);
            n/=2;temp--;
        }
        else{
            ins(1,temp,n-1);
            ins(temp-1,temp,n/2);
            ins(temp-1,temp,0);
            n/=2;temp--;
        }
    }
    cout<<20<<" "<<m<<endl;
    if(m>60)return 0;
    rep(i,m){
        printf("%d %d %d\n",e[i].from,e[i].to,e[i].cost);
    }
    return 0;
}

Measured memory_bytes: 256
h, n = map(int, input().split())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
DP = [0 for _ in range(h+1)]

for i in range(1,h+1):
    magic = 10 ** 10
    for j in range(n):
        magic = min(DP[max(0, i-A[j])] + B[j], magic)
    DP[i] = magic

print(DP[-1])

    

Measured memory_bytes: 42220
N=int(input())
A=list(map(int,input().split()))

L=[]
R=[]
for i in range(N):
    l=A[i]+i
    r=i-A[i]
    L.append(l)
    R.append(r)

x=dict()
y=dict()
for i in range(N):
    val=R[i]
    if val in x:
        x[val]+=1
    else:
        x[val]=1

ans=0
for i in range(N):
    val=L[i]
    if val in x:
        ans+=x[val]

print(ans)

Measured memory_bytes: 50244
N = int(input())
A = list(map(int, input().split()))

nSwap = 0
for i in range(N):
    for j in range(N-1, i, -1):
        if A[j] < A[j-1]:
            A[j-1], A[j] = A[j], A[j-1]
            nSwap += 1

print(' '.join(map(str, A)))
print(nSwap)

Measured memory_bytes: 7720
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    void solve()
    {
        N = cin.nextint;
        WriteLine(N * N - cin.nextint);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

void solve(long long N, std::vector<long long> s) {
    sort(s.begin(), s.end());
    ll sum = accumulate(s.begin(), s.end(), 0LL);
    if (sum % 10 == 0) {
        rep(i, N) {
            if (s[i] % 10 != 0) {
                sum -= s[i];
                cout << sum << endl;
                return;
            }
        }
        cout << 0 << endl;
        return;
    } else {
        cout << sum << endl;
        return;
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> s(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &s[i]);
    }
    solve(N, std::move(s));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;
vector<int> S[MAX];
int need[MAX];

int solve(int u){
    vector<int> T;
    for(int i=0;i<S[u].size();i++){
        int a=S[u][i];
        if(need[a]!=-1) T.push_back(need[a]);
        else T.push_back(solve(a));
    }
    
    if(T.size()==0) return need[u]=0;
    sort(all(T));
    int ans=0;
    for(int i=0;i<T.size();i++){
        ans=max(ans,T[i]+int(T.size())-i);
    }
    return need[u]=ans;
}

int main(){
    
    int N;cin>>N;
    
    for(int i=0;i<N;i++){
        need[i]=-1;
    }
    
    for(int i=0;i<N-1;i++){
        int a;cin>>a;
        a--;
        S[a].push_back(i+1);
    }
    
    cout<<solve(0)<<endl;
    
}



Measured memory_bytes: 15488
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1e9 + 7;

// ll dp[200010] = {0};
ll h[200010] = {0};
ll a[200010] = {0};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	while(t != 0) {
        int n;
        cin >> n;
        for(int i = 0; i < n; i++) {
            cin >> h[i];
        }
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        ll base = 1;
		while(base <= n) {
			base *= 2;
		}

		// this question is solved using dp on segment trees
		vector<ll> tree(2*base);
		// dp stores values for height of flowers
		vector<ll> dp(n+1);

		for(int flower = 0; flower < n; flower++) {
			int x = h[flower] + base;
			// find the flower with given hight in tree

			ll best = 0;
			// go from leaf till root and whenever we are at right child, choose the left child
			while(x > 1) {
				if(x%2 == 1) {
					best = max(best, tree[x-1]);
				}
				x /= 2;
			}

			// for current height, get the previous best and current flower beauty
			dp[h[flower]] = best + a[flower];

			// update the tree
			for(int i = base + h[flower]; i >= 1; i /= 2) {
				tree[i] = max(tree[i], dp[h[flower]]);
			}
		}

		ll ans = 0;
		for(int i = 0; i <= n; i++) {
			ans = max(ans, dp[i]);
		}
		cout << ans << "\n";
	    t--;
	}
	return 0;
}


Measured memory_bytes: 11900
from collections import deque
class edge:
    def __init__(self,to,cost):
        self.to=to
        self.cost=cost

N=int(input())
G=[list() for i in range(N)]
P=[False for i in range(N)]
A=[-100 for i in range(N)]
for i in range(N-1):
    a,b,c=map(int,input().split())
    G[a-1].append(edge(b-1,c))
    G[b-1].append(edge(a-1,c)) #無向グラフならこれも



def solve(G,K,P):
    q=deque()
    q.append(K)
    while q:
        s=q.pop()
        for i in G[s]:
            if(P[i.to]):
                continue
            P[i.to]=True
            A[i.to]=A[s]+i.cost
            q.append(i.to)

Q,K=map(int,input().split())
A[K-1]=0
P[K-1]=True
solve(G,K-1,P)


for i in range(Q):
    x,y=map(int,input().split())
    
    print(A[x-1]+A[y-1])



Measured memory_bytes: 64964
def a_falling_asleep():
    N = int(input())
    Playlist = []
    for _ in range(N):
        s, t = input().split()
        Playlist.append((s, int(t)))
    X = input()

    ans = 0
    is_sleeping = False
    for s, t in Playlist:
        if is_sleeping:
            ans += t
            continue
        if s == X:
            is_sleeping = True
    return ans

print(a_falling_asleep())

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

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

int main() {
    string s; cin >> s;
    int a = 0; int z = 0;
    rep(i,s.size()){
        if(s[i] == 'A') break;
        a++;
    }
    for(int i = s.size() - 1; i > 0; i--){
        if(s[i] == 'Z') break;
        z++;
    }
    cout << s.size() - a - z << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstring>
#define Nmax 3005
#define MOD 1000000007

using namespace std;

ifstream f("doipe.in");
ofstream g("doipe.out");

int n, t;
char s[Nmax];
int dp[3][Nmax]; // dp[i][j]-number of ways to put numbers in prefix of size i
                    // such that the last number is j
int sum[Nmax];

void add_self(int &a, int b)
{
    a+=b;
    if(a>= MOD) a-=MOD;
}

int main()
{
        cin >> n >> s;
        dp[0][0]=1;
        for (int i = 1; i <= n; i++)
        {
            sum[0]=dp[(i-1)%2][0];
            for (int j = 1; j <= i; j++) sum[j]=(sum[j-1]+dp[(i-1)%2][j])%MOD;
            for (int j = 0; j <= i; j++)
                if (s[i-1]=='>')
                    dp[i%2][j]=(sum[i]-(j>0?sum[j-1]:0)+MOD)%MOD;
                 else
                    dp[i%2][j]=(j>0?sum[j-1]:0);
        }
        int ans=0;
        for (int i = 0; i < n; i++) ans=(ans+dp[(n-1)%2][i])%MOD;
        cout << ans << '\n';

    return 0;
}



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

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

    int b;
    while (cin >> b, b) {
        int ansP = -1, ansN = -1;
        int n = 1;
        while (n * (n - 1) < 2 * b) {
            if ((2 * b - n * (n - 1)) % (2 * n) == 0) {
                ansP = (2 * b - n * (n - 1)) / (2 * n);
                ansN = n;
            }
            ++n;
        }
        cout << ansP << " " << ansN << endl;
    }
}


Measured memory_bytes: 3144
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(deftype int32 () '(signed-byte 32))
(deftype int64 () '(signed-byte 64))


;;macros
(defmacro println (n)
  `(format t "~a~%" ,n))
(defmacro vint-out (vec)
  `(progn
     (rep i (length ,vec)
          (princ (vref ,vec i))
          (princ " "))
     (fresh-line)))
(defmacro aif (test-form then-form &optional else-form)
  `(let ((it ,test-form))
     (if it ,then-form ,else-form)))

;;vector
(defmacro vec (type &optional (num 100) (val 0))
  (let* ((g (gensym)))
    `(let* ((,g ,num))
       (make-array ,g :element-type ',type :initial-element ,val
                   :adjustable nil :fill-pointer ,g))))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vint (&optional (num 0) (val 0))
  `(vec int32 ,num ,val))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vref (vector pos &optional value)
  (let ((g (gensym)))
    `(let ((,g ,value))
       (if ,g
           (setf (aref ,vector ,pos) ,g)
           (aref ,vector ,pos)))))

(defmacro chvar (sym comp predicate)
  (let ((g (gensym)))
    `(let ((,g ,comp))
       (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))
           (setf ,sym ,g)))))

(defmacro chmax (sym comp &optional (predicate #'>))
  `(chvar ,sym ,comp ,predicate))

(defmacro chmin (sym comp &optional (predicate #'<))
  `(chvar ,sym ,comp ,predicate))

(defmacro defchangef (name op default-val)
  `(defmacro ,name (var &optional (val ,default-val))
     `(setq ,var (,',op ,val ,var))))
(defmacro read-str ()
  `(write-to-string (read)))

;;本体
(defun main ()
  (let ((n (read)) (x (read)) (d 0))
    (println
     (1+ (loop for i below n
            do (incf d (read))
            if (<= d x)
            count i)))))

#-swank(main)


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

using namespace std;

int main(){
    int64_t n;
    cin >> n;
    vector<int64_t> A(5);
    for (auto &a: A) cin >> a;

    int64_t mi = *min_element(A.begin(), A.end());

    cout << ((n + mi - 1) / mi) + 4;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

const int MAX_N = 200005;
double A[MAX_N];

double E(int x) {
    return (double)(x+1)/2;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, k; cin >> n >> k;
    REP(i, n) {
        int a; cin >> a;
        A[i] = E(a);
    }

    double ans=0, temp=0;

    REP(i, n) {
        temp+=A[i];
        if(i>=k) temp-=A[i-k];
        chmax(ans, temp);
    }
    cout << setprecision(10) <<  ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


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


Measured memory_bytes: 256
import * as fs from "fs";
 
let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
var cList = input[0].split(" ").map(x => parseInt(x));

var result = cList.filter(function (x, i, self) { 
    return self.indexOf(x) === i;
});


console.log(result.length);




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

using namespace std;

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

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

int main() {
	int n;
	cin >> n;
	int a[n];
	for (auto &i : a) {
		cin >> i;
	}
	int sum = abs(a[0]) + abs(a[n - 1]);
	for (int i = 1; i < n; i++) {
		sum += abs(a[i - 1] - a[i]);
	}
	cout << sum - abs(a[0]) - abs(a[0] - a[1]) + abs(a[1]) << endl;
	for (int i = 1; i < n - 1; i++) {
		cout << sum - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) << endl;
	}
	cout << sum - abs(a[n - 1]) - abs(a[n - 2] - a[n - 1]) + abs(a[n - 2]) << endl;
	return 0;
}

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

#define srev                reverse(s.begin(),s.end())
#define sortstr             sort(s.begin(), s.end());
#define gtl(x)              getline(cin, (x))
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define PI                  acos(-1)
#define Precision(a) 		cout << fixed << setprecision(a)
#define Faster       		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template <typename T> T Sqr(T x) { T n = x * x ; return n ;}
template <typename T> T Pow(T B,T P){ if(P==0) return 1; if(P&1) return B*Pow(B,P-1);  else return Sqr(Pow(B,P/2));}
template <typename T> T Abs(T a) {if(a<0)return -a;else return a;}
template <typename T> T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template <typename T> T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int cnt=0;
    if(a>=k)
    {
        cout << k << endl;
        return 0;
    }
    cnt+=a;
    k-=a;
    if(b>=k)
    {
        cout << cnt << endl;
        return 0;
    }
    k-=b;
    cout << cnt-k << endl;
    return 0;
}


Measured memory_bytes: 3640