akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int N;
    cin >> N;
    cout << (N+1) / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

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

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

void print(int u) {
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if(T[u].p == NIL) cout << "root, ";
  else if(T[u].l == NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for(i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}
void 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);
}

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

  for(i = 0;i < n;i++) {
    cin >> v >> d;
    for(j = 0;j < d;j++) {
      cin >> 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: 7752
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  int N,M,a,b;
  cin>>N>>M;
  vector <int> ans(N);
  for(int i=0;i<M;i++){
    cin>>a>>b;
    ans[a-1]++;
    ans[b-1]++;
  }
  for(int i=0;i<N;i++){
    cout<<ans[i]<<endl;
  }
}


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

long gcd(long a, long b) {
  if (a < b) {
    swap(a, b);
  }

  long mod = a % b;
  while (mod > 0) {
    a = b;
    b = mod;
    mod = a % b;
  }

  return b;
}

int main() {
  int N;
  long X;
  cin >> N >> X;

  long distances[N];
  for (int i = 0; i < N; i++) {
    long x;
    cin >> x;

    distances[i] = abs(X - x);
  }

  if (N == 1) {
    cout << distances[0] << endl;
    return 0;
  }

  long answer = distances[0];
  for (int i = 1; i < N; i++) {
    answer = gcd(answer, distances[i]);
    if (answer == 1) {
      break;
    }
  }

  cout << answer << endl;
}

Measured memory_bytes: 1024
import sys
#import bisect
#from collections import deque

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())
#D = list(map(int, input().split()))

#D = deque(D)
#sum0 = D.pop()
#hp = 0

T = []

for i in range(1,10):
    for j in range(1,10):
        T.append(i*j)

if N in T:
    print('Yes')
else:
    print('No')


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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define scn(var)         cin >> var;
#define pYes()           prt("Yes")
#define pNo()            prt("No")
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"
//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;
  int year = (s[0]-'0')*1000 + (s[1]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0');
  int month = (s[5]-'0')*10 + (s[6]-'0');
  //int day = (s[8]-'0')*10 + (s[9]-'0');

  if(year<=2019 && month<5){
    prt("Heisei");
  } else {
    prt("TBD");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;
using int64 = long long;
#define ForInt(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define ForIntInit(i, begin, end) for (int i = (begin); i < (end); ++i)
#define ForItr(it, itBegin, itEnd) for (auto (it) = (itBegin); (it) != (itEnd); ++(it))




int main()
{
	auto comparer = [](const pair<int, int>& x, const pair<int, int>& y)
	{
		return x.first < y.first;
	};

	int n;
	cin >> n;
	priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(comparer)> a(comparer);
	int cur;
	ForInt(i, n)
	{
		cin >> cur;
		a.emplace(cur, i);
	}

	pair<int, int> maxPair = a.top();
	int max = maxPair.first;
	int maxIndex = maxPair.second;
	a.pop();
	int secondMax = a.top().first;
	int i = 0;
	for (; i < maxIndex; ++i)
	{
		cout << max << endl;
	}
	cout << secondMax << endl;
	++i;
	for (; i < n; ++i)
	{
		cout << max << endl;
	}

	return 0;
}


Measured memory_bytes: 3312
N, M = map(int, input().split())
Height = list(map(int, input().split()))
Pt = [i for i in range(N)]
Ans = 0

for i in range(M):
  check = 0
  A, B = map(int, input().split())
  if Height[A - 1] > Height[B - 1]:
    Pt[B - 1] = A - 1
  elif Height[A - 1] == Height[B - 1]:
    Pt[B - 1] = A - 1
    Pt[A - 1] = B - 1
  else:
    Pt[A - 1] = B - 1
  
for i in range(N):
  if Pt[i] == i:
    Ans += 1
    
print(Ans)

Measured memory_bytes: 20048
def is_balanced(txt):
    """ ????????????????????????????????¨??????????????¶
    1. ????????????????????¬??§(???(???)?????????????????????????????¬??§(???)???)??????????????????????????????
    2. ????????????????§???¬??§(???[???)?????????????????????????§???¬??§(???]???)??????????????????????????????
    3. ?????????????????¬??§??????????????????????????¬??§????????????
    4. ??¬??§???????????????????????§???????????????????????????????????¬??§????????°?????¬??§??¨?????????????????¨????????????
    ??? ????????????????????????????????¬??§???????????§?????£??????pop()??¨??????????????????????????????????????????????????????????????????????????¨

    5. ?????????????????????????????¬??§??¨?????¬??§????????????????????????????????????????????????????????§ ??¬??§??????????????????????????????
    ??? '( [  ) ]' ??????????????????????????????????????????NG
    """
    round_brackets = []  # ?????¬??§????¨??????¨????????????
    square_brackets = []  # ??§??¬??§??¨

    for c in txt:
        if c == '(':
            round_brackets.append(len(square_brackets))  # '('?????????????????????[]?????¶???????¨???¶????????????
        elif c == ')':
            try:  # ')'?????????????????¨pop()??¨????????§??????????????????????????§
                level = round_brackets.pop()
                if level != len(square_brackets):  # ')'??§???????????????[]?????¶??????'('???????????¨????????¬????????§???????????°?????¶5????????????????????????
                    return False
            except IndexError:
                return False
        elif c == '[':
                square_brackets.append(len(round_brackets))
        elif c == ']':
            try:
                level = square_brackets.pop()
                if level != len(round_brackets):
                    return False
            except IndexError:
                return False

    # ??¬??§?????????????????????????????????????????§??????
    if len(round_brackets) == 0 and len(square_brackets) == 0:
        return True
    else:
        return False


if __name__ == '__main__':
    # ??????????????\???
    # txt = 'So when I die (the [first] I will see in (heaven) is a score list).'
    while True:
        txt = input()
        if txt == '.':
            break

        # ??¬??§?????????????§£???
        ans = is_balanced(txt)

        # ???????????¨???
        if ans:
            print('yes')
        else:
            print('no')

Measured memory_bytes: 7412
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll count=0;
    for(ll i=0;i<s.length();i++)
    {
        if(s[i]=='R')
            count++;
    }
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            if(s[i]+s[j]=='G'+'B')
            {
                sum+=count;
                ll idx=i-(j-i);
                if(idx>=0 && s[idx]=='R')
                    sum-=1;
                idx=(i+j)/2;
                if((i+j)%2==0 && s[idx]=='R')
                    sum-=1;
                idx=j+(j-i);
                if(idx<n && s[idx]=='R')
                    sum-=1;
            }
        }
    }
    cout<<sum;
}


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


int main(){
    int n,m;
    cin >>n >>m;
    vector<int> c(m);
    for(int i=0;i<m;i++){
        cin >>c[i];
    }
    vector<int> dp(100000,100000000);
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            dp[i+c[j]] = min(dp[i+c[j]],dp[i]+1);
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3108
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

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

int main(){
	
	int N;
	cin >> N;
	vector<ll> T(N), A(N);
	for(int i=0;i<N;i++) cin >> T[i] >> A[i];
	
	ll t = T[0];
	ll a = A[0];
	
	for(int i=1;i<N;i++){
		
		ll k1 = (t +T[i] - 1) / T[i];
		ll k2 = (a + A[i] - 1) / A[i];
		ll k = max(k1, k2);
		t = k * T[i];
		a = k * A[i];
	}
	
	cout << (t + a) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  int N,M;cin >> N >> M;
  vector<set<int> > v;
  vector<int> p(M);
  int i,j;REP(i,M){
    set<int> s;
    int k;cin >> k;
    REP(j,k){
      int x; cin >> x;
      s.insert(x);
    }
    v.push_back(s);
  }

  REP(i,M) cin >> p[i];
  int N_2 = 1 << N;

  int count = 0;
  REP(i,N_2){
    int x = i;
    int k;
    //wのスイッチ数
    vector<int> w(M,0);
    REP(j,N){
      int c = x%2;
      if(c != 0){
        REP(k,M){
          if(v[k].count(j+1))w[k]++;
        }
      }
      x/=2;
      if(x==0) break;
    }
    bool f = true;
    REP(k,M){
      if(w[k]%2 != p[k]){
        f = false;
        break;
      }
    }
    if(f){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int r = 1000000;
int l = 0;
int N,M;

int main(){
  cin >> N >> M;
  rep(i,M){
    int a = 0; int b = 0;
    cin >> a;
    cin >> b;
    r = min(b,r);
    l = max(a,l);
  }
  if(r < l) cout << 0 << endl;
  else  cout << r - l +1 << endl;
  return 0;
}



Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int x, y;
	vector<int> ga = { 1,3,5,7,8,10,12 }, gb = { 4,6,9,11 }, gc = { 2 };
	cin >> x >> y;

	if ((count(ga.begin(), ga.end(), x) && count(ga.begin(), ga.end(), y))
		|| (count(gb.begin(), gb.end(), x) && count(gb.begin(), gb.end(), y))
		|| (count(gc.begin(), gc.end(), x) && count(gc.begin(), gc.end(), y)))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B

solv bs = go bs (0,0) where
  go bs (z,o)
    | B.null bs      = 2 * min z o
    | B.head bs=='0' = go (B.tail bs) (z+1,o)
    | otherwise      = go (B.tail bs) (z,o+1)

main = do
  xs <- B.getLine
  print $ solv xs


Measured memory_bytes: 7548
i,m,n,x;main(a){for(;1;){scanf("%d",&i);if(!i)exit(0);for(a=1,x=0;a<13;a++){sca\
nf("%d%d",&m,&n),i-=m-n;if(i<1&&!x)x=a;}x?printf("%d\n",x):puts("NA");}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
//#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 4000000000000000000
int dx8[8]={-1,0,1,1,1,0,-1,-1};
int dy8[8]={1,1,1,0,-1,-1,-1,0};
int dx4[4]={-1,0,1,0};
int dy4[4]={0,-1,0,1};
int gcd(int a,int b){
    if(b==0)return a;
    return abs(gcd(b,a%b));
}
int uni[100010];
int root(int a){
    if(uni[a]<0)return a;
    return uni[a]=root(uni[a]); 
}
bool connect(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b)return false;
    if(uni[a]>uni[b]){
        swap(a,b);
    }
    uni[a]=uni[a]+uni[b];
    uni[b]=a;
    return true;
}
signed main(void){
    int n;cin>>n;
    vector<int>P(n),Q(n),V(n);
    rep(i,n)cin>>P[i];
    rep(i,n)cin>>Q[i];
    rep(i,n)V[i]=i+1;
    int a,b;
    int now=0;
    do{
        now++;
        bool judge=true;
        rep(i,n){
            judge&=(V[i]==P[i]);
        }
        if(judge)a=now;
        judge=true;
        rep(i,n){
            judge&=(V[i]==Q[i]);
        }
        if(judge)b=now;
    }while(next_permutation(all(V)));
    //cout<<a<<':'<<b<<endl;
    cout<<abs(a-b)<<endl;
}
        


Measured memory_bytes: 256
#define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;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 Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    vi p(n+2);
    rep(i,n){
        p[a[i]]=i+1;
    }
    int ans=0;
    set<int> set;
    set.insert(0);
    set.insert(n+1);
    REP(i,1,n){
        auto r=set.upper_bound(p[i]);
        ans+=i*(*r-p[i])*(p[i]-*--r);
        set.insert(p[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 12800
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    A = read_ints()
    front = 0
    total = 0
    for a in A:
        if a < front:
            total += front-a
        else:
            front = a
    return total


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 92620
#include <iostream>
#include <vector>

int main() {
  int H, W;

  while (true) {
    std::cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    }

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if ((i + j) % 2 == 0) {
          std::cout << "#";
        } else {
          std::cout << ".";
        }
      }
      std::cout << std::endl;
    }
    std::cout << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3124
#include <stdio.h>

int main(){
	int N;
	if(scanf("%d", &N) == 1);
	int l;
	for(l=1; l<N; l++){
		N -= l;
	}
	if(N != l){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	printf("%d\n", l+1);
	int answer[l+1][l];
	int Index = 1;
	for(int i=0; i<=l; i++){
		printf("%d", l);
		int j=0;
		for(; j<i; j++){
			printf(" %d", answer[j][i-1]);
		}
		for(; j<l; j++){
			printf(" %d", answer[i][j]=Index++);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
 
#define int             long long
#define ld              long double
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int, int>
#define mk(arr,n,type)  type *arr=new type[n];
#define vi              vector<int>
#define si              set<int>
#define usi             unordered_set<int>
#define mii             map<int, int>
#define umii            unordered_map<int, int>
#define pqmax           priority_queue<int>
#define pqmin           priority_queue<int, vi, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define trailzrobits(x) __builtin_ctzll(x)
#define leadzrobits(x)  __builtin_clzll(x)
#define paritybits(x)   __builtin_parityll(x)
#define gcd             __gcd
#define lcm(x, y)       (x * y) / gcd(x, y)
#define mod             1000000007
#define endl            '\n'
#define PI              3.14159265358979323846
#define inf             1e18
#define sp(x,y)         fixed<<setprecision(y)<<x

void __print(int x) {cout<<x;}
void __print(float x){cout<<x;}
void __print(double x){cout<<x;}
void __print(ld x) {cout<<x;}
void __print(char x){cout <<'\''<<x<<'\'';}
void __print(const char *x){cout <<'\"' <<x<<'\"';}
void __print(const string &x) {cout<<'\"'<<x<<'\"';}
void __print(bool x) {cout<<(x?"true":"false");}
template<typename T,typename V>     void __print(const pair<T,V> &x) {cout<<'{';__print(x.first);cout<<',';__print(x.second);cout<<'}';}
template<typename T>                void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}void _print() {cout << "]\n";}
template <typename T,typename... V> void _print(T t, V... v) {__print(t);if(sizeof...(v))cout<<", ";_print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_print(x)
#else 
#define dbg(x...)
#endif

int power(int x, int y, int p = mod){
    int res = 1;
    x %= p;
    while(y > 0){
        if(y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res; 
}

int inv(int x, int p = mod){
    return power(x, p - 2) % p;
}

const int N = 1e5 + 5;
list<int> l[N];
int n;

void dfsHelper(int u, unordered_map<int, bool> &visited, umii &dist){

    // cout<<u<<" ";
    visited[u] = 1;
    for(auto a: l[u]){
        if(!visited[a]){
            dfsHelper(a, visited, dist);
        }
        if(dist[u] < 1 + dist[a]){
            dist[u] = 1 + dist[a];
        }
    }
    
}

void dfs(){

    unordered_map<int, bool> visited;
    umii dist;
    for(int i=1; i<=n; i++){
        if(!visited[i]){
            dfsHelper(i, visited, dist);
        }
    }
    cout<<endl;
    int mx = 0;
    for(auto a: dist)
        mx = max(mx, a.ss);
    
    cout<<mx;

}

int32_t main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int t = 1;
    // cin >> t;
    while(t--){
        
        int m; cin>>n>>m;

        for(int i=1; i<=m; i++){
            int x, y; cin>>x>>y;
            l[x].pb(y);
        }

        dfs();
        
    }

    return 0;

}

Measured memory_bytes: 16572
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 int n,m;
  cin>>n>>m;
  
  ll val[n];
  rep(i, n){
    cin>>val[i];
}
  
  ll ans=0;
  
 vector<pair<ll, ll>> vec;
  
  rep(i, m){
     ll a,b;
    cin>>a>>b;
		vec.push_back(make_pair(b,a));
  }
  
  sort(val, val+n);
  sort(ALL(vec));
  reverse(ALL(vec));
  
  int p=0;
for(int i=0;i<=m-1;i++){
  for(int j=0;j<vec[i].second;j++){
    if(val[p]<=vec[i].first){
      val[p]=vec[i].first;
      p++;}
    else{
      break;}
  }
}
  
  rep(i, n){
    ans+=val[i];}
  
  cout<<ans<<endl;
    
  
  
  
  
  
  
  
 
}

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

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

int main(){
	static ll n,k,a[100010];
	vector<ll> v;
	cin>>n>>k;
	REP(i,n){
		cin>>a[i];
	}
	REP(i,n){
		if(i==0){
			v.push_back(abs(k-a[i]));
		}
		else{
			v.push_back(abs(a[i]-a[i-1]));
		}
	}
	ll ans=v[0];
	for(int i=1;i<v.size();i++){
		ans=gcd(ans,v[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2168
#include<stdio.h>

int main()
{
	char a,b;
	while(scanf("%c %c",&a,&b)!=EOF)
	{
		if(a=='H'&&b=='H') printf("H\n");
		if(a=='H'&&b=='D') printf("D\n");
		if(a=='D'&&b=='H') printf("D\n");
		if(a=='D'&&b=='D') printf("H\n");


	}
}

Measured memory_bytes: 128
N = gets.chomp.split('').map(&:to_i)

max = N.inject(:+)
N.length.times do |i|
    next if N[i] == 0
    sum = N[0...i].inject(0, :+)
    sum += N[i] - 1
    sum += (N.length - 1 - i) * 9
    max = sum if max < sum
end

puts max

Measured memory_bytes: 1788
N= int(input())
Nstr = str(N)
Box = ['3','5','7']
Boxi = set(Box)
Box = []
Box2 = set()
for _ in range(10**9):
    B = Boxi.pop()
    if len(B) < len(Nstr) and int(B) <= N:
        Boxi.add('3'+B)
        Boxi.add('5'+B)
        Boxi.add('7'+B)
        Box2.add('3'+B)
        Box2.add('5'+B)
        Box2.add('7'+B)
    if Boxi == set():
      break
for i in Box2:
    Bint = int(i)
    if Bint <= N and '3' in i and '5' in i and '7' in i:
        Box.append(Bint)
print(len(Box))

Measured memory_bytes: 14184
a, b, m = [ int(v) for v in input().split() ]
a_list = [ int(v) for v in input().split() ]
b_list = [ int(v) for v in input().split() ]
ans_list = []
for i in range(m):
    x, y, c = [ int(v) for v in input().split() ]
    ans_list.append(a_list[x - 1] + b_list[y - 1] - c)
a_list.sort()
b_list.sort()
ans_list.append(a_list[0] + b_list[0])
print(min(ans_list))

Measured memory_bytes: 18500
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n, t; cin >> n >> t;
	vector<int> a(n);
	for( auto &k : a ) cin >> k;
	int b[n]; b[0] = a[0];
	int c[n]; c[n-1] = a[n-1];
	int d[n];
	d[0] = d[n-1] = 0;
	int maxd = 0;
	for( int i = 1; i < n; ++i ) b[i] = min(a[i], b[i-1]);
	for( int i = n-2; i >= 0; --i ) c[i] = max(a[i], c[i+1]);
	for( int i = 1; i < n-1; ++i ){
		d[i] = max(0, c[i]-b[i]);
		maxd = max(maxd, d[i]);
	}
	int p = -1, q = -1;
	int cnt = 0;
	for( int i = 0; i < n; ++i ){
		if( maxd == d[i] && b[i] != p && c[i] != q ){
			++cnt;
			p = b[i];
			q = c[i];
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
int N;
std::pair<int, int> max, min;
std::vector<int> a;
int main() {
	max.first = -10000000;
	min.first = 10000000;
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		std::cin >> tmp;
		a.push_back(tmp);
		if (max.first < tmp)max = { tmp, i };
		if (min.first > tmp)min = { tmp,i };
	}
	std::cout << N * 2 - 1 << std::endl;
	if (max.first + min.first >= 0) {
		for (int i = 0; i < N; i++) {
			std::cout<< max.second + 1 <<" "<< i + 1 << std::endl;
		}
		for (int i = 1; i < N; i++) {
			std::cout << i << " " << i + 1 << std::endl;
		}
	}
	else {
		for (int i = 0; i < N; i++) {
			std::cout << min.second + 1 << " " << i + 1 << std::endl;
		}
		for (int i = N; i > 1; i--) {
			std::cout << i << " " << i - 1 << std::endl;
		}
	}
	return 0;
}

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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    string s;
    cin >> s;

    string a = "resare", b = "esare", c = "remaerd", d = "maerd";
    reverse(All(s));

    LL L = s.size();

    for(LL i = 0; i < L;){
        if(s.substr(i, 5) == b || s.substr(i, 5) == d)
            i += 5;
        else if(s.substr(i, 6) == a)
            i += 6;
        else if(s.substr(i, 7) == c)
            i += 7;
        else
            return cout << "NO\n", 0;
    }

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



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

using namespace std;

const int N = 105;
int x, n, arr[N];

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

    cin >> x >> n;
    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        arr[a] = 1;
    }
    int ans = -1;
    int fmin = 1000000;
    for(int i = 0; i <= 200; i++){
        if(i < 0 || arr[i] == 0){
            if(abs(i - x) < fmin){
                fmin = abs(i - x);
                ans = i;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

ll factional(int n){ll ret = 1; FOR(i, 2, n+1) ret *= i; return ret;}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    vi x(n),y(n);
    vi p(n);
    REP(i,n){
        cin>>x[i]>>y[i];
        p[i] = i;
    }

    double sum=0;
    do{
        REP(i,n-1)
            sum += sqrt(pow(x[p[i]]-x[p[i+1]], 2) + pow(y[p[i]]-y[p[i+1]], 2));
    }while(next_permutation(ALL(p)));

    sum = sum / factional(n);
    cout << setprecision(10)<< sum << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter 
n = int(input())
v = list(map(int,input().split()))
 
odd = []
even = []
for i in range(n//2):
	odd.append(v[2*i+1])
	even.append(v[2*i])

odd = sorted(odd)
even = sorted(even)
ac = Counter(odd).most_common(2)
bc = Counter(even).most_common(2)
def cnt(X):
	count = 0
	ans = 0
	for i in range(len(X)-1):
		if X[i+1] == X[i]:
			count += 1
			ans = max(ans,count)
		else:
			count = 0
	return ans+1
            
if ac[0][0] != bc[0][0]:
  print(len(v)-cnt(odd)-cnt(even))
elif len(ac) == 1 and len(bc) == 1:
	print(n//2)
else:
	print(n-max(ac[0][1]+bc[1][1],ac[1][1]+bc[0][1]))


Measured memory_bytes: 16100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  ll a;cin>>a;
  cout<<pow(a,3)+pow(a,2)+a<<endl;
}

Measured memory_bytes: 4192
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  set<int> X;
  rep(i, N) {
	int x;
	cin >> x;
	X.insert(x);
  }
  cout << X.size();
}



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

signed main(void)
{
	int v[5];
	rep(i, 4) v[i] = 0;
	rep(i, 3)
	{
		int a, b;
		cin >> a >> b;
		v[a]++;
		v[b]++;
	}
	if (v[1] <= 2 && v[2] <= 2 && v[3] <= 2 && v[4] <= 2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple


ll N, A, B, C;

bool check(ll n, vector<ll>& Hs) {
    ll extra = 0;
    ll base = n * B;

	auto it = upper_bound(ALL(Hs), base);
	while (it != Hs.end()) {
		auto h = *it;
		if (h > base) {
			ll remain = h - base;
			extra += (remain + (C - 1)) / C;
		}
		++it;
	}
    return n >= extra;
}

int main(void)
{
    cin.sync_with_stdio(false);
    cin >> N >> A >> B;
    vector<ll> Hs(N);
    C = A - B;
    ll lo = 0;
    ll hi = 0;
    REP(n, N) {
        cin >> Hs[n];
        hi += Hs[n] / A + 1;
    }
    sort(ALL(Hs));

    while(lo < hi) {
        ll k = (lo + hi) / 2;
        if (check(k, Hs)) {
            hi = k;
        } else {
            lo = k + 1;
        }
    }
    cout << lo << endl;

    return 0;
}


Measured memory_bytes: 1024
// pnEans.cpp.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MX = 2005;
bool d[3][3][MX];

int main()
{
	vector<string> s(3);
	rep(i, 3) cin >> s[i];
	sort(s.begin(), s.end());
	int ans = MX*3;
	do {
		rep(i, 3)rep(j, 3)rep(k, s[i].size()) {
			if (i >= j)continue;
			bool ok = true;
			for (int ni = k; ni < s[i].size(); ni++) {
				int nj = ni - k;
				if (nj >= s[j].size())break;
				if (s[j][nj] == '?' || s[i][ni] == '?')continue;
				
				if(s[i][ni] != s[j][nj]) ok = false;	
			}
			d[i][j][k] = ok;
		}
		auto f = [&](int i, int j, int k) {
			if (k >= s[i].size())return true;
			return d[i][j][k];
		};
		rep(x, MX)rep(y, MX) {
			if (!f(0, 1, x))continue;
			if (!f(1, 2, y))continue;
			if (!f(0, 2, x+y))continue;
			int now = 0;
			now = max<int>(now, s[0].size());
			now = max<int>(now, x + s[1].size());
			now = max<int>(now, x + y + s[2].size());
			ans = min(ans, now);
		}
	} while (next_permutation(s.begin(), s.end()));

	cout << ans << endl;

	
	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * POW(n, m - 1)) % MOD;
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, A, B;
  cin >> N >> A >> B;
  if ((B - A) % 2 == 0)
    cout << "Alice" << endl;
  else
    cout << "Borys" << endl;
  return 0;
}


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

long long GCD(long long a, long long b) {
    return b == 0 ? a : GCD(b, a % b);
}

void Main()
{
	int N;
	cin >> N;
	vector<ll> A(N);
	rep(i,N) cin >> A[i];
	vector<ll> SL(N + 1);
	vector<ll> SR(N + 1);
	SL[0] = 0; SL[1] = A[0];
	SR[0] = 0; SR[1] = A[N - 1];
	for (int i = 1; i < N; ++i) {
		SL[i + 1] = GCD(SL[i], A[i]);
	}
	for (int i = 1; i < N; ++i) {
		SR[i + 1] = GCD(SR[i], A[N - 1 - i]);
	}
	ll res = -1;
	rep(i,N) {
		res = max(res, GCD(SL[i], SR[N - 1 - i]));
	}
	cout << res;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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

int main() {
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    
    while(s.size()>7){
        if(s.substr(0,5) == "maerd" || s.substr(0,5) == "esare" ) s = s.substr(5);
        else if(s.substr(0,6) == "resare") s = s.substr(6);
        else if(s.substr(0,7) == "remaerd") s = s.substr(7);
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    if(s == "maerd" || s == "remaerd" || s == "esare" || s == "resare") cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
template<class T> void chmin(T& x, T y){if(x < y) x = y;}
template<class T> void chmax(T& x, T y){if(x > y) x = y;}
int N;
map<int, ll> mp;
int A[200010];
ll sum;

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        mp[A[i]]++;
    }
    for(auto u : mp){
        ll cnt = u.second;
        sum += cnt * (cnt - (ll)1) / (ll)2;
    }
    for(int i = 0; i < N; i++){
        ll c = mp[A[i]];
        cout << sum - c + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 10240
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll weight[100005];
ll value[100005];
ll dp[10005][10005];
int main(void) {
    ll n, W;
    cin >> n >> W;
    for (int i = 0; i < n; i++) {
        cin >> value[i] >> weight[i];
    }
    for (int i = 0; i <= W; i++) {
        dp[0][i] = 0;
    }

    for (int i = 0; i < n; i++) {
        for (int w = 0; w <= W; w++) {
            if (w >= weight[i]) {
                dp[i + 1][w] = max(dp[i][w - weight[i]]+value[i], dp[i][w]);
            }
            else {
                dp[i + 1][w] = dp[i][w];
            }
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}



Measured memory_bytes: 10976
H,W = map(int, input().split())
S = [list(input()) for _ in range(H)]

MH = [[0] * W for _ in range(H)]
MW = [[0] * W for _ in range(H)]

ans = 0
for h in range(H):
  for w in range(W):
    if ('#' != S[h][w]):
      if ((0 < h) & ('#' != S[h-1][w])):
        mh = MH[h-1][w]
      else:
        mh = 0
        for h2 in range(h,H):
          if ('#' == S[h2][w]):
            break
          mh += 1
      MH[h][w] = mh
      if ((0 < w) & ('#' != S[h][w-1])):
        mw = MW[h][w-1]
      else:
        mw = 0
        for w2 in range(w,W):
          if ('#' == S[h][w2]):
            break
          mw += 1
      MW[h][w] = mw
      a = (mh + mw) - 1
      if (ans < a):
        ans = a
      
print(ans)


Measured memory_bytes: 248968
#pragma GCC optimize("Ofast,fast-math,unroll-loops")

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

typedef long long ll;
typedef string str;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	int k;
	cin >> k;
	ll ans = 0;
	for(int a = 1; a <= k; a++){
		for(int b = 1; b <= k; b++){
			for(int c = 1; c <= k; c++){
				ans += __gcd(__gcd(a,b),c);
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int N, K;
    cin >> N >> K;
    if (K >= (1 << N)) {
        cout << -1 << endl;
        return 0;
    }
    if (N == 1) {
        if (K == 1) {
            cout << -1 << endl;
            return 0;
        }
        else {
            cout << "0 0 1 1" << endl;
            return 0;
        }
    }
    int n = (1 << N);
    vector<int> res;
    for (int i = 0; i < n; i++) {
        if (i != K) {
            res.push_back(i);
        }
    }
    res.push_back(K);
    for (int i = n - 1; i >= 0; i--) {
        if (i != K) {
            res.push_back(i);
        }
    }
    res.push_back(K);
    for (int i = 0; i < res.size(); i++) {
        if (i > 0)cout << " ";
        cout << res[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2932
#include<iostream>
#include<string>

using namespace std;

int main(){
  string s;
  cin >> s;
  for(int i=0;i<s.length();i++){
    if(s[i]=='1'){
      cout << '9';
    }
    else if(s[i]=='9'){
      cout << '1';
    }
    else{
      cout << s[i];
    }
  }
  cout << endl;
}

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

using namespace std;

#define IOS ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);

#define endl "\n";

#define loop(i,s,n)  for(ll i=s;i<n;i++)
#define test  ll t; cin>>t; while(t--)
#define p push_back
typedef long long ll;
int main()
{IOS
ll n,w;
cin>>n;
ll a[10001]={0};
for(auto x=1;x<=100;x++)
{for(auto y=1;y<=100;y++)
{for(auto z=1;z<=100;z++)
{w=(x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
if(w<=10000)
{a[w]++;}}}}


for(auto i=1;i<=n;i++)
{cout<<a[i]<<endl}





return 0;
}


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

int main()
{
  int h,w;
  int flag=0;
  cin>>h>>w;
  char a[h][w];
  bool wide[h][w];
  bool height[h][w];

  for(int i=0;i<h;i++)
  {
    for(int j=0;j<w;j++)
    {
      cin>>a[i][j];
      wide[i][j]=false;
      height[i][j]=false;
    }
  }


  for(int i=0;i<h;i++)
  {
    for(int j=0;j<w;j++)
    {
      if(a[i][j]=='#') flag=1;
    }
    if(flag==1)
    {
      for(int j=0;j<w;j++) wide[i][j]=true;
    }
    flag=0;
  }

  for(int j=0;j<w;j++)
  {
    for(int i=0;i<h;i++)
    {
      if(a[i][j]=='#') flag=1;
    }
    if(flag==1)
    {
      for(int i=0;i<h;i++) height[i][j]=true;
    }
    flag=0;
  }


  for(int i=0;i<h;i++)
  {
    for(int j=0;j<w;j++)
    {
      if(wide[i][j])
      {
        if(height[i][j])
        {
          cout<<a[i][j];
          flag=1;
        }
      }
    }
    if(flag==1)cout<<endl;
    flag=0;
  }
}

//   bad



Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int a[200000 + 10];
int ma[200000 + 10];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n, k;
	cin >> n >> k ;
	rep(i, 1, n + 1){
		cin >> a[i];
	}
	rep(j, 1, k + 1){
		int flag = 0;
		rep(i, 1, n + 1) ma[i] = 0;
		rep(i, 1, n + 1){
			if(i - a[i] <= 1) ma[1] ++;
			else ma[i - a[i]]++;
			if(i + a[i] <= n) ma[i + a[i] + 1] --;
		}
		int sum = 0;
		rep(i, 1, n + 1){
			sum += ma[i];
			a[i] = sum;
			if(sum != n) flag = 1;
		}
		if(flag == 0) break;
	}
	rep(i, 1, n + 1) cout << a[i] << " ";
	return 0;
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
#define LL long long
using namespace std ;
void Read ( int &x, char c = getchar(), bool f = 0 ) {
	for ( x = 0 ; !isdigit(c) ; c = getchar() ) if (c == '-') f = 1 ;
	for ( ;isdigit(c) ; c = getchar() ) x = 10*x + c - '0' ;
	if (f) x = -x ;
}
const int maxn = 105 ;
int A, B, n, m ;
char g[maxn][maxn] ;
void print() {
	for ( int i = 1 ; i <= n ; i ++, puts("") )
		for ( int j = 1 ; j <= n ; j ++ )
			if (g[i][j]) putchar(g[i][j]) ;
			else putchar('0') ;
	puts("") ;
}
int main() {
	int i, j, Max1, Max2 ;
	Read(A), Read(B) ;
	n = m = 100 ;
	for ( j = 1 ; j <= m && A > 1 ; j += 2 ) {
		Max1 = j ;
		for ( i = 1 ; i <= n && A > 1 ; i += 2 )
			g[i][j] = '.', A -- ;
	}
	for ( j = m ; j > 0 && B > 1 ; j -= 2 ) {
		Max2 = j ;
		for ( i = 1 ; i <= n && B > 1 ; i += 2 )
			g[i][j] = '#', B -- ;
	}
	for ( j = Max1+1 ; j ; j -- )
		for ( i = 1 ; i <= n ; i ++ )
			if (!g[i][j]) g[i][j] = '#' ;
	for ( j = 1 ; j <= m ; j ++ )
		for ( i = 1 ; i <= n ; i ++ )
			if (!g[i][j]) g[i][j] = '.' ;
	printf ( "%d %d\n", n, m ) ;
	for ( i = 1 ; i <= n ; i ++, puts("") )
		for ( j = 1 ; j <= m ; j ++ )
			putchar(g[i][j]) ;
	return 0 ;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int a,b,cnt;
void solve(){
    cin>>a>>b;
    a=__gcd(a,b);
    for(int i=2;i*i<=a;i++){
        if(a%i==0){
            cnt++;
            while(a%i==0) a/=i;
        }
    }
    if(a>1) cnt++;
    cout<<cnt+1<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
from sys import stdin 
a = []
b = []
c = [] 
d = []
cur = 2
hi = 30000
while cur <= hi:
    a.append(cur)
    cur = cur + 2 
cur = 3
while cur <= hi:
    b.append(cur)
    cur = cur + 6 
cur = 3
ans = [2,5,63]
cur = 630
while cur <=hi:
    ans.append(cur)
    cur = cur + 630
c = [] 
d = [] 
cur = 3
while cur <= hi:
    c.append(cur)
    cur = cur + 3 
cur = 2 
while cur <= hi:
    d.append(cur)
    d.append(cur+2)
    cur += 6 
n = int(stdin.readline())
if n <= 10:
    ans = ans[:n]
else:
    if n!=19999:
        for x in xrange(1,len(a)+1):
            y = n - x 
            if x > 0 and y > 0 and x <= len(a) and y <= len(b) and x%3==0 and y%2==0:
                break 
        ans = a[:x] + b[:y]
    else:
        for x in xrange(1,len(d)+1):
            y = n - x 
            if x > 0 and y > 0 and x <= len(d) and y <= len(c) and x%3==0 and y%2==0:
                break 
        ans = c[:x] + d[:y]
for i in ans:
    print i,
    


Measured memory_bytes: 4456
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define sort(v) sort(v.begin(),v.end()) 
#define pb push_back
/*ll ar[1000000+9]={0}; 
void seiv() { 
ll n=1000000,i,j; 
ar[1]=1; 
for(i=4;i<=n;i+=2)ar[i]=1; 
for(i=3;i<=n;i+=2) 
{ if(ar[i]==0) 
{ for(j=i*i;j<=n;j+=i*2)ar[j]=1; }
 } 
*/
int main()
{
    
    ll a,b,c,d=0,e,i,j;
    cin>>a>>b;
    vector<ll>v;
  e=1;
for(i=1,j=0;i<=a;i++)
{cin>>c;v.pb(c);
if(i<=b)e*=c;
}d=e;
   // cout<<e<<endl;
for(i=b,j=0;i<a;i++,j++)
{
   
    if(v[i]>v[j]){cout<<"Yes\n";}
     else cout<<"No\n";

}
}

Measured memory_bytes: 5360