akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define fi first
#define se second
using namespace std;
ll fix(ll x){
	return (x%mod+mod)%mod;
}
ll K(ll x,int y=mod-2){
	ll t=1; for (;y;y>>=1,x=x*x%mod) if (y&1) t=x*t%mod; return t;
}
int n,fa[202000][19],dep[202000],id[202000],tid;
vector<int>G[202000],vec[202000];
map<int,vector<int> >mp;
unordered_map<int,int>up;

void dfs(int x){
	vec[dep[x]].push_back(x);
	for (int i=1;i<=18;++i) fa[x][i]=fa[fa[x][i-1]][i-1];
	for (auto y:G[x]) {
		dep[y]=dep[x]+1;
		dfs(y);
	}
	id[x]=++tid;
}

int lca(int x,int y){
	if (dep[x]<dep[y]) swap(x,y);
	for (int i=18;~i;--i) if (dep[fa[x][i]]>=dep[y])
		x=fa[x][i];
	if (x==y) return x;
	for (int i=18;~i;--i) if (fa[x][i]-fa[y][i])
		x=fa[x][i], y=fa[y][i];
	return fa[x][0];
}

int in[202000],f[202000],g[202000],sz[202000],ans;
int GI(int x){
	return in[x]==x? x: in[x]=GI(in[x]);
}

void doit(vector<int>&the){
	mp.clear();
	for (int i=0,l;i<the.size();++i){
		if (i) mp[id[lca(the[i-1],the[i])]].push_back(i);
		in[i]=i; f[i]=g[i]=1; sz[i]=1;
	}
	
	for (auto it:mp){
		ll res=1,ff=0; int x,y;
		up.clear();
		for (auto o:it.se){
			x=GI(o-1), y=GI(o);
			up[x]=up[y]=1;
			sz[x]+=sz[y]; in[y]=x;
		}
		for (auto o:up) res=res*g[o.fi]%mod;
		for (auto o:up) ff=(ff+ res*K(g[o.fi])%mod *f[o.fi])%mod;
		f[x]=ff, g[x]=fix(K(2,sz[x])-ff);
	}
	ans=(ans+(ll)f[GI(0)]*K(2,n+1-the.size()))%mod;
}

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&fa[i][0]), G[fa[i][0]].push_back(i);
	dfs(0); ans=K(2,n);
	for (int i=1;i<=200000;++i) if (vec[i].size()) doit(vec[i]);
	cout<<ans;
}

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

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


a, b, n = map(int, input().split())
x=0
score=0
cnt=0
print(max(int(a*(min(b, n)-1)/b)-a*int((min(b, n)-1)/b),
      int(a*(min(b, n))/b)-a*int((min(b, n))/b)))



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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    vector<i64> a, b;
    i64 asum = 0, bsum = 0;
    for(int i=0;i<n;++i){
        i64 tmp;
        cin >> tmp;
        a.push_back(tmp);
        asum += tmp;
    }
    for(int i=0;i<n;++i){
        i64 tmp;
        cin >> tmp;
        b.push_back(tmp);
        bsum += tmp;
    }

    if(bsum > asum){
        cout << -1 << endl;
        return 0;
    }

    i64 ans = 0, sum = 0;
    vector<i64> v;
    for(int i=0;i<n;++i){
        v.push_back(a[i]-b[i]);
        if(a[i] < b[i]){
            ans++;
            sum += abs(a[i]-b[i]);
        }
    }

    sort(v.rbegin(), v.rend());
    for(int i=0;i<n;++i){
        if(sum <= 0)break;
        sum -= v[i];
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3444
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x:x[0])
ans = 0
num = M
for a,b in AB:
  if b < num:
    ans += a*b
    num -= b
  else:
    ans += a*num
    num -= num
    break
print(ans)



Measured memory_bytes: 29792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 233;
int p[maxn],vis[maxn],cnt=0;
void init(){
	memset(vis,0,sizeof(vis));
	int n = 1e6;
	for(int i=2;i<=n;i++){
		if(!vis[i]){p[++cnt] = i;;}
		for(int j=1;j<=cnt&&i*p[j]<=n;j++){
			if(i%p[j]==0){
				vis[i*p[j]] = 1;
				break;
			}
			else{
				vis[i*p[j]] = 1; 
			} 
		}
	}
//	for(int i=1;i<=30;i++)
//		cout<<i<<": "<<" "<<vis[i]<<endl;
	return ;
}
int main()
{
	init();
	ll a,b;cin>>a>>b;
	ll d = __gcd(a,b);
	int ans = 1;
	for(int i=1;i<=cnt;i++)
		if(d%p[i]==0){
			ans++;
//			cout<<"!"<<p[i]<<endl;
			while(d%p[i]==0)d /= p[i];
		}
	if(d>1)ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;


int main(){
	int n;
    int t, a;
    int h[1005];
    int id;
    double d;

    cin >> n;
    cin >> t >> a;
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    
    id = 0;
    d = abs(a - (t - (double)h[0] * 0.006));
    for(int i=0;i<n;i++){
        double d_ = abs(a - (t - (double)h[i] * 0.006));
        if(d > d_){
            id = i;
            d = d_;
        }
    }
	
    cout << id+1 << endl;
	
	return 0;
}


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

int main(){
    int nanbyou;
    cin>>nanbyou;
    int jikann,fun,byou;
    jikann=(nanbyou-(nanbyou%3600))/3600;
    fun=((nanbyou%3600)-(nanbyou%60))/60;
    byou=nanbyou%60;
    cout<<jikann<<":"<<fun<<":"<<byou<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define rr int
using namespace std;
typedef long long ll;
ll read() {
    char i = getchar();
    ll f = 1, res = 0;
    while (i < '0' || i > '9') {
        if (i == '-') f = -1;
        i = getchar();
    }
    while (i >= '0' && i <= '9') {
        res = res * 10 + i - '0';
        i = getchar();
    }
    return f * res;
}
int n;
ll K;
const int N = 3e5 + 50;
ll a[N];
ll sum[N], c[N];
ll ans = 0;
inline void merge(int l, int r) {
    if (l < r) {
        int mid = (l + r) >> 1;
        merge(l, mid);
        merge(mid + 1, r);
        int i = l, j = mid + 1, now = l;
        while (i <= mid && j <= r) {
            if (a[i] <= a[j]) {
                c[now++] = a[i++];
                ans += r - j + 1; //这里注意不能重复计算，每次取得取单独更新贡献
            } else
                c[now++] = a[j++];
        }
        while (i <= mid) c[now++] = a[i++];
        while (j <= r) c[now++] = a[j++];
        for (rr i = l; i <= r; ++i) a[i] = c[i];
    }
}
int main() {
    n = read() + 1, K = read();
    for (rr i = 2; i <= n; ++i) {
        a[i] = read();
        sum[i] = sum[i - 1] + a[i];
        a[i] = sum[i] - K * ll(i - 1);
    }
    // for (rr i = 1; i <= n; ++i) cout << a[i] << ' ';
    merge(1, n);
    // for (rr i = 1; i <= n; ++i) cout << a[i] << endl;
    cout << ans;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  if (h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }

  ll ans = 0;
  if (w%2 == 0) {
    ans = (w/2) * h;
  } else {
    ans = (w/2+1) * ((h%2 == 0) ? (h/2) : (h/2+1));
    ans += (w/2) * (h/2);
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
    ll N,W;
    cin>>N>>W;
    V w(N),v(N);
    rep(i,N)cin>>w[i]>>v[i];
    ll MAX_V=200000;
    vector<vector<ll>> dp(N+1,vector<ll>(MAX_V,1e9+7));
    dp[0][0]=0;
    rep(i,N){
        rep(j,MAX_V){
            if(j<v[i]){
                dp[i+1][j]=dp[i][j];
            }else{
                dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
            }
        }
    }
    ll ans=0;
    rep(i,MAX_V){
        if(dp[N][i]<=W){
            ans=i;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 159744
import java.util.Arrays;
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       int size = s.nextInt();
       int k = s.nextInt();
       int elements[] = new int[size];
       for(int i=0;i<size;i++) {
           elements[i] = s.nextInt();
       }
       Arrays.sort(elements);
       long sum = 0;
       for(int i=0;i<k&&i<size;i++) {
           sum += elements[i];
       }
       System.out.println(sum);
   }
}


Measured memory_bytes: 38844
#include <stdio.h>

int main(){
  int n,i=0,b;

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

  for(i=1;i<=n-1;i++){
    printf("%d",a[0]);
    for(b=1;b<n;b++){
      printf("% d",a[b]);
    }
    printf("\n");
    int v=a[i];
    int j=i-1;
    while(j>=0 && a[j] > v){
      a[j+1]=a[j];
      j--;
      a[j+1]=v;
    }
  }
  printf("%d",a[0]);
  for(b=1;b<n;b++){
    printf(" %d",a[b]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

struct unionfind
{
    vector<long long> d;

    unionfind(long long n) : d(n, -1) {}

    long long root(long long x)
    {
        if (d[x] < 0)
        {
            return x;
        }
        else
        {
            return d[x] = root(d[x]);
        }
    }

    bool unite(long long x, long long y)
    {
        x = root(x);
        y = root(y);

        if (x == y)
        {
            return false;
        }

        if (d[x] > d[y])
        {
            swap(x, y);
        }

        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(long long x, long long y)
    {
        return root(x) == root(y);
    }

    long long size(long long x)
    {
        return -d[root(x)];
    }
};

int main(void)
{
    int n, m;
    cin >> n >> m;

    unionfind u(n);

    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        u.unite(a, b);
    }

    ll ans = 0;

    for (int i = 0; i < n; i++)
    {
        ans = max(u.size(i), ans);
    }

    cout << ans << endl;
}


Measured memory_bytes: 4844
#include<bits/stdc++.h>
#define show(x) cout<<#x" = "<<x<<endl;
#define show2(x,y) cout<<#x" = "<<x<<" "<<#y<<" = "<<y<<endl;
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> iipair;
typedef pair<unsigned,unsigned> uupair;
typedef vector<int> vec;
typedef vector<unsigned> uvec;
typedef map<string,unsigned> ds;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    unsigned n;
    string s;
    cin>>n;
    unsigned smax=0;
    ds freq;
    while(n--)
    {
        cin>>s;
        freq[s]++;
        smax=max(smax,freq[s]);
    }    
    for(auto x : freq)
    {
        if(x.second == smax) cout<<x.first<<"\n";
    }
}

Measured memory_bytes: 23936
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl

/*--------------------template--------------------*/

ll d[500000] = { 1 };

int main() {
    fill(d, d + 500000, 1);
    cin >> n;
    vi v(n);
    REP(i, n) {
        cin >> v[i];
    }
    set<ll> st;
    st.insert(v[0]);

    FOR(i, 1, n) {
        if (v[i] == 1) {
            st.insert(v[i]);
            continue;
        }
        if (st.count(v[i] - 1) != 0) {
            d[v[i]] = d[v[i] - 1] + 1;
        }
        st.insert(v[i]);
    }
    REP(i, n+1) {
        chmax(ans, d[i]);
    }
    cout << n - ans << endl;
}

Measured memory_bytes: 15104
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();
	        int D = sc.nextInt();
	        int ans = 0;
	        
	        int D1 = D + D + 1;
	        
	        if(N % D1 == 0){
	          ans = N / D1;
	        } else {
	          ans = N / D1 +1;
	        }
	        
	        System.out.println(ans);
	}
}

Measured memory_bytes: 21204
a = [[['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 
[['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
 [['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 
 [['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]
n = input()
for i in range(n):
    b, f, r, v = map(int, raw_input().split())
    a[b - 1][f - 1][r] += v
print ' '.join(map(str, a[0][0]))
print ' '.join(map(str, a[0][1]))
print ' '.join(map(str, a[0][2]))
print '####################'
print ' '.join(map(str, a[1][0]))
print ' '.join(map(str, a[1][1]))
print ' '.join(map(str, a[1][2]))
print '####################'
print ' '.join(map(str, a[2][0]))
print ' '.join(map(str, a[2][1]))
print ' '.join(map(str, a[2][2]))
print '####################'
print ' '.join(map(str, a[3][0]))
print ' '.join(map(str, a[3][1]))
print ' '.join(map(str, a[3][2]))

Measured memory_bytes: 6448
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        string s;
        cin >> s;
        set<char> st;
        for (int i = 0; i < s.size(); i ++) {
                st.insert(s[i]);
        }
        if (st.count('a') && st.count('b') && st.count('c')) {
                puts("Yes");
        } else {
                puts("No");
        }
        return 0;
}



Measured memory_bytes: 256
#include <cstring>
#include <algorithm>
#include <iostream>

using namespace std;

int N, X[24], Y[24], R[24], C[24];

bool isCoverd(int i, int j)
{
  int x = abs(X[i] - X[j]), y = abs(Y[i] - Y[j]), r = R[i] + R[j];
  return ((x * x) + (y * y)) < (r * r);
}

bool noCoverd(int j, int s) {
  for (int i = 0; i < j; i++)
    if ( (s >> i & 1) && isCoverd(i, j))
      return false;

  return true;
}

char memo[1 << 25];
int dfs(int s)
{
  if (memo[s] != -1) {
    return memo[s];
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if ( C[i] == C[j] && (s >> i & 1) && (s >> j & 1) &&
           noCoverd(i, s) && noCoverd(j, s) ) {
        ans = max(ans, dfs(s & ~(1 << i) & ~(1 << j)) + 2);
      }
    }
  }
  
  return memo[s] = ans;
}


int main()
{
  while (cin >> N && N) {
    for (int i = 0; i < N; i++) 
      cin >> X[i] >> Y[i] >> R[i] >> C[i];

    memset(memo, -1, sizeof(memo));

    cout << dfs((1 << N) - 1) << endl;
    
  }
}

Measured memory_bytes: 32000
#include <cstdio>

using namespace std;

int main()
{
	int num, tmp[10] = {0}, num_out[100] = {0};
	int cnt_1 = 9, cnt_2 = 0;
	
	while (scanf("%d", &num) != EOF){
		if (num == 0){
			num_out[cnt_2] = tmp[cnt_1 + 1];
			//printf("num_out[%d]=%d\n", cnt_2, num_out[cnt_2]);
			cnt_2++;
			cnt_1++;
		}
		else {
			tmp[cnt_1] = num;
			//printf("tmp[%d]=%d\n", cnt_1, tmp[cnt_1]);
			cnt_1--;
		}
	}
	
	for (int i = 0; i < 100; i++){
		if (num_out[i] != 0){
			printf("%d\n", num_out[i]);
		}
	}
	
	return (0);
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    if (b==0) return (int)1;
    int x = p(a, b>>1);
    if (b & 1) return m(x*m(a*x));
    return m(x*x);
}
signed main(){
    fast();
    int n, k;
    cin >> n >> k;
    vector<int> a(n+1);
    for(int i=1; i<=n; i++)  cin >> a[i];
    vector<bool> vis(n+1, false);
    int start = 1;
    while(!vis[start]){
        vis[start] = true;
        start = a[start];
    }
    // cerr << start << endl;
    int u = 1, moves = 0;
    while(u != start){
        u = a[u];
        moves++;
    }
    // cerr << moves << endl;
    if(k <= moves){
        int u = 1;
        for(int i=0; i<k; i++){
            u = a[u];
        }
        cout << u << endl;
        return 0;
    }
    k -= moves;
    int cycle = 1;
    u = start;
    while(a[u] != start){
        u = a[u];
        cycle++;
    }
    // cerr << cycle << endl;
    k %= cycle;
    // cerr << k << endl;
    int prev = start, curr = prev;
    for(int i=0; i<k; i++){
        curr = a[prev];
        prev = curr;
    }
    cout << curr << endl;
}

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b||a==c||b==c){
    if(a==b&&b==c){
    cout<<"1"<<endl;
  }
    else {
    cout<<"2"<<endl;
  }
  }
  else {
    cout<<"3"<<endl;
  }
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int length;
		while ((length = scanner.nextInt()) > 0) {
			int sum = 0;
			int min = Integer.MAX_VALUE;
			int max = Integer.MIN_VALUE;

			for (int i = 0; i < length; i++) {
				int next = scanner.nextInt();
				sum = sum + next;
				if (min > next) {
					min = next;
				}
				if (max < next) {
					max = next;
				}
			}
			System.out.println((sum - min - max) / (length - 2));
		}
		scanner.close();
	}
}

Measured memory_bytes: 28592
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	lint N, M;

	cin >> N >> M;
	vector<lint> node(N, -INF64);

	vector<vector<pair<int, lint>>> root(N, vector<pair<int, lint>>());

	for (int i = 0; i < M; i++)
	{
		int a, b;
		lint c;
		cin >> a >> b >> c;
		root[a - 1].push_back(make_pair(b - 1, c));
	}
	node[0] = 0;

	for (int i = 0; i < 2 * N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			for (auto n : root[j])
			{
				if (node[n.first] == -INF64 || node[n.first] < node[j] + n.second)
				{
					node[n.first] = node[j] + n.second;
					if (N < i && n.first == N - 1)
					{
						cout << "inf" << endl;
						return;
					}
				}
			}
		}
	}
	cout << node[N - 1] << endl;

	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 384
fn = lambda: map(int, input().split())
N, M = fn()
a, b = [0]*M, [0]*M
ones, goals = set(), set()
for i in range(M):
    ai, bi = fn()
    if ai == 1 and bi == N:
        print('POSSIBLE')
        exit()
    elif ai == 1:
        ones.add(bi)
    elif bi == N:
        goals.add(ai)

if len(ones.intersection(goals)) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Measured memory_bytes: 22152
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  long long H;
  cin >> H;

  long long h = H,branch = 1,sum = 0;
  
  while(h > 1) {
    h /= 2;
    sum += branch;
    branch *= 2;
  }

  sum += branch;
  cout << sum << endl;


  
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int t;
  while(cin >> t && t){
    int n,sum = 0;
    cin >> n;
    while(n--){
      int from,to;
      cin >> from >> to;
      sum += to-from;
    }
    if(sum >= t) cout << "OK" << endl;
    else cout << t-sum << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

ll f(ll x) {
  ll ans = 0;
  for(ll i = 1; i <= x; ++i) {
    if(x % i == 0) ++ans;
  }
  return ans;
}

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll ans = a[n - 1];
  bool flag = true;
  for(int i = n - 3, j = n - 2; i >= 0; --i) {
    ans += a[j];
    flag = !flag;
    if(flag) --j;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4756
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n), dp(n, INT_MAX);
  
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  dp[0] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 1; j <= k; j++){
       if(i >= j){
          dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
       }
    }
  }
  
  cout << dp[n - 1];
  return 0;
}

Measured memory_bytes: 4044
import sys
import bisect
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = [int(i) for i in sys.stdin.readline().split()]
c_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort()
b_ls.sort()
c_ls.sort()
comb_a = []
comb_b = []
len_b = len(b_ls)
len_c = len(c_ls)
for a in a_ls:
    ind = len_b - bisect.bisect_right(b_ls, a)
    comb_a.append(ind)

prod_b = []
res = 0
for b in b_ls[::-1]:
    ind = len_c - bisect.bisect_right(c_ls, b)
    comb_b.append(ind)
    res += ind
    prod_b.append(res)
comb_b = comb_b[::-1]
_sum = 0
for a in comb_a:
    if a <= 0:
        continue
    _sum += prod_b[a-1]
print(_sum)

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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A+B > C+D){
    cout << "Left" << endl;
  }else if(A+B == C+D){
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }
  
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//Everything Starts With Your Vote
public class Main{

	class R implements Comparable<R>{
		String s;
		int x;
		public R(String s, int x) {
			this.s = s;
			this.x = x;
		}
		int win(R r){
			return s.compareTo(r.s)<0?r.x-x:(r.x-x+1);
		}
		public int compareTo(R o) {
			return x!=o.x?o.x-x:s.compareTo(o.s);
		}
	}
	
	int N, M, K, L, B;
	R[] r;
	boolean[] fav;
	Set<String> fn;
	
	long need(int x){
		if(x<=B)return 0;
		int n = x-B, c = 0;
		int k = K-1;
		for(;;){
			if(fav[k])n++;
			else c++;
			if(c==x-B)break;
			k--;
		}
		R tar = r[k];
		long res = 0;
		for(int i=k+1;i<N&&0<n;i++){
			if(!fav[i])continue;
			n--;
			res+=r[i].win(tar);
		}
		return res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		fav = new boolean[100000];
		for(;;){
			N = sc.nextInt(); M = sc.nextInt(); K = sc.nextInt(); L = sc.nextInt();
			if((N|M|K|L)==0)break;
			r = new R[N];
			for(int i=0;i<N;i++)r[i]=new R(sc.next(), sc.nextInt());
			Arrays.sort(r);
			Arrays.fill(fav, false);
			fn = new HashSet<String>();
			for(int i=0;i<M;i++)fn.add(sc.next());
			B = 0;
			for(int i=0;i<N;i++){
				if(fn.contains(r[i].s)){
					fav[i] = true;
					if(i<K)B++;
				}
			}
			int left = B, right = Math.min(M, K);
			while(right-left>1){
				int m = (left+right)/2;
				if(L<need(m))right=m;
				else left=m;
			}
			System.out.println(need(right)<=L?right:left);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 38000
(function(input) {
    var p = input.replace(/\n$/, '').split(' ');
    console.log(calc(p));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function calc(a) {
    var stack = [];
    for (var i = 0; i < a.length; i++) {
        var n = a[i];
        //console.log(n);
        if (isNaN(n)) {
            var str = stack.pop();
            str = stack.pop() + ' ' + n + ' ' + str;
            //console.log(str);
            var acm = eval(str);
            //console.log(acm);
            stack.push(acm);
            continue;
        }
        stack.push(Number(n));
    }
    return stack.pop();
}

Measured memory_bytes: 8548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	string s;
	cin>>s;
	ll ans=0;
	vector<vector<ll>> sum(3,vector<ll>(n+1,0));
	rep(i,n){
		rep(j,3) sum[j][i+1]=sum[j][i];
		if(s[i]=='R') sum[0][i+1]++;
		if(s[i]=='G') sum[1][i+1]++;
		if(s[i]=='B') sum[2][i+1]++;
	}
	vector<char> tar={'R','G','B'};
	rep(i,n)FOR(j,i+1,n){
		if(s[i]==s[j]) continue;
		int ind;
		rep(k,3){
			if(tar[k]!=s[i] && tar[k]!=s[j]){
				ind=k;
				break;
			}
		}
		ans+=sum[ind][n]-sum[ind][j];
		if(2*j-i<n && s[2*j-i]==tar[ind]) ans--;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3748
n = int(input())

countMap = {}
for i in range(n):
  s = input()
  if s in countMap:
    countMap[s] += 1
  else:
    countMap[s] = 1

maxCount = max(countMap.values())
maxCountKeys = [k for k, v in countMap.items() if v == maxCount]
for maxCountKey in sorted(maxCountKeys):
  print(maxCountKey)



Measured memory_bytes: 32988
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

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

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
fast_io
int a,b; cin>>a>>b;
if((a*b)&1) cout<<"Odd";
else cout<<"Even";
return 0;
}

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

int main() {
	int Number = 0;//カードの枚数
	int Alice = 0;//Aliceの得点
	int Bob = 0;//Bobの得点
	int Max = 0;//最適な戦略
	int Cheak = 0;//この数が最大かどうか確認
	int Max_index = 0;//一回使用した配列の要素番号を記録
	cin >> Number;
	vector<int> Card(Number);//カードの数字を記録  
	for (int Loop = 0; Loop < Number; Loop++) {
    	cin >> Card.at(Loop);
    }  
	for (int Loopi = 0; Loopi < Number; Loopi++) {
        Max = 0;
        Max_index = 0;
		for (int Loopii = 0; Loopii < Number; Loopii++) {
        	Cheak = Card.at(Loopii);
    		if (Cheak > Max) {
            	Max = Cheak;
        		Max_index = Loopii;
            }
        }
        //cout << Max << endl;
        //cout << Max_index << endl;
        	if (Loopi % 2 == 0) {
            	Alice += Max;
            }
      		else {
            	Bob += Max;
            }
         	Card.at(Max_index) = 0;
    }
    cout << Alice - Bob << endl;
    //cout << Alice << endl;
    //cout << Bob << endl;
}

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

int main()
{
	int P, Q, R;
	cin >> P;
	cin >> Q;
	cin >> R;
	int M = max(P, max(Q, R));
	cout << P + Q + R - M << endl;
	return 0;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

class UnionFindTree
    attr_accessor:par,:rank
    def initialize(n)
        @par=Array.new(n){|i| i}
        @rank=array(n,0)
    end

    def find(x)
        return x if @par[x]==x
        @par[x]=find(@par[x])
        return @par[x]
    end
    
    def union(x,y)
        x=find(x)
        y=find(y)
        return if x==y
        if @rank[x]<@rank[y]
            @par[x]=y
        else
            @par[y]=x
            @rank[x]+=1 if @rank[x]==@rank[y]
        end
    end

    def same?(x,y)
        return find(x)==find(y)
    end
end
N,M=get_i
g=array(N)
M.times do|i|
  a,b=get_i.map{|x| x-=1}
  g[a]=[] if g[a].nil?
  g[a].push(b)
  g[b]=[] if g[b].nil?
  g[b].push(a)
end
ans=array(N,-1)
def bfs(g,ans)
    que=[]
    ans[0]=0
    que.push(0)
    until que==[]
        cur=que.shift
        next if g[cur].nil?
        g[cur].each do|v|
          next if ans[v]!=-1
          ans[v]=cur
          que.push(v)
        end
    end
    return ans
end
ans=bfs(g,ans)
puts "Yes"
1.upto(N-1) do|i|
  puts ans[i]+1
end

Measured memory_bytes: 30776
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;



int main() {
  int n,m,v,p;
  scanf("%d%d%d%d",&n,&m,&v,&p);
  vi a(n);
  cin>>a;
  sort(rrng(a));
  int l = 0, r = n;
  while (l+1<r) {
    int c = (l+r)>>1;
    auto f = [&](int c) {
      ll s = (ll)m*v;
      ll tag = a[c]+m;
      vi t(n);
      t[c] = 1;
      int rest = p-1;
      rep(i,n) {
        if (t[i]) continue;
        if (!rest) break;
        --rest;
        t[i] = 1;
      }
      rep(i,n) {
        if (t[i]) {
          s -= m;
        } else {
          ll x = tag-a[i];
          if (x < 0) return false;
          mins(x,(ll)m);
          s -= x;
        }
      }
      if (s <= 0) return true;
      return false;
    };
    if (f(c)) l = c; else r = c;
  }
  int ans = r;
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 1024
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <numeric>
#include <sstream>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

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

  int k;
  cin >> k;
  string s;
  cin >> s;

  if (s.size() <= k) {
    cout << s << endl;
  }
  else {
    cout << s.substr(0, k).append("...") << endl;
  }


  return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

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

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	ll a, b, k;
	in(a);
	in(b);
	k = a + b;
	if (k % 2 == 1) {
		outn("IMPOSSIBLE");
	}
	else {
		outn(k / 2);
	}

	return 0;
}


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

using namespace std;
const int maxn = 1010;
int x[maxn], y[maxn], n, d[maxn], m, flg[2];

void solve(int a, int b){
    for(int i=0; i<m-flg[0]; i++){
        if(abs(a)>abs(b)){
            if(a>0) putchar('R'),a-=d[i];
            else    putchar('L'),a+=d[i];
        }else{
            if(b>0) putchar('U'),b-=d[i];
            else    putchar('D'),b+=d[i];
        }
    }
    if(flg[0]) putchar('L');
    puts("");
}
int main(){
    cin >> n;
    for(int i = 0; i < n; i++) 
        cin >> x[i] >> y[i], flg[(abs(x[i])+abs(y[i]))%2]=1;
    if(flg[0]&&flg[1]) return puts("-1"),0;
    for(int j = 30; j >= 0; j--)  d[m++]=(1<<j);
    if(flg[0]) d[m++] = 1;
    printf("%d\n", m); 
    for(int i=0;i<m;i++)printf("%d%c",d[i]," \n"[i==m-1]);
    for(int i = 0; i < n; i++) solve(x[i]+flg[0],y[i]);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int r=scan.nextInt();
		if(n>=10) System.out.println(r);
		else
		{
			int a=100*(10-n);
			System.out.println(a+r);
		}

	}

}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

bool isSosu(ll n) {
    ll b = sqrt(n) + 1;
    for (int i = 2; i < b; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    vector<ll> ans;
    int now = 1;
    while (ans.size() < n) {
        now += 5;
        if (isSosu(now)) {
            ans.push_back(now);
        }
    }

    rep(i, n) {
        cout << ans[i] << ' ';
    }

    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    if (a > 0) PRINT("Positive");
    else if (b >= 0) PRINT("Zero");
    else if (((b-a)+1)%2) PRINT("Negative");
    else PRINT("Positive");
}

Measured memory_bytes: 256
N,M,X = gets.split.map(&:to_i)
As = gets.split.map(&:to_i)
ans = []
cost = 0
(0..X).each do |i|
    cost += 1 if As.include?(i)
end
ans << cost
cost = 0
(X..N).each do |i|
    cost += 1 if As.include?(i)
end
ans << cost

puts ans.min

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

using namespace std;

const int N = 303;
const int md = 998244353;

int add(int x, int y) {
  x += y;
  if (x > md) {
    x -= md;
  }
  if (x < 0) {
    x += md;
  }
  return x;
}

int dp[N][N][N];
int pref1[N][N];
int pref2[N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n, k;
  cin >> k;
  n = s.size();
  k = min(n, k);
  vector<int> x;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    while (i < n && s[i] == '1') {
      ++cnt;
      ++i;
    }
    x.push_back(cnt);
  }
  int r = x.size();
  for (int i = 0; i <= k; i++) {
    dp[0][0][i] = 1;
  }
  for (int i = 0; i < r; i++) {
    for (int s = 0; s <= n; s++) {
      pref1[s][0] = dp[i][0][s];
      pref2[s][0] = dp[i][0][s];
    }
    for (int s = 0; s <= n; s++) {
      for (int j = 1; j + s <= n; j++) {
        pref1[s][j] = add(pref1[s][j - 1], dp[i][j][j + s]);
      }
      for (int j = 1; j <= n; j++) {
        pref2[s][j] = add(pref2[s][j - 1], dp[i][j][s]);
      }
    }
    for (int j = 0; j <= n; j++) {
      for (int k = j; k <= n; k++) {
        dp[i + 1][j][k] = add(pref2[k][j], pref1[k - j][j + x[i]] - pref1[k - j][j]);
      }
    }
  }
  cout << dp[r][0][0] << '\n';
  return 0;
}


Measured memory_bytes: 111404
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g)
{
    for(int i = g; i < n; i++)
    {
        int v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v)
        {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void shellSort(int A[], int n)
{
    for(int h = 1; ;)
    {
        if(h > n) break;
        G.push_back(h);
        h = 3*h + 1;
    }
    for(int i = G.size() - 1; i >= 0; i--)
    {
        insertionSort(A, n, G[i]);
    }

}

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &A[i]);
    }
    cnt = 0;
    shellSort(A, n);

    cout << G.size() << endl;
    for(int i = G.size() - 1; i >= 0; i--)
    {
        printf("%d", G[i]);
        if(i) printf(" ");
    }
    printf("\n");
    printf("%d\n", cnt);
    for(int i = 0; i < n; i++) printf("%d\n", A[i]);
    return 0;
}



Measured memory_bytes: 7136
from collections import deque
X, Y, Z, K = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

out = deque()
out2 = deque()

for i in range(X):
    for j in range(Y):
        out.append(A[i]+B[j])
out = sorted(out, reverse=True)
del out[K:]
for i in range(len(out)):
    for j in range(Z):
        out2.append(out[i]+C[j])
out2 = sorted(out2, reverse=True)
for i in range(K):
    print(out2[i])


Measured memory_bytes: 184092
#include <cstdio>
#include <algorithm>

const int MAXN = 100005;
const int MOD = 1000000007;

struct Edge;
struct Node {
    Edge *e;
    int f[2];
} N[MAXN];

struct Edge {
    Node *u, *v;
    Edge *next;

    Edge() {}
    Edge(Node *u, Node *v) : u(u), v(v), next(u->e) {}
} _pool[MAXN << 1], *_curr = _pool;

void addEdge(int u, int v) {
    N[u].e = new (_curr++) Edge(&N[u], &N[v]);
    N[v].e = new (_curr++) Edge(&N[v], &N[u]);
}

void dp(Node *u, Node *fa = NULL) {
    u->f[0] = u->f[1] = 1;
    for (Edge *e = u->e; e; e = e->next) if (e->v != fa) {
        dp(e->v, u);
        u->f[0] = 1ll * (e->v->f[0] + e->v->f[1]) * u->f[0] % MOD;
        u->f[1] = 1ll * e->v->f[0] * u->f[1] % MOD;
    }
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1, u, v; i < n; i++) {
        scanf("%d %d", &u, &v);
        addEdge(u, v);
    }

    dp(&N[1]);

    int ans = N[1].f[0] + N[1].f[1];
    ans >= MOD ? ans -= MOD : 0;
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 10624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BHinaArare solver = new BHinaArare();
        solver.solve(1, in, out);
        out.close();
    }

    static class BHinaArare {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            boolean four = false;
            for (int i = 0; i < n; i++) {
                char c = in.next().charAt(0);

                if (c == 'Y')
                    four = true;
            }

            out.println(four ? "Four" : "Three");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 22740
#include <stdio.h>

int main(void)
{
	int N, K, X, Y;
	int money = 0;
	int i;

	scanf("%d%d%d%d", &N, &K, &X, &Y);

	for (i = 1;i <= N;i++)
	{
		if (i <= K)
		{
			money += X;
		}
		else
		{
			money += Y;
		}
	}

	printf("%d\n", money);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S,T,U;
    cin >> S >> T;
    int A,B;
    cin >> A >> B;

    cin >> U;
    if(S == U){
        A--;
    }else{
        B--;
    }

    cout << A << ' ' << B << endl;

}

Measured memory_bytes: 256