akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 998244353;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
ll dp[3001][3001];
int main(void) {
	int n, s;
	cin >> n >> s;
	vector<int> a(n);
	rep(i, 0, n)cin >> a[i];
	dp[0][0] = mpower(2, n);
		for (int j = 0; j <= s; ++j) {
	for (int i = 0; i < n; ++i) {
			dp[i + 1][j] += dp[i][j];
			dp[i + 1][j] %= mod;
			if (j >= a[i])dp[i + 1][j] += dp[i][j - a[i]] * mpower(2, mod - 2);
			dp[i + 1][j] %= mod;
		}
	}
	printf("%lld\n", dp[n][s]);
	return 0;
}


Measured memory_bytes: 73976
a,b,x=map(int,input().split())
v=a*a*b/2
import math
k=(2*v-x)*2/(a*a)
g=2*x/(a*b)
if x<=v:
  print(math.atan(b/g)*180/math.pi)
else:
  print(math.atan(k/a)*180/math.pi)

Measured memory_bytes: 3188
// M - Candies  https://atcoder.jp/contests/dp/tasks/dp_m
/* 入力例
3 4
1 2 3
// →出力 5 longlongintにしたらあと1個1-08以外は通った。unsilonglongintだとint同様９番目以下全滅なぜだ？
// longlongintでも ３５行目のif(dp[i][j]<0){dp[i][j]=0;}//最後の変更点処理を加えると9番目以下が全滅。longlongintで通ったテストでDPが負になっているということ？
*/
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    long long int a[N], dp[K + 1][N];
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for(int j = 0; j < N; j++) {
        dp[0][j] = 1;
    }
    for(int i = 1; i <= K; i++) {
        if(i <= a[0]) {
            dp[i][0] = 1;
        } else {
            dp[i][0] = 0;
        }
        for(int j = 1; j < N; j++) {
            if(a[j] == 0) {
                dp[i][j] = dp[i][j - 1];
            } else {
                if(i <= a[j]) {
                    dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]+1000000000+7) % (1000000000 + 7);
                } else {
                    dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1]+1000000000+7) % (1000000000 + 7);
                    if(dp[i][j]<0){dp[i][j]=0;}//最後の変更点
                }
            }
        }
    }
    cout << dp[K][N - 1] % (1000000000 + 7) << endl;
    return 0;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
struct dt
{
    int idx, num;
    bool operator<(const dt rhs){
        return num < rhs.num;
    }
}s[100005];

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> s[i].num;
        s[i].idx = i;
    }
    sort(s + 1, s + n + 1);
    for(int i = 1; i <= n; ++i){
        cout << s[i].idx << ' ';
    }

}




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

int main() {

long long t;
//cin >> t;
t = 1;
while(t--){
	int m1,d1,m2,d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if(m1 + 1 == m2) cout << "1";
	else cout << "0";
}
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        
        int n = k;
        while (n <= b) {
            if (n >= a) {
                System.out.println("OK");
                return;
            }
            n = n + k;
        }

        System.out.println("NG");
    }
}

Measured memory_bytes: 35768
#include <bits/stdc++.h>
#include <math.h>
#define _USE_MATH_DEFINES
using namespace std;

int a[10010];
int main() {
  int N;
  int M;
  vector<int> A;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a[i];
  }
  int sum = 0;
  for (int i = 0; i < M; i++) {
    sum += a[i];
  }
  if (sum > N) {
    cout << -1 << "\n";
  } else {
    cout << N - sum << "\n";
  }
}

Measured memory_bytes: 3604
from collections import defaultdict
A = input()
N = len(A)

d = defaultdict(list)
for i, a in enumerate(A):
    d[a].append(i)

pair = 0
for k, v in d.items():
    n = len(v)
    pair += n * (n - 1) // 2

ans = N * (N - 1) // 2
ans = ans - pair + 1
print(ans)


Measured memory_bytes: 12004
#include<stdio.h>
#define INF (1<<30)

int main(){
	int i,n,ans,min,x;	scanf("%d",&n);
	scanf("%d",&min);
	ans=INF*(-1);

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

		if(min>x)min=x;
	}

	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 2760
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        for(int i = 0; i < n; i++){
            b[a[i] - 1] = i + 1;
        }
        for(int i = 0; i < n; i++){
            System.out.print(b[i] + " ");
        }
    }
}

Measured memory_bytes: 65276
N = int(input())
A = list(map(int, input().split()))
X = []
for i in range(N):
	n = 0
	while True:
		if A[i] % 2 == 0:
			n += 1
			A[i] = int(A[i] // 2)
		else:
			break
	X.append(n)

print(min(X))

Measured memory_bytes: 3060
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int[] l, v;
    int i, j, k, sum;
    String str;
    char[] ch;
    double d;

    l = new int[10]; v = new int[2];
    for(;sc.hasNext();){
      str = sc.next();
      ch = new char[str.length()];
      for(j = 0;j < str.length();j++)ch[j] = str.charAt(j);
      k = 0; j = 0;

      for(i = 0;i < 10;i++){
        for(;j < str.length();j++){
          if(ch[j] == ','){
            l[i] = readint(ch, k, j);
            k = ++j; break;
          }
        }
      }
      for(;j < str.length();j++){
        if(ch[j] == ','){
          v[0] = readint(ch, k, j);
          k = ++j; break;
        }
      }
      v[1] = readint(ch, k, str.length());

      d = 0;
      for(i = 0;i < 10;i++)d += (double)l[i];
      d = d * (double)v[0] / (double)(v[0] + v[1]);

      sum = 0;
      for(i = 0;i < 10;i++){
        sum += l[i];
        if(d <= sum){
          out.println(i + 1);
          break;
        }
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
  private static int readint(char[] ch, int l, int r){
    int i, d, res;
    d = 1; res = 0;
    for(i = r - 1;i >= l;i--){
      res += d * (int)(ch[i] - '0');
      d *= 10;
    }
    return res;
  }
}

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

#define deb(x)        cerr << #x << " = " << x << "\n";
#define deb2(x, y)    cerr << #x << " = " << x << ", " << #y << " = " << y << "\n";
#define deb3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << "\n";

#define pb push_back
#define mp make_pair
#define F  first
#define S  second

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

typedef long long ll;  

void solve() {
    string s;
    cin >> s;
    if (s[sz(s) - 1] == 's') {
        cout << s << "es";
    } else {
        cout << s << "s";
    }
}

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

    ll tc = 1;
    //cin >> tc;

    while(tc--) {
        solve();
        cout << '\n';
    }

    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n+1], b[n+1], c[n+1];
  memset(c, 0, sizeof(c));
  memset(b, 0, sizeof(b));
  memset(a, 0, sizeof(a));
  int x, y, z;
  cin>>x>>y>>z;
  a[1]=x;
  b[1]=y;
  c[1]=z;
  for(int i=2; i<=n; i++){
    cin>>x>>y>>z;
    a[i] = x+max(b[i-1], c[i-1]);
    b[i] = y+max(a[i-1], c[i-1]);
    c[i] = z+max(a[i-1], b[i-1]);    
  }
  cout<<max(c[n], max(a[n], b[n])); 
  
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    vector<int> M(n), D(n), h(n), m(n);
    vector<char> e(n);
    vector<int> p(n);
    for (int i = 0; i < n; i++){
      char c1, c2;
      cin >> M[i] >> c1 >> D[i] >> h[i] >> c2 >> m[i] >> e[i] >> p[i];
    }
    vector<int> time(n);
    for (int i = 0; i < n; i++){
      time[i] = ((M[i] * 40 + D[i]) * 24 + h[i]) * 60 + m[i];
    }
    vector<int> t(1000, 0);
    vector<bool> c(1000, false);
    for (int i = 0; i < n; i++){
      if (e[i] == 'I'){
        c[p[i]] = true;
      }
      if (e[i] == 'O'){
        c[p[i]] = false;
      }
      if (i < n - 1 && c[0]){
        int dt = time[i + 1] - time[i];
        for (int j = 1; j < 1000; j++){
          if (c[j]){
            t[j] += dt;
          }
        }
      }
    }
    int ans = 0;
    for (int j = 1; j < 1000; j++){
      ans = max(ans, t[j]);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3092
import java.math.BigDecimal;
import java.util.Scanner;

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

		BigDecimal volume = new BigDecimal(Math.pow(l/3, 3));

		System.out.println(volume);
	}
}

Measured memory_bytes: 23764
// https://atcoder.jp/contests/abc056/tasks/arc070_a
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    ll X;
    cin >> X;
    ll n = 1;
    while(1)
    {
        ll s = n * (n + 1) / 2;
        ll spre = n * (n - 1) / 2;
        if (X <= s && X > spre) break;
        ++n;
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n;cin >> n;
	vector<int>d(n);
	for (int i = 0;i < n;i++) {
		cin >> d[i];
	}
	sort(d. begin(), d.end());
	int cnt = 0;
	for (int i = 0;i < n;i++) {
		if (d[i] < d[n / 2]) {
			cnt++;
		}
	}
	if (cnt == n / 2) {
		cout << d[n / 2] - d[n / 2 - 1] << endl;
	}
	else cout << "0" << endl;

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
int main()
{
    double t,c=0;
    cin>>t;
    for(int i=t;i>=1;i--)
    {
        if(i%2!=0)
            c++;
    }
    double x=c/t;
    cout<<fixed<<setprecision(10)<<x<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    int sa[120],ta[120] ;
    char s[120],t[120],z[30]="abcdefghijklmnopqrstuvwxyz" ;
    scanf ("%s%s",s,t) ;
    for (int i=0; i<strlen(s); i++ ){
        for (int j=0; j<30; j++ ){
            if ( s[i]==z[j] ){
                sa[i] = j ;
            }
        }
    }
    for (int i=0; i<strlen(s); i++ ){
        for (int j=i+1; j<strlen(s); j++){
            int tmp=0 ;
            if ( sa[i]>sa[j] ){
                tmp = sa[i] ;
                sa[i] = sa[j] ;
                sa[j] = tmp ;
            }
        }
    }
    for (int i=0; i<strlen(t); i++ ){
        for (int j=0; j<30; j++ ){
            if ( t[i]==z[j] ){
                ta[i] = j ;
            }
        }
    }
    for (int i=0; i<strlen(t); i++ ){
        for (int j=i+1; j<strlen(t); j++){
            int tmp=0 ;
            if ( ta[i]<ta[j] ){
                tmp = ta[i] ;
                ta[i] = ta[j] ;
                ta[j] = tmp ;
            }
        }
    }
    for (int i=strlen(s); i<120; i++){
        sa[i] = -999 ;
    }
    for (int i=strlen(t); i<120; i++){
        ta[i] = -999 ;
    }
    int cnt = 0;
    for (int i=0; i<120; i++){
        if ( sa[i]<ta[i] ){
            printf ("Yes\n") ;
            break ;
        } else if ( sa[i]>ta[i] ){
            printf ("No\n") ;
            break ;
        } else if ( cnt==119 ){
            printf ("No\n") ;
            break ;
        } else {
            cnt ++ ;
        }
    }
    return 0 ;
}

Measured memory_bytes: 128
#include<iostream>
 
using namespace std;
 
 
class DICE {
    enum {
        Top,
        Front,
        Right,
        Left,
        Rear,
        Bottom
    };
 
public:
    int Num[6];
 
    void Roll(const char*Directions) {
        for (int i = 0; Directions[i] != '\0'; i++) {
            Roll(Directions[i]);
        }
    }
 
    void Roll(const char Direction) {
        int tmpTop = Num[Top];
 
        switch (Direction) {
        case'E':
            Num[Top] = Num[Left];
            Num[Left] = Num[Bottom];
            Num[Bottom] = Num[Right];
            Num[Right] = Num[tmpTop];
            break;
        case'N':
            Num[Top] = Num[Front];
            Num[Front] = Num[Bottom];
            Num[Bottom] = Num[Rear];
            Num[Rear] = tmpTop;
            break;
        case'S':
            Num[Top] = Num[Rear];
            Num[Rear] = Num[Bottom];
            Num[Bottom] = Num[Front];
            Num[Front] = tmpTop;
            break;
        case'W':
            Num[Top] = Num[Right];
            Num[Right] = Num[Bottom];
            Num[Bottom] = Num[Left];
            Num[Left] = tmpTop;
            break;
        }
    }
 
    int TopFrontToRight(const int TopNum, const int FrontNum) {
        const char Directions[][3] = { "N","N","N","NW","WW","\0" };
        DICE Dice;
 
        for (int i = 0; i < 6; i++)Dice.Num[i] = Num[i];
 
        for (int i = 0; i < 6; i++) {
            if (TopNum == Dice.Num[Top]) {
                for (int j = 0; j < 4; j++) {
                    if (FrontNum == Dice.Num[Front])
                        return Dice.Num[Right];
 
                    int tmpFront = Dice.Num[Front];
                    Dice.Num[Front] = Dice.Num[Right];
                    Dice.Num[Right] = Dice.Num[Rear];
                    Dice.Num[Rear] = Dice.Num[Left];
                    Dice.Num[Left] = tmpFront;
                }
            }
 
            Dice.Roll(Directions[i]);
        }
 
        return 0;
    }
};
 
int main() {
    DICE Dice;
    int q;
 
    for (int i = 0; i < 6; i++) {
        cin >> Dice.Num[i];
    }
    cin >> q;
 
    for (int i = 0; i < q; i++) {
        int Top, Front;
         
        cin >> Top >> Front;
 
        cout << Dice.TopFrontToRight(Top, Front) << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3084
open System

let [| X; A; B |] = stdin.ReadLine().Split(' ') |> Array.map int
let f x a b = 
    match (x, a, b) with
      | (x, a, b) when -a + b <= 0 -> "delicious"
      | (x, a, b) when -a + b >= (x + 1) -> "dangerous"
      | _ -> "safe"

f X A B |> printfn "%s"


Measured memory_bytes: 11996
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
LL dp[400003];
LL sum[200003];
LL mod=998244353;
static const int MAX_SIZE = 1 << 20;

LL all[2 * MAX_SIZE - 1], part[2 * MAX_SIZE - 1];

void add(int a, int b, LL x, int k = 0, int l = 0, int r = MAX_SIZE)
{
    if (a <= l && r <= b){
        all[k] += x;
    }
    else if (l < b && a < r){
        part[k] += (min(b, r) - max(a, l)) * x;
        add(a, b, x, k * 2 + 1, l, (l + r) / 2);
        add(a, b, x, k * 2 + 2, (l + r) / 2, r);
    }
}
LL sum2(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE)
{
    if (b <= l || r <= a){
        return (0);
    }
    else if (a <= l && r <= b){
        return (all[k] * (r - l) + part[k]);
    }
    else {
        LL res = (min(b, r) - max(a, l)) * all[k];
        res += sum2(a, b, k * 2 + 1, l, (l + r) / 2);
        res += sum2(a, b, k * 2 + 2, (l + r) / 2, r);
        return (res);
    }
}
int main(){
    CLR(all);CLR(part);
    int N,K;cin>>N>>K;
    vector<PII>pi;
    REP(i,K){
        int L,R;
        cin>>L>>R;
        pi.PB(MP(L,R));
    }
    CLR(dp);
    //dp[0]=1;
    add(1,2,1);
    FOR(i,1,N+1){
        REP(k,SZ(pi)){
            int s=pi[k].first;
            int e=pi[k].second;
            LL addval=sum2(i,i+1)%mod;
            add(i+s,i+e+1,addval);
        }
    }
    cout<<sum2(N,N+1)%mod<<endl;
    return 0;
}

Measured memory_bytes: 39516
#include <bits/stdc++.h>
using namespace std;
int N;
vector<vector<int> > vt;
vector<int> w;
int cnt = 0;
int depth = -1;
bool dfs1(int i, int from, int d) {
	
	bool res = false;
	for (int j = 0; j < vt[i].size(); j++) {
		if (vt[i][j] != from) {
			res = (res || dfs1(vt[i][j], i, d + 1));
		}
	}

	if (i == (N - 1)) {
		depth = d;
		//cerr << d << endl;
		res = true;
	}
	
	if (res) {
		if (d > (depth / 2)) {
			//cerr << i << endl;
			w[i] = 1;
		}
	}

	return res;
}
void dfs2(int i, int from) {
	cnt++;
	
	for (int j = 0; j < vt[i].size(); j++) {
		if (vt[i][j] != from && (w[vt[i][j]] == 0)) {
			dfs2(vt[i][j], i);
		}
	}
}
int main() {
	
	cin >> N;
	vt.clear();
	w.clear();
	vt.resize(N);
	w.resize(N, 0);
	int a, b;
	for (int i = 0; i < N - 1; i++) {
		cin >> a >> b;
		a--;
		b--;
		vt[a].push_back(b);
		vt[b].push_back(a);
	}
	dfs1(0, -1, 0);
	dfs2(0, -1);
	cerr << cnt << endl;
	if (cnt > N / 2) {
		cout << "Fennec" << endl;
	}
	else {
		cout << "Snuke" << endl;
	}
	return 0;
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline int read() {
    int x = 0, fh = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')
            fh = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = (x << 1) + (x << 3) + c - '0';
        c = getchar();
    }
    return x * fh;
}
const int N = 2e5 + 10;
int n, x, y, i, a[N], b[N];
int kmax(int a, int b, int c, int d) { return max(max(max(a, b), c), d); }
int main() {
	n = read();
	for (i = 1; i <= n; i++) {
		x = read(); y = read();
		a[i] = x + y;
		b[i] = x - y;
	}
	sort(a + 1, a + 1 + n);
	sort(b + 1, b + 1 + n);
	cout << kmax(a[n] - a[1], b[n] - b[1], b[1] - b[n], a[1] - a[n]);
	return 0;
}

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

long long N, K, L, A[200009], P[200009];

long long solve(long long pos) {
	P[0] = 0;
	for (int i = 1; i <= N; i++) {
		if (A[i] <= pos) P[i] = P[i - 1] + 1;
		else P[i] = P[i - 1];
	}
	long long cnt = 0;
	for (int i = 1; i <= N; i++) {
		if (P[i] < K) continue;
		int pos1 = lower_bound(P, P + N + 1, P[i] - (K - 1)) - P;
		cnt += pos1;
	}
	return cnt;
}

int main() {
	cin >> N >> K >> L;
	for (int i = 1; i <= N; i++) cin >> A[i];

	long long L1 = 0, R1 = (1LL << 30), M1, minx = (1LL << 30);
	for (int i = 0; i < 40; i++) {
		M1 = (L1 + R1) / 2;
		long long v1 = solve(M1);
		if (v1 >= L) { minx = min(minx, M1); R1 = M1; }
		else { L1 = M1; }
	}
	cout << minx << endl;
	return 0;
}


Measured memory_bytes: 6192
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
r=[0]*n
for i in range(m):
    r[a[i]-1]+=1
cnt_1=0
cnt_2=0
for i in range(x-1):
    cnt_1+=r[i]
for j in range(x,n):
    cnt_2+=r[j]
print(min(cnt_1,cnt_2))

Measured memory_bytes: 8988
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int w;
    for(;;out.println(-solve(w) + 4280)){
      w = sc.nextInt(); if(w == -1)break;
    }

    sc.close();
  }
  private static int solve(int w){
    int res = 0;
    if(w < 10)return 1150;
    res += 1150; w -= 10;
    if(w < 10)return (res + 125 * w);
    res += 1250; w -= 10;
    if(w < 10)return (res + 140 * w);
    res += 1400; w -= 10;
    return (res + 160 * w);
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 26148
#include<bits/stdc++.h>
using namespace std;
int main()
{int n,flag=0;
cin>>n;
string s;
cin>>s;
if(n%2!=0)
cout<<"No";
else
{for(int i=0;i<n/2;i++)
{if(s[i]!=s[n/2+i])
{flag=1;
break;
}
}
if(flag==0)
cout<<"Yes";
else
cout<<"No";
}
return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long max = long.MinValue;
		for(int s = 1; s < (1<<10); s++){
			long[] cnt = new long[N];
			for(int i=0;i<N;i++){
				for(int k=0;k<10;k++){
					if(((s >> k) & 1 ) == 1) cnt[i] += F[i][k];
				}
			}
			long earn = 0;
			for(int i=0;i<N;i++) earn += P[i][cnt[i]];
			max = Math.Max(max,earn);
		}
		Console.WriteLine(max);
		
	}
	int N;
	int[][] F;
	long[][] P;
	public Sol(){
		N = ri();
		F = new int[N][];
		for(int i=0;i<N;i++) F[i] = ria();
		P = new long[N][];
		for(int i=0;i<N;i++) P[i] = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13396
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

struct WeightedUnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;
    vector<int> diff_weight; 
 
    WeightedUnionFind (int n = 1 ) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n); siz.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; i++) par[i] = i, rank[i] = 0, siz[i] = 1, diff_weight[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }
 
    bool same(int x, int y) {
        return root(x) == root(y);
    }
 
    void unite(int x, int y, int w) {
        w += weight(x);
        w -= weight(y);

        x = root(x);
        y = root(y);
        if (x == y) return;
 
        if (rank[x] < rank[y]) {
            par[x] = y;
            siz[y] += siz[x];
            diff_weight[x] = -w;
        }
        else {
            par[y] = x;
            siz[x] += siz[y];
            if (rank[x] == rank[y]) rank[x]++;
            diff_weight[y] = w;
        }
    }
 
    int size(int x) {
        return siz[root(x)];
    }

    int weight(int x) {
        root(x);
        return diff_weight[x];
    }

    int diff (int x, int y) {
        return weight(y) - weight(x);
    }
};

//--------------------------- Solve ---------------------------//

void solve() {
    int N, M; cin >> N >> M;
    WeightedUnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int L, R, D; cin >> L >> R >> D;
        L--; R--;
        if (uf.same(L, R)) {
            if (uf.diff(L, R) != D) {
                cout << "No" << '\n';
                return;
            }
        }
        else uf.unite(L, R, D);
    }
    cout << "Yes" << '\n';
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

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

int main()
{
    double n;

    cin>>n;
    n=n/3;
    n=n*n*n;
    string st = to_string(n);
    //std::string s = boost::lexical_cast<std::string>(n);
    cout<<st<<endl;
    return 0;
}


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

int main(){
  int W,H,N;
  cin >> W >> H >> N;
  int x_l= 0;
  int y_l= 0;
  int x_u= W;
  int y_u= H;

  int query,xq,yq;
  for(int i=0; i<N; i++){
    cin >> xq >> yq >> query;
    if(query==1) x_l= min(x_u, max(xq, x_l));
    if(query==2) x_u= max(x_l, min(xq, x_u));
    if(query==3) y_l= min(y_u, max(yq, y_l));
    if(query==4) y_u= max(y_l, min(yq, y_u));
  }
  
  cout << (x_u- x_l)* (y_u- y_l) << endl;
}

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

class Saikoro{
public:
	int me[6];
	void South();
	void North();
	void East();
	void West();
};

void Saikoro::South()
{
	int temp = me[5];
	me[5] = me[0];
	me[0] = me[4];
	me[4] = me[1];
	me[1] = temp;
}

void Saikoro::North()
{
	int temp = me[4];
	me[4] = me[0];
	me[0] = me[5];
	me[5] = me[1];
	me[1] = temp;
}

void Saikoro::West()
{
	int temp = me[3];
	me[3] = me[0];
	me[0] = me[2];
	me[2] = me[1];
	me[1] = temp;
}
void Saikoro::East()
{
	int temp = me[2];
	me[2] = me[0];
	me[0] = me[3];
	me[3] = me[1];
	me[1] = temp;
}

int main()
{
	Saikoro sai;
	cin >> sai.me[0] >> sai.me[5] >> sai.me[2] >> sai.me[3] >> sai.me[4] >> sai.me[1];
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'S')sai.South();
		if (s[i] == 'N')sai.North();
		if (s[i] == 'E')sai.East();
		if (s[i] == 'W')sai.West();
	}
	cout << sai.me[0] << endl;
	return 0;
}

Measured memory_bytes: 3136
#include <stdio.h>
int main()
{ 
 int a,b,c,d,e;     
 scanf("%d %d%d",&a,&b,&c);
 d=abs(a-b);
 e=abs(a-c);
 if(e>d)
   printf("A");
 else
   printf("B");
 
 return 0;
}


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

int main()
{
  int N , K , x , sum ;
  
  cin >> N >> K ;
  
  for(int i=0; i<N; i++)
  { 
    cin >> x ;
    
    if(x<=K/2) 
      sum += x ;
    else
      sum += K-x ;
  }
  
  if(K==1)
    cout << 0 << endl ;
  else
    cout << sum*2 << endl ;
}

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

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }

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

	int m;
	cin >> m;

	for(int i = 0; i < m; ++i) {
		int money, year, n;
		cin >> money >> year >> n;

		int mx = 0;
		for(int j = 0; j < n; ++j) {
			int kind, cost;
			double p;
			cin >> kind >> p >> cost;

			int tmp = money;
			if(kind) {
				for(int k = 0; k < year; ++k)
					tmp += tmp * p - cost;
			}
			else {
				int add = 0;
				for(int k = 0; k < year; ++k) {
					add += tmp * p;
					tmp -= cost;
				}

				tmp += add;
			}

			chmax(mx, tmp);
		}

		cout << mx << endl;
	}

	return EXIT_SUCCESS;
}

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

public class Main {
 public static void main (String[] args) {
  Scanner sc = new Scanner(System.in);
  String x = sc.next();
  String y = sc.next();
  String[] a = {"1","3","5","7","8","10","12"};
  String[] b = {"4","6","9","11"};
   if(x==y){
    System.out.print("Yes");
   }else if(x=="2" && y=="2"){
    System.out.print("Yes");
   }else if(Arrays.asList(a).contains(x)){
    if(Arrays.asList(a).contains(y)){
     System.out.print("Yes");
    }else{
     System.out.print("No");
    }
   }else if(Arrays.asList(b).contains(x)){
    if(Arrays.asList(b).contains(y)){
     System.out.print("Yes");
    }else{
   	 System.out.print("No");
    }
   }else {
    System.out.print("No");
   }
  }
}

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

using namespace std;

#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define M 1000000007
#define MXN 1007
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
ll res[MXN];
ll dp[MXN];
ll t,k,n;
string str;
int main()
{
    fastio;
    cin>>t>>k>>n;
    ll ans = max(max(t,k),n)*10+(t+k+n-max(max(t,k),n));
    cout<<ans<<"\n";
    return 0;
}   

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

int main(){

    int n,m;
    cin >> n >> m;


    cout << (n-1)*(m-1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <queue>

#define MAX_W 30
#define MAX_H 30

using namespace std;

const int INF = 100000000;

typedef pair<int, int> P;

int W, H;
int maze[MAX_W][2*MAX_H-1];

int d[MAX_W][MAX_H]; //???????????§??????????????¢

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

int bfs(){
	queue<P> que;

	for(int i = 0; i < W; i++){
		for(int j = 0; j < H; j++){
			d[i][j] = INF;
		}
	}
	que.push(P(0, 0));
	d[0][0] = 1;

	while(que.size()){
		P p = que.front(); que.pop();
		if(p.first == W-1 && p.second == H-1) break;
		for(int i = 0; i < 4; i++){
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if(dx[i] == 1){ // ?¨??§????
				if(0 <= nx && nx < W && maze[p.first][2*p.second] != 1 && d[nx][ny] == INF){
					que.push(P(nx, ny));
					d[nx][ny] = d[p.first][p.second]+1;
				}
			}else if(dx[i] == -1){ // ?¨??§????
				if(0 <= nx && nx < W && maze[p.first-1][2*p.second] != 1 && d[nx][ny] == INF){
					que.push(P(nx, ny));
					d[nx][ny] = d[p.first][p.second]+1;
				}
			}else if(dy[i] == 1){ // ????§????
				if(0 <= ny && ny < H && maze[p.first][2*p.second+1] != 1 && d[nx][ny] == INF){
					que.push(P(nx, ny));
					d[nx][ny] = d[p.first][p.second]+1;
				}
			}else if(dy[i] == -1){ // ????§????
				if(0 <= ny && ny < H && maze[p.first][2*p.second-1] != 1 && d[nx][ny] == INF){
					que.push(P(nx, ny));
					d[nx][ny] = d[p.first][p.second]+1;
				}
			}
		}
	}
	return d[W-1][H-1];
}

void solve() {
	int res = bfs();
	if(res != INF) cout << res << endl;
	else cout << 0 << endl;
}

int main(){

	while(true){
		cin >> W >> H;
		if(W == 0 && H == 0) break;
		for(int i = 0; i < 2*H-1; i++){
			for(int j = 0; j < W-1+(i%2); j++){
				cin >> maze[j][i];
			}
		}
		solve();
	}
	return 0;
}

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

#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 ALL(v) v.begin(), v.end()

int main() {
  int64_t N;
  string S;
  cin >> N;
  cin >> S;

  char t;
  t = ' ';
  int count = 0;
  REP(i,N){
    if(S[i] != t){
      count++;
      t = S[i];
    }
  }
  cout << count << endl;

  
}

Measured memory_bytes: 3756
#include"stdio.h"

int main(){
  char a[7]="Sunny",b[7]="Cloudy",c[7]="Rainy",s[7];
  scanf("%s",&s);
  if(strcmp(a,s)==0)printf("%s",b);
  if(strcmp(b,s)==0)printf("%s",c);
  if(strcmp(c,s)==0)printf("%s",a);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int a, b, c; cin >> a >> b >> c;

    if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
        cout << 0 << endl;
        return 0;
    }

    int ans = min(a * b, min(b * c, c * a));

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


Measured memory_bytes: 256
def dif_row(r1, r2)
  x = []
  3.times{|i| x<<r1[i]-r2[i]}
  x.uniq.size == 1
end
c = []
3.times{c << gets.chomp.split.map(&:to_i)}
d = c.transpose
if dif_row(c[0], c[1]) && dif_row(c[0], c[2]) &&
  dif_row(d[0], d[1]) && dif_row(d[0], d[2])
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 14392
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize, k: usize,
        a: [usize; n],
    }
    let mut a = a;
    for _ in 0..k {
        if a.iter().all(|&x| x == n) {
            break;
        }
        let mut b = vec![0i32; n];
        for i in 0..n {
            let lo = max(i, a[i]) - a[i];
            let hi = min(i + a[i], n - 1);
            b[lo] += 1;
            if hi + 1 < n {
                b[hi + 1] -= 1;
            }
        }
        for i in 0..n - 1 {
            b[i + 1] += b[i];
        }
        for i in 0..n {
            a[i] = b[i] as usize;
        }
    }
    for i in 0..n {
        puts!("{}{}", a[i], if i + 1 == n { "\n" } else { " " });
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 4124
'''
https://atcoder.jp/contests/abc065/tasks/arc076_b
最小全域木を考える際にある頂点について他の頂点への最小コストを
考えて繋げていくのは間違い(全域木になる保証がない)
考えたいのはあくまでも全辺のコスト

今回はxとyでそれぞれソートして隣り合う2点のコストのみを考えれば良い
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    N = int(input())
    xy = []
    for i in range(N):
        x,y = map(int, input().split())
        xy.append([x, y, i])
    x_sort = sorted(xy, key=lambda x: x[0])
    y_sort = sorted(xy, key=lambda x: x[1])

    #[cost, 頂点1, 頂点2]
    cost = []
    for i in range(N-1):
        cost.append([abs(x_sort[i][0]-x_sort[i+1][0]), x_sort[i][2], x_sort[i+1][2]])
        cost.append([abs(y_sort[i][1]-y_sort[i+1][1]), y_sort[i][2], y_sort[i+1][2]])
    cost = sorted(cost, key=lambda x: x[0])

    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]
    
    def unite(x,y):
        x = find(x)
        y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x,y = y,x
            par[x] += par[y]
            par[y] = x
            return True
    
    def same(x,y):
        return find(x) == find(y)

    par = [-1]*N

    res = 0
    for c, v1, v2 in cost:
        if not same(v1, v2):
            unite(v1, v2)
            res += c
    print(res)


if __name__ == '__main__':
    main()

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

#define NDEBUG
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

vector<ll> m(51), n(51);

ll sub(int N, ll X) {
    if (N == 0) { return X; }
    ll w = m[N-1];
    if (X <= 1) return 0;
    X -= 1;
    if (X <= w) return sub(N-1, X);
    X -= w;
    if (X <= 1) return n[N-1] + X;
    X -= 1;
    if (X <= w) return n[N-1] + 1 + sub(N-1, X);
    X -= w;
    return n[N];
}

ll solve(int N, ll X) {
    return sub(N, X);
}

int main() {
    m[0] = n[0] = 1;
    for (int i=1; i<=50; ++i) {
        m[i] = m[i-1]*2 + 3;
        n[i] = n[i-1]*2 + 1;
    }


    int N; ll X;
    cin >> N >> X;
    cout << solve(N,X) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 150
#define NIL -1
#define NNN 10000
int graph[MAX][MAX];
int d[MAX];
int n;
int Que[100000];
int head=0, tail=0;

void enQue(int q){
  Que[head]=q;
  head++;
}

int deQue(void){
  tail++;
  return Que[tail-1];
}

int size(void){
  return head-tail;
}

void bfs(int i){
  int j;
  for(j=0; j<n; j++){
    if(graph[i][j]==1 && d[j]==NIL){
      d[j]=d[i]+1;
      enQue(j);
    }
  }
}

void aaaaa(int a){
  int i, count=0;
  for(i=0; i<a; i++){
    count++;
  }
}

int main(){
  int u, k, i, j, v, a=10;
  scanf("%d", &n);
  for(i=0; i<MAX; i++)d[i]=NIL;
  for(i=0; i<n; i++){
    scanf("%d", &u);
    scanf("%d", &k);
    for(j=0; j<k; j++){
      scanf("%d", &v);
      graph[u-1][v-1]=1;
    }
  }
  d[0]=0;
  bfs(0);
  while(size()!=0){
    bfs(deQue());
  }
  for(i=0; i<n; i++){
    printf("%d %d\n", i+1, d[i]);
  }
  aaaaa(a);
  return 0;
}



Measured memory_bytes: 2148
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef vector<int> Edges;
typedef vector<Edges> Graph;

inline int square(int x) { return x * x; }

int n, t1, t2;
vector<int> state;
int x[1010];
int y[1010];
Graph g;
vector<int> cand;

int main() {
  int test;
  scanf("%d", &test);
  while (test--) {
    int sx, sy;
    scanf("%d %d %d %d %d", &n, &t1, &t2, &sx, &sy);
    t2++;
    g = Graph(n);
    state = vector<int>(n, 0);
    REP(i, n) {
      scanf("%d %d", &x[i], &y[i]);
    }
    REP(i, n) {
      if (square(x[i] - sx) + square(y[i] - sy) <= 100) {
        //cout << i << endl;
        state[i] = t1;
      }
      REP(j, i) {
        if (square(x[i] - x[j]) + square(y[i] - y[j]) <= 2500) {
          //cout << i << " " << j << endl;
          g[i].push_back(j);
          g[j].push_back(i);
        }
      }
    }
    ll ans = 0;
    set<vector<int> > open;
    while (true) {
      if (open.count(state)) {
        puts("You're always welcome!");
        goto next;
      }
      open.insert(state);
      int nt = 1 << 20;
      REP(i, n) {
        if (state[i] > 0) { nt = min(nt, state[i]); }
      }
      if (nt == (1 << 20)) { break; }

      queue<int> que;
      ans += nt;
      REP(i, n) {
        int l = nt;
        if (state[i] > 0) {
          if (state[i] == nt) { que.push(i); }
          int t = min(state[i], l);
          state[i] -= t;
          l -= t;
          if (state[i] == 0) { state[i] = -t2; }
        }
        if (state[i] < 0 && l > 0) {
          state[i] += l;
          state[i] = min(state[i], 0);
        }
      }

      while (!que.empty()) {
        int from = que.front();
        que.pop();
        FORIT(it, g[from]) {
          int to = *it;
          if (state[to] == 0) { state[to] = t1; }
        }
      }
    }
    printf("%lld\n", ans);
next:;
  }
}

Measured memory_bytes: 2188
#include <iostream>
#include <deque>
using namespace std;
deque<int> D;
int rev=0;
int a;
int N;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>a;
        if(!rev)D.push_back(a);
        else D.push_front(a);
        rev^=1;
    }
    if(!rev)for(auto it:D)cout<<it<<" ";
    else for(deque<int> :: reverse_iterator it=D.rbegin();it!=D.rend();it++)cout<<*it<<" ";
    return 0;
}


Measured memory_bytes: 3072
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

struct Input {
    N: usize,
    M: usize,
    qs: Vec<(usize, usize, usize, usize)>,
}

fn go(v: &mut Vec<usize>, input: &Input) -> usize {
    if v.len() == input.N + 1 {
        let mut res = 0;
        for q in &input.qs {
            let (a, b, c, d) = q;
            if v[*b] - v[*a] == *c {
                res += *d;
            }
        }
        res
    } else {
        let mut res = 0;
        for i in (*v.last().unwrap())..=input.M {
            let mut p = v.clone();
            p.push(i);
            res = max(res, go(&mut p, &input));
        }
        res
    }
}

#[fastout]
fn main() {
    input! {
        N: usize,
        M: usize,
        Q: usize,
        qs: [(usize, usize, usize, usize); Q],
    }

    let input = Input { N, M, qs };

    let mut u = vec![1];
    let ans = go(&mut u, &input);
    println!("{}", ans);
}


Measured memory_bytes: 2148
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	arr := make([]int, N)
	for i := range arr {
		fmt.Scan(&arr[i])
	}
	sort.Ints(arr)
	var ra []int
	b := arr[0]
	ra = append(ra, b)
	for i := 1; i < len(arr); i++ {
		if arr[i] == b {
			continue
		}
		ra = append(ra, arr[i])
		b = arr[i]
	}
	fmt.Println(len(ra))
}


Measured memory_bytes: 512
N = int(input())

A = []
a, *an = map(int, input().split())
A.append(a)
A += an
A.sort()

Node = []
score = 0
Node.append(A.pop())

#print(A)
start = 0

for n in range(N - 1):
    score += Node[start]
    num = A.pop()
    start += 1
    #Node = Node[1:]
    Node.append(num)
    Node.append(num)

#print(Node)
print(score)
    

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

using namespace std;
int main()
{
    string s,t;
    cin >> s >> t;
    int n = s.size(),m = t.size();
    int dmax = 0x3f3f3f3f;


    for(int i = 0;i <= n - m;i++)
    {
        string p = s.substr(i,m);
        //cout << p << endl;
        int cnt = 0;
        for(int j = 0;j < p.size();j++)
        {
            if(p[j] != t[j])cnt++;
        }
        dmax = min(dmax,cnt);
        cnt = 0;
    }
    if(s == t)cout << 0;
    else
    cout << dmax;
#ifdef LOCAL 
    system("pause");
#endif
    return 0;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int result = 0;
  if (s[0] == '1') result++;
  if (s[1] == '1') result++;
  if (s[2] == '1') result++;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	for(int i=max(b - a + 1, -100000); i<=min(100000, b + a - 1); i++)
		printf("%d ",i);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int cal(int x,int D,int r){
    return r*x-D ;
}
int main(void){
    // Your code here!
    int r,D,x;
    cin >> r >> D >> x;
    for(int i=0;i<10;i++){
        x= cal(x,D,r);
        cout << x << endl;
    }
}



Measured memory_bytes: 256
n = int(input())
A = []
B = []

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

A.sort()
B.sort()

if n % 2 == 0:
    print(B[n//2] + B[n//2-1] - A[n//2] - A[n//2-1] + 1)
else:
    print(B[(n-1)//2] - A[(n-1)//2] + 1)


Measured memory_bytes: 25424
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int n,d;
    cin >> n >> d;
    vector<vector<int> > x(n, vector<int>(d));
    int ans=0;
    for (int i=0;i<n;i++){
        for (int j=0;j<d;j++){
            cin >> x[i][j];
        }
    }

    for (int i=0;i<n;i++){
        for (int j=i+1;j<n;j++){
            int calc = 0;
            for (int k=0;k<d;k++){
                calc += (abs(x[i][k]-x[j][k]))*(abs(x[i][k]-x[j][k]));
            }
    
            int flag = 0;
            for(int p=0;p<=calc;p++){
                if(p*p==calc) flag=1;
            }
            if (flag){
                
                ans += 1;
            } 
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256