akhauriyash/Code-Regression huggingface dataset:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}


n, m = map(int,input().split())
uf = UnionFind(n)
for i in range(m):
    x,y,z = map(int,input().split())
    uf.union(x-1, y-1)
print(uf.group_count())

Measured memory_bytes: 7856
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    int v[n][3];
    for(long long int i=0;i<n;i++)
    {
        long long int a,b,c;
        cin>>a>>b>>c;
        v[i][0]=a;
        v[i][1]=b;
        v[i][2]=c;
    }
    long long int dp[n][3];
    dp[0][0]=v[0][0];
    dp[0][1]=v[0][1];
    dp[0][2]=v[0][2];
    for(long long int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+v[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+v[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+v[i][2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <unordered_map>

using namespace std;

struct uftree {
    int *par, *rank, *size;
    uftree(int N) {
        par  = new int[(size_t)N];
        rank = new int[(size_t)N];
        size = new int[(size_t)N];
        for (int i = 0; i < N; i++) {
            par[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    int root(int x) {
        if (par[x] == x)
            return x;
        else {
            int r = root(par[x]);
            size[x] = size[par[x]];
            return par[x] = r;
        }
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y])
            par[y] = x;
        else {
            par[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
        size[x] += size[y];
        size[y] = size[x];
    }
    int getsize(int x) {
        root(x);
        return size[x];
    }
    bool same(int x, int y) { return root(x) == root(y); }
};

int main() {
    int n, max = 100010;
    cin >> n;
    uftree uft(2*max + 1);
    for (int i=0; i<n; i++) {
        int x, y;
        cin >> x >> y;
        uft.unite(x, y+max);
    }
    unordered_map<int, long> xm, ym;
    for (int i=1; i<=2*max; i++) {
        int r = uft.root(i);
        if (i <= max)
            xm[r]++;
        else 
            ym[r]++;
    }
    long cnt = 0;
    for (auto xmi:xm) 
        cnt += xmi.second * ym[xmi.first];
    cout << cnt - n << '\n';
    return 0;
}


Measured memory_bytes: 14920
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <unordered_set>
#include <complex>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
// typedef complex<double> C;

const int MOD = 1e9 + 7;
const int _MOD = 1000000009;
const ll INF = LLONG_MAX / 2;
double EPS = 1e-10;

int main() {
	int N, M; cin >> N >> M;
	vector<vector<int> > dp(2, vector<int>(N * 2 + 1));
	for (int x = 0; x <= N * 2; x += 2) dp[!x][x] = 1;
	rep(t, M * 2) {
		vector<vector<int> > _dp(2, vector<int>(N * 2 + 1));
		rep(z, 2) for (int x = 0; x <= N * 2; x++) {
			if (x - 1 >= 0) _dp[z][x - 1] = (_dp[z][x - 1] + dp[z][x]) % MOD;
			if (x + 1 <= N * 2) _dp[z][x + 1] = (_dp[z][x + 1] + dp[z][x]) % MOD;
		}
		dp = _dp;
		dp[1][0] = (dp[1][0] + dp[0][0]) % MOD;
		dp[1][1] = (dp[1][1] + dp[0][1]) % MOD;
		dp[0][0] = dp[0][1] = 0;
	}
	int ans = 0;
	for (int x = 0; x <= N * 2; x++) ans = (ans + dp[1][x]) % MOD;
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
using ll = long long;
ll MOD = 1e9 + 7;

int main() {
  ll N, M;
  cin >> N >> M;
  ll bigger = max(N, M);
  ll smaller = min(N, M);
  ll diff = bigger - smaller;
  if(diff > 1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = diff == 0 ? 2 : 1;
  for(int i = bigger; i > 0; --i) {
    ans = (ans * i) % MOD;
  }
  for(int i = smaller; i > 0; --i) {
    ans = (ans * i) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int bit_table[1024][10];
int table[1024];
int sum_table[1024];

void MakeTable()
{
        int i = 0, j = 0, tmp;
        for ( i = 0 ; i < 1024 ; i++ )
        {
                tmp = i;
                for ( j = 9 ; j > -1; j-- )
                {
                        bit_table[i][9-j] = tmp % 2;
                        table[i] = table[i] + tmp % 2;
                        sum_table[i] = (9-j) * bit_table[i][9-j] + sum_table[i];
                        tmp = tmp >> 1;
                }
        }
}

void PrintBitTable()
{
        int i = 0;
        for ( i = 0 ; i < 1024 ; i++ )
        {
                fprintf( stdout, "%4d = %d { %d %d %d %d %d %d %d %d %d %d } = %d\n", i, table[i],
                        bit_table[i][0], bit_table[i][1], bit_table[i][2], bit_table[i][3],
                        bit_table[i][4], bit_table[i][5], bit_table[i][6], bit_table[i][7],
                        bit_table[i][8], bit_table[i][9], sum_table[i] );
        }
}

int Check( int n, int s )
{
        int i = 0, ans = 0;
        for ( i = 0 ; i < 1024 ; i++ )
        {
                if ( table[i] == n && sum_table[i] == s )
                {
                        ans = ans + 1;
                }
        }
        return ans;
}


int main()
{
        int n, s, ans;
        MakeTable();
        //PrintBitTable();
        while ( 1 )
        {
                scanf( "%d %d", &n, &s );
                if ( n == 0 && s == 0 )
                {
                        break;
                }
                ans = Check( n, s );
                fprintf( stdout, "%d\n", ans );
        }
        return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  string S, T;
  cin >> S >> T;
  int Sn = S.size();
  int Tn = T.size();

  if (Sn < Tn) 
  {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  string ans = S;
  bool flg0 = false;
  for (int i = Sn - Tn; i >= 0; i--)
  {
    bool flg1 = true;
    if (!flg0)
    {
      for (int j = i; j < i + Tn; j++)
      {
        if (S.at(j) != '?' && S.at(j) != T.at(j - i))
        {
          flg1 = false;
          break;
        }
      }
    }
    else flg1 = false;

    if (flg1)
    {
      for (int k = i; k < i + Tn; k++)
      {
        ans.at(k) = T.at(k - i);
      }
      flg0 = true;
    }
    else
    {
      for (int k = i; k < i + Tn; k++)
      {
        if (ans.at(k) == '?') ans.at(k) = 'a';
      }
    }
    
  }
  
  if (!flg0) ans = "UNRESTORABLE";

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
template<class T=ll> 
T in(){T x;cin>>x;return (x);}
template<class T> 
void print(T &x){cout<<x<<"\n";}
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cerr << #x"="<< (x) << "\n"
#define dbgv(x) cerr<<#x<<"\n";reps(y,x){cerr<<y<<" ";}cerr<<"\n"

int main(){
  ll n=in(),total=0;
  vector<ll> a(n);  
  rep(i,n){
    scanf("%lld",&a[i]);
    total+=a[i];
  }
  ll snuke=0,ans=INF;
  rep(i,n-1){
    snuke+=a[i];
    ans=min(ans,abs(2*snuke-total));
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    double r;
    cin >> r;
    cout << r * 2 * PI << endl;
}

Measured memory_bytes: 3804
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

const int N = 410;
typedef long long LL;

int n;
LL a[N];
LL dp[N][N];  //区间dp，dp[i][j] 表示合并区间[i,j]的最小花费

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    cin>>n;
    for(int i = 1; i<=n; i++){
        cin>>a[i];
        a[i] += a[i-1];
    }
    
    
    for(int len = 2; len<=n; len++){
        for(int i = 1; i+len-1<=n; i++){
            int l = i, r = l+len-1;
            dp[l][r] = 1e14;
            for(int k = l; k<r; k++)
                dp[l][r] = min(dp[l][r],dp[l][k]+dp[k+1][r]+a[r]-a[l-1]);
        }
    }
    cout<<dp[1][n];
    
    return 0;
}

Measured memory_bytes: 4400
/**

  @@@@@@@  @@@@  @@@@  @@@@  @@@@  @ 
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @@@@  @@@@  @@@@  @  @  @

**/
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define str string
#define pi pair
#define tup tuple
#define vec vector
#define temp template
#define tn typename

#define ff first
#define ss second
#define SZ(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rsz resize
#define ins insert
#define fr front 
#define bc back
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk make_pair

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++) 
#define ROF(i, a, b) for (ll i = (a); i >= (b); i--)
#define trav(a, x) for (auto &a : x)
#define popcount __builtin_popcount
#define ctz __builtin_ctz
#define clz __builtin_clz
#define gcd __gcd

// DEBUG
#define ts to_string
temp<tn A, tn B> str ts(pi<A, B> p);
temp<tn A, tn B, tn C> str ts(tup<A, B, C> p);
str ts(const str& s) { return '"' + s + '"'; }
str ts(const char* s) { return ts((str) s); }
str ts(bool b) { return (b ? "true" : "false"); }
str ts(vec<bool> v) { bool f = true; str res = "{";
FOR(i, 0, static_cast<ll>(v.size()) - 1) 
{ if (!f) res += ", "; res += ts(v[i]);
f = false; } res += "}"; return res; }
temp<size_t N> str ts(bitset<N> v) { str res = "";
trav(a, v) { res += (char) ('0' + a); } return res; }
temp<tn A> str ts(A v) { bool f = true; str res = "{";
trav(x, v) { if (!f) res += ", "; res += ts(x);
f = false; } res += "}"; return res; }
temp<tn A, tn B> str ts(pi<A, B> p) { 
  return "(" + ts(p.ff) + ", " + ts(p.ss) + ")"; }
temp<tn A, tn B, tn C> str ts(tup<A, B, C> t) {
  return "(" + ts(get<0>(t)) + ", " + ts(get<1>(t)) + ", " + ts(get<2>(t)) + ")"; }
void DBG() { cerr << endl; }
temp<tn H, tn... T> void DBG(H h, T... t) { cerr << " " << ts(h); DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", DBG(__VA_ARGS__);

// INPUT AND OUTPUT
temp<tn T> void re(T& x) { cin >> x; };
temp<tn H, tn... T> void re(H& h, T&... t) { re(h); re(t...); }
temp<tn T> void pr(T x) { cout << x; };
temp<tn H, tn... T> void pr(H h, T... t) { pr(h); pr(t...); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  str s;
  re(s);
  FOR(i, 0, SZ(s) - 1) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  pr(s, '\n');
  return 0;
}

Measured memory_bytes: 3944
//
//AtCoder Beginner Contest 141
//B - Tap Dance
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    string s;
    cin >> s;

    string ans = "Yes";

    REP(i, s.size()){
        if ((i+1)%2==0){
            if (s[i] == 'R') {
                ans="No";
                break;
            }
        }else{
            if (s[i] == 'L') {
                ans="No";
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import heapq


def jd(x, y, z, i):
    t = 0
    if i & 4:
        t += x
    else:
        t -= x
    if i & 2:
        t += y
    else:
        t -= y
    if i & 1:
        t += z
    else:
        t -= z
    return t


n, m = map(int, input().split())
c = []
for i in range(n):
    x, y, z = map(int, input().split())
    c.append((x, y, z))


mv = -float('inf')
for i in range(8):
    s = []
    for j in range(n):
        sj = jd(c[j][0], c[j][1], c[j][2], i)
        s.append((sj, c[j]))

    s.sort(reverse=True)
    value = sum([abs(sum([cn[1][k] for cn in s[:m]])) for k in range(3)])
    mv = max(mv, value)
print(mv)


Measured memory_bytes: 3316
x = 1
y = 1
while not(x == 0 and y == 0):
    x, y = map(int, input().split())
    if x <= y and not(x ==0 and y == 0):
        print(x, y)
    elif y <= x and not(x ==0 and y == 0):
        print(y, x)

Measured memory_bytes: 7464
N, M = map(int, input().split())
Q_n = [0] * N
C = [0] * N

Ans = 0
Pen = 0
for i in range(M):
    p, S = input().split()
    p = int(p)-1
    if (S == 'AC') and (Q_n[p] == 0):
        Q_n[p] = 1
        Ans += 1
        Pen += C[p]
    elif (S == 'WA'):
        C[p] += 1
        
print(Ans, Pen)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int> a(3);
    cin >> a;
    sort(a.begin(), a.end());
    cout << a[0] * a[1] / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int dpx[4005][16005];
int dpy[4005][16005];
int main(void){
    dpx[0][8001]=1;
    dpy[0][8001]=1;
    string s;
    cin>>s;
    int F=0;
    int cx=0,cy=0,tx=0,ty=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='F'){
            if(F%2==0){
                tx++;
            }
            else{
                ty++;
            }
        }
        else{
            if(F%2==0){
                cx++;
                for(int j=1;j<=16001;j++){
                    //dpx[cx][j]+=dpx[cx-1][j];
                    dpx[cx][j]+=dpx[cx-1][max(0,j-tx)];
                    if(cx!=1){dpx[cx][j]+=dpx[cx-1][j+tx];}
                    if(dpx[cx][j]>0)dpx[cx][j]=1;
                }
                tx=0;
            }
            else{
                cy++;
                for(int j=1;j<=16001;j++){
                    //dpy[cy][j]+=dpy[cy-1][j];
                    dpy[cy][j]+=dpy[cy-1][max(0,j-ty)];
                    dpy[cy][j]+=dpy[cy-1][j+ty];
                    if(dpy[cy][j]>0)dpy[cy][j]=1;
                }
                ty=0;
                //cout<<dpy[0][8001]<<endl;
            }
            F++;
        }
    }
    if(tx){
        cx++;
        for(int j=1;j<=16001;j++){
            //dpx[cx][j]+=dpx[cx-1][j];
            dpx[cx][j]+=dpx[cx-1][max(0,j-tx)];
            if(cx!=1){dpx[cx][j]+=dpx[cx-1][j+tx];}
            
        }
    }
    if(ty){
        cy++;
        for(int j=1;j<=16001;j++){
            //dpy[cy][j]+=dpy[cy-1][j];
            dpy[cy][j]+=dpy[cy-1][max(0,j-ty)];
            dpy[cy][j]+=dpy[cy-1][j+ty];
        }
    }
    int x,y;
    cin>>x>>y;
    if(dpx[cx][x+8001]&&dpy[cy][y+8001]){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    //cout<<dpx[2][8001-2]<<dpy[1][8001-2]<<cy<<cx<<endl;
}


Measured memory_bytes: 499968
#include <stdio.h>

int main(void) {
	int N;
	int a[200000];

	long long int ans;

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

	long long int sumAll = 0;
	for (int i = 0; i < N; i++){
		sumAll += a[i];
	}

	long long int sum = a[0];
	long long int buf = sumAll - (sum * 2);
	if (buf < 0) buf *= -1;
	ans = buf;
	for (int i = 1; i < N - 1; i++){
		sum += a[i];
		buf = sumAll - (sum * 2);
		if (buf < 0) buf *= -1;

		if (buf < ans){
			ans = buf;
		}
	}

	printf("%lld", ans);

	return 0;
}


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

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

s=abs(A[0]-X)
for i in range(1,N):
    s=gcd(s,abs(A[i]-X))

print(s)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bitcnt(n) __builtin_popcountll(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++)cout << c[pos] << " ";
#define PI acos(-1)
const int M = 1000000007;
const int N=3e5 + 7;

#ifdef LOCAL
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__)
#endif

void solve(){
    int i , j , n ;

}
signed main()
{
    int tc , i ,j;
    string s;
    cin >> s;
    if(s.find('7')!=string::npos){
        cout <<"Yes\n";
    }
    else {
        cout << "No\n";
    }
}

Measured memory_bytes: 3624
S = input()
A = [chr(i) for i in range(ord("a"),ord("z")+1)]

if len(S) < 26 :
    for i in range(len(A)) :
        if A[i] not in S :
            ans = S + A[i]
            break
elif S == "".join(A[::-1]) :
    ans = -1
else :
    B = []
    for i in range(len(A)-1) :
        right = S[len(A)-1-i]
        left = S[len(A)-1-(i+1)]
        B.append(right)
        if left < right:
            last = "z"
            for b in B :
                if left > b :
                    continue
                last = min(last,b)
            ans = S[:len(S)-1-(i+1)] + last
            break
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX + 1];

void maxHeapify(int i) {
	int l, r, largest;
	l = 2 * i;
	r = 2 * i + 1;

	if (l <= H && A[l] > A[i])largest = l;
	else largest = i;
	if (r <= H && A[largest] < A[r])largest = r;

	if (largest != i) {
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}
}

int extract() {
	int maxv;
	if (H < 1)return -INFTY;
	maxv = A[1];
	A[1] = A[H--];
	maxHeapify(1);
	return maxv;
}

void increaseKey(int i, int key) {
	if (key < A[i])return;
	A[i] = key;
	while (i > 1 && A[i / 2] < A[i]) {
		swap(A[i], A[i / 2]);
		i = i / 2;
	}
}
void insert(int key) {
	H++;
	A[H] = -INFTY;
	increaseKey(H, key);
}
int main() {

	int key;
	char com[10];

	while (1) {
		scanf("%s", com);
		if (com[0] == 'e' && com[1] == 'n')break;
		if (com[0] == 'i') {
			scanf("%d", &key);
			insert(key);
		}
		else {
			printf("%d\n", extract());
		}
	}

	return 0;
}


Measured memory_bytes: 7032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace past10.Abc
{
    public class Question7
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            long N = long.Parse(Console.ReadLine());
            long[] d = new long [N];
            for(long i=0;i<N;++i) d[i] = long.Parse(Console.ReadLine());
            HashSet<long> hs = new HashSet<long>(d);

            Console.WriteLine(hs.Count);

            Console.Out.Flush();
        }
    }
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e18+7;


int main(){
	//ios_base::sync_with_stdio(false);
	ll N, ans=0;
	ll x[200005], s[200005];

	cin >> N;
	rep(i,N) cin >> x[i] >> s[i];

	ll sum = 0, mn = 0;
	rep(i,N){
		sum += s[i];
		chmax(ans, sum - mn);
		ll d = x[i+1] - x[i];
		sum -= d;
		chmin(mn, sum);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3328
#include <cstdio>
int n;
int main(void){
	scanf("%d",&n);
	if(n==0 || n==2){
		printf("1\n");
	}
	if(n==1){
		printf("2\n");
	}
	if(n>=3){
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 1008
#include<iostream>
#include<string>
using namespace std;
int main(){
	double n,a,b[6]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a<165)
			b[0]++;
		if(a>=165&&a<170)
			b[1]++;
		if(a>=170&&a<175)
			b[2]++;
		if(a>=175&&a<180)
			b[3]++;
		if(a>=180&&a<185)
			b[4]++;
		if(a>=185)
			b[5]++;
	}
	for(int i=0;i<6;i++){
		cout<<i+1<<":";
		for(int j=0;j<b[i];j++)
			cout<<"*";
		cout<<endl;
	}
    return 0;
}
 

Measured memory_bytes: 1224
#N = int(input())
n, m = map(int, input().split())
#hl = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
pl = list(map(int, input().split()))
count=0
for i in range(2**n):
    b = bin(i)
    switch = [False for i in range(n)]
    boollist=[]
    for j in range(n):
        if ((i >> j) & 1):
            switch[j] = True
    for j in range(m):
        k = l[j][0]
        sl = l[j][1:]
        total=0
        for sij in sl:
            if switch[sij-1]:
                total+=1
        if total % 2 == pl[j]:
            boollist.append(True)
        else:
            boollist.append(False)
    if all(boollist):
        count += 1
print(count)



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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    for(int i=0;i<=k;++i){
        int bb = b;
        for(int d=0;d<i;++d)bb *= 2;
        for(int j=0;j+i<=k;++j){
            int cc = c;
            for(int d=0;d<j;++d)cc *= 2;
            if(a < bb and bb < cc){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
    
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstring>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

#define F first
#define S second
#define siz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define MP make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define debug(x) cout << " > " << #x << ':' << x << endl;
#define kiyohime ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using vec = vector<T>;
template<typename T> using Prior = priority_queue<T>;
template<typename T> using prior = priority_queue<T, vec<T>, greater<T>>;

const int INF = 1e9;
const ll LLINF = (ll)4*1e18;
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;
const int xx[8] = {0,1,0,-1,1,1,-1,-1};
const int yy[8] = {1,0,-1,0,1,-1,-1,1};

void pmod(ll &a, ll b) {a = (a+b)%MOD;}
void mmod(ll &a, ll b) {a = (a-b+MOD)%MOD;}
void tmod(ll &a, ll b) {a = (a*b)%MOD;}
ll POW(ll a, ll b) {ll res=1; do{if(b%2)tmod(res,a);tmod(a,a);}while(b>>=1); return res;}
template<typename T> void amax(T &a, T b) {if(a < b) a = b;}
template<typename T> void amin(T &a, T b) {if(a > b) a = b;}

#define N 100010

vec<int> v[N], ord;
bool vis[N];

void dfs(int x){
    vis[x] = true;
    for(auto i:v[x])
        if(!vis[i])
            dfs(i);
    ord.EB(x);
}

void solve(){
    int n, m;
    
    cin >> n >> m;
    int ipa, ipb;
    vec<bool> deg(n+1, true);
    rep(i, m){
        cin >> ipa >> ipb;
        v[ipa].EB(ipb);
        deg[ipb] = false;
    }
    
    rep1(i, n) if(deg[i])
        dfs(i);
    
    vec<int> dp(n+1);
    for(auto i:ord){
        for(auto j:v[i])
            amax(dp[i], dp[j] + 1);
    }
    
    int ans = 0;
    rep1(i, n)
        amax(ans, dp[i]);
    cout << ans << endl;
}

int main(){
//    kiyohime
    int T = 1;
    
//    cin >> T;
    while(T--){
        solve();
    }
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int amax,amin,bmax,bmin;
    if (a%2==0){
        amin=a*100/8;
    }
    else{
        amin=a*100/8+1;
    }
    

    amax=(a+1)*100/8;
    if ((((a+1)*100)%8)==0){
        --amax;
    }
    
    bmin=b*100/10;
    
    

    bmax=(b+1)*100/10-1;

    
    
    if(amax<bmin or amin>bmax){
        cout << -1 << endl;
    }
    else{
        if(amin > bmin){
            cout << amin << endl;
        }
        else{
            cout << bmin << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int D = sc.nextInt();
        int x[] = new int[11];
        x[0] = sc.nextInt();
        for (int i = 1; i <= 10; i++) {
            x[i] = (r * x[i -1]) - D;
            System.out.println(x[i]);
        }
    }
}


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

using namespace std;

int n;
int a[110];
long long sum;
long long minn = 1000000010;

int main(void)
{
	scanf("%d", &n);
	
	for(int i = 0 ; i < n ; i++)
	{
		scanf("%d", &a[i]);
	}
	
	for(int i = 1 ; i <= 100 ; i++)
	{
		sum = 0;
		
		for(int j = 0 ; j < n ; j++)
		{
			sum += (a[j] - i) * (a[j] - i);
		}
		
		if(sum < minn)
		{
			minn = sum;
		}
	}
	
	printf("%lld", minn);
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    _ = int(readline())
    hs = list(map(int, readline().split()))
    ok_len = []
    ok_list = [(left >= right) for left, right in zip(hs, hs[1:])]
    tmp_len = 0
    for ok in ok_list:
        if ok:
            tmp_len += 1
        else:
            ok_len.append(tmp_len)
            tmp_len = 0
    ok_len.append(tmp_len)
    print(max(ok_len))


if __name__ == '__main__':
    main()


Measured memory_bytes: 12524
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define all(x) x.begin(),x.end()
#define YES {cout << "YES\n"; return;}
#define NO {cout << "NO\n"; return;}

const int INF=INT_MAX;
const ld PI=acos(-1);//3.1415926535897932384626433
const ld E=2.71828183;
const int MOD=1e9+7;

vi bfs(vector<vi>adj,int src){
    //adjacency list, not-weighted, possibly directed ,src is 1-indexed, adj[0].size()=0!!!
    //for n vertices, adj.size()=n+1. (constructed via push_back() ).

    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return dst;
}
vi bfsParents(vector<vi>adj,int src){
    vi parents=vi(adj.size(),INF);
    parents[src]=-1;
    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                parents[nbr]=c;
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return parents;
}
vi shortestPath(vector<vi>adj,int src,int dst){
    vi bfsParetns=bfsParents(adj,src);
    vi ans;
    while(src!=dst){
        if(bfsParetns[src]==INF)
            return {};
        ans.push_back(src);
        src=bfsParetns[src];
    }
    return ans;
}
int powMod(int base,int exp,int mod){
    //(base^exp) %mod
    int ans=1;
    for(int i=0; i<exp; i++)
        ans=((ans%mod)*(base%mod))%mod;
    return ans;
}
vi divisorsOf(int n){
    //vector of divisors of n (inc. 1 , excl.n)
    vi ans;
    for(int i=1; i*i<=n; i++){
        if(n%i==0)
            ans.push_back(i);
        if(i*i!=n && i!=1)
            ans.push_back(n/i);
    }
    return ans;
}

ll gcd(ll a,ll b){if(a%b==0) return b; else return gcd(b,a%b);}
ld log (ld a,ld b){return log(b)/log(a);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll power(ll base, ll exp){ll res=1;while(exp){exp--;res*=base;}return res;}

void solve();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
        solve();
    return 0;
}
void solve (){
    int n;
    cin >> n;
    for(int i=1; i<10 && i*i<=n; i++){
        if(n%i==0 && n/i<10){
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";

}

Measured memory_bytes: 3680
N,M=list(map(int,input().split()))
def f(n):
   return n*(n-1)//2
ans=f(N)
root=[i for i in range(N+1)]
height=[1]*(N+1)
def find(a):
   f=a
   if a==root[a]:
      return a
   while a!=root[a]:
      a=root[a]
   root[f]=a
   return a
def union(a,b):
   A=find(a)
   B=find(b)
   global ans
   if A==B:
      return
   ans+=f(height[A])+f(height[B])
   if height[A]>height[B]:
      root[B]=root[A]
      height[A]+=height[B]
      height[B]=0
   else:
      root[A]=root[B]
      height[B]+=height[A]
      height[A]=0
   ans-=f(max(height[A],height[B]))
l=[tuple(map(int,input().split())) for i in range(M)]
l=l[::-1]
ans_m=[ans]
for i in range(M):
   a,b=l[i]
   union(a,b)
   ans_m.append(ans)
ans_m=ans_m[::-1]
for i in range(1,M+1):
   print(ans_m[i])

Measured memory_bytes: 29372
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
 
using namespace std;
 
typedef vector<int> vi;
typedef pair<int, int> P;
 
int main(){
    int n;
    while(cin >> n, n){
        vector<int> v(2*n+1, 0);
        rep(i, n){
            int k;
            cin >> k;
            v[k] = 1;
        }
        for(int i = 1; i <= 2*n; i++){
            if(!v[i]) v[i] = 2;
        }
        int t = 0, c = 0;
        int cnt[2] = {n, n};
        while(cnt[0] && cnt[1]){
            rep(i, v.size()){
                if(!cnt[0] || !cnt[1]) break;
                if((t == 0 && v[i] == 1) || (t == 1 && v[i] == 2)){
                    cnt[t]--;
                    c = v[i];
                    v[i] = 0;
                    t = !t;
                }
            }
            c = 0;
            t = !t;
        }
        cout << count(v.begin(), v.end(), 2) << endl;
        cout << count(v.begin(), v.end(), 1) << endl;
    }
 
 
    return 0;
}

Measured memory_bytes: 1196
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	// input1 = input[0].split('').map((n) => (parseInt(n)))
	// input[0].split(' ').map((n) => (parseInt(n)))
	arr = input[0].split(' ').map((n) => (parseInt(n)))
	var ans = arr[0] * 3 + arr[1]
	ans = Math.floor(ans/2)



	//出力
	console.log(ans )
}
// *この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

Measured memory_bytes: 7372
fn q2(n:i32) -> bool {
    let m = n / 7;
    match (0..m+1).find(|x| ((n - x * 7) % 4 == 0)) {
        None => false,
        _ => true
    }
}

fn main() {
    let n = read::<i32>();
    println!("{}", if q2(n) { "Yes" } else { "No" });
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int S, a[105];

bool flag[1000000] = {0};

int calc(int n){
    if (n%2==0) return n/2;
    else return 3*n+1;
}

int main(){
    cin >> S;
    int index = 1;
    a[index] = S;
    // cout << a[index] << " ";
    flag[a[index]] = true;
    while(true){
        a[index+1] = calc(a[index]);
        // cout << a[index+1] << " ";
        if(flag[a[index+1]]) break;
        else flag[a[index+1]] = true;
        index++;
    } 
    // cout << endl;
    cout << index+1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <map>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define for_p(i, a, b) for(int i = a; i < b; i++)
#define for_m(i, a, b) for(int i = a - 1; i >= b; i--)

//a = s1.size();
//vector<string> s1;
//string s2 = accumulate( s1.begin(), s1.end(), string() );

using namespace std;

int main()
{
  int a = 0 , b = 0, c = 0, d = 0, e = 0, f = 0;
  int i = 0, j = 0;
  double d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0;
  int a1[100000], a2[512], a3[1024];
  char s1[200000], s2[200000], s3[200000];
  
  cin >> a >> b;
  
  for(i = 0; i < a; i++){
    cin >> a1[i];
    if(b <= a1[i]){
      c++;
    }
  }
  cout << c << endl;
}
  


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree:
    def __init__(self, array, operator, identity_element):
        _len = len(array)
        self.__op = operator
        self.__size = 1 << (_len - 1).bit_length()
        self.__tree = [identity_element] * self.__size + \
            array + [identity_element] * (self.__size - _len)
        self.__ie = identity_element

        for i in range(self.__size - 1, 0, -1):
            self.__tree[i] = operator(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def update(self, i, v):
        i += self.__size
        self.__tree[i] = v
        while i:
            i //= 2
            self.__tree[i] = self.__op(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def query(self, l, r):
        """[l, r)
        """
        l += self.__size
        r += self.__size
        ret = self.__ie
        while l < r:
            if l & 1:
                ret = self.__op(ret, self.__tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.__op(ret, self.__tree[r])
            l //= 2
            r //= 2
        return ret


@mt
def slv(N, A):
    ai = [(a, i) for i, a in enumerate(A)]
    ai.sort()

    lst = SegmentTree([-1] * N, max, -1)
    rst = SegmentTree([N] * N, min, N)
    ans = 0
    for a, i in ai:
        l = lst.query(0, i)
        r = rst.query(i+1, N)
        ans += (i-l) * (r-i) * a
        lst.update(i, i)
        rst.update(i, i)
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 102040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,a[55],ans=0,s,k;
  cin>>n;
  fr(i,n) cin>>a[i];
  while(1){
    bool f=1;
    fr(i,n) f=f&&(a[i]<n);
    if(f) break;
    s=0;
    fr(i,n){
      if(a[i]<n) continue;
      k=a[i]/n;
      a[i]-=k*(n+1);
      ans+=k;
      s+=k;
    }
    fr(i,n) a[i]+=s;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,x[5+1],min1,min2,answer;
	min1=2000;
	min2=2000;
	for(i=1;i<=5;i++) {
		scanf("%d",&x[i]);
	}
	for(i=1;i<=3;i++) {
		if(x[i]<=min1) {
			min1=x[i];
		}
	}
	for(i=4;i<=5;i++) {
		if(x[i]<=min2) {
			min2=x[i];
		}
	}
	answer=min1+min2-50;
	printf("%d\n",answer);
	return 0;
}

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("fibsubseq.in","r",stdin)
#define write()         freopen("fibsubseq.out","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long int
#define endll           printf("\n")
#define pf              printf
#define pi              acos(-1.0)
#define eps             1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())

bool Check(unsigned int  N,int pos){return (bool)(N & (1LL<<pos));}
ll  Set(unsigned int N,int pos){    return N=N | (1LL<<pos);}
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod  1000000007
#define mod1 1000000009
#define var    int ii,i,j,k,z=0,c=0,t,x,y,l,r,mid,m
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};

ll n;
double a[3005],dp[3005][3005];

double fn(ll pos,ll c)
{
    if(pos==n)
    {
        return c>n-c;
    }
    double &z=dp[pos][c];
    if(z!=-1.0)return z;
    z=0.0;
    z+=a[pos]*fn(pos+1,c+1);
    z+=(1.0-a[pos])*fn(pos+1,c);
    return z;
}

int main()
{
    double z;
    sfl(n);
    for(int i=0;i<n;i++)sfd(a[i]);
    for(int i=0;i<=3000;i++)for(int j=0;j<=3000;j++)dp[i][j]=-1.0;
    z=fn(0,0);
    cout<<fixed<<setprecision(15)<<z<<endl;
}


Measured memory_bytes: 70912
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {


  case class Edge(a: Int, b: Int)

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val edges = IndexedSeq.fill(n - 1) {
      //0-origin
      val a = sc.nextInt() - 1
      val b = sc.nextInt() - 1
      IndexedSeq(Edge(a, b), Edge(b, a))
    }.flatten
    val c = IndexedSeq.fill(n)(sc.nextInt())
    (n, edges, c)
  }

  def solve(n: Int, edges: IndexedSeq[Edge], c: IndexedSeq[Int]): Unit = {
    val sc = c.sortBy(-_)
    val nextList = IndexedSeq.fill(n)(ArrayBuffer.empty[Edge])
    for (edge <- edges) {
      nextList(edge.a).append(edge)
    }
    val visited = Array.fill(n)(false)
    // 1から
    visited(0) = true
    val open: java.util.Queue[Int] = new java.util.ArrayDeque[Int]()
    open.add(0)
    val result2 = Array.fill(n)(-123)
    result2(0) = sc(0)
    var cnt = 1

    while (!open.isEmpty) {
      val current = open.remove()
      for (edge <- nextList(current)) {
        val next = edge.b
        if (!visited(next)) {
          result2(edge.b) = sc(cnt)
          visited(next) = true
          open.add(next)
          cnt += 1
        }
      }
    }
    val result1 = edges.map(edge => math.min(result2(edge.a), result2(edge.b)).toLong).sum/2
    println(result1)
    println(result2.mkString(" "))
  }


  def main(args: Array[String]): Unit = {
    val (n, edges, c) = read()
    solve(n, edges, c)
  }
}


Measured memory_bytes: 52832
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)

typedef long long ll;

using namespace std;
//using namespace boost::multiprec

int main(){

    int n;

    cin >> n;

    if(n / 100 == n % 10){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n;
  int d[200];
  int count;
  int sum=0;
  int count2;
  scanf("%d",&n);
  for(count=0;count<=n;count++){
  scanf("%d",&d[count]);
  }
  
for(count2=0;count2<n;count2++){
for(count=count2+1;count<n;count++){
sum=sum+(d[count2]*d[count]);
}
}
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=5e5+5;
const int MM=25e5+5;
int A,B,C,D;
ll n;
map<ll,ll>f;
set<ll>S;
ll dfs(ll n){
	if(!n)return 0;
	if(f.count(n))return f[n];
	reg ll res;
	if((double)n*D>9e18)res=9e18;
	else res=n*D;
	for(reg ll i=max(0ll,n-5);i<=n+5;i++){
		if(i%2==0&&i/2<n)res=min(res,dfs(i/2)+llabs(i-n)*D+A);
		if(i%3==0&&i/3<n)res=min(res,dfs(i/3)+llabs(i-n)*D+B);
		if(i%5==0&&i/5<n)res=min(res,dfs(i/5)+llabs(i-n)*D+C);
	}
	return f[n]=res;
}
int main(){
	reg int T;scanf("%d",&T);
	while(T--){
		scanf("%lld%d%d%d%d",&n,&A,&B,&C,&D);
		f.clear();printf("%lld\n",dfs(n));
	}
	return 0;
}

Measured memory_bytes: 7260
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,v,m=2e18;
    cin>>n>>k;
    v=n/k;
    m=min(m,abs(v*k-n));
    v++;
    m=min(m,abs(v*k-n));
    cout<<m;
    
}

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

int main() {
	//10^6=2^20;
	int n;cin>>n;
	if(n==2){
		cout<<2<<' '<<2<<endl;
		cout<<1<<' '<<2<<' '<<0<<endl;
		cout<<1<<' '<<2<<' '<<1<<endl;
		return 0;
	}
	n--;
	int digit=0;
	int n2=n;
	while(n2){
		digit++;
		n2/=2;
	}
	int vn=digit;
	vector<vector<int>> v;
	vector<int> add(3);
	int num=1;
	for(int i=1;i<=digit-1;i++){
		add[0]=i;
		add[1]=i+1;
		add[2]=num;
		v.push_back(add);
		add[2]=0;
		v.push_back(add);
		num*=2;
	}
//	add[0]=digit;
//	add[1]=digit+1;
//	add[2]=0;
//	v.push_back(add);
	num=1;
	num<<=digit-1;
	int sum=num;
	num>>=1;
	for(int i=digit-1;i>0;i--){
//		cout<<i<<endl;
		if(n&num){
			add[0]=i;
			add[1]=digit;
			add[2]=sum;
			sum+=num;
			v.push_back(add);
		}
		num>>=1;
	}
//	cout<<digit<<endl;
	add[0]=1;
	add[1]=digit;
	add[2]=sum;
	v.push_back(add);
	cout<<vn<<' '<<v.size()<<endl;
	for(int i=0;i<v.size();i++){
		cout<<v[i][0]<<' '<<v[i][1]<<' '<<v[i][2]<<endl;
	}
	return 0;
}


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

const int N = 1e5 + 5;

int n, a[N], b[N];

int main(void) {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++ i) b[i] = a[i];
	sort(b + 1, b + 1 + n);
	int ans = 0;
	for (int i = 1; i <= n; ++ i) {
		int idx = lower_bound(b + 1, b + 1 + n, a[i]) - b;
		int diff = abs(i - idx);
		if (diff & 1) ++ ans;
	}
	printf("%d\n", ans >> 1);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <map>

typedef long long int ll;
using namespace std;
int main(){
	int s;
	vector<int> k;
	for(int i=0;i<3;i++){
		cin >> s;
		k.push_back(s);
	}
	sort(k.begin(),k.end());
	cout<< k[0]+k[1]<<endl;
	return 0;
}

Measured memory_bytes: 256