akhauriyash/Code-Regression huggingface dataset:
def solve(N,W,wv):
    dp=[-1]*(W+1)
    dp[0]=0
    for i in range(N):
        cur_w=wv[i][0]
        cur_v=wv[i][1]
        for j in range(W-cur_w,-1,-1):
            if dp[j]==-1:
                continue
            if dp[j+cur_w]<dp[j]+cur_v:
                dp[j+cur_w]=dp[j]+cur_v
    return max(dp)


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))

Measured memory_bytes: 9512
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define forn(i,p,n); for(long long i=p;i<n;++i)
#define rofn(i,p,n); for(long long i=p;i>n;--i)
#define pb push_back
#define pi pair
#define ff first
#define ss second
#define vi vector
#define ump unordered_map
ll m =  1e9+7;
void solve(){
	ll n;
	cin >> n;
	ll count = 0;
	ll flag = 0;
	while(n--){
		ll x,y;
		cin >> x >> y;
		if(x!=y){
			count = 0;
		}
		if(x==y)count++;
		if(count>=3){
			flag=1;
		}
	}
	if(flag){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}
int main()
{
	fast;
	// int test;
	// cin >> test;
	// while(test--){
		solve();
	// 	cout<<"\n";
	// }
}

Measured memory_bytes: 3644
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
vector<int> tree[101010];

int solve(int p, int rt)
{
	int ans = 1;
	for (int q : tree[p]) if (q != rt) {
		int v = solve(q, p);
		if (v == -1) return -1;
		ans -= v;
	}

	if (ans < 0) return -1;
	return ans;
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		--a; --b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}

	puts(solve(0, -1) == 0 ? "Second" : "First");

	return 0;
}


Measured memory_bytes: 5888
//骗分不规范，爆零两行泪
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
using namespace std;
const int mxn=2e5+5;
int n,a[mxn];
inline bool ok(int md){
	if(md==1){
		for(int i=1;i<n;++i)if(a[i]>=a[i+1])return 0;
		return 1;
	}
	map<int,int>m;m.clear();
	for(int i=2;i<=n;++i)if(a[i]<=a[i-1]){
		m.erase(m.upper_bound(a[i]),m.end());
		int k=a[i];++m[k];
		for(;k and m[k]==md;)m.erase(k),++m[--k];
		if(!k)return 0;
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	int l=1,r=n,md;
	for(;l<r;){
		md=l+r>>1;
		if(ok(md))r=md;
		else l=md+1;
	}
	printf("%d\n",l);
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;

int arr[maxr];
int32_t main()
{
	GO;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int ans = 0;
	for (int i = 1; i < n; i++) {
		int count = 0;
		while (i < n && arr[i - 1] >= arr[i]) {
			count++;
			i++;
		}
		ans = max(ans, count);
	}
	cout << ans << endl;
	return 0;
}

//!

Measured memory_bytes: 4380
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    
    double argh = 2.0 * M_PI * (h + (double)m / 60.0) / 12.0;
    double argm = 2.0 * M_PI * (double)m / 60.0;
    
    //cout << "H:" << argh / M_PI * 180 << " M:" << argm / M_PI * 180 << endl;
    
    double hx = a * cos(argh), hy = a * sin(argh);
    double mx = b * cos(argm), my = b * sin(argm);
    
/*     cout << "hx:" << hx << " hy:" << hy <<endl;
    cout << "mx:" << mx << " my:" << my <<endl; */
    
    double ans = sqrt((hx - mx) * (hx - mx) + (hy - my) * (hy - my));
    cout << setprecision(12) << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4128
"use strict";

new Promise(function(resolve, reject) {
    let content = "";
    process.stdin.on("data", chunk => { content += chunk; })
    process.stdin.on("end", () => { resolve([content, process.stdout]); });
}).then(function([cin, cout]) {
    const data = cin.split("\n").slice(0, 10).map(elt => parseInt(elt));
    data.sort((a, b) => {
        if (a > b) return -1;
        if (b > a) return 1;
        return 0;
    });
    for (let i = 0; i < 3; ++i) {
        cout.write(`${data[i]}\n`);
    }
});



Measured memory_bytes: 15280
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n, k;
    cin, n, k;
    ll res = n % k;
    cout << min(res, k - res) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define mp make_pair

const int MAXN = 55;
int R, C;
char mat[MAXN][MAXN];
int viz[MAXN][MAXN];
int powerPerTime[MAXN][MAXN];
int turnOn[MAXN][MAXN];
int turnOff[MAXN][MAXN];
vector<int> times[MAXN][MAXN];

void readMat(int k[MAXN][MAXN]) {
  for (int i = 0; i < R; ++i)
    for (int j = 0; j < C; ++j)
      scanf("%d", &k[i][j]);
}

int d[] = { 0, 1, 0, -1, 1, 0, -1, 0 };

LL solveFor(int i, int j) {
  vector<int> &v = times[i][j];
  if (v.size() == 0)
    return 0;
  LL ans = turnOn[i][j];
  for (int k = 0; k < (int)v.size() - 1; ++k) {
    int timeSpent = v[k + 1] - v[k];
    LL costStingAprind = turnOff[i][j] + turnOn[i][j];
    LL costLasLumina = 1LL * timeSpent * powerPerTime[i][j];
    ans += min(costLasLumina, costStingAprind);
  }
  ans += turnOff[i][j];
  return ans;
}

vector< pair< int, pair<int, int> > > DFSrez;
int tari, tarj;
int dfsmark;

bool DFSsol(int curi, int curj, int lvl) {
  viz[curi][curj] = dfsmark;
  if (curi == tari && curj == tarj)
    return true;
  for (int di = 0; di < 4; ++di) {
    int ni = curi + d[di * 2], nj = curj + d[di * 2 + 1];
    if (ni < 0 || nj < 0 || ni >= R || nj >= C)
      continue;
    if (mat[ni][nj] == '#')
      continue;
    if (viz[ni][nj] == dfsmark)
      continue;
    if (!DFSsol(ni, nj, lvl + 1))
      continue;
    DFSrez.push_back(mp(lvl + 1, mp(ni, nj)));
    return true;
  }
  return false;
}

int main() {
  int M;
  scanf("%d%d%d", &R, &C, &M);
  memset(viz, 0xFF, sizeof viz);
  for(int i=0; i<R; ++i)
    for (int j = 0; j < C; ++j) {
      scanf(" %c", &mat[i][j]);
      if (mat[i][j] == '#')
        continue;
    }
  readMat(powerPerTime);
  readMat(turnOn);
  readMat(turnOff);
  int curi, curj;
  scanf("%d%d", &curi, &curj);
  int curTime = 0;
  times[curi][curj].push_back(0);
  for (dfsmark = 0; dfsmark < M - 1; ++dfsmark) {
    scanf("%d%d", &tari, &tarj);
    DFSrez.clear();
    assert(DFSsol(curi, curj, curTime));
    for (int itt = 0; itt < (int)DFSrez.size(); ++itt) {
      auto &it = DFSrez[itt];
      times[it.second.first][it.second.second].push_back(it.first);
    }
    curTime = DFSrez[0].first;
    curi = tari, curj = tarj;
  }
  LL ans = 0;
  for(int i=0; i<R; ++i)
    for(int j=0; j<C; ++j)
      ans += solveFor(i, j);
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 8164
#include <cstdio>
#include <set>

int main()
{
  int s, t; //number of integers for S and T

  int count = 0; // number of integers of T in S
  
  std::set<int> S; // set S to be checked against

  scanf("%d", &s);
  
  for (int i = 0; i < s; ++i) {
    int input;
    scanf("%d", &input);
    S.insert(input);
  }

  scanf("%d", &t);

  for (int i = 0; i < t; ++i) {
    int input;
    scanf("%d", &input);
    if ( S.find(input) != S.end() ) ++count; // increment count if found in S
  }

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

Measured memory_bytes: 2744
class BinTree():
    def __init__(self):
        self.parent = -1
        self.left, self.right = -1, -1
        self.sib = -1
        self.dep, self.deg, self.h = 0, 0, 0
        self.state = "internal node"

    def set_node(self, nid, l, r):
        global root
        root -= {l, r}
        self.left, self.right = l, r
        self.deg = (l != -1) + (r != -1)
        if l != -1:
            left = trees[l]
            left.parent = nid
            left.sib = r
        if r != -1:
            right = trees[r]
            right.parent = nid
            right.sib = l

    def set_param(self):
        if self.parent != -1:
            self.dep = trees[self.parent].dep + 1
        if self.deg == 0:
            self.state = "leaf"
        if self.left != -1:
            left = trees[self.left]
            left.set_param()
            self.h = left.h + 1
        if self.right != -1:
            right = trees[self.right]
            right.set_param()
            if self.h <= right.h:
                self.h = right.h + 1
        if self.parent == -1:
            self.state = "root"

def pre_walk(nid):
    tree = trees[nid]
    print(" {}".format(nid), end="")
    if tree.left != -1:
        pre_walk(tree.left)
    if tree.right != -1:
        pre_walk(tree.right)

def preoder(root):
    print("Preorder")
    pre_walk(root)
    print()

def in_walk(nid):
    tree = trees[nid]
    if tree.left != -1:
        in_walk(tree.left)
    print(" {}".format(nid), end="")
    if tree.right != -1:
        in_walk(tree.right)

def inorder(root):
    print("Inorder")
    in_walk(root)
    print()

def post_walk(nid):
    tree = trees[nid]
    if tree.left != -1:
        post_walk(tree.left)
    if tree.right != -1:
        post_walk(tree.right)
    print(" {}".format(nid), end="")

def postorder(root):
    print("Postorder")
    post_walk(root)
    print()

n = int(input())
trees = [BinTree() for _ in range(n)]
root = set(range(n))
for _ in range(n):
    inp = list(map(int, input().split()))
    trees[inp[0]].set_node(*inp)
root = root.pop()
trees[root].set_param()
preoder(root)
inorder(root)
postorder(root)

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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll x[3];
	forn(i,3)cin>>x[i];
	sort(x,x+3);
	if((x[0]==x[1] || x[1]==x[2]) && x[0]!=x[2]) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""
 


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string Ans = "Three";
  
  for (int i = 0; i < N; i++) {
    string C;
    cin >> C;
    
    if (C == "Y") {
      Ans = "Four";
      break;
    }
  }
  
  cout << Ans << endl;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int x,a; cin >> x >> a;

  int ans;
  if(x<a) ans = 0;
  else ans = 10;
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define chal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
    int q=1;
    //cin>>t;
    while(q--)
    {
        ll n,x,t;
        cin>>n>>x>>t;
        ll p=ceil((float)n/x);
        ll ans=t*p;
        cout<<ans;
    }
    return 0;
}


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

ll mod=1e9+7;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> check(n);
  for(int i=0;i<n;i++) {
    int temp;
    cin >> temp;
    check[temp]++;
  }
  ll key=n%2;
  bool cal=true;
  for(int i=0;i<n;i++) {
    if(key) {
      if(i==0) {
        if(check[i]!=1) {
          cal=false;
          break;
        }
      }
      else {
        if(i%2==0&&check[i]!=2) {
          cal=false;
          break;
        }
        else if(i%2==1&&check[i]!=0) {
          cal=false;
          break;
        }
      }
    }
    else {
      if(i%2==0&&check[i]!=0) {
        cal=false;
        break;
      }
      else if(i%2==1&&check[i]!=2) {
        cal=false;
        break;
      }
    }
  }
  if(cal) {
    cout << mpow(2, n/2)<< endl;
  }
  else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define MAX 1e9+7
#define i(a) cin>>a
#define in(a,b) cin>>a>>b
#define o(a) cout<<a
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loop1(i,a,b) for(ll i=a;i<=b;i++)
#define v(a) vector<ll>a
#define mp(a,b) make_pair(a,b)
using namespace std;
int main()
{
    ll n;
    i(n);
    ll a[n],b[n],p=0,k=0,c=0;
    loop1(i,0,n)
    {
        i(a[i]);
    }
    loop(i,0,n){
        i(b[i]);
    }
    loop(i,0,n){
        if(b[i]>=a[i])
        {
            k += a[i];
            p = b[i] - a[i];
            if(p >= a[i+1])
            {
                k += a[i+1];
                a[i+1] = 0;
            }
            else{
                a[i+1] = a[i+1] - p;
                k += p;
            }
        }
        else{
            k += b[i];
        }

    }
    cout<<k;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

bool enough(vi &h, ll num, ll a, ll b){
    // a>bであるため、num回bの蓄積ダメージが全体に入り、かつnum回a-bの追加ダメージを与えられる。
    ll sumDamage = num * b;
    ll cnt = 0;
    for(ll i=0; i<(ll)h.size(); i++){
        if(h[i] <= sumDamage) continue;
        cnt += (ll)ceil((1.0*(h[i]-sumDamage))/(a-b));
    }
    return (cnt <= num) ? true : false;
}

int main(){
    Init();
    // n; monster, a;centerDamage, b;otherDamage
    ll n, a, b; cin >> n >> a >> b;

    // monster; <hp, number>;
    vi h(n); rep(i, n) cin >> h[i];

    // binary-search
    ll l = 0, r = 1111111111;
    while(abs(r-l)>1){
        ll mid = (l+r)/2;
        (enough(h, mid, a, b) ? r : l) = mid;
    }

    // output
    cout << r << endl;
}

Measured memory_bytes: 3980
n, k = map(int, input().split())
As = list(map(int, input().split()))


def solve(t):
    count = 0
    for a in As:
        if a % t == 0:
            count += a // t - 1
        else:
            count += a // t
    if count <= k:
        return True
    else:
        return False


def main(l, r):
    if r - l == 1:
        print(r)
    else:
        m = (l + r) // 2
        if solve(m):
            r = m
            return main(l, r)
        else:
            l = m
            return main(l, r)

if solve(1):
  print('1')
else:
  main(1, max(As))


Measured memory_bytes: 94008
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue> 
#include <map>
#include <set>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){

  int h,w;
  cin >> h >> w;
  
  int dist[10][10];
  REP(i,10){
    REP(j,10){
      cin >> dist[i][j];
    }
  }
  
  int wall[h][w];
  REP(i,h){
    REP(j,w){
      cin >> wall[i][j];
    }
  }
  
  REP(k,10){
    REP(i,10){
      REP(j,10){
        dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  
 /* REP(i,10){
    REP(j,10){
      cout << dist[i][j];
    }
    cout << endl;
  }
  */
  
  int ans = 0;
  REP(i,h){
    REP(j,w){
      if(wall[i][j] != -1)
        ans += dist[wall[i][j]][1];
    }
  }

  
  cout << ans << endl;
  
 return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=110;
int n;
char s[maxn],t[maxn];
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	for (int i=1;i<=n;i++)
		printf("%c%c",s[i],t[i]);
	printf("\n");
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 256
// 関節点
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>

using namespace std;

#define MAX 100000

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

// 深さ優先探索を実施する処理
void dfs(int current, int prev)
{
    // --------------------------------
    // ノード current を訪問した直後の処理
    // --------------------------------
    // lowest の初期値の設定
    prenum[current] = lowest[current] = timer;
    timer++;

    // 訪問情報の設定
    visited[current] = true;

    int next;

    for(int i = 0; i < G[current].size(); i++)
    {
        // 次に訪問する頂点の頂点No.
        next = G[current][i];

        if( !visited[next] )
        {
            // ----------------------------------------------
            // ノード current からノード next へ訪問する直前の処理
            // ----------------------------------------------

            // 次に訪問する頂点の親を設定しておく
            parent[next] = current;

            // 再帰Call
            dfs(next, current);

            // ----------------------------------
            // ノード next の探索が終了した直後の処理
            // 訪問の終了順にlowest[]の値を決めていく
            // ----------------------------------
            // ここで、current は next の親になっている
            // 自分の子の値と比較する
            lowest[current] = min(lowest[current], lowest[next]);
        }
        else if( next != prev )
        {
            // エッジ current --> next が Back-edge の場合の処理
            lowest[current] = min(lowest[current], prenum[next]);
        }
    }

    // -------------------------------------
    // ノード current の探索が終了した直後の処理
    // -------------------------------------
}

void art_points()
{
    for(int i = 0; i < N; i++)
    {
        visited[i] = false;
    }

    timer = 1;

    // lowest の計算
    dfs(0, -1); // 0 == root_num

    set<int> ap;
    int np = 0;

    for(int i = 1; i < N; i++)
    {
        int p = parent[i];

        if( p == 0 )
        {
            // rootの子供の数を計算
            np++;
        }
        else if( prenum[p] <= lowest[i] )
        {
            // 各頂点が関節点であるかを調査
            ap.insert(p);
        }
    }

    if( np > 1 )
    {
        // rootが関節点である
        ap.insert(0);
    }

    for(set<int>::iterator it = ap.begin(); it != ap.end(); it++)
    {
        cout << *it << endl;
    }
}

int main(void)
{
    int m;

    cin >> N >> m;

    for(int i = 0; i < m; i++)
    {
        int s, t;
        cin >> s >> t;

        // 無向グラフのため、双方向に経路を設定する
        G[s].push_back(t);
        G[t].push_back(s);
    }

    art_points();

    return 0;
}



Measured memory_bytes: 6800
#include <bits/stdc++.h>
#define pii pair<int,int>
#define int long long int 

using namespace std ;
const int N=105 ;

vector<int> adj[N] ;
int maxi[N] ;
vector<pii > edges ;
int max_depth=1 ;

void dfs(int node, int par, int dep, int prohib)
{
	// cout << node << endl ;
	int branch=0 ;
	max_depth=max(dep,max_depth) ;
	for(int i=0 ; i<adj[node].size() ; i++){
		if(adj[node][i]==prohib or adj[node][i]==par)
			continue; 
		int nxt=adj[node][i] ;
		branch++ ;
		dfs(nxt,node,dep+1,prohib) ;
	}
	maxi[dep]=max(maxi[dep],branch) ; 
}

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

	pii best={N,N} ;

	for(int i=0 ; i<n-1 ; i++){
		int a,b ;
		cin >> a >> b ;
		edges.push_back({a,b}) ;
		adj[a].push_back(b) ;
		adj[b].push_back(a) ;
	}

	for(int i=1 ; i<=n; i++){
		for(int j=0 ; j<N; j++){
			maxi[j]=1 ;
		}
		max_depth=1 ;
		dfs(i,i,1,-1) ;
		int leaves=1 ;
		for(int i=0 ; i<N;  i++){
			leaves*=maxi[i] ;
		}
		best=min(best,{max_depth,leaves}) ;
	}

	for(int i=0 ; i<n-1; i++){
		for(int j=0 ; j<N; j++){
			maxi[j]=1 ;
		}
		int a=edges[i].first ;
		int b=edges[i].second ;
		maxi[0]=2 ;
		max_depth=1 ;
		dfs(a,a,1,b) ;
		dfs(b,b,1,a) ;
		int leaves=1 ;
		for(int i=0 ; i<N;  i++){
			leaves*=maxi[i] ;
		}
		best=min(best,{max_depth,leaves}) ;
	}	

	cout << best.first << " " << best.second << endl ;

	return 0 ;
}

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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    vector<vector<int>> a(n,vector<int>(30,0));
    vector<LL> x(n,0);
    int f,c;
    for(int i=0;i<n;i++){
      cin >> f;
      x[i]=(1ll<<i);
      for(int j=0;j<f;j++){
        cin >> c;
        a[i][c-1]=1;
      }
    }
    for(int i=0;i<30;i++){
      LL aaa=0;
      for(int j=0;j<n;j++){
        if(a[j][i]) aaa|=x[j];
      }
      for(int j=0;j<n;j++){
        if(a[j][i]){
          x[j]|=aaa;
          if(x[j]==(1ll<<n)-1){
            cout << i+1 << endl;
            goto next;
          }
        }
      }
    }
    cout << -1 << endl;
    next:;
  }
  return 0;
}



Measured memory_bytes: 3096
import sys
sys.setrecursionlimit(1000000)
n,m=map(int,input().split())
al=[int(input()) for i in range(m)]+[n+1]
mod=1000000007
ms=[0]*(n+1)

def dd(n):
    if ms[n]>0:
        return ms[n]
    if n==1:
        ms[n]=1
        return 1
    if n==2:
        ms[n]=2
        return 2
    m=dd(n-1)+dd(n-2)
    ms[n]=m
    return m

ans=1
now=0
b=-1
for a in al:
    if a-1==b:
        print(0)
        exit()
    b=a
    if a-1!=now:
        ans=(ans%mod)*(dd(a-now-1)%mod)%mod
    now=a+1

print(ans)

Measured memory_bytes: 494324
n = int(input())
ans = 1
if 400 <= n < 600: ans = 8
if 600 <= n < 800: ans = 7
if 800 <= n < 1000: ans = 6
if 1000 <= n < 1200: ans = 5
if 1200 <= n < 1400: ans = 4
if 1400 <= n < 1600: ans = 3
if 1600 <= n < 1800: ans = 2
if 1800 <= n < 2000: ans = 1
print(ans)

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;

void solve() {
	string x; cin >> x;
	int t = 0, s = 0;
	int ans = 0;
	for (int i = 0; i < x.size(); i++) {
		if (x[i] == 'S') {
			s++;
		}
		else {
			t++;
			ans = max(ans, t - s);
		}
	}
	cout << ans * 2 << endl;
}

int main() {

	solve();

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<double >    vecd;
typedef vector<vector<int> >  vec2int;
typedef vector<vector<double> >  vec2d;
typedef vector<ll >     vecll;
typedef vector<string > vecstr;
typedef vector<bool > vecbool;
typedef vector<vector< bool > > vec2bool;
typedef vector<bool > vecbool;
////////////////////////////////////////////////
int main()
{
  string s; cin >> s;
  int n = s.size();
  vecll numb(n,0);
  if(s[0] == 'B')numb[0] = 1;
  REP(i, n - 1){
    numb[i + 1] = numb[i] + (ll)(s[i + 1] == 'B');
  }
  ll ans = 0;
  REP(i,n){
    if(s[i] == 'W'){
      ans += numb[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2180
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

ll d[302][302], d2[302][302];

int main() {
	IOS();
	Fill(d, INF);
	ll n, m, l;
	cin >> n >> m >> l;
	for (ll i = 0; i < m; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		d[a][b] = d[b][a] = c;
	}
	for (ll i = 0; i < n; i++) {
		d[i][i] = 0;
	}
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			for (ll k = 0; k < n; k++) {
				d[j][k] = min(d[j][i] + d[k][i], d[j][k]);
			}
		}
	}
	Fill(d2, INF);
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			if (i == j)
				d2[i][j] = 0;
			else if (d[i][j] <= l)
				d2[i][j] = 1;
		}
	}
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			for (ll k = 0; k < n; k++) {
				d2[k][j] = min(d2[i][j] + d2[k][i], d2[j][k]);
			}
		}
	}
	ll q;
	cin >> q;
	for (ll i = 0; i < q; i++) {
		ll s, t;
		cin >> s >> t;
		s--;
		t--;
		dump(d2[s][t] != INF ? d2[s][t] - 1 : -1);
	}
}

Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;

#define N 10000


//stack
typedef struct{
  int num[N];
  int head;
}Stack;


void push(int);
  //delete head position
void pop(void);
  //return head of stack
int top(void);


Stack stack;

int main(){

  string str;
  int x,y;
  stack.head=0;
  //load  and caluculation
  while(cin >> str){

    if(str=="+"){
      x=top();
      pop();
      y=top();
      pop();
      push(x+y);
    }
    else if(str=="-"){
      x=top();
      pop();
      y=top();
      pop();
      push(y-x); 
    }
    else if(str=="*"){
      x=top();
      pop();
      y=top();
      pop();
      push(x*y);
    }
    else{
      //string -> int
      x = atoi(str.c_str());
      push(x);
    }
  }

  //print
  cout <<top()<<endl;
  
  return 0;
  
}



 //add to head position
  void push(int x){
    stack.head++;
    stack.num[stack.head]=x;
  }
  //delete head position
  void pop(void){
      stack.head--;
  }
  //return head of stack
  int top(void){
    return stack.num[stack.head];
  }

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using VVI = vector<vector<int> >;

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

    int n, m;
    cin >> n >> m;
    VVI to(n);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    vector<int> dist(n, -1);
    vector<int> pre(n, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int nv : to[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            pre[nv] = v;
            que.push(nv);
        }
    }

    cout << "Yes" << '\n';
    for (int i = 1; i < n; i++)
        cout << pre[i] + 1 << '\n';
    return 0;
}

Measured memory_bytes: 10668
#include<iostream>
using namespace std;
int N,A[100000];
int min(int n,int a[])
{
  int i;
  int min=a[0];
  for(i=1;i<n;i++)
    {
      if(a[i]<min)
	{
	  min=a[i];
	}
    }
  return min;
}
int max(int n,int a[])
{
  int i;
  int max=a[0];
  for(i=1;i<n;i++)
    {
      if(a[i]>max)
	{
	  max=a[i];
	}
    }
  return max;
}
long int sum(int n,int a[])
{
  int i;
  long int sum=0;
  for(i=0;i<n;i++)
    {
      sum+=a[i];
    }
  return sum;
}
int main()
{
  cin>>N;
  for(int i=0;i<N;i++)
    {
      cin>>A[i];
    }
  cout<<min(N,A)<<' '<<max(N,A)<<' '<<sum(N,A)<<endl;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9 + 10

// 区間更新・区間取得
template <typename T>
struct Segment {
    using u32 = uint_fast32_t;
    u32 n;
    vector<T> node, lazy;
    T ef, eg;               // 単位元∧初期値
    function<T(T, T)> f;    // 更新
    function<T(T, T)> g;    // 取得
    function<T(T, u32)> p;  // 更新 f(a,a, ...,a)

    void eval(u32 len, u32 k) {
        if (lazy[k] != ef) {
            if (2 * k + 1 < 2 * n - 1) {
                lazy[2 * k + 1] = f(lazy[2 * k + 1], lazy[k]);
                lazy[2 * k + 2] = f(lazy[2 * k + 2], lazy[k]);
            }
            node[k] = f(node[k], p(lazy[k], len));
            lazy[k] = ef;
        }
    }

   public:
    Segment(u32 N, T ef, T eg, function<T(T, T)> f, function<T(T, T)> g,
            function<T(T, u32)> p = [](T a, u32 b) { return a; }, vector<T> v = vector<T>())
        : ef(ef), eg(eg), f(f), p(p), g(g) {
        n = 1;
        while (n < N) n *= 2;
        node.assign(2 * n - 1, eg);
        lazy.assign(2 * n - 1, ef);
        if (N == (u32)v.size()) {
            for (int i = 0; i < N; i++) node[i + n - 1] = v[i];
            for (int i = n - 2; i >= 0; i--) {
                node[i] = g(node[2 * i + 1], node[2 * i + 2]);
            }
        }
    }

    // [a,b)をxで更新
    void update(u32 a, u32 b, T x, u32 k, u32 l, u32 r) {
        eval(r - l, k);
        if (b <= l || r <= a) return;  // 含まない
        if (a <= l && r <= b) {        // 完全に含む
            lazy[k] = f(lazy[k], x);
            eval(r - l, k);
        } else {
            update(a, b, x, 2 * k + 1, l, (l + r) / 2);
            update(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = g(node[2 * k + 1], node[2 * k + 2]);
        }
    }
    void update(u32 a, u32 b, T x) { update(a, b, x, 0, 0, n); }

    // [a,b)の区間取得
    T get(u32 a, u32 b, u32 k, u32 l, u32 r) {
        eval(r - l, k);
        if (b <= l || r <= a) return eg;       // 含まない
        if (a <= l && r <= b) return node[k];  // 完全に含む
        T vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
        return g(vl, vr);
    }
    T get(u32 a, u32 b) { return get(a, b, 0, 0, n); }
};

struct Section {
    int S, T, X;
};

int main() {
    int N, Q, cnt = 0;
    cin >> N >> Q;

    vector<Section> v(N);
    set<int> st;
    st.insert(-1);
    for (int i = 0; i < N; i++) {
        cin >> v[i].S >> v[i].T >> v[i].X;
        v[i].S = max(v[i].S - v[i].X, 0);
        v[i].T = max(v[i].T - v[i].X, 0);
        st.insert(v[i].S), st.insert(v[i].T);
    }
    unordered_map<int, int> mp;
    for (auto &x : st) mp[x] = cnt++;
    sort(v.begin(), v.end(), [](Section &x, Section &y) { return x.X > y.X; });

    auto f = [](int a, int b) { return b; };
    auto g = [](int a, int b) { return min(a, b); };
    Segment<int> tree(st.size(), 0, INF, f, g);

    for (int i = 0; i < N; i++) tree.update(mp[v[i].S], mp[v[i].T], v[i].X);
    for (int i = 0; i < Q; i++) {
        int D, ans;
        cin >> D;
        D = mp[*(--st.upper_bound(D))];
        ans = tree.get(D, D + 1);
        cout << (ans == INF ? -1 : ans) << endl;
    }
    return 0;
}

Measured memory_bytes: 47092
#include<bits/stdc++.h>
using namespace std;
int main(){
  long double A,B,C;cin>>A>>B>>C;
  if(A==B&&B==C&&A!=1)cout<<-1<<endl;
  else{
    long D,E,F;long long G,H,I;int M;
    for(int X=0;;X++){
      D=A;E=B;F=C;
      A=E/2+F/2;B=D/2+F/2;C=D/2+F/2;
      G=E/2+F/2;H=D/2+F/2;I=D/2+F/2;
      if(F%2==1||D%2==1||E%2==1){
        M=X;break;
      }
    }
    cout<<M<<endl;
  }
}

Measured memory_bytes: 3676
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    bool flag=false;
    if(abs(a-c)<=d)
    {
        flag=true;
    }
    if(abs(a-b)<=d&&abs(b-c)<=d)
    {
        flag=true;
    }
    if(flag)
    {
        puts("Yes");
    }
    else
        puts("No");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e10;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int b[3][3];
    bool bi[3][3] = {0};
    int n,a;
    rep(i,3) rep(j,3) cin >> b[i][j];
    cin >> n;
    rep(i,n){
        cin >> a;
        rep(i,3){
            rep(j,3){
                if (b[i][j] == a) bi[i][j] = 1;
            }
        }
    }
    if ((bi[0][0] & bi[0][1] & bi[0][2]) || (bi[1][0] & bi[1][1] & bi[1][2]) || (bi[2][0] & bi[2][1] & bi[2][2]) ||
        (bi[0][0] & bi[1][0] & bi[2][0]) || (bi[0][1] & bi[1][1] & bi[2][1]) || (bi[0][2] & bi[1][2] & bi[2][2]) ||
        (bi[0][0] & bi[1][1] & bi[2][2]) || (bi[0][2] & bi[1][1] & bi[2][0])){
            PRINT("Yes");
    }
    else PRINT("No");

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a, b, h;
    cin >> a >> b >> h;
    
    /*
    if(c7 == 1 && c5 == 2 ){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    */
    
    cout << h * ( a + b ) / 2 << endl;

    return 0; 
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
  int a,b;cin >> a >> b;
  cout << a*b << endl;
}

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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}
int a[200500],n;
long long s;
int main()
{
	n=read();
	for(int i=1; i<=n; ++i)a[i]=read();
	if(a[1]){
		cout<<-1;
		exit(0);
	}
	
	for(int i=2; i<=n; ++i)if(a[i]>a[i-1]+1){
		cout<<-1;
		return 0;
	}
	
	for(int i=2; i<=n; ++i){
		if(a[i]==a[i-1]+1)++s;else s+=a[i];
	}
	cout<<s;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

typedef pair<int,int> P;

int n;
map<int,int> sc;

int main(void){
  while(cin>>n,n){
    sc.clear();

    for(int i=0;i<n;i++){
      int m,a,b;
      cin>>m>>a>>b;
      sc[a] += m;
      sc[b] -= m;
    }

    vector<P> v;
    for(map<int,int>::iterator iter=sc.begin();iter!=sc.end();iter++){
      v.push_back(P(iter->first,iter->second));
    }
    sort(v.begin(),v.end());

    int w = 0;
    int i;
    for(i=0;i<v.size();i++){
      w += v[i].second;
      if(w > 150){
        break;
      }
    }
    cout<<(i==v.size() ? "OK" : "NG")<<endl;
  }

  return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 1000000007;
	static long inf = (long) 1e14;
	static int n, q;
	static ArrayList<Integer>[] ad;
	static long[][] memo;
	static boolean f;
	static boolean vis[];
	static int[] size, pa;
	static double[] x, y;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n = sc.nextInt();
		long ans = 0;
		if (n >= 3)
			ans = 1;
		long[] f = new long[3000];
		f[0] = 1;
		for (int i = 1; i < f.length; i++)
			f[i] = i * f[i - 1] % mod;
		for (int i = 2; i <= n; i++) {
			int rest = n - i * 3;
			if (rest < 0)
				break;
			if (rest == 0) {
				ans++;
				break;
			}
			long kcp = f[i + rest - 1] * modPow(f[rest], mod - 2) % mod;
			kcp = kcp * modPow(f[i - 1], mod - 2) % mod;
			ans = (ans + kcp) % mod;
		}
		System.out.println(ans);
		out.close();
	}

	static long modPow(long a, long e)

	{
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res = (res * a) % mod;
			a = (a * a) % mod;
			e >>= 1;
		}
		return res;
	}

	static int[] si;
	static ArrayList<Integer> primes;

	static void seive(int N) {
		si = new int[N];
		primes = new ArrayList<>();
		si[1] = 1;
		for (int i = 2; i < N; i++) {
			if (si[i] == 0) {
				si[i] = i;
				primes.add(i);
			}
			for (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)
				si[primes.get(j) * i] = primes.get(j);
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

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

int main(){
	int w, a, b;
	int dist;
	cin >> w >> a >> b;
	if(a > b) dist = a - b;
	else dist = b - a;
	if (dist < w)
		cout << 0;
	else
		cout << dist - w;
	return 0;
}

Measured memory_bytes: 256
// created by anaksoleh
// 26 Feb 2020
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pi;
 
ll lcm(ll a,ll b){
    return a * b / __gcd(a,b);
}
ll abself(ll a){
    if(a < 0){
        a *= -1;
    }
    return a;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    ll N;
    cin >> N;
    ll x,y;
    for(ll i = 1 ; i * i <= N ; i++){
        if((N % i) == 0){
            x = i;
            y = N / i;
        }
    }
    cout << abself(1-x) + abself(1-y) << '\n';   
    return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
H = list(map(int, input().split()))
ans_list = [1 for x in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    if H[A - 1] == H[B - 1]:
        ans_list[A - 1] = 0
        ans_list[B - 1] = 0
    elif H[A - 1] > H[B - 1]:
        ans_list[B - 1] = 0
    else:
        ans_list[A - 1] = 0
print(ans_list.count(1))


Measured memory_bytes: 20120
import numpy as np
import sys
sys.setrecursionlimit(100000)

def main():
    n, m, x = map(int, input().split())
    cl = [None]*n
    al = [None]*n
    total = np.array([0]*m)
    global ans
    ans = 10**7
    for i in range(n):
        c, *a = map(int, input().split())
        a = np.array(a)
        cl[i] = c
        al[i] = a
        total += a
    def dfs(i, cost, A):
        i += 1
        if i == n:
            global ans
            if all([ai >= x for ai in A]) and ans > cost:
                ans = cost
            return
        dfs(i, cost, A[:])
        dfs(i, cost+cl[i], A[:]+al[i])
    dfs(-1, 0, np.array([0]*m))
    if ans == 10**7:
        print(-1)
    else:
        print(ans)
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 27184
#include <iostream>
#include<vector>
#include<bits/stdc++.h>

using namespace std;

int main()
{
    string  s;
    cin >> s;
    int c=0;
    vector<int>v;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='R')
        c++;
        else
        {
            v.push_back(c);
            c=0;
        }
    }
    v.push_back(c);
    sort(v.begin(),v.end());
    cout << v.at(v.size()-1);
    
}


Measured memory_bytes: 3624
n, m = map(int, input().split())
ps = [int(x) for x in input().split()]
xs = [tuple(map(int, input().split())) for _ in range(m)]

union = {x:x for x in range(1, n+1)}
def root(n):
    if union[n] == n:
        return n
    union[n] = root(union[n])
    return union[n]

for x,y in xs:
    union[root(x)] = root(y)

print(sum(root(i+1) == root(ps[i]) for i in range(n)))

Measured memory_bytes: 33992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100;
char s[maxn];
int main()
{
    int n,i,flag;
    //freopen("text.in","r",stdin);
    scanf("%s",s+1);
    n=strlen(s+1);
    flag=1;
    if (n%2) {
        printf("No\n");
        return 0;
    }
    for (i=1;i<=n/2;i++) {
        if (!(s[(i-1)*2+1]=='h'&&s[i*2]=='i')) {
            flag=0;
            break ;
        }
    }
    if (flag) {
        printf("Yes\n");
        //cout<<"Yes"<<endl;
    }else {
        printf("No\n");
        //cout<<"No"<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        long m = (long)n * (n + 1) / 2;
        long[] a = new long[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            sum += a[i];
        }
        System.out.println(sum % m == 0 && f(a, n, sum / m) ? "YES" : "NO");
    }

    static boolean f(long[] a, int n, long k) {
        for (int i = 0; i < n; i++) {
            long b = a[i] - a[(i + 1) % n] + k;
            if (b < 0 || b % n != 0) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 56048
inputs = input().split()
N = int(inputs[0])
M = int(inputs[1])
K = int(inputs[2])
a = [[0 for y in range(M)] for x in range(N)]

flag = False

for i in range(N + 1):
    for j in range(M + 1):
        if M*i + N*j - (j)*(i)*2 == K:
            flag = True

if flag or (N == 1 and M == 1):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 11892
import collections

n, p = map(int, input().split())
res = []
x = p
y = 2
while y*y <= x:
    while x % y == 0:
        res.append(y)
        x //= y
    y += 1
if x > 1:
    res.append(x)

res = collections.Counter(res)
ans = 1
for d in res.items():
    ans *= d[0]**(d[1]//n)
print(ans)

Measured memory_bytes: 3316
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if((a + b <= b + c) && (a + b <= c + a)){
		cout << a + b << endl;
	}
	else if((b + c <= a + b) && (b + c <= c + a)){
		cout << b + c << endl;
	}
	else if((c + a <= a + b) && (c + a <= b + c)){
		cout << c + a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;

const ll mod197 = 1000000007LL;
const ll INF = INT_MAX;

const double PI11 = 3.14159265359;

int main() {

	map<ll, bool> m;

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		m[a] = !m[a];
	}

	int ans = 0;

	for (auto t : m) {
		if (t.second)
			ans++;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	int a, b, n;
	while(scanf("%d %d %d", &a, &b, &n) != EOF) {
		int r = 0;
		a = a % b;
		a *= 10;
		rep(i,n) {
			rep(j,11) {
				if(b * j > a) {
					r += j - 1;
					a -= b * (j - 1);
					break;
				}
			}
			a *= 10;
		}
		cout << r << endl;
	}
	return 0;
}

Measured memory_bytes: 1208