akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef OJ
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const char en = '\n';
const int MOD = 0;
const int MAXN = 0;
const int INF = 1e9;

int solve() {
    int k; cin >> k;
    vector<int> seen(k);
    int r = 0;
    for(int i = 1; ;i++) {
        r = (r*10 + 7)%k;
        if(r == 0) RETURN(i);
        if(seen[r]) RETURN(-1);
        seen[r] = 1;
    }
    return 0;
} 

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    int t = 1;
    fori(test, ntest) {
        //cout << "Case #" << t << ": ";
        solve();
        t++;
    }

    return 0;
}


Measured memory_bytes: 7148
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x, n;
    cin >> x >> n;
   // we have a sequence.
   set<int> s;
   for (int i = 0; i < n; i++)
   {
      int k; cin >> k;
      s.insert(k);
   }
   // we should start from the number 
   if(s.count(x) == 0) cout << x << endl;
   else{
       // that means the number x is already present in the set.
       // we Then, start with a number less than it and then we take
       // a number greater than.
       int dec = 1, inc = 1, l = 0, r = 0;
       bool jill = true;
       int ans = x;
       while(jill){
           l = x-dec;
           if(s.count(l) == 0){
               ans = l;
               jill = false;
               break;
           }
           r = x+inc;
           if(s.count(r) == 0){
               ans = r;
               jill = false;
               break;
           }
           dec++;
           inc++;
       }
       cout << ans << endl;
   }
   
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k,s;
    cin>>k>>s;
    int ans=0;
    for(int i=0;i<=k;i++){
        if(i>s) break;
        for(int j=0;j<=k;j++){
            if(i+j>s) break;
            int z=s-i-j;
            if(z<=k) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;

int main() {
	int N, M;
	cin >> N >> M;

	priority_queue<ll> A;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		A.push(a);
	}

 	while (M--) {
		ll a = A.top();
		A.pop();
		A.push(a / 2LL);
 	}

	ll ans = 0;
	while (A.size()) {
		ans += A.top();
		A.pop();
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1400
n,m = map(int,input().split())
a = [False]*n
b = [0]*n
for i in range(m):
    p,s = input().split()
    p = int(p)
    if s == 'AC':
        a[p-1] = True
    if s == 'WA' and a[p-1] == False:
        b[p-1] += 1
correct = a.count(True)
penalty = 0
for i in range(len(a)):
    if a[i] == True:
        penalty += b[i]
print(correct, penalty)

Measured memory_bytes: 4596
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 5e5 + 10;

long long ans = 0, a[N];
int n;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        string str;
        cin >> str;
        if (str[0] == 'M')
            a[1]++;
        if (str[0] == 'A')
            a[2]++;
        if (str[0] == 'R')
            a[3]++;
        if (str[0] == 'C')
            a[4]++;
        if (str[0] == 'H')
            a[5]++;
    }
    for (int i = 1; i <= 5; i++)
        for (int j = i + 1; j <= 5; j++)
            for (int k = j + 1; k <= 5; k++)
                ans += a[i] * a[j] * a[k];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

bool is_prime(int n)
{

    for (int i = 2; i*i <= n;i++){
        if(n % i == 0){
            return false;
        }
    }

    return true;
}

int main(void)
{

    int x;
    cin >> x;
    int i = 0;
    for (; !is_prime(x + i); i++)
    {
    }

    cout << x + i << endl;

    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> x;
	int temp;
	for(int i=0;i!=n;++i){
		cin>>temp;
		x.push_back(temp);
	}
	sort(x.begin(),x.end());
	int k=-1;
	for(auto i:x){
		if(i%10){
			k=i;
			break;
		}
	}
	int sum=0;
	for(auto i:x)
		sum+=i;
	if(!(sum%10)){
		if(k==-1)
			cout<<0;
		else
			cout<<sum-k;
	}
	else
		cout<<sum;
}

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

using namespace std;
using ll = long long;

const int N = 55;

int n , A;
int a[N];

ll mem[N][N][N*N];

ll dp(int i  , int cnt , int sum){
    if(i == n){
        if(cnt == 0)return 0;

        if( (sum/cnt == A) && (sum%cnt == 0) )return 1;
        return 0;
    }

    ll &ret = mem[i][cnt][sum];
    if(ret != -1)return ret;

    return ret = dp(i + 1 , cnt , sum) + dp(i + 1 , cnt + 1 , sum + a[i]);
}

main(){

    scanf("%d %d" , &n , &A);

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

   memset(mem , -1 , sizeof mem);
   printf("%lld\n" , dp(0 , 0 , 0));

    return 0;
}


Measured memory_bytes: 71680
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	int n,m,X,Y; cin >> n >> m >> X >> Y;
	vector<int> x(n),y(m);
	for(int i=0;i<n;i++){
		cin >> x[i];
	}
	for(int i=0;i<m;i++){
		cin >> y[i];
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	if(x[n-1]<y[0]&&x[n-1]<Y&&y[0]>X){
		cout << "No War" << endl;
	}
	else{
		cout << "War" << endl;
	}
}

Measured memory_bytes: 256
def lscan; gets.split.map(&:to_i); end

a, b, c = lscan
k = gets.to_i
(0..k).to_a.repeated_permutation(3) do |x,y,z|
  next if x+y+z > k
  a2 = a*(2**x)
  b2 = b*(2**y)
  c2 = c*(2**z)
  if a2 < b2 && b2 < c2
    puts 'Yes'
    exit
  end
end
puts 'No'

Measured memory_bytes: 14428
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define Rep(i, N) for(int i = 0; i < N; i++)
#define pb push_back
#define LLINF 1LL << 60
#define INF 1 << 28
#define F first
#define S second
typedef pair<int, int> Pi;
typedef vector<int> vint;

inline void chmax(int &a, int b) { a = max(a, b); }
inline void chmin(int &a, int b) { a = min(a, b); }

int N, M;
int val[100005];
int A, B, X;
vint bs, D;
int dfs(int v) {
  if(v < N) {
    if(val[v] == LLINF) {
      return 1;
    } else {
      if(val[v] >= X) return 0;
      else return LLINF;
    }
  }
  
  vint s;
  for(int i = (v - N) * 3; i < (v - N) * 3 + 3; i++) s.pb(dfs(i));
  sort(s.begin(), s.end());
  return min(s[0] + s[1], LLINF);
}
  

signed main()
{
  
  cin >> N >> M;
  fill_n(val, 100005, LLINF);
  
  Rep(i, M) {
    cin >> A >> B; B--;
    val[B] = A;
    bs.pb(A);
  }

  Rep(i, N - M) {
    cin >> A;
    bs.pb(A); D.pb(A);
  }
  
  sort(bs.begin(), bs.end());

  int l = 0, r = N;
  while(l + 1 < r) {
    int m = (l + r) / 2;
    int cnt = 0; X = bs[m];
    Rep(i, D.size()) if(D[i] >= X) cnt++;
    if(dfs(N + N / 2 - 1) <= cnt) l = m;
    else r = m;
  }

  cout << bs[l] << endl;
  return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int N, M;
  cin >> N >> M;
  int l1 = 1, r1 = M+1;
  int l2 = M+2, r2 = 2*M+1;
  REP(m,M) {
    if (m%2 == 0) {
      cout << l1 << " " << r1 << endl;
      l1++; r1--;
    } else {
      cout << l2 << " " << r2 << endl;
      l2++; r2--;
    }
  }
  return 0;
}


Measured memory_bytes: 3632
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int K = sc.nextInt(), S = sc.nextInt();
                        int ans = 0;
                        for (int i = 0; i <= K; i++) {
                                for (int j = 0; j <= K; j++) {
                                        int k = S - i - j;
                                        if (0 <= k && k <= K) {
                                                ans++;
                                        }
                                }
                        }
                        System.out.println(ans);
                }
        }
}

Measured memory_bytes: 9808
#include<bits/stdc++.h>
using namespace std;
bool ACGT(string s)
{
	int n=s.size();
	for(int i=0;i<n;i++)
		if(s[i]!='A'&&s[i]!='C'&&s[i]!='G'&&s[i]!='T')
			return false;
	return true;
}
int main(void)
{
	string s;
	cin>>s;
	int l=s.size(),anslen=0;
	for(int i=0;i<l;i++)
		for(int j=1;j<=l-i;j++)
		{
			string t=s.substr(i,j);
			if(ACGT(t))
				if(anslen<j)
					anslen=j;
		}
	cout<<anslen;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000

int main()
{
  int N;cin>>N;
  string S;cin>>S;
  int len = S.size();
  
  if (len % 2 ==1)
  {
    cout<<"No"<<endl;
    return (0);
  }
  
  for (int i=0;i<len/2;i++)
  {
    if (S[i]!=S[i+len/2])
    {
      cout<<"No"<<endl;
      return (0);
    }
  }
  cout<<"Yes"<<endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

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

#define INF 1000000000
#define F first
#define S second
#define forn(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)

using namespace std;

vector<ll> w[4];
ll sums[4][105];


int main(){
	int n, maxx;
	scanf("%d %d", &n, &maxx);
	ll ww1,vv1;
	scanf("%lld %lld", &ww1, &vv1);
	w[0].push_back(vv1);
	rep(i,n-1){
		ll ww,vv;
		scanf("%lld %lld", &ww, &vv);
		w[ww-ww1].push_back(vv);
	}
	rep(i,4){
		sort(w[i].begin(), w[i].end());
		reverse(w[i].begin(), w[i].end());
	}
	sums[0][0] = 0;
	sums[1][0] = 0;
	sums[2][0] = 0;
	sums[3][0] = 0;
	rep(i,4){
		rep(j,w[i].size()){
			sums[i][j+1] = sums[i][j]+w[i][j];
		}
	}

	ll mx = 0;

	rep(a,w[0].size()+1){
		rep(b,w[1].size()+1){
			rep(c,w[2].size()+1){
				rep(d,w[3].size()+1){
					ll weight = a*ww1 + b*(ww1+1) + c*(ww1+2) + d*(ww1+3);
					//printf("am here\n");
					if(weight > maxx) continue;
	//				printf("%d %d %d %d\n", a,b,c,d);
					ll val = sums[0][a] + sums[1][b] + sums[2][c] + sums[3][d];
					mx = max(mx, val);
				}
			}
		}
	}
	printf("%lld\n", mx);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(v) v.begin(),v.end()
#define ll long long
#define pb(a) push_back(a)
#define pf(a) push_flont(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
	long n,k;
	cin >> n >> k;
	vector<long> h;
	long element;
	rep(i,n){
		cin >> element;
		h.push_back(element);
	}
	sort(all(h));
	long min_tree = 0;
	long max_tree = min_tree+k-1;
	long ans_sa = INF;
	for(;max_tree < n;){
		if(ans_sa>h[max_tree]-h[min_tree]){
			ans_sa = h[max_tree]-h[min_tree];
		}
		max_tree++;
		min_tree++;
	}

	cout << ans_sa << endl;

	return 0;
}


Measured memory_bytes: 1400
#include<stdio.h>

int prime(int);

int main()
{
   int n, i, x;
   int ans = 0;

   scanf ("%d", &n);

   for (i=0; i<n; i++){
      scanf ("%d", &x);
      if (prime(x))
         ans++;
   }

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

   return 0;
}


int prime(int x)
{
   int i = 3;   /*1????????§??????????°?????\???°*/

   if (x==2)
      return 1;   /*return 1??§2????´???°*/

   if(x<2 || x%2==0)
      return 0;   /*return 0??§x????´???°??§?????????*/

   while (i*i<=x){
      if (x%i==0)
         return 0;   /*i*i=x?????¨???x%i==0??§x????´???°??§?????????*/
      i = i+2;   /*i=3???+=2????????????????\???°????¶????*/
   }

   return 1;
}

Measured memory_bytes: 1800
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1
 
struct Node { int p, l, r;};
 
Node T[MAX];
int n, D[MAX];
 
void print(int u) {
  int i,c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";
 
  if( T[u].p == NIL ) cout << "root, ";
  else if( T[u].l == NIL ) cout << "leaf, ";
  else cout << "internal node, ";
 
  cout << "[";
 
  for(i=0, c=T[u].l; c!=NIL; i++,c=T[c].r) {
    if(i) cout <<", ";
    cout << c;
  }
  cout << "]" << endl;
}
 
void rec(int u, int p) {
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r,p);
  if(T[u].l != NIL) rec(T[u].l,p+1);
}
 
int main(void) {
  int i,j,d,v,c,l,r;
  cin >> n;
  for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i=0;i<n;i++) {
    cin >> v >> d;
    for(j=0;j<d;j++) {
      cin >> c;
      if(j==0) T[v].l=c;
      else T[l].r =c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0;i<n;i++) {
    if(T[i].p == NIL) r = i;
  }
   
  rec(r,0);
   
  for(i=0;i<n;i++) print(i);
   
  return 0;
}


Measured memory_bytes: 7756
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define ff                                         first
#define ss                                         second
#define pb                                         push_back
#define int                                        long long
#define mp                                         make_pair
#define pii                                        pair<int,int>
#define vi                                         vector<int>
#define mii                                        map<int,int>
#define umii                                       unordered_map<int,int>
#define pqb                                        priority_queue<int>
#define pqs                                        priority_queue<int,vi,greater<int>>
#define setbits(x)                                 __builtin_popcountll(x)
#define zerobits(x)                                 __builtin_ctzll(x)
#define mod                                        1000000007
#define inf                                        1e18
#define ps(x,y)                                    fixed<<setprecision(y)<<x
#define mk(arr,n,type)                             type *arr=new type[n]
#define test(t)                                    int t;cin>>t;while(t--)
#define rep(i,n)                                   for(int i=0;i<n;i++)
#define rep1(i,n)                                  for(int i=1;i<=n;i++)
#define fio                                        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SIZE                                       100005
#define all(x)                                     (x).begin(),(x).end()
#define sclk()                                     auto start_time = Clock::now()
#define eclk()                                     auto end_time = Clock::now();  cout << "\nTime Taken : " << chrono::duration_cast<chrono::milliseconds>(end_time    - start_time).count() << " ms"
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef std::chrono::high_resolution_clock Clock;
 
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) { return b?gcd(b,a%b):a;}
 
void f_io()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
int dp[405][405];
int arr[405];
int pre[405];
int solve(int s,int e)
{
    if(s==e)
    return 0;
    if(dp[s][e]==-1)
    {
        int ans=inf;
        for(int i=s;i<e;i++)
        {
            ans=min(ans,solve(s,i)+solve(i+1,e)+pre[e]-pre[s-1]);
        }
        dp[s][e]=ans;
    }
    return dp[s][e];
}
int32_t main()
{
    memset(dp,-1,sizeof dp);
    int n;
    cin>>n;
    pre[0]=0;
    rep(i,n)
    {
        cin>>arr[i+1];
        pre[i+1]=pre[i]+arr[i+1];
    }
    cout<<solve(1,n);
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

ll n;
int ans = 0;

bool check(string tmp){
    int k = tmp.size();
    bool t = false;
    bool f = false;
    bool s = false;
    bool all = false;
    rep(i,k){
        if(tmp[i] == '3') t = true;
        if(tmp[i] == '5') f = true;
        if(tmp[i] == '7') s = true;
    }
    if(t && f && s) all = true;
    return all;
}

void dfs(string tmp){
    ll now = stol(tmp);
    if(now <= n){
        if(check(tmp)) ans++;
        dfs(tmp+'3');
        dfs(tmp+'5');
        dfs(tmp+'7');
    }
}

int main()
{
    cin >> n;
    dfs("3");
    dfs("5");
    dfs("7");
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define p pair<int,int>
#define pb push_back
#define endl '\n'
void fast()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);

}
int a[105];
int main()
{
    fast();
    int x;
    int n;
    cin>>x>>n;
    for(int i=0;i<n;i++)
    {
        int temp;
        cin>> temp;
        a[temp]++;
        //cout<<temp<<" "<<a[temp]<<endl;
    }
    int left=0,right=0;
  if(a[x]==0)
    {
        cout<<x<<endl;
        return 0;
    }
    for(int i=x;i<=100;i++)
    {
        //cout<<a[i]<<" ";
        if(a[i]==0)
        {
            break;
        }
        else
        {
            right++;
        }
    }
    for(int i=x;i>=1;i--)
    {
        if(a[i]==0)
        {
            break;
        }
        else
        {
            left++;
        }
    }
    //cout<<right<<" "<<left<<endl;
   cout<<(left<=right?x-left:x+right)<<endl;
}


Measured memory_bytes: 3644
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let a: usize = scan(tokens);
    let b: usize = scan(tokens);
    if a <= 9 && b <= 9 {
        println!("{}", a * b);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 4352
N = int(input())
S = input()
l = 0
r = S[1:N].count('E')
ans = l+r

for n in range(1,N):
  if S[n-1]=="W":
    l+=1
  if S[n]=="E":
    r-=1
  ans=min(ans,l+r)

print(ans)

Measured memory_bytes: 9632
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
int n, k;
int a[200009];
int dp[200009];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n >> k;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        dp[i] = 1e9;
    }
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i; j <= i+k; ++j)
            dp[j] = min(dp[j], dp[i] + abs(a[j]-a[i]));
    }
    cout << dp[n-1] << "\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main() {
    int x,y;
    cin >> x >> y;
    int ans = 0;
    if(x<4){
        ans += 400000 - x * 100000;
    }
    if(y<4){
        ans += 400000 - y * 100000;
    }
    if(x == 1 and y == 1){
        ans += 400000;
    }
    cout << ans << endl;
}


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

int main() {
    int a, p;
    cin >> a >> p;
    int sum = a*3+p;
    int ans = sum/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int N = 405;
 
int n;
vector<int> a[N];
map<long long, int> mp, m;
 
void add(vector<int>& a, map<long long, int>& mp) {
    for (int r = 0; r < 4; ++r) {
        long long cur = 0;
        for (int j = 0; j < 4; ++j) {
            cur = cur * 1000 + a[(j + r) % 4];
        }
        ++mp[cur];
    }
}
 
void remove(vector<int>& a, map<long long, int>& mp) {
    for (int r = 0; r < 4; ++r) {
        long long cur = 0;
        for (int j = 0; j < 4; ++j) {
            cur = cur * 1000 + a[(j + r) % 4];
        }
        --mp[cur];
    }
}
 
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        a[i].resize(4);
        for (int j = 0; j < 4; ++j) {
            scanf("%d", &a[i][j]);
        }
        add(a[i], mp);
    }
    long long result = 0;
    vector<int> b, q;
    for (int i = 0; i < n; ++i) {
        remove(a[i], mp);
        for (int j = i + 1; j < n; ++j) {
            remove(a[j], mp);
            m = mp;
            q = a[j];
            reverse(q.begin(), q.end());
            for (int r = 0; r < 4; ++r) {
                long long cur = 1;
                for (int x = 0; x < 4; ++x) {
                    b.clear();
                    b.resize(4);
                    b[0] = a[i][x]; 
                    b[3] = a[i][(x + 1) % 4];
                    b[1] = q[(x + r) % 4];
                    b[2] = q[(x + r + 1) % 4];
                    long long val = 0;
                    for (int y = 0; y < 4; ++y) {
                        val = val * 1000 + b[y];
                    }
                    cur *= m[val];
                    remove(b, m);
                }
                result += cur;
                for (int x = 0; x < 4; ++x) {
                    b.clear();
                    b.resize(4);
                    b[0] = a[i][x]; 
                    b[3] = a[i][(x + 1) % 4];
                    b[1] = q[(x + r) % 4];
                    b[2] = q[(x + r + 1) % 4];
                    long long val = 0;
                    for (int y = 0; y < 4; ++y) {
                        val = val * 1000 + b[y];
                    }
                    add(b, m);
                }
            }
            add(a[j], mp);
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
	
typedef long long ll;
typedef unsigned long long ull;
typedef long double db;
	
#define MOD 1000000007
#define mini 18446744073709551615
#define ff first
#define ss second
#define pb push_back
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T=1;
	//cin>>T;
	while(T--)
	{
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		cout<<max(max(a*c,a*d),max(b*c,b*d));
	}
	return 0;
}

Measured memory_bytes: 3688
def main():
    n,k = map(int, input().split())

    ls = []
    ans = 0

    for i in range(n):
        ab = list(map(int, input().split()))
        ls.append(ab)
    
    ls.sort()

    index = 0

    for i in range(n):
        if index < k:
            index += ls[i][1]
        if index >= k:
            ans = ls[i][0]
            break
    
    print(ans)
        

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 27872
import sys
X, K, D = map(int,input().split())
cnt = 0
a = X
b = 0
tmp = 0
if abs(X) >= K*D:
  if X > 0:
    print(X - K*D)  
  else:
    print(abs(X + K*D))
  sys.exit()
if K % 2 == 0:
  tmp = int(X/D)
  if tmp% 2 == 0:
    a = X - D*tmp
  else:
    a = X - D*tmp + D
  b = a - D*2
else:
  tmp = int(X/D)
  if tmp% 2 == 1:
    a = X - D*tmp
  else:
    a = X - D*tmp + D
  b = a - D*2
print(min(abs(a),abs(b)))



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

int main(){
    int n,a,b,sum,total,x;
    cin>>n>>a>>b;
    total=0;
    for(int i=1;i<=n;i++){
        sum=0;
        x=i;
        while(x!=0){
            sum=sum+x%10;
            x/=10;
        }
        if(sum>=a && sum<=b)
            total+=i;
    }
    cout<<total<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    long long x,y,a,b;
    scanf("%lld %lld",&x,&y);
    if(llabs(x-y)<2)printf("Brown");
    else
    {
        printf("Alice");
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [0]*N
B = [0]*N
C = [0]*N

lineA = list(map(int, input().split()))
lineB = list(map(int, input().split()))
lineC = list(map(int, input().split()))

for i in range( 1, lineA[0]+1 ): A[lineA[i]-1] = 1
for i in range( 1, lineB[0]+1 ): B[lineB[i]-1] = 1
for i in range( 1, lineC[0]+1 ): C[lineC[i]-1] = 1
    
ans = 0
for i in range( N ) :
    if ( ((not A[i]) and C[i]) or (B[i] and C[i]) ):
        ans += 1
print(ans)



Measured memory_bytes: 5604
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int n = sc.nextInt();
        Set<Integer> set = new HashSet<Integer>();
        
        for (int i = 0; i < n; i++) {
            set.add(sc.nextInt());
        }
        
        for (int i = 0; i <= 3000; i++) {
            if (!set.contains(x-i)) {
                System.out.println(x-i);
                return;
            }
            if (!set.contains(x+i)) {
                System.out.println(x+i);
                return;
            }
        }
        
    }
}


Measured memory_bytes: 35840
n=[int(i) for i in input().split()]
array=[]
abs_array=[]
for i in range(1,n[0]+1):
  array.append(n[1]+i-1)
  abs_array.append(abs(n[1]+i-1))
abs_array.sort()
if abs_array[0] in array :
  print(sum(array)-abs_array[0])
else:
  print(sum(array)+abs_array[0])

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

#define int long long
#define MAX2 47
#define MAX5 23
int g[10][MAX2][MAX5];
char s[20];

int32_t main(){
    memset(g, 0, sizeof g);
    int pot10[10]; pot10[0] = 1;
    for(int i = 1; i <= 9; ++i) pot10[i] = pot10[i - 1] * 10;

    int n; scanf("%lld", &n);

    int ans = 0;
    for(int i = 0; i < n; ++i){
        scanf("%s", s);
        string a, b; bool ponto = false;
        for(int j = 0; s[j]; ++j){
            if(s[j] == '.') ponto = true;
            else{
                if(!ponto) a.push_back(s[j]);
                else b.push_back(s[j]);
            }
        }
        string c = a + b;

        int x = stoll(c);
        int qntdFats2 = 0;
        int qntdFats5 = 0;

        while(x){
            if(x % 2 == 0){
                qntdFats2++;
                x /= 2;
            }else if(x % 5 == 0){
                qntdFats5++;
                x /= 5;
            }else{
                break;
            }
        }

        int numCasas = b.size();
        int qntdZeros = min(qntdFats2, qntdFats5);
        if(numCasas > 0 && qntdZeros > 0){
            qntdFats2 -= min(numCasas, qntdZeros);
            qntdFats5 -= min(numCasas, qntdZeros);
            numCasas -= min(numCasas, qntdZeros);
        }

        // cerr << "String fats2 fats5 casas\n";
        // cerr << s << " " << qntdFats2 << " " << qntdFats5 << " " << numCasas << endl;

        // query
        // se numCasas > 0, ou qntdFats2 > 0 ou qntdFats5 > 0
        // quero
        for(int i = 0; i < MAX2; ++i){
            for(int j = 0; j < MAX5; ++j){
                // i + qntdFats2 eh a qntd de fats2 no prod
                // j + qntdFats5 eh a qntd de fats5 no prod
                for(int k = 0; k < 10; ++k){
                    if(g[k][i][j] == 0) continue;
                    int prodFats2 = i + qntdFats2;
                    int prodFats5 = j + qntdFats5;
                    int casas = numCasas + k;
                    // cerr << casas << " " << prodFats2 << " " << prodFats5 << endl;
                    // cerr << g[k][i][j] << endl;
                    if(min(prodFats2, prodFats5) >= casas) ans += g[k][i][j];
                }
            }
        }

        // update
        for(int i = qntdFats2; i <= qntdFats2; ++i){
            for(int j = qntdFats5; j <= qntdFats5; ++j){
                g[numCasas][i][j]++;
            }
        }
    }
    printf("%lld\n", ans);
}


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

struct Node{
    int x,y,cost;
};

char s[51][51]={0};
bool visited[51][51]={0};
int dx[4]={0,1,0,-1}, dy[4]={-1,0,1,0};

int main(){
    int h, w;
    cin >> h >> w;
    int white = -2;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cin >> s[i][j];
            if(s[i][j] == '.')white++;
        }
    }

    queue<Node> que;
    que.push((Node){0,0,0});
    visited[0][0] = true;
    int cost = -1;
    while(!que.empty()){
        Node curr = que.front(); que.pop();
        if(curr.x == w-1 && curr.y == h-1){
            cost = curr.cost;
            break;
        }
        for(int i=0;i<4;++i){
            int nx = curr.x + dx[i], ny = curr.y + dy[i];
            if(nx >= 0 && nx < w && ny >= 0 && ny < h && !visited[ny][nx]
                && s[ny][nx] == '.'){
                visited[ny][nx] = true;
                que.push((Node){nx, ny, curr.cost+1});
            }
        }
    }

    if(cost == -1)cout << -1 << endl;
    else cout << white - cost + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 50

int F[N];

int fib(int n){
  if(n == 1 || n == 0) return F[n] = 1;
  if(F[n] != -1) return F[n];
  return F[n] = fib(n-1)+fib(n-2);
}

int main(){
  int n,i;

  for(i=0; i<N; i++){
    F[i] = -1;
  }

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;

}



Measured memory_bytes: 2044
n = int(input())
li = list(map(int,input().split()))

while len(li) > 1:
  a = min(li)
  for i in range(len(li)):
    if li[i] != a:
      li[i] %= a
  li = list(set(li))
  if 0 in li:
    li.remove(0)
      
print(li[0])
    

Measured memory_bytes: 14252
#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 INF 9999999999999
const double PI = acos(-1.0);
int N,M,X;
ll ans,ret;
struct book{
    int p;
    int a[12];
};
book b[12];
int skill[12];
bool ok;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> N >> M >> X;
    rep1(i,0,N){
        cin >> b[i].p;
        rep1(j,0,M)
            cin >> b[i].a[j];
    }

    ans = INF;
    for(int i = 0; i < (1 << N); i++){
        ret = 0;
        ok = true;
        memset(skill,0,sizeof(skill));
        for(int j = 0; j < N; j++){
            if(i & (1 << j)){
                rep1(k,0,M) skill[k] +=b[j].a[k];
                ret += b[j].p;
            }
        }
        rep1(j,0,M)
            if(skill[j] < X)
                ok = false;
        if(ok) ans = min(ans,ret);
    }
    if(ans == INF) cout << -1;
    else cout << ans;

    return 0;
}

Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int N, a[1000];
    scanf("%d\n", &N);
    for(int i=0; i<N; i++)
        scanf("%d", &a[i]);
    while(N){
        printf("%d", a[N-1]);
        if(N-1)
            printf(" ");
        N--;
    }
    printf("\n");
    return 0;
}

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

#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int N = 2002;

void solve() {
    
    string s;
    cin >> s;
    int n = s.size() , m = 2019 , h = 0 , cur = 1 , ans = 0;
    map<int , int> st;
    st[0] = 1;
    for(int i = n - 1 ; i >= 0 ;i --) {
        h = ((cur * (s[i] - '0')) % m  + h) % m;
        cur = (cur * 10) % m;
        ans += st[h];
        st[h] ++;
    }
    cout << ans;
    cout << '\n';
    return;
}

/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    while(testcase --) {
        solve();
    }
    
    return 0;
}
 



Measured memory_bytes: 3704
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    string s;
    cin >> s;

    bool ans = true;
    int i = s.size() - 1;
    while (i >= 0 && ans)
    {
        if (i >= 6 && s.substr(i - 6, 7) == "dreamer")
        {
            i -= 7;
        }
        else if (i >= 5 && s.substr(i - 5, 6) ==  "eraser")
        {
            i -= 6;
        }
        else if (i >= 4 && s.substr(i - 4, 5) == "dream")
        {
            i -= 5;
        }
        else if (i >= 4 && s.substr(i - 4, 5) == "erase")
        {
            i  -= 5;
        }
        else
        {
            ans = false;
        }
    }

    cout << (ans ? "YES\n" : "NO\n");
    return 0;
}



Measured memory_bytes: 512
fun main(args: Array<String>) {
    val N = nextInt()
    var n = 0
    var p = 11
    var ans = IntArray(N)
    while (p <= 55555 && n < N) {
        if (isPrime(p)) {
            ans[n] = p
            n += 1
        }
        p += 5
    }
    println(ans.joinToString(" "))
}
fun isPrime(n: Int): Boolean {
    if (n == 1) return false
    for (k in 2 .. Math.sqrt(n.toDouble()).toInt()) {
        if (n % k == 0) return false
    }
    return true
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfIntg(d: Int = 0) = listOfString().map { it.toInt() + d }


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

int main() {
  int n,m;
  cin >> n >> m;
  int count = 0;
  long long h[n+1];
  vector <int> v[n+1];
  for(int i = 1; i <= n; i++){
    cin >> h[i];
  }
  for(int i = 0; i < m; i++){
    int begin,end;
    cin >> begin >> end;
    v[begin].push_back(end);
    v[end].push_back(begin);
  }
  for(int i = 1; i <= n; i++){
    bool isGood = true;
    for(int j = 0; j < v[i].size(); j++){
      if(h[i] <= h[v[i][j]]){
        isGood = false;
      }
    }
    if(isGood){
      count++;
    }
  }
  cout << count;
}

Measured memory_bytes: 9472
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    ll n;
    cin >> n;
    int k = 1;
    while(true) {
        ll now = 1;
        rep(_,k) now *= 26;
        if(now < n) {
            n -= now;
            k++;
        } else break;
    }
    vi ans(k,0);
    ll now = 1;
    rep(_,k-1) {
        now *= 26;
    }
    rep(i,k) {
        ans[i] = (n+now-1)/now;
        n -= now*(ans[i]-1);
        now /= 26;
    }
    rep(i,k) cout << char('a'+ans[i]-1) << (i == k-1 ? "\n": "");
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main(void){
  int m, f, r;
  int total;
  char grade;

  while(true){
    cin >> m >> f >> r;
    if(m == -1 && f == -1 && r == -1)
      break;

    total = m + f;

    if(m == -1 || f == -1)
      grade = 'F';

    else if(total >= 80)
      grade = 'A';

    else if(total >= 65)
      grade = 'B';

    else if(total >= 50)
      grade = 'C';

    else if(total >= 30){
      if(r >= 50)
	grade = 'C';
      else
	grade = 'D';
    }
    else
      grade = 'F';
    // if else. end
    
    cout << grade << endl;

  }

  return 0;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define INF2 (1e18)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    dsu d(n);
    int ans = n-1;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        if (!d.same(a, b)) {
            d.merge(a, b);
            --ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3756
#include<iostream>
#include<cstdio>
#include<iomanip>
#include <math.h>
using namespace std;

int main() {
	int n, m, l;
	int p[200000];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> p[i];
	
	m = 300000;
	l = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] < m) {
			m = p[i];
			l++;
		}
	}


	cout << l << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	char mat[3][4];

	for (i = 0; i < 3; i++) {
		for (j = 0; j < 3; j++) {
			cin >> mat[i][j];
		}
	}

	cout << mat[0][0];
	cout << mat[1][1];
	cout << mat[2][2];


	getchar();
	getchar();
	return 0;
}

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

using namespace std;

#define fst first
#define snd second
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef pair<int,int> pii;

int n,m;
pii cost[110][110];

const int inf=1<<27;

int main(void){
	while(cin >> n >> m,n|m){
		rep(i,110)rep(j,110) cost[i][j].fst=cost[i][j].snd=((i==j)?0:inf);
		rep(i,n){
			int f,t;
			cin >> f >> t;
			f--;t--;
			int cos,tim;
			cin >> cos >> tim;
			cost[f][t].fst=cost[t][f].fst=cos; 
			cost[f][t].snd=cost[t][f].snd=tim;
		}

		rep(k,m)rep(i,m)rep(j,m){
			cost[i][j].fst=min(cost[i][j].fst,cost[i][k].fst+cost[k][j].fst);
			cost[i][j].snd=min(cost[i][j].snd,cost[i][k].snd+cost[k][j].snd);
		}
		int q;
		cin >> q;
		rep(i,q){
			int f,t,c;
			cin >> f >> t >> c;
			f--;t--;
			if(c)
				cout << cost[f][t].snd << endl;
			else
				cout << cost[f][t].fst << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1252
n, t = map(int, input().split())
a = list(map(int, input().split()))
INF = 10 ** 9 + 1

profit = [0] * n
buy_mn = INF
for i, e in enumerate(a):
    profit[i] = e - buy_mn
    buy_mn = min(buy_mn, e)

profit_mx = max(profit)
ans = profit.count(profit_mx)
print(ans)


Measured memory_bytes: 15020
import itertools
N = int(input())
P = tuple(map(lambda x: int(x), input().split()))
Q = tuple(map(lambda x: int(x), input().split()))

p = list(itertools.permutations([i for i in range(1, N+1)], N))
print(abs(p.index(P) - p.index(Q)))

Measured memory_bytes: 8052
k = int(input())
if k==1 or k==7:
  print(1)
elif k%2==0:
  print(-1)
else:
  cnt = 1
  pre = 7
  while(True):
    surp = (pre*10+7)%k
    cnt += 1
    if surp==0:
      break
    if cnt>1000000:
      cnt = -1
      break
    pre = surp
  print(cnt)

Measured memory_bytes: 9048
using System;
using System.IO;
using System.Text;
using static Scanner;
using static System.Math;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        var S = Scan().AsSpan();
        long answer = 0;
        var sb = new StringBuilder();
        while (S.IndexOf("><") != -1) {
            answer += Calc(sb.Append(S[..(S.IndexOf("><") + 1)]));
            S = S[(S.IndexOf("><") + 1)..];
        }
        answer += Calc(sb.Append(S));
        Console.WriteLine(answer);

        static long Calc(StringBuilder sb) {
            long lt = sb.Length - sb.Replace("<", "").Length;
            long gt = sb.Length - sb.Replace(">", "").Length;
            var max = Max(lt, gt);
            sb.Clear();
            return max + lt * (lt - 1) / 2 + gt * (gt - 1) / 2;
        }
    }
}

public static class Scanner
{
    static readonly Stream stdin = Console.OpenStandardInput();
    static readonly byte[] buffer = new byte[1024];
    static int length, p;
    static bool isEof;
    private static byte StdIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stdin.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = StdIn();
        while ((by < '!' || '~' < by) && !isEof) by = StdIn();
        return (char) by;
    }
    public static string Scan() {
        var sb = new StringBuilder();
        for (var ch = GetChar(); '!' <= ch && ch <= '~'; ch = (char) StdIn()) {
            sb.Append(ch);
        }
        return sb.ToString();
    }
}

Measured memory_bytes: 37912
#include<iostream>
using namespace std;
int main() {

	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int m = (h2 - h1) * 60 + m2 - m1;
	cout << m - k << endl;
	return 0;
	

}

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

#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    int N;
    cin >> N;

    vector<int> L(2 * N);
    forn(i, 2 * N)
        cin >> L[i];

    sort(L.begin(), L.end());

    int ans = 0;
    forn(i, N)
        ans += L[2 * i];

    cout << ans << endl;
}


Measured memory_bytes: 256
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
P = [(int(x) + 1) / 2 for x in stdin.readline().rstrip().split()]

D = sum(P[:K])
index = 0
ans = D

for i in range(1, N - K + 1):
    if D + P[i + K - 1] - P[i - 1] > ans:
        ans = D + P[i + K - 1] - P[i - 1]
    D = D + P[i + K - 1] - P[i - 1]
print(ans)


Measured memory_bytes: 71792