akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
#Union-Find木
#par[i]:iの親　deep[i]:iの深さ　size[i]:iの大きさ
par=[i for i in range(n)]
deep=[1]*n
size=[1]*n

#親を見つける
def find(x):
  if par[x]==x:
    return x
  else:
    return find(par[x])

#二つのグループを統合する
def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return
  if deep[x]<deep[y]:
    par[x]=y
    size[y]+=size[x]
  else:
    par[y]=x
    size[x]+=size[y]
    if deep[x]==deep[y]:
      deep[x]+=1

#xとyが同じグループに属するかどうか
def same(x,y):
  return find(x)==find(y)

#xが属するグループの要素数を返す
def group_count(x):
  return size[find(x)]

#連結成分の個数を返す
def count():
  check=set()
  for i in range(n):
    parent=find(i)
    if parent not in check:
      check.add(parent)
  return len(check)

for i in range(m):
  a,b=map(int,input().split())
  unite(a-1,b-1)
s=count()
print(s-1)
    
  


Measured memory_bytes: 87892
#include <bits/stdc++.h>
using namespace std;
 
int getnum() {
  char C;
  while(!isdigit(C = getchar()));
  int n = C - '0';
  while(isdigit(C = getchar())) n = n * 10 + C - '0';
  return n;
}
 
int main() {
  string S;
  map<string,int> ans{};
  int N = getnum();
  while(N--){
    cin >> S;
    ans[S]++;
  }
  N = getnum();
  while(N--){
    cin >> S;
    ans[S]--;
  }
  int maxans = 0;
  for(auto itr = ans.begin(); itr != ans.end(); itr++) maxans = max(maxans, itr->second);
  printf("%d\n", maxans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    reverse(s.begin(), s.end());

    string ans = "";
    int cnt = 0;
    for (int i=0; i<n; i++) {
        while(s[i] == 'B') i++,cnt++;
        if (cnt > 0) {
            cnt--;
            continue;
        }

        ans += s[i];
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
def seprate(string):
    return int(string)%m
A = list(map(seprate,input().split()))

S = [0]*n
sm = 0
ans = 0
import math
def Comb(a,b):#aCbを返す
    if a>= b:
        return int(math.factorial(a)/(math.factorial(b)*math.factorial(a-b)))
    else:
        return 0

for a,i in zip(A,range(n)):
    sm = (sm+a)%m
    S[i] += sm
S.sort()
temp= S[0]
c = 1
zeros = 1 if temp == 0 else 0
for s in S[1:]:
    if s == 0:
        zeros += 1
        c += 1
    elif temp == s:
        c += 1
    else:
        ans += Comb(c,2)
        c = 1
    temp = s
ans += Comb(c,2)+zeros
print(ans)

Measured memory_bytes: 14404
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    rep(i,n){
        if(s[i] == '2') ++cnt;
    }   
    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef pair<int,int> abcd;

const int N=510;

int n,m;
char a[N][N],b[N][N],c[N][N];
set<int> h[N],w[N];

int main(){
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++){
    scanf("%s",a[i]+1);
    for(int j=1;j<=m;j++){
      if(a[i][j]=='#') h[i].insert(j),w[j].insert(i);
      b[i][j]=c[i][j]='.';
    }
  }
  for(int i=1;i<=n;i++) b[i][1]=c[i][m]='#';
  for(int i=1;i<=n;i++)
    if(i&1)
      for(int j=1;j<=m-1;j++) b[i][j]='#';
    else
      for(int j=2;j<=m;j++) c[i][j]='#';
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
      if(a[i][j]=='#') b[i][j]=c[i][j]='#';
  for(int i=1;i<=n;i++) puts(b[i]+1);
  puts("");
  for(int i=1;i<=n;i++) puts(c[i]+1);
  return 0;
}


Measured memory_bytes: 24832
#include <stdio.h>

int main(void) {
    int n,k,s,a[100000],i,j,l;
    scanf("%d %d %d",&n,&k,&s);
        for(i=0;i<k;i++) a[i]=s;
    if(s<1000000000)    for(i=k;i<n;i++) a[i]=s+1;
    else for(i=k;i<n;i++) a[i]=1;
    for(i=0;i<n;i++) printf("%d ",a[i]);
	return 0;
}



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

int main() {
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    if(abs(c-a)<=d || (abs(b-a)<=d&&abs(c-b)<=d)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
	fast;
	int arr[3][3];
	for(int i = 0 ;i < 3 ; i++ ){
		for(int j = 0 ; j <3 ; j++){
			cin >> arr[i][j];
		}
	}
	int n;
	cin >> n;
	int b[n];
	for(int i = 0 ; i < n ; i ++ )
	{
		cin >> b[i];
		for(int j = 0 ; j < 3 ; j ++ ){
			for(int k = 0 ; k < 3 ; k++ ){
				if(arr[j][k]==b[i]){
					arr[j][k]=-1;
				}
			}
		}
	}
	int c = 0;
	for(int i = 0 ; i < 3 ; i++ ){
		c = 0;
		for(int j = 0 ; j < 3 ; j ++ ){
			if(arr[i][j]==-1){
				c++;
			}
		}
		if(c==3){
			cout<<"Yes";
			return 0;
		}
	}
	c = 0;
	for(int i = 0 ; i < 3 ; i++ ){
		c = 0;
		for(int j = 0 ; j < 3 ; j ++ ){
			if(arr[j][i]==-1){
				c++;
			}
		}
		if(c==3){
			cout<<"Yes";return 0;
		}
	}
	if(arr[0][0]==-1 && arr[1][1]==-1 && arr[2][2]==-1){
		cout<<"Yes";
		return 0;
	}
	if(arr[0][2]==-1 && arr[1][1]==-1 && arr[2][0]==-1){
		cout<<"Yes";return 0;
	}
	cout<<"No";
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>
#include <set>
using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM = 1000000007;

int distance(vector<ll> &A, ll base)
{
    // cout << base << endl;
    vector<ll> amari;
    ll d = 0;
    ll amari_total = 0;
    for (auto a : A)
    {
        amari_total += a % base;
        amari.push_back(a % base);
    }
    // cout << "amari_total" << amari_total << endl;
    sort(amari.begin(), amari.end(), greater<ll>());
    ll nokori = amari_total;
    if (nokori != 0)
    {
        for (int i = 0; i < amari.size(); i++)
        {
            d += base - amari[i];
            nokori = nokori - amari[i];

            if (d == nokori)
            {
                break;
            }
        }
    }

    return d;
}

int main()
{
    // 整数の入力
    ll N, K, total, ans;
    vector<ll> A;
    total = 0;
    ans = 0;
    cin >> N >> K;
    for (int i = 1; i <= N; i++)
    {
        ll a;
        cin >> a;
        total += a;
        A.push_back(a);
    }
    // cout << total << endl;
    for (ll i = 1; i * i <= total; i++)
    {
        if (total % i == 0)
        {
            ll d1 = distance(A, i);
            if (d1 <= K)
            {
                ans = max(ans, i);
            }
            // cout << i << " " << d1 << endl;

            ll d2 = distance(A, total / i);
            if (d2 <= K)
            {
                ans = max(ans, total / i);
            }

            // cout << total / i << " " << d2 << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cstring>
using namespace std;
#define ll long long
ll n, k;
ll arr[100005];
ll rs[100005];
ll answer = 0;
vector<ll> v;

int main(){
	scanf("%lld%lld", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%lld", &arr[i]);
	}
	
	for (int i = 1; i <= n; i++){
		rs[i] = arr[i - 1] + rs[i - 1];
	}
	ll starting = 0;
	ll ending = 0;
	for (int i = k; i < n; i++){
		if (arr[i] > 0){
			ending += arr[i];
		}
	}
	
	for (int i = 0; i <= n - k; i++){
		answer = max(answer, rs[i + k] - rs[i] + starting + ending);
		answer = max(answer, starting + ending);
		if (arr[i] > 0){
			starting += arr[i];
		}
		if (arr[i + k] > 0){
			ending -= arr[i + k];
		}
	}
	
	printf("%lld\n", answer);
	
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

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

const int INF = 1e9;

int main() {
    int n, m, x, ans=INF;
    bool f = false;
    int c[12], a[12][12];

    std::cin >> n >> m >> x;
    rep(i, n) {
        std::cin >> c[i];
        rep(j, m) std::cin >> a[i][j];
    }

    rep(v, 1<<n) {
        std::vector<int> check(m, 0);
        int cost=0;
        rep(i, n) {
            if ((v >> i) & 1) {
                cost += c[i];
                rep(j, m) check[j] += a[i][j];
            }
        }
        bool g = true;
        rep(j, m) g &= check[j] >= x;
        if (g) ans = std::min(cost, ans);
    }
    if (ans == INF)
        std::cout << -1 << std::endl;
    else
        std::cout << ans << std::endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> l(n), d(n+1);
    for(int i = 0; i < n; i++) cin >> l[i];
    d[0] = 0;
    int ans = 0;
    for(int i = 1; i < n+1; i++){
        d[i] = d[i-1] + l[i-1];
        if(d[i] <= x) ans++;
    }
    cout << ans+1 << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class ALDS1
{

     struct X
    {
        public string c;
        public int d;
    };

    static void Main()
    {
        string str1 = Console.ReadLine();
        int a = int.Parse(str1.Split(' ')[0]);
        int b = int.Parse(str1.Split(' ')[1]);
        X[] x = new X[200000];
        int e = 0;
        for (int i = 0; i < a; i++)
        {
            string str2 = Console.ReadLine();
            x[i].c = str2.Split(' ')[0];
            x[i].d = int.Parse(str2.Split(' ')[1]);
        }
        for (int i = 0; i < a; i++)
        {
            x[i].d -= b;
            if (x[i].d <= 0)
            {
                e += x[i].d + b;
                Console.WriteLine(x[i].c +" "+ e);
            }
            else
            {
                x[a] = x[i];
                e += b;
                a++;
            }
        }
    }
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int h,w;
string table[110];
int dist[110][110][4];

char dir[4]={'N','E','S','W'};

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


int si(ll arg){
	rep(i,h)rep(j,w)rep(k,4) dist[i][j][k]=inf;

	int cx,cy,cd,cur=0;

	rep(i,h)rep(j,w)rep(k,4){
		if(table[i][j]==dir[k]){
			dist[i][j][k]=0;
			cy=i,cx=j,cd=k;
		}
	}

	int start,end;

	while(1){
		rep(i,3){
			int nd=(cd+i)%4;
			int nx=cx+dx[nd];
			int ny=cy+dy[nd];
			if(0<=nx&&nx<w&&0<=ny&&ny<h&&table[ny][nx]!='#'){
					cy=ny,cx=nx,cd=nd;
					cur++;
					break;
			}
		}

		if(dist[cy][cx][cd]!=inf){
			start=dist[cy][cx][cd];
			end=cur;
			break;
		}
		dist[cy][cx][cd]=cur;
	}
	if(arg<=end)
		return arg;
	else
		return (arg-start)%(end-start)+start;
}

int main(void){
	ll l;
	while(cin >> h >> w >> l){
		rep(i,h) cin >> table[i];
		if(h==0)
			break;
		int ans=si(l);
		rep(i,h)rep(j,w)rep(k,4){
			if(dist[i][j][k]==ans)
				cout << i+1 << " " << j+1 << " " << dir[k] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1412
d = {
    range(400, 600): 8,
    range(600, 800): 7,
    range(800, 1000): 6,
    range(1000, 1200): 5,
    range(1200, 1400): 4,
    range(1400, 1600): 3,
    range(1600, 1800): 2,
    range(1800, 2000): 1,
}
x = int(input())
for k, v in d.items():
    if x in k:
        print(v)

Measured memory_bytes: 61988
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>


using namespace std;

vector<int> array_left_rotation(vector<int> a, int n, int k) {
    
}

int main(){
    string a;
    string b;
    int i=1;
    cin >> a >> b;
    if(a[0]=='H'){
    }
    else{
      i=i*(-1);
    }
    if(b[0]=='H'){
    }
    else{
      i=i*(-1);
    }
    if(i==1){
      cout <<"H" <<endl; 
      }
    else{
      cout << "D"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = []
n.times{ a.push (gets.chomp.to_i) }
ans = a[0] - 1
a[0] = 1
th = 2
(1...n).each{ |i|
	if a[i] == th
		th += 1
	else
		ans += (a[i] - th - 1) / th + 1
	end
}
puts ans


Measured memory_bytes: 2684
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n[4], a[4] = {1, 4, 7, 9};
	for(int i = 0; i < 4; scanf("%d", &n[i++])){}
	sort(n, n + 4);	
	for(int i = 0; i < 4; ++i)
	{
		if(n[i] != a[i])
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
}

Measured memory_bytes: 764
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const int N=1e5+10;

int main(){
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n,k;
  cin>>n>>k;
  vector<int> dp(n,(int)1e9);
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
    for(int j=i-1;j>=max(0,i-k);j--){
      dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
    }
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<string.h>

#define M /* your task*/ 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return /* your task */ key % M; }
int h2(int key){ return /* your task */ 1+(key % (M-1)); }

int find(char str[]){
  /* your task */
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0){
      return 1;
    }else if(strlen(H[h])==0){
      return 0;
    }
  }
}

int insert(char str[]){
  /* your task */
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0){
      return 1;
    } else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
}

int main(){
  int i, n;
  char str[L], com[9];
  for ( i = 0; i < M; i++)H[i][0] = '\0';
    
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
	
    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
	printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }

  return 0;
}



Measured memory_bytes: 15460
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=10001;
char s[maxn];
int ans[maxn],lst[maxn];
signed main()
{
	cin>>s+1;
	int len=strlen(s+1);
	for(int i=1;i<=len;i++)
	{
		ans[s[i]]=max(ans[s[i]],i-lst[s[i]]-1),lst[s[i]]=i;
	}
	int anss=1e9;
	for(int i='a';i<='z';i++)
	{
		ans[i]=max(ans[i],len-lst[i]);
		anss=min(anss,ans[i]);
	}
	cout<<anss;
    
}
/*
规则就是每次相邻二选一产生一个新的串
whbrjpjyhsrywlqjxdbrbaomnw
*/

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

using namespace std;

const int N = 100000 + 7;

typedef long long ll;

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

  vector<double> v;
  for(int i = 0; i < n; ++i) {
    double x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());

  double ans = v[0];

  for(int i = 1; i < n; ++i) {
    ans += v[i];
    ans /= 2.0;
  }

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


Measured memory_bytes: 256
import numpy as np
N , M = map(int,input().split())
food_list = np.zeros(M)
for i in range(N):
    work = list(map(int,input().split()))
    work.pop(0)
    for idx in work:
        food_list[idx - 1] += 1
cnt = 0
for food in food_list:
    if food == N:
        cnt += 1
print(cnt)

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

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

    int w, l;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'o') {
            w += 1;
        }
        else {
            l += 1;
        }
    }

    if (s.length() <= 7) {
        cout << "YES" << "\n";
    }
    else {
        int rest = 15 - s.length();
        if (w >= (8 - rest)) {
            cout << "YES" << "\n";
        }
        else {
            cout << "NO" << "\n";
        }
    }
    return 0;
}

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

/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
 
 
ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/
/*
struct UnionFind{
    vector<int> par;
    vector<int> rank;
    vector<int> size;

    //こいつがいわゆるコンストラクタ
    //初期化している
    UnionFind(int N) : par(N),rank(N),size(N){
        for(int i=0;i<N;i++){
            par[i]=i;
            size[i]=1;
            rank[i]=0;
        }
    }

    int find(int x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }


    void unite(int x, int y){
        int rx,ry;
        rx = find(x);
        ry = find(y);
        if(rx == ry){
            return;
        }
        else{
            if(rank[rx]<rank[ry]){
                par[rx]=ry;
                size[ry]+=size[rx];
            }
            else{
                par[ry]=rx;
                size[rx]+=size[ry];
                if(rank[rx]==rank[ry]){
                    rank[rx]++;
                }
            }
        }
    }


    bool same(int x,int y){
        return find(x) == find(y);
    }
};
*/

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<ll> ans(4);
    ans.at(0)=a*c;
    ans.at(1)=a*d;
    ans.at(2)=b*c;
    ans.at(3)=b*d;
    sort(ans.begin(),ans.end());
    reverse(ans.begin(),ans.end());
    cout<<ans.at(0)<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// DAME:
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll inf = ll(1e18)+1;
    ll left = -inf, right = inf;
    // mid以下のものを数える
    while(left+1 < right){
        ll mid = (left+right)/2;
        ll cnt = 0;
        rep(i, n){
            ll tmp = a[i];
            if (tmp>0){
                int l = -1, r = n;
                while(l+1<r){
                    int c = (l+r)/2;
                    if(a[c]*tmp <= mid) l = c;
                    else r = c;
                }
                cnt += r;
            }else if (tmp==0){
                if (mid>=0) cnt+=n;
            }else{
                int l = -1, r = n;
                while(l+1<r){
                    int c = (l+r)/2;
                    if(a[c]*tmp <= mid) r = c;
                    else l = c;
                }
                cnt += n-r;
            }
            if (tmp*tmp <= mid) cnt--;
        }
        cnt /= 2;
        if (cnt >= k){
            right = mid;
        }else{
            left = mid;
        }
    }

    cout << right << endl;
    return 0;
}

Measured memory_bytes: 1792
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int K = Integer.parseInt(st.nextToken());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         //sort(arr);
         int res = K+arr[0]-arr[N-1];
         for(int i=0; i < N-1; i++)
            res = Math.max(res, arr[i+1]-arr[i]);
         System.out.println(K-res);
      }
      public static void sort(int[] arr)
      {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   }

Measured memory_bytes: 47828
#include<iostream>
#include<queue>
#include<algorithm>
#include <functional>
using namespace std;
typedef vector<int> VI;
int n,k;
VI topic[11];
int DP[11][2001];
int main(){
	int i,t,u,qsize[10] = {0};
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>t>>u;
		u--;
		topic[u].push_back(t);
		qsize[u]++;
	}
	for(i=0;i<11;i++){
		for(int j=0;j<2001;j++){
			DP[i][j] = -1;
		}
		sort(topic[i].begin(),topic[i].end(),greater<int>());
	}
	DP[0][0]=0;
	//ジャンル番号の低いほうから売る本の数(0<=x<=size)を考える。
	//売った本の冊数と、今から売ることが可能な冊数が同じならば、
	//その時の売り上げが最大のものをとってみる。
	for(i = 0;i < 10;i++){
		for(int j = 0;j <= k;j++){
			if(DP[i][j]==-1)
				continue;
			int gokei;
			gokei = 0;
			for(int l = 0;l <= qsize[i] && j+l <= k;l++){
				if(DP[i+1][j+l] < DP[i][j]+gokei+(l>1?l*l-l:0)){
					DP[i+1][j+l] = DP[i][j]+gokei+(l>1?l*l-l:0);
				}
				if(l < qsize[i])
					gokei += topic[i][l];
			}
		}
	}
	//あとはk冊売った集合から最大値を貪欲法で探す
	int saidai = 0;
	for(i = 0;i < 11;i++){
		if(saidai < DP[i][k])
			saidai = DP[i][k];
	}
	cout << saidai << endl;
	return 0;
}

Measured memory_bytes: 1320
<?php
fscanf( STDIN, "%s", $str );

$len = strlen( $str );
$last = $len - 1;
$middle = $len >> 1;
for( $i = 0; $i < $middle; $i ++ ){
  $j = $last - $i;
  list( $str[$j], $str[$i] ) = [ $str[$i], $str[$j] ];
}

printf("%s\n",$str);

Measured memory_bytes: 15352
A, B, C = map(int, input().split())

A_mod = []
i = 1
while 1:
    x = (A*i)%B
    if x in A_mod:
        break
    A_mod.append(x)
    i += 1

A_mod.remove(0)
A_mod = sorted(A_mod)
s = 0
for a in A_mod:
    while s < C:
        s += a

if s == C:
    print('YES')
else:
    print('NO')




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

using ll = long long;

int main() {
    int N;
    cin >> N;
    ll res1 = 0, res2 = 0;
    for(int i=0; i<N; ++i) {
        if(i == 0) {
            cin >> res1 >> res2;
        } else {
            ll t, a;
            cin >> t >> a;
            ll m = (res1 % t == 0) ? res1 / t : res1 / t + 1;
            m = max(m, (res2 % a == 0 ? res2 / a : res2 / a + 1));
            res1 = t * m;
            res2 = a * m;
        }
    }
    cout << res1 + res2 << endl;
}


Measured memory_bytes: 256
s = str(input())

numberOfSubstrings = 0
i = 0
while i < len(s)-1:
    if s[i] == s[i+1]:
        if i+2 < len(s):
            i += 3
            numberOfSubstrings += 2
        else:
            i += 2
            numberOfSubstrings += 1
    else:
        i += 1
        numberOfSubstrings += 1

if len(s) > 1 and i <= len(s)-1:
    numberOfSubstrings += 1

print(numberOfSubstrings)


Measured memory_bytes: 3500
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  int a[n]={};
  multiset<int> se;
  rep(i,n){
    cin >> a[i];
  }
  int ans=0;
  rep(i,n){
    if(i==0){
      se.insert(a[i]);
      continue;
    }
    auto it=se.lower_bound(a[i]);
    if(it==se.begin()){
      se.insert(a[i]);
    }else{
      it--;
      se.erase(it);
      se.insert(a[i]);
    }
  }
//  for(auto i=se.begin();i!=se.end();i++)cout << *i << endl;
  cout << se.size() << endl;
return 0;}

Measured memory_bytes: 5376
# C - たくさんの数式
s = list(input())
n = len(s)
a = 0
for i in range(2 ** (n-1)):
    l = []
    l.append(s[0])
    for j in range(n-1):
        if (i & 1 << j):
            l.append('+')
        l.append(s[j+1])
    a += eval(''.join(l))

print(a)



Measured memory_bytes: 8980
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-5-26 21:11:43
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
int A[200010];
ll X[200010];

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  int l = 0, r = 0;
  int sum = 0;
  while (l < N)
  {
    while (r < N && (sum + A[r] == (sum | A[r])))
    {
      sum += A[r++];
    }
    X[l] = r - 1;
    sum -= A[l++];
  }
  ll ans = 0;
  for (auto i = 0; i < N; i++)
  {
    // cerr << "X[" << i << "] = " << X[i] << endl;
    ans += X[i] - i + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
/***************************************************************\
 * half --
 *
 * Author: Cobalt Sato
 *
 * Purpose:
 *
 * Usage:
 *
 * Repository:
 *
 * Reference:
 *
 * File formats:
 *
 * Restrictions:
 *
 * Error handling:
 *
 * Warning:
 *
 * Notes:
 *
\***************************************************************/
#include <iostream>
#include <cassert>
#include <string>

using namespace std;
int main()
{
  /* input */
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
//cout << A << endl;
 // cout << B << endl;
 // cout << C << endl;
 // cout << X << endl;
 // cout << Y << endl;

  int m;
  int sum = 0;

  if ((A+B)/2 < C){
    sum += A * X + B * Y;
  }
  else {
    if (X < Y) {
      m = X;
    } else {
      m = Y;
    }
    //cout << m << endl;
    sum += C*2*m;
    if (X - m > 0) {
      if (2*C < A){
        sum += 2*C*(X-m);
      } else {
        sum += A*(X-m);
      }
    } else {
      if (2*C < B){
        sum += 2*C*(Y-m);
      } else {
        sum += B*(Y-m);
      }
    }
  }
  cout << sum;
  return (0);
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
    long long int n, i, j, flag;
    scanf("%lld", &n);
    flag = n;

    for(i=1; i<=sqrt(n); i++){
        if(n%i == 0 && (i+(n/i)-2)<flag)
            flag = i+(n/i)-2;
    }
    printf("%lld", flag);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<utility>
#define INF -1000000000000000000
#define WHITE 0
#define BLACK 1
using namespace std;

typedef long long ll;

ll dist[1005];
ll prev_node[1005];
ll color[1005];
pair<pair<ll, ll>, ll> adj[2005];

int main() {
    int N, M;
    cin >> N >> M;
    ll a, b, c;
    for (int i = 0; i < M; i++) {
        cin >> a >> b >> c;
        adj[i] = make_pair(make_pair(a, b), c);
    }
    for (int i = 1; i <= N; i++) {
        dist[i] = INF;
        prev_node[i] = INF;
        color[i] = WHITE;
    }
    dist[1] = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int e = 0; e < M; e++) {
            if (dist[adj[e].first.second] < dist[adj[e].first.first] + adj[e].second) {
                dist[adj[e].first.second] = dist[adj[e].first.first] + adj[e].second;
                prev_node[adj[e].first.second] = adj[e].first.first;
            }
        }
    }
    ll parent = N;
    color[N] = BLACK;
    while (prev_node[parent] != INF) {
        if (color[prev_node[parent]] != BLACK) {
            color[prev_node[parent]] = BLACK;
            parent = prev_node[parent];
        }
        else {
            cout << "inf" << endl;
            return 0;
        }
    }
    cout << dist[N] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<boost/multiprecision/cpp_int.hpp>
#define F for(j=i;(j+=i)<m;)b[i]-=n*b[j]
int n,m=1<<20,a,i,j;boost::multiprecision::cpp_int b[1<<20],s;main(){for(std::cin>>n;n--;b[a]+=a,s-=a)std::cin>>a;for(;++i<m;b[i]*=b[i])F;for(n=1;--i;s+=b[i]/i)F;std::cout<<s/2%998244353;}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int gcd(int a, int b){
	return (b > 0)? gcd(b, a % b) : a ;
}
int main(){
	int A, B, C; 
	cin >> A >> B >> C;
	int G = gcd(A, B); 
	if(C % G == 0){cout << "YES" << endl;}
	else{cout << "NO" << endl;}
}

Measured memory_bytes: 256
a=int(input())
if a==7:
  print("YES")
if a>7:
  print("NO")
if a<7:
  if a>3:
    if a==5:
      print("YES")
if a<7:
  if a>3:
    if a!=5:
      print("NO")
if a==3:
  print("YES")
if a<3:
  print("NO")

Measured memory_bytes: 3060
import java.util.*;
public class Main 
{
	static int[] dp = new int[32];
	static void DPCalc()
	{
		dp[0] = 1;
		dp[1] = 1;
		dp[2] = 2;
		for(int i = 0; i < 28; ++i)
		{
			dp[i + 3] = dp[i] + dp[i + 1] + dp[i + 2];
		}
	}
	
	public static void main(String[] args) 
	{
		DPCalc();
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int num = stdIn.nextInt();
			if(num == 0)
			{
				break;
			}
			System.out.println(dp[num] / 365 / 10 + 1);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;

int gcd_2(int a, int b){
	int r, tmp;
	if(a<b){
		tmp = a;
		a = b;
		b = tmp;
	}
	r = a % b;
	while(r != 0){
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int gcd_3(int a, int b, int c){
	int tmp = gcd_2(a,b);
	return gcd_2(tmp,c);
}

signed main()
{
	int k;
	cin >> k;
	int sum = 0;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int l=1;l<=k;l++){
				sum += gcd_3(i,j,l);
				//printf("%d",gcd_3(i,j,))
			}
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 3624
#include <iostream>

int main(int argc, char *argv[]) {
  int a, b, c;
  std::cin >> a >> b;
  if (a % 2 == 0 || b % 2 == 0)
    std::cout << "No"<< std::endl;
  else
    std::cout << "Yes" << std::endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
listA = []
listB = []
pntA = pntB = 0 

for i in range(n):
    A, B = map(str, input().split())
    listA.append(A)
    listB.append(B)

    if listA[i] > listB[i]:
        pntA += 3
    elif listA[i] == listB[i]:
        pntA += 1
        pntB += 1
    else:
        pntB += 3

print(str(pntA) + ' ' + str(pntB)) 


Measured memory_bytes: 5628
#include <stdio.h>

int main(void){

  int a, b, c;

  scanf("%d %d %d", &a, &b, &c);

  if (((a < c) && (c < b)) || ((a > c) && (c > b))) {
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;

}


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

int main()
{
    int n;
    cin>>n;
    int v[n+20],v2[n+20];
    v[n]=10;
    int maxx=0;
    for(int i=0; i<n; i++){
        cin>>v[i];
        if(v[i]>maxx)
            maxx=v[i];
    }
    int ttlz=0,ttl=0,fr,ls;
    for(int i=0; i<maxx; i++){
        ttlz=0;
        fr=v[0];ls=v[n-1];
        for(int j=0; j<n; j++){
            if(v[j]==0&&v[j+1]!=0){
                ttlz++;
            }
            if(v[j]!=0){
                v[j]--;
            }
        }
        if(ttlz==0)
            ttl++;
        if(ttlz>0){
            if(fr!=0&&ls!=0)
                ttl+=(ttlz+1);
            else if(fr==0&&ls==0)
                ttl+=(ttlz-1);
            else
                ttl+=ttlz;
        }
    }


    cout<<ttl;
    return 0;
}


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

int main() {
  long long a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  if(a==b){
    cout<<"YES"<< endl;
    return 0;
  }
  if(a>b){
    if(b-w*t<a-v*t){
      cout<<"NO"<< endl;
      return 0;
    }
    else{
      cout<<"YES"<< endl;
      return 0;
    }
  }
  if(b>a){
    if(b+w*t>a+v*t){
      cout<<"NO"<< endl;
      return 0;
    }
    else{
      cout<<"YES"<< endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3648
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N;
    vector<int> H(100010);
    cin >> N;
    for (int i=0;i<N;i++) cin >> H[i];
    vector<bool> R(100010,false);
    vector<int> C(100010,0);
    for (int i=0;i<N-1;i++) {
        if (H[i]>=H[i+1]) R[i] = true;
    }
    C[N-1] = 0;
    for (int i=N-2;i>=0;i--) {
        if (R[i]) C[i] = C[i+1] + 1;
    }
    auto itr = max_element(C.begin(), C.end());
    cout << *itr << endl;

    return 0;
}


Measured memory_bytes: 1024
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<LL,LL> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

const int maxn=1e6+5,v=5e5,N=1e6;
struct node {int x,y,dir;} a[maxn];
VI x[maxn],y[maxn],p[maxn],q[maxn];
int n,ans=1e9;
char s[10];
bool cmp1(int i,int j) {return a[i].x==a[j].x?a[i].y<a[j].y:a[i].x<a[j].x;}
bool cmp2(int i,int j) {return a[i].y==a[j].y?a[i].x<a[j].x:a[i].y<a[j].y;}

int main()
{
    n=read();
    REP(i,1,n)
    {
        a[i].x=read();
        a[i].y=read();
        scanf("%s",s);
        a[i].dir=s[0];
    }
    sort(a+1,a+n+1,[&](node a,node b){return a.x==b.x?a.y<b.y:a.x<b.x;});
    REP(i,2,n) if(a[i].x==a[i-1].x && a[i].y==a[i-1].y) return puts("0"),0;
    REP(i,1,n)
    {
        x[a[i].x+v].pb(i);
        y[a[i].y+v].pb(i);
        p[a[i].y-a[i].x+v].pb(i);
        q[a[i].y+a[i].x+v].pb(i);
    }

    REP(i,1,N)
    {
        sort(x[i].begin(),x[i].end(),cmp1);
        sort(y[i].begin(),y[i].end(),cmp2);
        sort(p[i].begin(),p[i].end(),cmp1);
        sort(q[i].begin(),q[i].end(),cmp1);
    }

    REP(i,1,N) if(x[i].size()>1)
    {
        int yy=-1;
        REP(j,0,x[i].size()-1)
        {
            int id=x[i][j];
            if(yy>=0 && a[id].dir=='D') ans=min(ans,abs(a[id].y-yy)*5);
            if(a[id].dir=='U') yy=a[id].y;
        }
    }
    REP(i,1,N) if(y[i].size()>1)
    {
        int xx=-1;
        REP(j,0,y[i].size()-1)
        {
            int id=y[i][j];
            if(xx>=0 && a[id].dir=='L') ans=min(ans,abs(a[id].x-xx)*5);
            if(a[id].dir=='R') xx=a[id].x;
        }
    }
    REP(i,1,N) if(p[i].size()>1)
    {
        int xx1=-1,xx2=-1;
        REP(j,0,p[i].size()-1)
        {
            int id=p[i][j];
            if(xx1>=0 && a[id].dir=='L') ans=min(ans,abs(a[id].x-xx1)*10);
            if(xx2>=0 && a[id].dir=='D') ans=min(ans,abs(a[id].x-xx2)*10);
            if(a[id].dir=='U') xx1=a[id].x;
            if(a[id].dir=='R') xx2=a[id].x;
        }
    }
    REP(i,1,N) if(q[i].size()>1)
    {
        int xx1=-1,xx2=-1;
        REP(j,0,q[i].size()-1)
        {
            int id=q[i][j];
            if(xx1>=0 && a[id].dir=='U') ans=min(ans,abs(a[id].x-xx1)*10);
            if(xx2>=0 && a[id].dir=='L') ans=min(ans,abs(a[id].x-xx2)*10);
            if(a[id].dir=='R') xx1=a[id].x;
            if(a[id].dir=='D') xx2=a[id].x;
        }
    }
    if(ans>=(1e9)-1) puts("SAFE");
    else printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 118468
(defmacro dotimes-unroll ((var count size &optional result) &body body)
  "DOTIMES macro with loop-unrolling by SIZE."
  (let ((whole (gensym))
        (_count (gensym)))
    (check-type var symbol)
    (check-type size (integer 1 #.most-positive-fixnum))
    `(block ,whole
       (let ((,_count ,count)
             (,var 0))
         (declare ((integer 0 #.most-positive-fixnum) ,var ,_count))
         (loop
           (when (> ,var (- ,_count ,size))
             (do ((,var ,var (1+ ,var)))
                 ((>= ,var ,_count)
                  (return-from ,whole ,result))
               ,@body))
           ,@(loop for i from 0 below size
                   collect `(locally ,@body (setq ,var (+ ,var 1)))))))))

(defun main ()
  (declare (optimize (speed 3) (safety 0)))
  (let* ((n (read))
         (res 0))
    (declare ((unsigned-byte 62) res)
             (uint32 n))
    (dotimes-unroll (i n 10)
      (incf res i))
    (princ res)
    (terpri)))

#-swank (main)


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

vector<int> g[5001];
ll dp[5001][5001][2];
ll dp2[2][5001][2];
int N;
int sz[5001];
ll ma[5001];

void dfs(int v,int pre){
  sz[v]=1;
  vector<int> ch;
  for(ll nv : g[v]){
    if(nv==pre)continue;
    dfs(nv,v);
    sz[v]+=sz[nv];
    ch.push_back(nv);
  }
  int m=ch.size();
  int sum=1;
  rep(j,2)dp2[0][j][0]=dp2[0][j][1]=0;
  dp2[0][1][0]=1;
  int crt=0,nxt=1;
  rep(i,m){
    ll nv=ch[i];
    rep(j,sum+sz[nv]+1)dp2[nxt][j][0]=dp2[nxt][j][1]=0;
    rep(j,sum+1)rep(f,2){
      rep(k,sz[nv]+1)rep(nf,2){
        (dp2[nxt][j][(f+nf+1)%2]+=((dp2[crt][j][f]*dp[nv][k][nf])%mod)*ma[k])%=mod;

        (dp2[nxt][j+k][(f+nf)%2]+=dp2[crt][j][f]*dp[nv][k][nf]%mod)%=mod;
      }
    }
    sum+=sz[nv];
    swap(crt,nxt);
  }
  rep(i,sz[v]+1)rep(j,2)dp[v][i][j]=dp2[crt][i][j];
}

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

  ma[0]=1;
  for(ll i=2;i<=5000;i+=2){
    ma[i]=ma[i-2]*(i-1)%mod;
  }

  cin>>N;
  rep(i,N-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0,-1);

  ll res=0;
  rep(i,N+1)(res+=((dp[0][i][0]-dp[0][i][1]+mod)%mod)*ma[i]%mod)%=mod;
  cout<<res<<endl;

  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll N;
vector<vector<ll>> dp;
vector<ll> W;

ll dfs(ll l, ll r) {
    if (dp[l][r] != -1) {
        return dp[l][r];
    }
    if (abs(r - l) == 1) {
        return dp[l][r] = 0;
    } else if (abs(r - l) == 2) {
        if (abs(W[l] - W[r - 1]) <= 1) {
            return dp[l][r] = 2;
        } else {
            return dp[l][r] = 0;
        }
    }

    ll res = 0;

    if (abs(W[l] - W[r - 1]) <= 1 && dfs(l + 1, r - 1) == abs(r - 1 - (l + 1))) {
        res = r - l;
    }

    for (ll k = l + 1; k < r; k++) {
        res = max(res, dfs(l, k) + dfs(k, r));
    }
    return dp[l][r] = res;
}

void solve() {
    while (true) {
        cin >> N;
        if (N == 0) break;
        dp.assign(N + 1, vector<ll>(N + 1, -1));
        W.assign(N, 0);
        rep(i, N) cin >> W[i];
        cout << dfs(0, N) << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}



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

const int N = 1 * 100 * 1000 + 20;

int n, m, x, y;
int arr_p[N], mark[N];

bool outDegree[N];

vector <int> gr[N];

queue <pair<int, int>> ans;

void dfs(int);

int main() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> x >> y;
		gr[x].push_back(y);
		gr[y].push_back(x);
	}
	if (m % 2 == 1) {
		cout << -1;
		return 0;
	}
	dfs(1);
	while (ans.size() > 0) {
		cout << ans.front().first << " " << ans.front().second;
		cout << (ans.size() > 1? "\n": "");
		ans.pop();
	}
}

void dfs(int a) {
	mark[a] = 1;
	for (int u = 0; u < gr[a].size(); u++) {
		if (gr[a][u] == arr_p[a])
			continue;
		if (mark[gr[a][u]] == 1) {
			outDegree[a] = (outDegree[a] + 1) % 2;
			ans.push({a, gr[a][u]});
		}
		if (mark[gr[a][u]] == 0) {
			arr_p[gr[a][u]] = a;
			dfs(gr[a][u]);
		}
	}
	if (outDegree[a] == 0 && a != 1) {
		outDegree[arr_p[a]] = (outDegree[arr_p[a]] + 1) % 2;
		ans.push({arr_p[a], a});
	}
	if (outDegree[a] == 1 && a != 1)
		ans.push({a, arr_p[a]});
	mark[a] = 2;
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

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

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int a;
    cin >> a;
    cout << 180 * (a-2) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;using int32=int_fast32_t;using uint32=uint_fast32_t;using int64=int_fast64_t;using uint64=uint_fast64_t;using pi=pair<int32,int32>;using pll=pair<int64,int64>;using vi=vector<int32>;using vvi=vector<vector<int32>>;using vll=vector<int64>;using ll=int64;using ull=uint64;constexpr int32 INF=1<<30;constexpr ll INFLL=1LL<<62;
#define all(x)x.begin(),x.end()
#define LB(V,x)lower_bound(all(V),x)-V.begin()
#define uint uint32
void Main(){
    int T, X;
    cin >> T >> X;
    cout << (float)T/X << endl;
}
int main(){cin.tie(0);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
const int N = 3e5 + 10 ;
typedef long long ll ;
struct node
{
  ll val , f ;
}v[N];
bool cmp(node a , node b)
{
  return a.val > b.val ;
}
int main()
{
  int x , y , a , b , c ;
  cin >> x >> y >> a >> b >> c ;
  int cnt = 0 ;
  ll d;
  for(int i = 1 ;i <= a ;i ++) cin >> d , v[++ cnt].val = d , v[cnt].f = 1 ;
  for(int i = 1 ;i <= b ;i ++) cin >> d , v[++ cnt].val = d , v[cnt].f = 2 ;
  for(int i = 1; i <= c ;i ++) cin >> d , v[++ cnt].val = d , v[cnt].f = 3 ;
  sort(v + 1 , v + cnt + 1 , cmp) ;
  int xx = 0 , yy = 0 , mm = 0 ;
  ll ans = 0 , res = 0 ;
  for(int i = 1; i <= cnt ;i ++)
   {

     if(v[i].f == 1 && xx < x && res < x + y) xx ++ , res ++  , ans += v[i].val;
     if(v[i].f == 2 && yy < y && res < x + y) yy ++ , res ++ , ans += v[i].val;
     if(v[i].f == 3 && res < x + y) mm ++ , res ++ , ans += v[i].val ;
     if(res == x + y) break ;
   }
   cout << ans << endl ;
  return 0 ;
}


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

int main() {
	int n,cnt=0,ma=0;
	string s;
	cin>>n>>s;
	for(int i=0;i<s.length();i++){
		if(s.substr(i,1)=="I"){
			cnt++;
		}else{
			cnt--;
		}
		ma=max(cnt,ma);
	}
	cout<<ma<<endl;
	return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0
for f in range(0, A+1):
    for o in range(0, B+1):
        for hf in range(0, C+1):
            s = f*500 + o*100 + hf*50
            if s == X : cnt +=1

print(cnt)

Measured memory_bytes: 3064
#![allow(unused_imports)]

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        n: u64,
    }

    let mut ans = 0;
    for i in 1..=n {
        if i % 3 != 0 && i % 5 != 0 {
            ans += i;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2124