akhauriyash/Code-Regression huggingface dataset:
N, M = [int(_) for _ in input().split()]
mod = 10**9+7


def fact(x):
    res = 1
    for i in range(1, x+1):
        res *= i
        res %= mod
    return res


if N < M:
    N, M = M, N
if N == M:
    ans = 2*fact(N)**2 % mod
elif N == M+1:
    ans = N*fact(M)**2 % mod
else:
    ans = 0
print(ans)


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

int main() {

  int a,b,c;
  cin>>a;
  vector<int> vec(a);
  
  for(int i=0;i<a;i++){
  	cin>>vec.at(i);	
  }
  
  b = *min_element(vec.begin(),vec.end());
  c = *max_element(vec.begin(),vec.end());
  
  cout<<c-b<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++){
		int ans = 0;
		for (int x = 1; x * x + x <= i; x++)
			for (int y = 1; x * x + y * y + x * y + y + x + 1 <= i; y++)
				for (int z = 1; x * x + y * y + z * z + x * (y + z) + y * z <= i; z++)
					if (x * x + y * y + z * z + x * (y + z) + y * z == i){
						ans += 1;
						break;
					}
		cout << ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 3564
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N,x; R(N,x);
    VI AA(N);
    REP(i,N)R(AA[i]);
    sort(ALL(AA));
    LL sum=0;
    REP(i,N){
        sum+=AA[i];
        if(sum>x){
            W(i);
            return 0;
        }
    }
    if(sum==x)W(N);
    else W(N-1);
    return 0;
}


Measured memory_bytes: 764
def count1(s):
    L = len(s)
    abc=[]
    s0 = s[0]
    abc.append(s[0])
    ans1 = ""
    ans2=""
    cnt = 1
    cnt2=0
    a0=0
    for i in range(1, L):
        if s0 == s[i]:
            cnt += 1
        else:
            ans1 = ans1 + str(cnt)
            ans2=ans2+str(a0)
            cnt = 1
            s0=s[i]
            if s[i] in abc:
                a0=abc.index(s[i])
            else:
                abc.append(s[i])
                cnt2+=1
                a0=cnt2

    ans1 = ans1 + str(cnt)
    ans2 = ans2 + str(a0)

    return ans1,ans2


S = input()
T = input()

if len(S)==1:
    print("Yes")
    exit()

Sx,Sy = count1(S)
Tx,Ty = count1(T)

if Sx == Tx and Sy==Ty:
    print("Yes")
else:
    print("No")


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

typedef long double ld;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

#define FOR(i, b, e) for (int i = b; i <= e; i++)
#define FORD(i, b, e) for (int i = b; i >= e; i--)
#define SIZE(x) ((int)(x).size())
#define pb push_back
#define st first
#define nd second
#define all(a) begin(a), end(a)
#define watch(x) cerr << (#x) << " is " << (x) << '\n';

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

    int n, a;
    cin >> n;

    int res = 0;
    int cnt = 0;
    int last;
    cin >> last;
    FOR(i, 2, n) {
        cin >> a;
        if (last >= a) {
            cnt++;
        } else {
            res = max(res, cnt);
            cnt = 0;
        }
        last = a;
    }
    res = max(res, cnt);
    cout << res;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll MAXN = 


ll cA,cB,cC,cost;
ll n,a,b,c,l[10];

ll ans = INF;
void dfs(ll idx) {
    if (idx == n) {
        if (cA && cB && cC) {
            ans = min(ans,abs(cA-a)+abs(cB-b)+abs(cC-c)+cost);

        }
        return; 
    }
    dfs(idx+1);

    if (cA != 0) {
        cost += 10;
    }
    cA += l[idx];
    dfs(idx+1);
    cA -= l[idx];
    if (cA != 0) {
        cost -= 10;
    }

    if (cB != 0) {
        cost += 10;
    }
    cB += l[idx];
    dfs(idx+1);
    cB -= l[idx];
    if (cB != 0) {
        cost -= 10;
    }

    if (cC != 0) {
        cost += 10;
    }
    cC += l[idx];
    dfs(idx+1);
    cC -= l[idx];
    if (cC != 0) {
        cost -= 10;
    }
    
}
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> n >> a >> b >> c;
    REP (i,n) {
        cin >> l[i];
    }

 
    dfs(0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <vector>

using namespace std;
using ll = long long int;

ll N, Q;
vector<vector<ll>> tree;
vector<ll> ctr;
vector<ll> value;

struct entry {
  ll node;
  ll sum;
};

void solve() {
  stack<entry> stk;
  stk.push({1, ctr[1]});

  while (!stk.empty()) {
    entry e = stk.top();
    stk.pop();
    value[e.node] = e.sum;

//    cout << e.node << endl;
//    cout << e.sum << endl;

    for (ll child : tree[e.node]) {
      ll sum = e.sum + ctr[child];

      stk.push({child, sum});
    }
  }
}


int main() {
  cin >> N >> Q;
  tree = vector<vector<ll>>(N + 1);
  ctr = vector<ll>(N + 1, 0);
  value = vector<ll>(N + 1, 0);

  for (int i = 0; i < N-1; i++) {
    ll a, b;
    cin >> a >> b;
    tree[a].push_back(b);
  }

  for (int i = 0; i < Q; i++) {
    ll p, x;
    cin >> p >> x;
    ctr[p] += x;
  }

  solve();

  for (int i = 1; i < N; i++) {
    cout << value[i] << " ";
  }
  cout << value[N] << endl;

  return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  vector<ll> p(n); 
  vector<ll> q(n); 
  vector<ll> r(n); 
  rep(i,n){
    cin>>p[i]>>q[i]>>r[i];
  }

  rep(i,101){
    rep(j,101){
      ll h=0;
      ll hmax=INF;
      bool ok=true;
      rep(k,n){
        if(r[k]==0) chmin(hmax,abs(p[k]-i)+abs(q[k]-j));
        else {
          if(h==0) h=abs(p[k]-i)+abs(q[k]-j)+r[k];
          else if(h!=abs(p[k]-i)+abs(q[k]-j)+r[k]) ok=false;
        }
        if(hmax!=INF && h>hmax) ok=false;
      }
      if(ok && 1<=h) cout << i << " " << j << " " << h << endl; 
    }
  }

}

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

int main(){
    int N, sum=0;
    cin >> N;
    vector<int> a(N+2), ans(N);
    a[0] = 0;
    for(int i=0; i<N; i++){
	cin >> a[i+1];
    }
    a[N+1] = 0;
    
    for(int i=1; i<N+2; i++){
	sum += abs(a[i-1] - a[i]);
    }

    for(int i=1; i<N+2; i++)
	ans[i-1] = sum - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1] - a[i-1]);


    for(int i=0; i<N; i++){
	cout << ans[i] << endl;
    }

}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t k, a, b;
    cin >> k >> a >> b;

    if (b - a <= 2) {
        cout << k + 1 << endl;
        return 0;
    }

    int64_t remains = k, current = 1;
    while (remains > 0) {
        if (remains < 2) {
            current += 1;
            break;
        }

        if (current < a) {
            auto delta = min(remains, a - current);
            remains -= delta;
            current += delta;
            continue;
        }

        auto m = remains / 2;
        remains -= 2 * m;
        current += m * (b - a);
    }

    cout << current << endl;
}

Measured memory_bytes: 256
def resolve():
    N, M = [int(i) for i in input().split()]
    AB = [[] for _ in range(N + 1)]
    AB[0] = [1]
    for _ in range(M):
        A, B = [int(i) for i in input().split()]
        AB[A].append(B)
        AB[B].append(A)
    from collections import deque
    dq = deque([1])
    ans = [-1] * (N + 1)
    while len(dq) > 0:
        p = dq.popleft()
        c = AB[p]
        for cc in c:
            if ans[cc] == -1:
                ans[cc] = p
                dq.append(cc)
    if -1 in ans[2:]:
        print("No")
        print(ans, file=sys.stderr)
    else:
        print("Yes")
        for a in ans[2:]:
            print(a)


resolve()


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


int main()
{
	int n, count = 0;
	int a[101];
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		count++;
	}
	for (int i = 0; i < n; i++){
		cout << a[count - i - 1];
		if (i == n - 1){
			cout << endl;
		}
		else{
			cout << " ";
		}
	}
	return 0;
}

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount

const int INF = (int) 1e15;

int n;
int a[55], b[55];
ll dis[55][55];

void wf(set<int> st) {
    for (int i = 0; i < 55; i++)for (int j = 0; j < 55; j++)dis[i][j] = INF;
    for (int k : st) {
        for (int i = 0; i < 55; i++) {
            dis[i][i % k] = 1;
        }
    }

    for (int k = 0; k < 55; k++)
        for (int i = 0; i < 55; i++)
            for (int j = 0; j < 55; j++) {
                dis[i][j] = min(dis[i][j], dis[i][k] | dis[k][j]);
            }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++)cin >> a[i];
    for (int i = 0; i < n; i++)cin >> b[i];

    bool flg_same = true, flg_zero = true;
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i])flg_same = false;
        if (b[i] != 0)flg_zero = false;
    }

    if (flg_same) {
        cout << 0 << endl;
        return 0;
    }

    if (flg_zero) {
        cout << 2 << endl;
        return 0;
    }

    set<int> st;
    for (int i = 1; i <= 50; i++)st.insert(i);
    ll ans = 0LL;

    wf(st);
    for (int i = 0; i < n; ++i) {
        if (dis[a[i]][b[i]] == INF) {
            cout << -1 << endl;
            return 0;
        }
    }

    for (int k = 50; k >= 1; k--) {
        st.erase(k);
        wf(st);
        for (int i = 0; i < n; i++) {
            if (dis[a[i]][b[i]] == INF) {
                ans |= (1LL << k);
                st.insert(k);
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N, M, R = gets.split.map(&:to_i)
r = gets.split.map(&:to_i).map{ |i| i-=1 }

d = Array.new(N){ Array.new(N,1e9) }

M.times do
  a, b, c = gets.split.map(&:to_i)
  a-=1
  b-=1
  d[a][b] = d[b][a] = c
end

(0...N).each{ |i| d[i][i] = 0 }

N.times do |k|
  N.times do |i|
    N.times do |j|
      v = d[i][k]+d[k][j]
      d[i][j] = v if d[i][j] > v
    end
  end
end

p = r.permutation(R).to_a
ans = 1e9

p.each do |k|
  dist = 0
  (1...R).each do |i|
    dist += d[k[i]][k[i-1]]
  end
  ans = dist if ans > dist
end

p ans

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

int main(){
  int n;
  cin >> n;
  int a,b,c;
  cin >> b >> c;
  int ans =0;
  for(int i=0; i<n-2; i++){
    a = b;
    b = c;
    cin >> c;
    //cout << a << b << c << endl;
    if(a<b&&b<c)ans++;
    if(a>b&&b>c)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    S = str(input())
    T = str(input())
    
    ans = len(T)
    for i in range(len(S)-len(T)+1):
        count = 0
        for j in range(len(T)):
            if S[i+j] != T[j]:
                count += 1
        if count <= ans:
            ans = count
    
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9084
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            int[] arr = new int[3];
            for (int j = 0; j < 3; j++) {
                arr[j] = sc.nextInt();
            }
            Arrays.sort(arr);
            if (Math.pow(arr[0], 2) + Math.pow(arr[1], 2) == Math.pow(arr[2], 2)) {
                sb.append("YES");
            } else {
                sb.append("NO");
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
}



Measured memory_bytes: 33400
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

struct PrimeNumber {
    const ll MOD = 1000000007;  // 10**9 + 7
    ll add(ll a, ll b)
    {
        return (a + b) % MOD;
    }
    ll sub(ll a, ll b)
    {
        return (a + MOD - b) % MOD;
    }
    ll mul(ll a, ll b)
    {
        return ((a % MOD) * (b % MOD)) % MOD;
    }
    ll power(ll x, ll y)
    {
        if (y == 0) {
            return 1;
        }
        else if (y == 1) {
            return x % MOD;
        }
        else if (y % 2 == 0) {
            ll t = this->power(x, y / 2);
            return this->mul(t, t);
        }
        else {
            ll t = this->power(x, y / 2);
            return this->mul(this->mul(t, t), x);
        }
    }
    ll div(ll a, ll b)
    {
        return this->mul(a, this->power(b, MOD - 2));
    }

    #define FACTORIAL_MAX 10000
    ll memo_factorial[FACTORIAL_MAX+1];
    void init_factorial(void)
    {
        this->memo_factorial[0] = 1;
        for (ll i = 1; i <= FACTORIAL_MAX; ++i) {
            this->memo_factorial[i] = this->mul(i, this->memo_factorial[i-1]);
        }
    }
    ll factorial(ll n)
    {
        return this->memo_factorial[n];
    }
    ll combination(ll n, ll r)
    {
        ll ret = this->factorial(n);
        ret = this->div(ret, this->factorial(r));
        ret = this->div(ret, this->factorial(n-r));
        return ret;
    }
};


void solve()
{
    PrimeNumber prime;
    prime.init_factorial();

    ll N,K;
    cin >> N >> K;
    for2(i,1,K+1) {
        ll ans = 0;
        if (i == 1) {
            ans = N-K+1;
        }
        else if (i == 2) {
            if (N-K >= 1) {
                ans = prime.combination(N-K-1 + 2, 2);
                ans = prime.mul(ans, prime.combination(K-2 + 1, 1));
            } else {
                ans = 0;
            }
        }
        else {
            if (N-K >= i-1) {
                ans = prime.combination(N-K-(i-1) + i, i);
                ans = prime.mul(ans, prime.combination(K-i + (i-1), i-1));
            } else {
                ans = 0;
            }
        }
        cout << ans << endl;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    do {
        solve();
    } while (DEBUG);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    cout << pow(n, 3.0) << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=10e9+7;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}

int main(void){
    string N;
    cin>>N;
    if(N.at(0)==N.at(1)&&N.at(1)==N.at(2)) cout<<"Yes"<<endl;
    else if(N.at(1)==N.at(2)&&N.at(2)==N.at(3)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
            
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;

int a[100005];
bool memo[100005];

int bot(int u,int c){
  if(memo[u]) return 0;
  memo[u]=1;
  int to=a[u];
  c++;
  if(to==1)
  return c;
  else
  return bot(to,c);
}

int main(){
  int n; cin>>n;
  rep(i,n){
    int A; cin>>A;
    A--;
    a[i]=A;
  }
  int c=0;
  int ans=bot(0,c);
  if(ans==0)
  cout<<-1<<endl;
  else
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll N,M;
  cin >> N >> M;
  cout << abs((N-2)*(M-2)) << endl;
  return 0;
}


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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var allStr = "abcdefghijklmnopqrstuvwxyz";
            var r = Console.ReadLine();
            foreach (var c in r)
            {
                var index = allStr.IndexOf(c);
                if (index >= 0)
                {
                    allStr = allStr.Remove(index,1);
                }
            }
            if (string.IsNullOrEmpty(allStr))
            {
                Console.WriteLine("None");
            }
            else
            {
                Console.WriteLine(allStr.FirstOrDefault());
            }
        }
        

    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1}; 
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++) 
#define LB lower_bound
#define UP upper_bound
#define INF 999999999999
const double PI = acos(-1.0);
int N,K;
int D,A;
int a[101];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> N >> K;
    rep1(i,0,K){
        cin >> D;
        rep1(j,0,D){
            int x;
            cin >> x;
            a[x]++; 
        }
    }
    int ans = 0;
    rep2(i,1,N) ans += !a[i];
    cout << ans;
    return 0;   
}



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

using namespace std;

int main()
{
    int n, k, pos[100];
    cin >> n >> k;
    int sum=0;
    for (int i = 0; i < n; i++)
    {
        cin >> pos[i];
        if (pos[i] < abs(pos[i]-k))
        {
            sum += pos[i]*2;
        } else
        {
            sum += abs(pos[i]-k)*2;
        }
    }
    cout << sum << endl;
    return 0;
}


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

int main(void){
    int N;
    cin >> N;
    int T, X, Y;
    int t = 0, x = 0, y = 0;
    string ans = "Yes";

    for(int i =0 ;i < N ; i++){
        cin >> T >> X >> Y;
        if ((abs(X - x) + abs(Y - y)) > (T-t) ||
        (abs(X - x) + abs(Y - y))%2 != (T-t)%2  ) {
             ans = "No";
             break;
             }
        t = T; x = X; y = Y;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
white = 0
black = 0
for i in range(n):
    if s[i] == ".":
        white += 1
ans = white + black
for j in range(n):
    if s[j] == ".":
        white -= 1
    else:
        black += 1
    if white + black < ans:
        ans = white + black
print(ans)

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

using namespace std;

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

#define N 100010
#define M 200010
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n;
	string s;
	map<string, int> cnt;
	
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s;
		cnt[s]++;
	}
	
	cout << "AC x " << cnt["AC"] << endl;
	cout << "WA x " << cnt["WA"] << endl;
	cout << "TLE x " << cnt["TLE"] << endl;
	cout << "RE x " << cnt["RE"] << endl;
	
	return 0;
}

Measured memory_bytes: 3660
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define INF 2147483647
#define full(c) c.begin(), c.end()
#define PRIME 1000000007
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	int r;
	cin >> r;
	if (r < 1200) cout << "ABC" << endl;
	else if (r < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	return 0;
}


Measured memory_bytes: 256
import bisect
A,B,Q = map(int,input().split())
INF = 10**18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
q = [int(input()) for i in range(Q)]
for x in q:
    b,d = bisect.bisect_left(s,x),bisect.bisect_left(t,x)
    res  = INF
    for S in [s[b-1],s[b]]:
        for T in [t[d-1],t[d]]:
            d1,d2 = abs(S-x)+abs(T-S),abs(T-x)+abs(S-T)
            res = min(res,d1,d2)
    print(res)

Measured memory_bytes: 94512
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll N = 2e5+3;
int n,m,k;
ll fact[N];
ll modpow(ll b, ll e, ll m){
	ll r = 1;
	while(e){
		if(e&1) r = (r*b)%m;
		b = (b*b)%m;
		e >>= 1;
	}
	return r;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> m >> k;
	fact[0] = 1;
	for(int i=1;i<N;i++) fact[i] = (fact[i-1]*i)%MOD;
	ll ans = 0;
	for(int i=n-k;i<=n;i++){
		ll permut = (fact[n-1]*modpow(fact[i-1],MOD-2,MOD))%MOD;
		permut = (permut*modpow(fact[n-i],MOD-2,MOD))%MOD;
		ll clr = (m*modpow(m-1,i-1,MOD))%MOD;
		ans = (ans+(clr*permut))%MOD;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 5212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5002;
int n,A,B,a[N],i,j;
ll f[N][N],ans=1e18,tmp;
inline void Min(ll &x,ll y){if(y<x)x=y;}
int main(){
	scanf("%d%d%d",&n,&A,&B);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	memset(f,63,sizeof(f));
	f[0][0]=0;
	for (i=1;i<=n;i++)
		for (j=0;j<=n;j++){
			tmp=f[i-1][j];
			if (j<a[i]) Min(f[i][a[i]],tmp),Min(f[i][j],tmp+A);
			else Min(f[i][j],tmp+B);
		}
	for (i=1;i<=n;i++) Min(ans,f[n][i]);
	printf("%lld",ans);
}

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

#define MAXN (1<<20)


int spf[MAXN], set_gcd, pairwise = 1;
unordered_set<int> factors;

void init_spf(int n) {
    for(int i = 2; i <= n; ++i) {
        if(!spf[i]) {
            for (int j = i; j <= n; j += i) {
                if (!spf[j])spf[j] = i;
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    init_spf(MAXN-1);
    vector<int> a(n);
    for (int& i : a) cin >> i;
    set_gcd = a[0];
    for (int i : a) {
        set_gcd = __gcd(set_gcd, i);
        // cout << i << endl;
        vector<int> new_factors;
        while (i > 1) {
            int f = spf[i];
            i /= f;
            // cout << spf[i] << endl;
            if (factors.count(f)) pairwise = 0;
            new_factors.push_back(f);
        }
        for (int f: new_factors) factors.insert(f);
    }

    if (pairwise) {
        cout << "pairwise coprime";
    } else if(set_gcd == 1) {
        cout << "setwise coprime";
    } else {
        cout << "not coprime";
    }
}

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

using namespace std;
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PI; 
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;
typedef pair<double,double> PD;

#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())

#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007

#define MAXSIZE 100010

int n;
int dp[MAXSIZE][3];

int main(){
	
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	
	REP(j,3)
		cin>>dp[1][j];
		
	FOR(i,2,n){
		REP(j,3){
			cin>>dp[i][j];
			dp[i][j]+=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
		}
	}
	
	int odp=0;
	REP(j,3)
		odp=max(odp,dp[n][j]);
		
	cout<<odp;
	return 0;
}


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

int main() {
  ll N;
  cin >> N;
  ll q = sqrt(N);
  for (ll i = q; i > 0; i--) {
    if (N%i == 0) {
      ll a = to_string(i).size();
      ll b = to_string(N/i).size();
      cout << max(a,b) << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	var n, cnt, d int
	fmt.Scanf("%d %d", &n, &d)
	sc := bufio.NewScanner(os.Stdin)
	d = d * d
	for i := 0; i < n; i++ {
		sc.Scan()
		tmp := strings.Split(sc.Text(), " ")
		x, _ := strconv.Atoi(tmp[0])
		y, _ := strconv.Atoi(tmp[1])
		if x*x+y*y <= d {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 6300
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n;i>s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

ll p[100001] = {};
int main() {
	string s; cin >> s;

	ll L, R;
	bool LR = false;
	ll cnt = 0;
	rep(i, 0, s.size()) {
		if (s[i] == 'R' && s[i+1] == 'L') {
			LR = true;
			R = i;
			L = i + 1;
			cnt = 0;
			continue;
		}
		if (LR && s[i] == 'R') {
			LR = false;
			continue;
		}

		if (LR && s[i] == 'L') {
			if (cnt & 1) {
				p[R]++;
			}
			else {
				p[L]++;
			}
			cnt++;
		}
	}

	//
	L = 0, R = 0;
	LR = false;
	cnt = 0;
	rep_re(i, 0, s.size()-1) {
		if (LR && s[i] == 'R') {
			if (cnt & 1) {
				p[L]++;
			}
			else {
				p[R]++;
			}
			cnt++;
			continue;
		}

		if (s[i-1] == 'R' && s[i] == 'L') {
			LR = true;
			R = i-1;
			L = i;
			cnt = 0;
			continue;
		}
		if (LR && s[i] == 'L') {
			LR = false;
			continue;
		}
	}

	rep(i, 0, s.size()) {
		cout << p[i];
		if (i != s.size() - 1) {
			cout << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
                #include <vector>
                using namespace std;
                using Graph = vector<vector<int>>;
                
                // 深さ優先探索
                vector<bool> seen;
                void dfs(const Graph &G, int v, int counter, vector<int> &C, vector<int> &answer) {
                    seen[v] = true; // v を訪問済にする
                    
                    counter +=  C.at(v);
                    answer.at(v) = counter; 
                    //cout<< v << endl; 
                
                    // v から行ける各頂点 next_v について
                    for (auto next_v : G[v]) { 
                        if (seen[next_v]) continue; // next_v が探索済だったらスルー
                        dfs(G, next_v, counter, C, answer ); // 再帰的に探索
                    }
                }
                
                int main() {
                    // 頂点数と辺数
                    int N, M, Q; cin >> N;
                    M= N-1; 
                    cin >> Q; 
                
                    // グラフ入力受取 (ここでは無向グラフを想定)
                    Graph G(N);
                    for (int i = 0; i < M; ++i) {
                        int a, b;
                        cin >> a >> b;
                        G[a-1].push_back(b-1);
                        G[b-1].push_back(a-1);
                    }
                    
                    //
                    
                    vector<int> C(N); 
                    for (int i = 0; i < Q; ++i) {
                        int p, x; 
                        cin >> p >> x; 
                        C.at(p-1)+= x; 
                    }
                
                    // 頂点 0 をスタートとした探索
                    
                    vector<int> answer(N,0);
  
                    
                    seen.assign(N, false); // 全頂点を「未訪問」に初期化
                    dfs(G, 0, 0, C, answer);
                    
                    for(int i=0; i<N; i++){
                        cout<< answer.at(i) <<" "; 
                    }
                    
                }

Measured memory_bytes: 30592
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
    	Scanner sc = new Scanner(System.in);
    	String s = sc.nextLine();
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < s.length(); i++) {
    		sb.append(s.charAt(i));
    		if (i == 3) {
    			sb.append(" ");
    		}
    	}
    	System.out.println(sb.toString());
    }
}


Measured memory_bytes: 9680
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN=200005;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;

int n;
int L[MAXN],R[MAXN];
int dp[MAXN];
struct node
{
	int X,V,id;
	node(){};
	node(int _X,int _V):X(_X),V(_V){};
}nd[MAXN+5];

bool cmp1(const node &a,const node &b){return a.X<b.X;}
bool cmp2(const node &a,const node &b){return a.V<b.V;}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d %d",&nd[i].X,&nd[i].V);
	sort(nd+1,nd+1+n,cmp2);
	for(int i=1;i<=n;i++)
		nd[i].id=i;
	sort(nd+1,nd+1+n,cmp1);
	int mx=-1,mn=INF;
	for(int i=1;i<=n;i++){
		mx=max(mx,nd[i].id);
		R[i]=mx;
	}
	for(int i=n;i>=1;i--){
		mn=min(mn,nd[i].id);
		L[i]=mn;
	}
	int pos=0,sum=1;
	dp[0]=1;
	for(int i=1;i<=n;i++){
		while(R[pos]<L[i]-1)
			sum=((1ll*sum-1ll*dp[pos])%MOD+MOD)%MOD,pos++;
		dp[i]=sum;
		sum=(1ll*dp[i]+1ll*sum)%MOD;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(R[i]>=n)
			ans=(1ll*ans+1ll*dp[i])%MOD;
	printf("%d\n",ans);
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	int n;
	cin>>n;
	ll ans = 0ll;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j)
		{
			for(int k=1;k<=n;++k)
			{
				ans = ans + __gcd(__gcd(i,j),k);
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct node
{
    ll x,y;
    int id;
}a[100005],b[100005];
bool cmp1(node p1,node p2)
{
    return p1.x-p2.y>p2.x-p1.y;
}
bool cmp2(node p1,node p2)
{
    return p1.y-p2.x>p2.y-p1.x;
}
bool vis[100005];
int main()
{
    int n;
    ll ans1=0,ans2=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld%lld",&a[i].x,&a[i].y),a[i].id=i,b[i]=a[i];
    sort(a+1,a+1+n,cmp1);
    sort(b+1,b+1+n,cmp2);
    int i=1,j=1;
    bool flag=true;
    while(n--)
    {
        if(flag)
        {
            while(vis[a[i].id]) i++;
            ans1+=a[i].x;
            vis[a[i].id]=true;
            i++;
        }
        else
        {
            while(vis[b[j].id]) j++;
            ans2+=b[j].y;
            vis[b[j].id]=true;
            j++;
        }
        flag=!flag;
    }
    printf("%lld\n",ans1-ans2);
}


Measured memory_bytes: 4992
// Problem : A - Blackjack
// Contest : AtCoder Beginner Contest 147
// URL : https://atcoder.jp/contests/abc147/tasks/abc147_a
// Memory Limit : 1024,000000 MB 
// Time Limit : 2000,000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

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

  cout.precision(16);
  cout << fixed;
  
  int a;
  int b;
  int c;
  cin >> a >> b >> c;
  
  if (a + b + c >= 22) {
    cout << "bust";
  } else {
    cout << "win";
  }
}


Measured memory_bytes: 256
n=int(input())
V=[]
for i in range(n):
    temp=input().split( )
    l=len(temp)
    v=[]
    for j in range(l):
        v.append(int(temp[j]))
    V.append(v)
A=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
    k=V[i][1]
    if k>0:
        for j in range(k):
            A[V[i][0]-1][V[i][j+2]-1]=1
for i in range(n):
    print(*A[i])



Measured memory_bytes: 6392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    int n, m; cin >> n;
    map<string, int> ma;
    string tmp;
    rep(i, n) cin >> tmp, ma[tmp]++;
    cin >> m;
    rep(i, m) cin >> tmp, ma[tmp]--;
    int ans = 0;
    for(auto x : ma) chmax(ans, x.second);
    cout << ans << endl;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>> &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T>> &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }

int main(){
    string s;
    cin >> s;
    cout << s[0] << sz(s)-2 << s[sz(s)-1] << endl;
    return 0;
}



Measured memory_bytes: 3560
<>=~$";$M=$';
@xyz=map[split],<>;
for(0..7){
	$x=(-1)**($_>>2&1);
	$y=(-1)**($_>>1&1);
	$z=(-1)**($_>>0&1);
	$p=0;
	$p+=$$_[0]*$x+$$_[1]*$y+$$_[2]*$z for(sort{$$b[0]*$x+$$b[1]*$y+$$b[2]*$z<=>$$a[0]*$x+$$a[1]*$y+$$a[2]*$z}@xyz)[0..$M-1];
	$q=$p if $p>$q
}
print$q+0


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

using namespace std;

#define int long long

int dp[105][105][405];

int32_t main()
{
        int n,w;
        cin>>n>>w;

        vector < int > a(n+1),val(n+1);
        for(int i=1;i<=n;i++)
        {
                cin>>a[i]>>val[i];
        }

        int x=a[1];
        int ans=0;
        for(int i=1;i<=n;i++)
        {
                for(int j=1;j<=n;j++)
                {
                        for(int k=0;k<=400;k++)
                        {
                                dp[i][j][k]=dp[i-1][j][k];
                                
                                int me=a[i]-a[1];
                                if(me<=k)
                                        dp[i][j][k]=max(dp[i][j][k],val[i]+dp[i-1][j-1][k-me]);
                                
                                int temp=j*a[1] + k;
                                if(temp <=w)
                                        ans=max(ans,dp[i][j][k]);
                                
                        }
                }
        }

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



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

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

		int N = scan.nextInt();
		int K = scan.nextInt();
		int[] p = new int[N];
		int ans = 0;

		for(int i = 0;i < N;i++) {
			p[i] = scan.nextInt();
		}

		Arrays.sort(p);

		for(int i = 0;i < K;i++) {
			ans += p[i];
		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 30068
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {

	int n;
	cin >> n;
	int w[n],allsum=0;
	REP(i,n) w[i]=0;
	REP(i,n) {
		cin >> w[i];
		allsum += w[i];
	}
//	REP(i,n) errln(w[i]);

	int ret = 1000000,minsum = 0;
	REP(i,n){
		minsum += w[i];
		ret = min(ret, abs((allsum-minsum)-minsum));
	}
	println(ret);

	return 0;
}


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

typedef long long ll;
const int MAX_N = 10;

int main() {
  int N, M, k[MAX_N], s[MAX_N][MAX_N], p[MAX_N];

  std::cin >> N >> M;
  for(int i = 0; i < M; ++i) {
    std::cin >> k[i];
    for(int j = 0; j < k[i]; ++j) {
      std::cin >> s[i][j];
      --s[i][j];
    }
  }
  for(int i = 0; i < M; ++i) {
    std::cin >> p[i];
  }

  int ans = 0;
  for(int b = 0; b < (1 << N); ++b) {
    bool flg = true;
    for(int i = 0; i < M; ++i) {
      int kb = 0;
      for(int j = 0; j < k[i]; ++j) {
        kb += (1 << s[i][j]);
      }

      int sub = b & kb, cnt = 0;
      for(int j = 0; j < N; ++j) {
        cnt += 1 & (sub >> j);
      }

      if(cnt % 2 != p[i]) {
        flg = false;
        break;
      }
    }
    if(flg) ++ans;
  }

  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

vector<vector<int>> ab;
int countt;
vector<int> color;
int nn;

void dfs(int n)
{
	//cout<<n<<endl;
	color[n]=1;
	//rep(i,nn){if(i)cout<<" ";cout<<color[i];}cout<<endl;
	rep(i,ab[n].size())
	{
		if(color[ab[n][i]]==0)
		{
			dfs(ab[n][i]);
		}
	}

	bool foo=true;
	rep(i,color.size())
	{
		if(color[i]==0)foo=false;
	}
	if(foo)countt+=1;
	color[n] = 0;
	return ;
}


int main()
{
	int m;cin>>nn>>m;

	rep(i,nn)
	{
		ab.push_back(vector<int>());
	}
	rep(i,m)
	{
		int foo,fooo;cin >> foo >> fooo;
		ab[foo-1].push_back(fooo-1);
		ab[fooo-1].push_back(foo-1);
	}
	countt=0;
	rep(i,nn)color.push_back(0);

	dfs(0);
	cout << countt << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	static String reverce(String str) {
		String strr="";
		for(int i=str.length()-1;i>=0;i--) {
			strr+=str.charAt(i);
		}
		return strr;
	}
	public static void main(String[] args) {
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
			System.out.println((a-b)%c);
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e6+10;
int fa[N],siz[N];
inline int find(int x)
{
	if(x == fa[x])
		return x;
	else
		return fa[x] = find(fa[x]);
}
inline void merge(int x,int y)
{
	int fx = find(x),fy = find(y);
	if(fx == fy) return ;
	else if(siz[fx] < siz[fy]) fa[fx] = fy,siz[fy] += siz[fx];
	else fa[fy] = fx,siz[fx] += siz[fy];
}
int main()
{
	int n,m;
	cin >> n >> m;
	for(int i=1; i<=n; i++)
		fa[i] = i, siz[i] = 1;
	for(int i=1; i<=m; i++)
	{
		int x,y;
		cin >> x >> y;
		merge(x,y);
	}
	int ans = 0;
	for(int i=1; i<=n; i++)
		ans = max(ans, siz[i]);
	cout << ans << '\n';
}

Measured memory_bytes: 5164
#include<bits/stdc++.h>
using namespace std;
const int N=4e5+5;
const int inf=1e9;
inline int read(){
	register int x=0;
	register char ch=getchar();
	while(ch<'0'||ch>'9')	ch=getchar();
	while(ch>='0'&&ch<='9')	x=x*10+(ch^48),ch=getchar();
	return x;
}
int n,s,nx,ny,ans,now=1,a[N],b[N],v[N],w[N],fx[N],fy[N],cr[N],nex[N],dis[N],head[N];
void addedges(int x,int y,int z){
	nex[++now]=head[x],v[now]=y;
	head[x]=now,w[now]=z;
}
void add(int x,int y){
	addedges(x,y,1);
	addedges(y,x,0);
}
queue<int>que;
bool bfs(){
	for(int i=0;i<=s;i++)	cr[i]=head[i],dis[i]=0;
	que.push(s),dis[s]=1;
	while(!que.empty()){
		int x=que.front();	que.pop();
		for(int i=head[x];i;i=nex[i])
			if(w[i]&&!dis[v[i]]){
				dis[v[i]]=dis[x]+1;
				que.push(v[i]);
			}
	}
	return dis[0];
}
int dfs(int x,int f){
	int ans=0;
	if(!x||!f)	return f;
	for(int &i=cr[x];i;i=nex[i])
		if(w[i]&&dis[v[i]]==dis[x]+1){
			int d=dfs(v[i],min(w[i],f));
			if(!d)	continue;
			ans+=d,w[i]-=d;
			w[i^1]+=d,f-=d;
			if(!f)	break;
		}
	if(!ans)	dis[x]=-1;
	return ans;
}
int main(){
	ans=n=read();
	for(int i=1;i<=n;i++)	a[i]=read()+1;
	for(int i=1;i<=n;i++)	b[i]=read()+1;
	for(int i=1,k;i<=n;i++){
		if(!fx[i]){
			++nx,k=i;
			while(!fx[k])	fx[k]=nx,k=a[k];
		}
		if(!fy[i]){
			++ny,k=i;
			while(!fy[k])	fy[k]=ny,k=b[k];
		}
	}
	s=nx+ny+1;
	for(int i=1;i<=n;i++){
		if(a[i]==i&&b[i]==i)	--ans;
		else	if(a[i]!=i&&b[i]==i)	add(s,fx[i]);
		else	if(a[i]==i&&b[i]!=i)	add(fy[i]+nx,0);
		else	if(a[i]!=i&&b[i]!=i&&a[i]!=b[i])	add(fy[i]+nx,fx[i]);
		else	add(fx[i],fy[i]+nx),add(fy[i]+nx,fx[i]);
	}
	while(bfs())
	while(int d=dfs(s,inf))	ans-=d;
	printf("%d\n",ans);
}


Measured memory_bytes: 15232