akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = [0]*n
b = [0]*n

for i in range(n):
    aa,bb = map(int, input().split())
    a[i] = aa
    b[i] = bb

a.sort()
b.sort()

if n%2 == 1:
    print(b[n//2] - a[n//2] + 1)
else:
    print(b[n//2] + b[(n//2)-1] - a[n//2] - a[(n//2)-1] + 1)


Measured memory_bytes: 25364
q,h,s,d = map(int,input().split())
n = int(input())
alitol = 0
if q*2 > h:
    if h*2 > s:
        alitol = s
    else:
        alitol = h*2
else:
    if q*4 > s:
        alitol = s
    else:
        alitol = q*4
if 2*alitol <= d:
    print(n*alitol)
else:
    print((n//2)*d + (n%2)*alitol)

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

typedef complex<double>Point;

struct Segment{
    Point p1,p2;
    Segment(const Point &p1=Point(),const Point &p2=Point()):p1(p1),p2(p2){}
};

struct Circle{
    Point p;
    double r;
    Circle(const Point &p=Point(),double r=0.0):p(p),r(r){}
};

typedef Point Vector;
typedef Segment Line;
typedef vector<Point>Polygon;

const double PI=acos(-1);
const double EPS=1e-8;
const double INF=1e16;
const int COUNTER_CLOCKWISE=1;
const int CLOCKWISE=-1;
const int ONLINE_BACK=2;
const int ONLINE_FRONT=-2;
const int ON_SEGMENT=0;

inline double square(double a){return a*a;}
inline double norm(const Point &a){return square(a.real())+square(a.imag());}
inline double dot(const Point &a,const Point &b){return (conj(a)*b).real();}
inline double cross(const Point &a,const Point &b){return (conj(a)*b).imag();}
inline double toDeg(double t){return t/PI*180.0;}
inline double toRad(double t){return t/180.0*t;}
#define equals(a,b) (fabs((a)-(b))<EPS)

void getPoint(Point &p){
    double x,y;
    scanf("%lf%lf",&x,&y);
    p=Point(x,y);
}

void getSegment(Segment &s){
    getPoint(s.p1);
    getPoint(s.p2);
}

bool orthogonal(Vector a,Vector b){
    return equals(dot(a,b),0.0);
}

bool orthogonal(Point a1,Point a2,Point b1,Point b2){
    return orthogonal(a1-a2,b1-b2);
}

bool orthogonal(Segment s1,Segment s2){
    return orthogonal(s1.p1-s1.p2,s2.p1-s2.p2);
}

bool parallel(Vector a,Vector b){
    return equals(cross(a,b),0.0);
}

bool parallel(Point a1,Point a2,Point b1,Point b2){
    return parallel(a1-a2,b1-b2);
}

bool parallel(Segment s1,Segment s2){
    return parallel(s1.p1-s1.p2,s2.p1-s2.p2);
}

Point project(Segment s,Point p){
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base)/norm(base);
    return s.p1+base*r;
}

Point reflection(Segment s,Point p){
    return p+(project(s,p)-p)*2.0;
}

int ccw(Point p0,Point p1,Point p2){
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS)return COUNTER_CLOCKWISE;
    if(cross(a,b)<-EPS)return CLOCKWISE;
    if(dot(a,b)<-EPS)return ONLINE_BACK;
    if(norm(a)<norm(b))return ONLINE_FRONT;
    return ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
    return ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
            ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0;
}

bool intersect(Segment s1,Segment s2){
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

Point getCrossPoint(Segment s1,Segment s2){
    Vector base=s2.p2-s2.p1;
    double d1=abs(cross(base,s1.p1-s2.p1));
    double d2=abs(cross(base,s1.p2-s2.p1));

    double t=d1/(d1+d2);
    return s1.p1+(s1.p2-s1.p1)*t;
}

void push(Point p){
    printf("%.20f %.20f\n",real(p),imag(p));
}

int main(){
    int N,K;
    cin>>N>>K;
    double t=2*PI/N;
    double a=(2*PI-2*t*K)/4;
    double s=t+2*a;
    double l=2*PI/N;

    double x=abs(polar(1.0,0.0)-polar(1.0,t));
    double h=x/2/tan(s/2);
    double S=h*x/2;
    h=x/2/tan(t/2);
    S+=t/2-h*x/2;
    printf("%.20f\n",PI-S*N);
    return 0;
}

Measured memory_bytes: 3568
#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};

char s[15][10005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, k;
    cin >> h >> w >> k;
    rep(i, h)rep(j, w) cin >> s[i][j];
    int ans = inf;

    // bit全探索
    for(int bit=0; bit < 1<<h-1; ++bit){
        bool flag = true;
        vector<int> id(h);
        int g = 0;
        rep(i, h){
            id[i] = g;
            if (bit>>i & 1) ++g;
        }
        ++g;
        int cnts[15][10005]; // cnts[i][j]: idとj

        rep(i, g)rep(j, w) cnts[i][j] = 0;
        rep(i, h)rep(j, w) cnts[id[i]][j] += (s[i][j]-'0');

        int num = g-1;
        vector<int> now(g);
        rep(j, w){
            bool ff = true;
            rep(i, g) now[i] += cnts[i][j];
            rep(i, g) {
                if (now[i] > k){
                    ff = false;
                }
            }
            if (!ff) {
                num++;
                now = vector<int>(g);
                rep(i, g) now[i] += cnts[i][j];
                rep(i, g) {
                    if (now[i] > k){
                        flag = false;
                    }
                }
                if (!flag){
                    num = inf;
                    break;
                }
            }
            if (!flag) break;
        }
        chmin(ans, num);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    string s, t;
    int i, l;
    getline(cin,s);
    getline(cin,t);
    l = s.length();
    for(i=0; i<l; i++) {
        if(s[i]-'a'==t[i]-'a') continue;
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

using static Input;
using static Util;
class Program
{
    static int N;
    static int M;
    static int[] W;
    static void INPUT()
    {
        N = NextInt();
        M = NextInt();
        W = LineInt();
    }
    static void OUT()
    {
        var d = N - W.Sum();
        Console.WriteLine(Math.Max(-1, d));
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{
}




Measured memory_bytes: 20396
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		int res1 = 0;
		int res2 = 0;
		foreach (i, c; s)
		{
			res1 += (c != ('0' ^ (i & 1)));
			res2 += (c != ('1' ^ (i & 1)));
		}
		writeln (min (res1, res2));
	}
}


Measured memory_bytes: 2456
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const int dx[] = {-1, 1, 0, 0};

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> M(h);
  rep(i,h)cin >> M[i];

  auto f = [&](int y,int x){
    int cnt = 0;
    rep(i,h){
      rep(j,w){
        if((y >> i) & 1)continue;
        if((x >> j) & 1)continue;
        if(M[i][j] == '#')cnt++;
      }
    }
    return cnt;
  };
  int ans = 0;
  rep(i,(1<<h)){
    rep(j,(1<<w)){
      if(f(i,j) == k){
        ans++;
      }
    }
  }
  rep(i,h)if(f(i,-1) == k)ans++;
  rep(i,w)if(f(-1,i) == k)ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<128>>;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << (x) << '\n'
typedef long long lint;
const int INF = 2e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const lint LINF = 1e18;
typedef vector<int> vint;
typedef pair<int, int> pint;
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
void print() { cout << endl; }
template <class T, class... A> void print(const T &first, const A &... rest) {
    cout << first;
    print(rest...);
}
template <class... A> void print(const A &... rest) { print(rest...); }
template <class T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int modulo(int a, int b, int n) {
    long long x = 1, y = a;
    while(b > 0) {
        if(b % 2 == 1) {
            x = (x * y) % n; // multiplying with base
        }
        y = (y * y) % n; // squaring the base
        b /= 2;
    }
    return x % n;
}
/* templates */ /* templates */ /* templates */ /* templates */ /* templates */

int MAXN = 3000;
vector<vector<bool>> flag(MAXN + 10, vector<bool>(MAXN + 10));
vector<vector<lint>> dp(MAXN + 10, vector<lint>(MAXN + 10));
vint a(MAXN + 10);

lint f(int l, int r) {
    if(flag[l][r]) {
        return dp[l][r];
    }
    flag[l][r] = true;
    if(l == r) {
        return dp[l][r] = a[l];
    }
    return dp[l][r] = max(a[l] - f(l + 1, r), a[r] - f(l, r - 1));
}

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

    int N = in();
    rep(i, 1, N + 1) { cin >> a[i]; }
    cout << f(1, N) << endl;
}


Measured memory_bytes: 74624
/*g++ main.cpp -o main.out*/
/*./main.out*/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int a[200005];

int main()
{
    int k,n,ans=0;
    cin>>k>>n;
    rer(i,1,n)cin>>a[i];
    sort(a+1,a+1+n);
    ans=abs(k-a[n]+a[1]);
    rer(i,2,n-1)ans=max(ans,max(abs(a[i]-a[i-1]),abs(a[i]-a[i+1])));
    cout<<k-ans<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second

mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin >> n;
  vii ans;
  for (int i = 1; i <= n; i++) {
	for (int j = i + 1; j <= n; j++) {
      if (j != n + 1 - n % 2 - i) {
        ans.push_back({i, j});
      }
    }
  }
  cout << ans.size() << endl;
  for (auto &x : ans) cout << x.f << " " << x.s << "\n";
}

/*
USE LONG LONG!!!!

5
15
1 14 4
2 13 3
3 12 2
4 11 1
5 10

1 6
2 5
3 4
4 3
5 2
6 1

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)    
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
	int n = 0;
	scanf("%d",&n);
	int A[n];
	int sum[n];
	sum[0] = 0;
	for (int i = 1; i < n; i++)
	{
		sum[i] = 0;
		scanf("%d",&A[i]);
		sum[A[i]-1]++;
	}
	for (int i = 0; i < n; i++)
	{
		printf("%d",sum[i]);
		if (i != n - 1)printf("\n");
	}
}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
constexpr int MOD = 1000000007;

int mod(const ll &x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(const ll &x,const ll &m){
    return (x % MOD) * (m % MOD) % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    int n; cin >> n;
    int ans = 1;
    FOR(i,1,n+1) ans = modm(ans,i);

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
antennas =[]
for i in range(5):
    antenna = int(input())
    antennas.append(antenna)
k = int(input())
antennas_max = max(antennas)
antennas_min = min(antennas)
antennas_distance_max = antennas_max - antennas_min
if k < antennas_distance_max:
    print(":(")
else:
    print("Yay!")

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

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> cnt(M);
  for (int x : a) {
    if (cnt[x] != 0) {
    	cnt[x] = 2;
      	continue;
    }
    for (int i = x; i < M; i += x) cnt[i]++;
  }
  int ans = 0;
  for (int x : a) {
    if (cnt[x] == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

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

    ll ans = 0;
    rep(bit, 1 << (S.size() - 1)) {
//        bool ok = true;
//        rep(i, S.size() - 1) {
//            int ib = (bit >> i) & 1;
//            int nb = (bit >> (i + 1)) & 1;
//            if (ib && nb) ok = false;
//        }
//        if (!ok) continue;

        string s;
        ll now = 0;
        rep(i, S.size()) {
            s += S[i];
            if ((bit >> i) & 1) {
                now += stoll(s);
                s = "";
            }
        }
        if (s != "") now += stoll(s);
        ans += now;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define llong long long
#define IFY 2000000000
#define MAX 10000
#define NIL -1
using namespace std;
struct Node{int parent,left,right;};
Node T[MAX];
int n;
void preparse(int u){
  if(u==NIL) return;
  printf(" %d",u);
  preparse(T[u].left);
  preparse(T[u].right);
}
void inparse(int u){
  if(u==NIL) return;
  inparse(T[u].left);
  printf(" %d",u);
  inparse(T[u].right);
}
void postparse(int u){
  if(u==NIL) return;
  postparse(T[u].left);
  postparse(T[u].right);
  printf(" %d",u);
}
int main(){
  int root=0,v,left,right;
  scanf("%d",&n);
  REP(i,n) T[i].parent=NIL;
  REP(i,n){
    scanf("%d %d %d",&v,&left,&right);
    T[v].left=left;
    T[v].right=right;
    if(left!=NIL) T[left].parent=v;
    if(right!=NIL) T[right].parent=v;
  }
  REP(i,n) if(T[i].parent==NIL) root=i;
  printf("Preorder\n");
  preparse(root);
  printf("\n");
  printf("Inorder\n");
  inparse(root);
  printf("\n");
  printf("Postorder\n");
  postparse(root);
  printf("\n");
  return 0;
}

Measured memory_bytes: 2728
#include<cstdio>
#include<algorithm>

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

using namespace std;

#define sq(x) (x)*(x)

int n,r;
double a[20],b[20],c[20];

double dfs(int i,int j,int S){
	if(j>r) return -1;

	if(n==i){
		if(j!=r) return -1;
		double sum=0;
		rep(l,n) rep(k,l) if(S&(1<<k) && S&(1<<l)) {
			sum+=sq(a[k]-a[l])+sq(b[k]-b[l])+sq(c[k]-c[l]);
		}
		return sum;
	}

	return max(dfs(i+1,j,S),dfs(i+1,j+1,S|(1<<i)));
}

int main(){
	scanf("%d%d",&n,&r);
	rep(i,n) scanf("%lf%lf%lf",a+i,b+i,c+i);

	printf("%.9f\n",dfs(0,0,0));

	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>

using namespace std;

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

int w,h;
vector<vector<int> > c(50,vector<int>(50,0));

void dfs(int y,int x){
    c[y][x]=0;
    for(int dy=-1;dy<=1;dy++){
        for(int dx=-1;dx<=1;dx++){
            int ny=y+dy,nx=x+dx;
            if(ny>=0&&ny<h&&nx>=0&&nx<w&&c[ny][nx]==1){
                dfs(ny,nx);
            }
        }
    }
    return ;
}

int main(){
    cin>>w>>h;
    while(!(w==0&&h==0)){
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>c[i][j];
            }
        }
        int cnt=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(c[i][j]==1){
                    dfs(i,j);
                    cnt++;
                }
            }
        }
        cout<<cnt<<endl;
        cin>>w>>h;
    }
    return 0;
}


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

using namespace std;

const int N=110;

int a[N],dp[N][N];

int main()
{
    int n;

    scanf("%d",&n);

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

    memset(dp,0x3f3f,sizeof(dp));

    for(int i=1;i<=n;i++) dp[i][i]=0;

    for(int l=2;l<=n;l++)
    {
        for(int i=1;i+l<=n+1;i++)
        {
            int j=i+l-1;
            for(int k=i;k<j;k++)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+a[i]*a[j+1]*a[k+1]);
            }
        }
    }

    printf("%d\n",dp[1][n]);

    return 0;
}



Measured memory_bytes: 3272
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    int A;
    cin >> A;
    A--;
    a[A]++;
  }

  sort(a.begin(),a.end());
  vector<int> sum;
  sum = a;

 

  for(int i = 1; i < a.size(); i++) {
    sum[i] += sum[i-1];
  }

 
  for(ll i = 1; i <= n; i++) {
    ll l = 0, r = n + 1;
   
    while(r - l > 1) {
      ll mid = (l + r) / 2;
      ll tmp = upper_bound(a.begin(),a.end(),mid) - a.begin();
      ll x = sum[tmp-1];
      ll y = (a.size() - tmp) * mid;
      //  cout <<"mid = "<<  mid <<"   tmp = "<< tmp <<"   x+y = "<<x+y<< endl;
      if(x + y >= mid * i) l = mid;
      else r = mid;
    }

     cout << l << endl;
  }
}






      


Measured memory_bytes: 3200
function Main (input) {
  input = input.split("\n").map(inp => inp.split(" ").map(Number));
  var N = input[0];
  var A = input[1];
  var ans = 0;
  A.forEach((e, i, ar) => {
    if (i > 0 && i < N-1) {
      if ([ar[i-1], e, ar[i+1]].sort((a, b) => b > a)[1] == e) {
        ans++;
      }
    }
  });
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

namespace AtCoderPre
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().OrderBy(c => c).ToArray();
            Console.WriteLine(a[0] == a[1] && a[2] == a[3] && a[0] != a[2] ? "Yes" : "No");
        }

    }
}

Measured memory_bytes: 13268
import bisect


def solve(s, t):
    indexes = {}
    for i, c in enumerate(s):
        indexes.setdefault(c, []).append(i)
    index = 0
    loop_count = 0
    for c in t:
        if c not in indexes:
            return -1
        else:
            found_i = bisect.bisect_left(indexes[c], index)
            if found_i == len(indexes[c]):
                loop_count += 1
                index = indexes[c][0] + 1
            else:
                index = indexes[c][found_i] + 1
    return index + loop_count * len(s)

if __name__ == "__main__":
    s = input()
    t = input()
    print(solve(s, t))


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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  
  if (A == B && A == C ) {
    cout <<"No"<<endl;
  }
  else if(A != B && B != C && C != A) {
    cout << "No" <<endl;
  }
  else {
    cout << "Yes" <<endl;
  }
  
  

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n= int(input())
h = [int(s) for s in input().split()]

yes = True
for i in reversed(range(len(h))):
    if i == len(h)-1:
        continue
    if h[i] <= h[i+1]:
        pass
    elif h[i] == h[i+1] + 1:
        h[i] -= 1
    else:
        yes = False
        break

if yes:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
#include<cstdio>
char str[100001];
int main() {
	int n, i, j, k=-1;
	char c, s[4] = { 's','s','w','w' }, t[4] = { 's','w','s','w' }, tmp;
	scanf("%d%s", &n, str);
	for (i = 0; i < n; i++) {
		c = str[i];
		if (c == 'o') {
			for (j = 0; j < 4; j++) {
				if (t[j] == 'w') {
					if (s[j] == 's') s[j] = 'w';
					else s[j] = 's';
				}
			}
		}
		else {
			for (j = 0; j < 4; j++) {
				if (t[j] == 's') {
					if (s[j] == 's') s[j] = 'w';
					else s[j] = 's';
				}
			}
		}
		for (j = 0; j < 4; j++) {
			tmp = s[j];
			s[j] = t[j];
			t[j] = tmp;
		}
	}
	if (s[0] == 's'&&t[0] == 's') k = 0;
	if (s[1] == 's'&&t[1] == 'w') k = 1;
	if (s[2] == 'w'&&t[2] == 's') k = 2;
	if (s[3] == 'w'&&t[3] == 'w') k = 3;
	if (k == -1) {
		printf("-1");
		return 0;
	}
	for (i = 0; i < n-1; i++) {
		printf("%c", t[k]-'a'+'A');
		c = str[i];
		if (c == 'o') {
			if (t[k] == 'w') {
				if (s[k] == 's') s[k] = 'w';
				else s[k] = 's';
			}
		}
		else {
			if (t[k] == 's') {
				if (s[k] == 's') s[k] = 'w';
				else s[k] = 's';
			}
		}
		tmp = s[k];
		s[k] = t[k];
		t[k] = tmp;
	}
	printf("%c", t[k]-'a'+'A');
	return 0;
}

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

using Int = int;
using namespace std;

#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; };
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; };
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

int main(){
	Int n, x, y;
	cin >> n >> x >> y;

	--x;
	--y;

	static Int a[2123][2123];
	RC(i, n) RC(j, i){
		a[j][i] = i - j;
	}
	RC(i, n) RC(j, i){
		onth(a[j][i], rng(j, x) + rng(i, y) + 1);
	}

	static Int ans[2123];

	RC(i, n) RC(j, n) {
		++ans[a[j][i]];
	}

	ARC(i, 1, n){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 16768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;

#pragma GCC optimize("O3")
#define MOD 1000000007
#define pb push_back
#define fi first
#define se second
#define fr front()
#define ba back()
#define tp top()
#define mem(x,n) memset(x,n,sizeof(x));
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,l) for(auto it=l.begin();it!=l.end();it++)
#define pnl printf("\n")
#define len(x) x.length()

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> pii;
typedef pair<pii,int> piii;
const int inf=(1<<30);
const LL llinf=(1ll<<60);
const double eps=(1e-10);
//const double pi=2*acos(0.0);
//const double GOLD=((1+sqrt(5))/2);
const int xx[8]={1,0,-1,0,1,-1,1,-1};
const int yy[8]={0,1,0,-1,-1,1,1,-1};
const int kx[8]={1,1,2,2,-1,-1,-2,-2};
const int ky[8]={2,-2,1,-1,2,-2,1,-1};

/* \( ·w·)~ Clapie ~(·w· )/ */

LL memo[3005][3005][2],arr[3005];
int n;

LL dp(int left,int right,int person){
	//0 taro max
	//1 jiro min
	
	if(left>right) return 0;
	if(memo[left][right][person]!=-1) return memo[left][right][person];
	
	if(person==0){
		return memo[left][right][person]=max(dp(left+1,right,1-person)+arr[left],dp(left,right-1,1-person)+arr[right]);
	}
	else{
		return memo[left][right][person]=min(dp(left+1,right,1-person)-arr[left],dp(left,right-1,1-person)-arr[right]);
	}
}

int main(){
	mem(memo,-1);
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&arr[i]);
	}
	LL ans=dp(0,n-1,0);
	printf("%lld\n",ans);
}

Measured memory_bytes: 141696
#abc152d

n=int(raw_input())
l=[[0 for i in range(10)] for j in range(10)]
for i in range(1,n+1):
 l[int(str(i)[0])][int(str(i)[-1])]+=1
res=0
for i in range(10):
 for j in range(10):
  res+=l[i][j]*l[j][i]
print res


Measured memory_bytes: 8964
n = int(input())
al = []
bl = []
for _ in range(n):
    a, b = map(int, input().split()) 
    al.append(a)
    bl.append(b)

al.sort()
bl.sort()


if n%2 == 1:
    print(bl[n//2] - al[n//2] + 1)
else:
    print(bl[n//2-1]-al[n//2]+bl[n//2]-al[n//2-1]+1)

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

int main() {
    ll N;
    ll MIN = 1LL << 60;
    for (int i = 0; i < 6; i++) {
        ll x;
        if (i == 0) {
            cin >> x;
            N = x;
        }
        else {
            cin >> x;
            MIN = min(MIN, x);
        }
    }
    
    cout << (N+MIN-1)/MIN + 4 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
using namespace std;
vector <int> x ;
int n , dp[100003] , k ;
int SAAD ( int idx ) {
	if ( idx == n-1 ) return 0 ;
	if ( dp[idx] != -1 ) return dp[idx] ;
	int res = 1e9 ;
	for ( int i = 1 ; i <= k ; i++ ) {
		if (idx+i<n) res = min(res,SAAD(idx+i)+abs(x[idx]-x[idx+i]));
	}
	return dp[idx] = res ;
}
int main() {
	memset(dp,-1,sizeof(dp));
	int p ;
	cin >> n >> k ;
	for (int i = 0 ; i < n ; i++ ) {
		cin >> p; 
		x.push_back(p);
	}
	cout << SAAD(0) ;
	return 0;
}

Measured memory_bytes: 7416
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    int mincnt=INFINITY;
    for(int i=0; i<=s.length()-t.length(); i++){
        int cnt=0;
        for(int j=0; j<t.length(); j++){
            if(s[i+j]!=t[j]) cnt++;
        }
        mincnt=min(cnt,mincnt);
    }
    cout << mincnt;
}


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

using namespace std;
using ll = long long;

int main(){
    string s;
    cin>>s;
    int ans;
    if(s == "SUN"){
        ans = 7;
    }
    if(s == "MON"){
        ans = 6;
    }
    if(s == "TUE"){

        ans = 5;
    }
    if(s == "WED"){

        ans = 4;
    }
    if(s == "THU"){

        ans = 3;
    }
    if(s == "FRI"){

        ans = 2;
    }
    if(s == "SAT"){
        ans = 1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 764
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; i++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	int M; cin >> M;
	cout << 24 + 24 - M << endl;
}

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

#define ll long long
#define s second
#define f first

int main()
{
	string s;
	cin >> s;
	
	if(s=="SUN") cout << 7 << endl;
	if(s=="MON") cout << 6 << endl;
	if(s=="TUE") cout << 5 << endl;
	if(s=="WED") cout << 4 << endl;
	if(s=="THU") cout << 3 << endl;
	if(s=="FRI") cout << 2 << endl;
	if(s=="SAT") cout << 1 << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = Long.parseLong(sc.next());
        int n = 0;
        while (h > 0) {
            n++;
            h /= 2;
        }
        System.out.println((long)Math.pow(2, n) - 1);
    }
}


Measured memory_bytes: 21844
fn main() {
  fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
  }
  fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
  }
  fn binary_search<F>(vec: &Vec<i32>, f: F) -> usize
  where
    F: Fn(&Vec<i32>, usize) -> bool,
    {
      let mut low = 0;
      let mut high = vec.len();
      while low < high {
        let mid = (low + high) / 2;
        if f(&vec, mid) {
          high = mid;
        } else {
          low = mid + 1;
        }
      }
    low
  }

  let mut ans = 0;
  let n = read::<usize>();
  let mut a = read_vec::<i32>();
  a.sort();
  let mut b = read_vec::<i32>();
  b.sort();
  let mut c = read_vec::<i32>();
  c.sort();
  for j in 0..n {
    let ab = binary_search(&a, |a, i| b[j] <= a[i]);
    let bc = n - binary_search(&b, |b, i| b[j] < c[i]);
    ans += ab * bc;
  }
  println!("{:?}", ans);
}

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

int main()
{
    int n;
    scanf("%d",&n);
    vector <int> a(n) ,frq(n);
    for(int&i : a)
        scanf("%d",&i) ,frq[i-1]++;

    sort(frq.begin() ,frq.end());
    vector <int> cfrq = frq;
    for(int i=1; i<n; i++)
        cfrq[i] += cfrq[i-1];

    vector <int> ans(n);
    for(int j=0,i=1; i<=n; i++){
        while(j<n && frq[j]<=i) j++;
        ans[cfrq[j-1]/i + n-j-1] = i;
    }

    for(int i=n-2; ~i; i--)
        ans[i] = max(ans[i] ,ans[i+1]);
    for(int i : ans)
        printf("%d\n",i);
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 +7;
constexpr int MAXNe6 = 1e6 + 7;
#pragma region 
inline long long read()
{
	char c = getchar();long long flag = 1, ans = 0;
	while(c < '0' || c > '9'){if(c == '-')flag = -1; c = getchar();}
	while(c >= '0' && c <= '9'){ans = ans * 10 + c - '0'; c = getchar();}
	return (ans * flag);
}
#pragma endregion
// C'est la vie
int main() {
    int h = read(), a = read();
    cout << ((h - 1) / a + 1 ) << endl;
    #ifndef ONLINE_JUDGE
    system("pause");
    #endif
}

Measured memory_bytes: 504
a, b = map(int, input().split())
b = b + 1
d = 1
res = 0
t1 = a % 4
t2 = b % 4
ls = [0, 1, 0, 1]
res += (sum(ls[:t2]) - sum(ls[:t1])) % 2
while 2 ** d < max(a, b):
    tmp1 = a % (2 ** (d + 1))
    tmp2 = b % (2 ** (d + 1))
    tmp3 = max(tmp1, tmp2)
    tmp4 = min(tmp1, tmp2)
    if tmp3 >= 2 ** d:
        tmp3 = tmp3 % 2
    else:
        tmp3 = 0
    if tmp4 >= 2 ** d:
        tmp4 = tmp4 % 2
    else:
        tmp4 = 0
    tmp = (tmp4 - tmp3) % 2
    res += tmp * (2 ** d)
    d += 1

print(res)

Measured memory_bytes: 3064
n, k = map(int, input().split())
a = list(map(int, input().split()))

l = 0
r = 10**9 + 1
ref = 0
ans = 10**9

while r - l > 1:
    now = (l + r)//2
    for i in a:
        ref += 0 - -i//now - 1
        if ref > k:
            ref = 0
            l = now
            break
    else:
        ans = now
        ref = 0
        r = now
print(ans)

Measured memory_bytes: 31036
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    int ans = 0;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i=0;i<n;i++){
       cin >> a[i];
    }
    for(int i=0;i<n;i++){
       cin >> b[i];
    }
    for(int i=0;i<n;i++){
        int asum=0;
        int bsum=0;
        for(int j=0;j<n;j++){
            if(j<=i){
            asum+=a[j];
            }
            if(j>=i){
            bsum+=b[j];
            }
        }
        if(asum+bsum>ans){
            ans = asum+bsum;
        }
    }
    cout << ans << endl;
}

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

int par[2][MAX_N];
int myrank[2][MAX_N];

void init(int n){
	rep(i,n){
		par[0][i] = par[1][i] = i;
		myrank[0][i] = myrank[1][i] =0;
	}
}

int find(int x, int z){
	return par[z][x]==x?x:par[z][x] = find(par[z][x], z);
}

void unite(int x, int y, int z){
	x = find(x,z);
	y = find(y,z);
	if(x == y) return;
	
	if(myrank[z][x] < myrank[z][y]){
		par[z][x] = y;
	} else {
		par[z][y] = x;
		if(myrank[z][x] == myrank[z][y]) myrank[z][x]++;
	}
}

signed main(){	
	int N, K, L, a, b;
	unordered_map<int,int> mp;
	cin>>N>>K>>L;
	
	init(N+10);
	
	rep(i, K){cin>>a>>b;unite(a,b,0);}
	rep(i, L){cin>>a>>b;unite(a,b,1);}
	
	// rep(i,N) mp[find(i,0)*(N+1) + find(i,1)]++;
	
	rep(i,N) mp[find(i,0)*(N+29) + find(i,1)]++;
	
	rep(i,N) cout<<(i-1?" ":"")<<mp[find(i,0)*(N+29)+find(i,1)];
	
	cout<<endl;
	
	
	return 0;
}

Measured memory_bytes: 14536
#include<stdio.h>
#include<string.h>
int main()
{
	int i,n = 1;
	char s[5][105];
	int len[5],t[5];
	for(i = 1;i <= 3;i++)
	{
		scanf("%s",s[i] + 1);
		len[i] = strlen(s[i] + 1);
		t[i] = 0;
	}
	t[1] = 1;
	while(1)
	{
		if(s[n][t[n]] == 'a')
		{
			t[1]++;
			n = 1;
		}
		else if(s[n][t[n]] == 'b')
		{
			t[2]++;
			n = 2;
		}
		else if(s[n][t[n]] == 'c')
		{
			t[3]++;
			n = 3;
		}
		if(t[n] == len[n] + 1)
		{
			if(n == 1)
				printf("A\n");
			else if(n == 2)
				printf("B\n");
			else if(n == 3)
				printf("C\n");
			break;
		}

	}
	return 0;
}


Measured memory_bytes: 128
n,m=gets.split.map(&:to_i)
cakes=[*1..n].map{gets.split.map(&:to_i)}
list=Array.new(n,0)
n.times{|i|
  cakes[i]=eval ([cakes[i]]*8).to_s
  8.times{|x|
    cakes[i][x][0]=cakes[i][7][0]*(x[2]*2-1)
    cakes[i][x][1]=cakes[i][7][1]*(x[1]*2-1)
    cakes[i][x][2]=cakes[i][7][2]*(x[0]*2-1)
    cakes[i][x]=cakes[i][x].inject(:+)
    }
  }
8.times{|i|
  temp=eval cakes.to_s
  temp.sort_by!{|x|x[i]}
   list<<temp[n-m,m].inject(0){|s,x|s+x[i]}
  }
p list.max

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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
const ll INFL = 1e18;
const int INFI = 1e9;
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	ll a; cin>>a;
	cout<<a+a*a+a*a*a<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	while(t--)
		solve();
}

Measured memory_bytes: 3656
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=998244353;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
class COM{
    vi fact;
    vi inv;
    ll N;
    ll mod;
public:
    COM(ll n,ll m=MOD){
        N=n;fact.resize(N+1);inv.resize(N+1);
        mod=m;
    }
    ll power(ll a, ll b){
        ll res=1;
        while(b>0){
            if(b&1) res=res*a%mod;
            a=a*a%mod;
            b>>=1;
        }
        return res;
    }
    void __init__(){
        fact[0]=1;
        REPS(i,N){fact[i]=fact[i-1]*i%mod;}
        inv[N]=power(fact[N],mod-2);
        RREPS(i,N){inv[i-1]=inv[i]*i%mod;}
    }
    ll nCr(ll n,ll r){
        return fact[n]%mod*inv[n-r]%mod*inv[r]%mod;
    }
};
//-----------------------------------------
int main(void){
    ll N,M,K;cin>>N>>M>>K;
    COM com(N);
    com.__init__();

    ll ans=0;
    REP(i,K+1){
        ans+=M*com.power(M-1,N-i-1)%MOD*com.nCr(N-1,i)%MOD;
    }
    cout<<ans%MOD<<"\n";
}

Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//std::ios::sync_with_stdio(false); cin.tie(NULL);
	int n;
	rd(n);
	vector<int> arr(n);
	vector<PII> order;
	fr(i,0,n)
	{
		rd(arr[i]);
		order.PB(MP(arr[i],i+1));
	}
	sort(ALL(order));
	for(auto i: order)
	{
		cout<<i.S<<" ";
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 200100;

int cnt[N], zeros, kek[N];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ++cnt[a[i]];
    }
    for (int i = n; i >= 1; --i) {
        for (int j = 0; j < min(cnt[i], i + 1); ++j) {
            ++kek[i - j];
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (!kek[i]) {
            ++zeros;
        }
    }
    while (m--) {
        int x, y;
        cin >> x >> y;
        --x;
        if (a[x] - cnt[a[x]] + 1 >= 1) {
            if (--kek[a[x] - cnt[a[x]] + 1] == 0) {
                ++zeros;
            }
        }
        --cnt[a[x]];
        a[x] = y;
        if (y - cnt[y] >= 1) {
            if (++kek[y - cnt[y]] == 1) {
                --zeros;
            }
        }
        ++cnt[y];
        cout << zeros << '\n';
    }
    return 0;
}

Measured memory_bytes: 3840
#include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N, M, K;
string s, t;

int main(){
	cin >> N >> M;
	p(max(0LL, N*(N-1)/2)+max(0LL, M*(M-1)/2));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            ((ll)5e18 + 5)
//#define inf             (ll)1e18 + 5
#define PI              (double)3.14159265358979323844
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

ll expo(ll base, ll exponent) {                     //return base^exponent modulo hell
    ll ans = 1;
    while(exponent !=0 ) {
        if((exponent&1) == 1) {
            ans = ans*base ;
            ans = ans%hell;
        }
        base = base*base;
        base %= hell;
        exponent>>= 1;
    }
    return ans%hell;
}
void solve() {
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    rep(i,0,n){
    	cin>>arr[i];
    	arr[i]--;
    }
    ll dp[n][61];
    rep(i,0,n){
    	dp[i][0]=arr[i];
    }
    rep(i,1,61){
    	rep(j,0,n){
    		dp[j][i]=dp[dp[j][i-1]][i-1];
    	}
    }
    ll start=61;
    ll pos=0;
    while (k){
    	ll x=(ll)log2(k);
    	//trace(x);
    	pos=dp[pos][x];
    	k-=(expo(2,x));
    	//trace(k);
    }
    cout<<pos+1<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}


Measured memory_bytes: 100604
import math
import bisect


def all_divisor(n):
  i = 1
  divisor_small = []
  divisor_large = []
  if n == 1:
    return [1]
  else:
    while i * i <= n:
      if n % i == 0:
        divisor_small.append(i)
        divisor_large.append(n // i)
      i += 1
  divisor_large.reverse()
  divisor = divisor_small + divisor_large 
  return divisor

n,m = map(int, input().split())
divisor = all_divisor(m)
max_div = m // n
insert_index = bisect.bisect(divisor,max_div)
print(divisor[insert_index-1])

Measured memory_bytes: 3188