akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void)
{
	int i,j,k,l,m,a[20],c[20],d[20],S,S1,dmax;
	char s[20],s1[2];
	
	while(1)
	{
		scanf("%d",&k);
		if(k==0) break;
		for(i=0;i<=k-1;i++)
		{
			scanf("%s",s);
			d[i]=strlen(s)-1;
			if(s[strlen(s)-1]=='+')
			{
				c[i]=1;
				a[i]=-1;
			}
			else if(s[strlen(s)-1]=='*')
			{
				c[i]=2;
				a[i]=-1;
			}
			else
			{
				c[i]=0;
				s1[0]=s[strlen(s)-1];
				s1[1]='\0';
				sscanf(s1,"%d",&a[i]);
			}
		}
		for(i=0;i<=19;i++)
		{
			dmax=-1;
			for(j=0;j<=k-1;j++)
			{
				if(dmax<d[j])
				{
					dmax=d[j];
					l=j;
				}
			}
			if(dmax==1)
			{
				S1=a[1];
				if(c[0]==1)
				{
					for(j=2;j<=k-1;j++)
					{
						S1+=a[j];
					}
					i=19;
				}
				else if(c[0]==2)
				{
					for(j=2;j<=k-1;j++)
					{
						S1*=a[j];
					}
					i=19;
				}
			}
			else if(dmax==0) 
			{
				S1=a[0];
				i=19;
			}
			j=l;
			while(j<=k-1 && dmax==d[j])
			{
				j++;
			}
			m=j;
			S=a[l];
			for(j=l+1;j<=m-1;j++)
			{
				if(c[l-1]==1)
				{
					S+=a[j];
				}
				else if(c[l-1]==2)
				{
					S*=a[j];
				}
			}
			a[l-1]=S;
			c[l-1]=0;
			for(j=l;j<=k-m+l-1;j++)
			{
				a[j]=a[j+m-l];
				c[j]=c[j+m-l];
				d[j]=d[j+m-l];
			}
			k=k-m+l;
		}
		printf("%d\n",S1);
	}
	return 0;
}

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

int main(void) {
	int A1, A2, A3;
	cin >> A1 >> A2 >> A3;

	int sum = A1 + A2 + A3;
	if (sum <= 21)
		cout << "win\n";
	else
		cout << "bust\n";

	return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import Data.Char
import Data.List (unfoldr)
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInt
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntN n = map readInt <$> replicateM (fromIntegral n) BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents


main = do
  xs <- getLine
  print $ length $ filter (\i -> i == '1') xs

Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+5;
void solve(){
	string s; 
	cin>>s; 
	int n = s.size();
	if(s[0]==s[n-1])n--;
	if(n%2)cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

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

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


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

   if(s=="ABC")printf("ARC\n");
   else{
    printf("ABC\n");
   }


    return 0;
}



Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define print(a) cout << (a) << endl; 
typedef long long ll;

int main() {
    int n; 
    cin >> n;
    unordered_map<int, int> mp; 
    vector<int> as(n);
    rep(i, n) {
        cin >> as[i];
        mp[as[i]]++; 
    } 
    ll tot = 0;
    for (auto& p : mp) {
        ll lp = p.second;
        tot += lp * (lp - 1) / 2;
    }
    for (int a : as) {
        cout << tot - mp[a] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 8392
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  count = 0
  for i in range(1, n+1):
    if len(str(i)) % 2 == 1:
      count += 1
  print(count)

if __name__=='__main__':
  main()



Measured memory_bytes: 2940
#include <cstdio>
#include <vector>

using namespace std;

const int MAX_N = 100005;

int main() {
    int n, l;
    long long max_time = 0;
    vector<int> lens(MAX_N, 0);
    vector<int> valleys;

    scanf("%d %d", &n, &l);
    for (int i = 1; i <= n; i++) {
        int ai;
        scanf("%d", &ai);
        lens[i] = ai;
    }

    valleys.push_back(1);
    for (int i = 2; i <= n - 1; i++) {
        if (lens[i] < lens[i - 1] && lens[i] < lens[i + 1]) {
            valleys.push_back(i);
        }
    }
    valleys.push_back(n);

    for (auto& pos: valleys) {
        auto left_time = l - lens[pos], right_time = l - lens[pos];
        auto now_pos = pos;
        while (lens[now_pos - 1] > lens[now_pos]) {
            left_time += l - lens[--now_pos];
        }
        now_pos = pos;
        while (lens[now_pos + 1] > lens[now_pos]) {
            right_time += l - lens[++now_pos];
        }
        if (left_time > max_time) { max_time = left_time; }
        if (right_time > max_time) { max_time = right_time; }
    }

    printf("%lld\n", max_time);

    return 0;
}

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

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


Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	void operator()(int n, int k, string s) {
		deque<int> ans;
		int p=n;
		for(;p>0;)
		{
			int cp=p;
			for(int i=1;i<=k && i<=p;i++)
			{
				int np=p-i;
				if(s[np]=='0')
				{
					min_u(cp, np);
				}
			}
			if(cp==p)
			{
				cout << "-1\n";
				return;
			}
			ans.push_front(p-cp);
			p=cp;
		}
		cout << ans[0]; ans.pop_front();
		for(int m:ans) cout << " " << m;
		cout << "\n";
		return;
	}
};

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

	for(;;)
	{
		int n, k;
		string s;
		cin >> n >> k >> s;
		if(cin.fail()) break;

		solve()(n, k, s);
	}
	return 0;
}


Measured memory_bytes: 1104
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 998244353
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define maxn 200001
vector<vector<ll>>v(maxn);
vector<ll>mark(maxn);
ll val=0;
void dfs(ll x)
{
    mark[x]=1;
    val++;
    for(auto itr:v[x])
    {
        if(mark[itr]==1)
        {
            continue;
        }
        dfs(itr);
    }
}
int main()
{
    fastIO;
    ll n,m;
    cin>>n>>m;
    ll x,y;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    vector<ll>vec;
    for(int i=1;i<=n;i++)
    {  
        if(mark[i]==0)
        {
            val=0;
            dfs(i);
            vec.push_back(val);
        }
    }
    sort(vec.begin(),vec.end());
    cout<<*vec.rbegin()<<endl;
}

Measured memory_bytes: 21824
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

signed main(){
	int a, b, c, ans = 0;
	scanf("%lld%lld%lld", &a, &b, &c);
	if(a == 1 and b == 1 and c == 0)ans = 1;
	if(a == 0 and b == 0 and c == 1)ans = 1;
	printf("%s\n", ans ? "Open" : "Close");
	return 0;
}





Measured memory_bytes: 3152
#include <iostream>

using namespace std;
int main()
{
    int a,b[10000]={},count=0,num[10000]={},num1=0,num2=0;
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>b[i];
    }
    for(int i=0;i<a;i++)
    {
        if(i!=a-1 && b[i]>b[i+1])
        {
            count=count+1;
            num[count]=b[i];
            if(count==1)
                {
                    num1=b[i+1];
                }
            if(count==2)
            {
                num2=b[i+1];
            }
        }
    }
    if(count==2)
    {
        if(num[1]>num[2] && num1>num2)
            {
                cout<<"YES";
            }
            else
            {
                cout<<"NO";
            }
    }
    else if(count == 0)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}

Measured memory_bytes: 384
import numpy as np
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

a = np.array(a).reshape(h, w)
a = [i for i in a if "#" in i]

a = np.array(a).T
a = [i for i in a if "#" in i]

a = np.array(a).T
for i in a:
    print("".join(i))


Measured memory_bytes: 14292
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

ll H, W, K;
const ll inf = 5e15;

ll dist_to_outside(ll h, ll w) {
    return var_min(h, (H - 1) - h,
                   w, (W - 1) - w);
}

ll rest_magic(ll h, ll w) {
    ll dist = dist_to_outside(h, w);
    return dist / K + !!(dist % K);
}

int main() {
    cin >> H >> W >> K;
    V<string> A(H);
    for(auto &&s : A) cin >> s;
    ll sh, sw;
    for(ll i = 0; i < H; i++) for(ll j = 0; j < W; j++) if(A[i][j] == 'S') {
        sh = i;
        sw = j;
        break;
    }

    ll ans = inf;
    queue<pair<PLL, ll>> que;
    que.emplace(PLL(sh, sw), 0);
    VV<ll> dists = make_v<ll>(inf, H, W);
    dists[sh][sw] = 0;
    ll dh[] = { 1, 0, -1, 0 };
    ll dw[] = { 0, 1, 0, -1 };

    while(que.size()) {
        ll h, w, d;
        tie(h, w) = que.front().first;
        d = que.front().second;
        que.pop();
        if(dists[h][w] < d) continue;
        chmin(ans, rest_magic(h, w));
        if(d == K) continue;
        for(ll i = 0; i < 4; i++) {
            ll nh = h + dh[i];
            ll nw = w + dw[i];
            ll nd = d + 1;
            if(!(0 <= nh && nh < H &&
                 0 <= nw && nw < W)) continue;
            if(dists[nh][nw] <= nd) continue;
            if(A[nh][nw] != '.') continue;
            DEBUG(make_tuple(nh, nw));
            dists[nh][nw] = nd;
            que.emplace(PLL(nh, nw), nd);
        }
    }
    cout << ans + 1 << endl;
    return 0;
}



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

const ll MOD = 1000000007;
int n, bitsum[70];
ll a[303030], xorsum[70];

int main(){
  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) rep(j, 60) bitsum[j] += ((a[i] >> j) & 1LL);
  
  rep(i, n - 1){
    rep(j, 60) bitsum[j] -= ((a[i] >> j) & 1LL);
    rep(j, 60){
      xorsum[j] += ((a[i] >> j) & 1)? (n - i - bitsum[j] - 1) : bitsum[j];
      xorsum[j] %= MOD;
    }
  }
  
  ll res = 0;
  rep(i, 60){
    xorsum[i] *= ((long)pow(2, i) % MOD);
    res += xorsum[i] % MOD;
    res %= MOD;
  }
  cout << res << endl;
  return 0;
}

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

using i64 = long long;

const int N = 2005;

char mx[N][N];
int nod[N][N], l[N][N], u[N][N];

int n, m, q;

static int sum(int mx[N][N], int x1, int y1, int x2, int y2) {
	--x1, --y1;
	return mx[x2][y2] + mx[x1][y1] - mx[x2][y1] - mx[x1][y2]; }

int main() {
#ifdef HOME
	freopen("agc15c.in", "r", stdin);
	freopen("agc15c.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int x1, y1, x2, y2;

	cin >> n >> m >> q;
	for (int i = 1; i <= n; ++i)
		cin >> (mx[i] + 1);

	for (int i = 1; i <= n; ++i)
	for (int j = 1; j <= m; ++j) {
		nod[i][j] = int(mx[i][j] == '1');
		u[i][j] = int(mx[i][j] == mx[i - 1][j] && mx[i][j] == '1');
		l[i][j] = int(mx[i][j] == mx[i][j - 1] && mx[i][j] == '1'); }

	for (int i = 1; i <= n; ++i)
	for (int j = 1; j <= m; ++j) {
		nod[i][j]+= nod[i - 1][j] + nod[i][j - 1] - nod[i - 1][j - 1];
		l[i][j]+= l[i - 1][j] + l[i][j - 1] - l[i - 1][j - 1];
		u[i][j]+= u[i - 1][j] + u[i][j - 1] - u[i - 1][j - 1]; }

	while (q--) {
		cin >> x1 >> y1 >> x2 >> y2;
		cout << sum(nod, x1, y1, x2, y2) - sum(l, x1, y1 + 1, x2, y2) - sum(u, x1 + 1, y1, x2, y2) << '\n'; }

	return 0; }


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

namespace ConsoleApp44 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            int K = int.Parse(Console.ReadLine());
            int X = int.Parse(Console.ReadLine());
            int Y = int.Parse(Console.ReadLine());

            if (N >= K) {
                Console.WriteLine(K * X + (N - K) * Y);
            } else {
                Console.WriteLine(N * X);
            }

        }
    }
}


Measured memory_bytes: 11092
x, y, z, k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort(reverse=1)
B.sort(reverse=1)
C.sort(reverse=1)

D = []

for i in range(min(k, x)):
    for j in range(min(k, y)):
        for l in range(min(k, z)):
            if i*j*l <= k:
                D.append(A[i] + B[j] + C[l])
            else:
                break

D.sort(reverse=1)
#dd = len(D)

#fa = open("d2.txt", "w")

for i in range(k):
    #fa.write(str(i)+" "+str(D[i])+"\n")
    print(D[i])

#fa.close()

# coo = 0
# for i in range(len(D)):
#     if D[i] >= 2977:
#         coo += 1
# print(coo)
# print(dd)

Measured memory_bytes: 135868
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

// 単調非減少 always a[i] <= a[i + 1]
int main(void)
{
    int N;
    cin >> N;

    vector<int> H(N);
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }

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

    bool isFine = true;
    for (int i = 0; i < N - 1; i++)
    {
        if (H[i] > H[i + 1])
        {
            isFine = false;
            break;
        }
    }

    if (isFine == true)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return (0);
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<stdio.h>
#include<cstdio>
#include<math.h>
using namespace std;
int main(){
    double s,w,h;
    char ch;
    while(cin>>s>>ch>>w>>ch>>h){
        if(w/(h*h)>=25){
            cout<<s<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3132
// https://atcoder.jp/contests/dp/tasks/dp_z

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>

using namespace std;
using ll = long long;

const ll maxH=1e6;
const ll INF=1e18;

struct Line {
  ll a, b; // y = ax + b

  ll at(ll x) { return a * x + b; } // return y
};

struct LiChaoST {
  vector<Line> t;
  LiChaoST() {
    t.assign(4*maxH+10, {0, INF});
  }

  void addLine(Line li, ll root, ll l, ll r) {
    if (l > r) return;

    bool checkleft  = li.at(l) <= t[root].at(l);
    bool checkright = li.at(r) <= t[root].at(r);

    if (checkleft && checkright) { // new line is better
      t[root] = li; return ;
    } else if (!checkleft && !checkright) return; //worse

    ll m = (l + r) / 2;
    addLine(li, root*2, l, m);
    addLine(li, root*2+1, m+1, r);
  }

  ll minQuery(ll x, ll root, ll l, ll r) {
    if (l > r) return INF;
    if (l==r) return t[root].at(x);

    ll m = (l+r) / 2;
    return min( t[root].at(x),   (x <= m)?
      minQuery(x, root*2, l, m) : minQuery(x, root*2+1, m+1, r) );
  }
};

int main() {
  ll N, C;

  scanf("%lld %lld", &N, &C);

  vector<ll> h(N);
  for (auto i =0; i< N; i++) scanf("%lld", &h[i]);

  vector<ll> F(N, 0);

  LiChaoST tree;

  for(auto i =0; i<N; i++) {
    // (hi - hj)^2 + C = hi^2 + hj^2 - 2hihj + C + F[j]
    F[i] = tree.minQuery( h[i], 1, 0, maxH) + h[i]*h[i] + C;
    if (i==0) F[i] =0; // first stone,  F[0] = 0

    // add new line ax + b, where a = -2hi, b = F[i] + hi^2
    tree.addLine( {-2*h[i],  h[i]*h[i] + F[i]}, 1, 0, maxH);
  }

  cout << F[N-1] << endl;

  return 0;
}


Measured memory_bytes: 65920
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
a,b=gsmi
a.upto(b) do |n|
  bin=n.to_s
  r=bin.reverse
  cnt+=1 if bin==r
end
puts cnt

Measured memory_bytes: 1788
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)


ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}


  

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  string s;
  cin>>s;
  ll ans[s.size()]={0};
  ll Lcnt=0,Rcnt=0;
  vector<ll> v;
  bool flag=false;
  for(ll i=0;i<s.size()-1;i++){//一旦RLの判定をしよう
    if(flag){//RL直後の処理
      flag=false;
      continue;
    }
    if(s[i]=='R' && s[i+1]=='L'){
      flag=true;
      ans[i]=1;
      ans[i+1]=1;
    }
    
  }
  flag=false;
  ll k,l;
  
  rep(i,s.size()){
   
    if(ans[i]==0){
      
      
      
      if(s[i]=='L' && s[i+1]=='R'){
        Lcnt++;
        if(Lcnt%2==1){
          ans[k]+=Lcnt/2+1;
          ans[l]+=Lcnt/2;
          Lcnt=0;
          
        }else{
          ans[k]+=Lcnt/2;
          ans[l]+=Lcnt/2;
          Lcnt=0;
          
        }
        if(flag) flag=false;
      }else if(s[i]=='R'){
         if(flag){
      flag=false;
      continue;
    }
        Rcnt++;
      }else if(s[i]=='L'){
         if(flag){
      flag=false;
      continue;
    }
        Lcnt++;
      }
      
      
    }else if(ans[i]!=0){
      
       if(flag){
      flag=false;
      continue;
    }
      
      flag=true;
      k=i;
      l=i+1;
      if(Rcnt%2==1){
        ans[k]+=Rcnt/2;
        ans[l]+=Rcnt/2+1;
        Rcnt=0;
      }else{
        ans[k]+=Rcnt/2;
        ans[l]+=Rcnt/2;
        Rcnt=0;
      }
      
      
      
    }
  }
  if(Rcnt%2==1){
        ans[k]+=Rcnt/2;
        ans[l]+=Rcnt/2+1;
        Rcnt=0;
      }else{
        ans[k]+=Rcnt/2;
        ans[l]+=Rcnt/2;
        Rcnt=0;
      }
  if(Lcnt%2==1){
          ans[k]+=Lcnt/2+1;
          ans[l]+=Lcnt/2;
          Lcnt=0;
          
        }else{
          ans[k]+=Lcnt/2;
          ans[l]+=Lcnt/2;
          Lcnt=0;
          
        }
  rep(i,s.size()){
    cout<<ans[i]<<' ';
  }
  cout<<endl;
}

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

using namespace std;

#define DIM 200009
#define INF ((long long)1e18+9ll)
#define pairll pair<long long,long long>
#define fi first
#define se second
#define ld long double
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define amen exit(0)

long long i,j,k,l,n,m,sz;

struct line{
    long long k,b;
};

long long dp[DIM],a[DIM],b[DIM];

line ln[DIM];

bool check(line a1,line a2,line a3){
    return (ld)(a1.b-a2.b)/(ld)(a1.k-a2.k)>=(ld)(a1.b-a3.b)/(ld)(a1.k-a3.k);
}

void add(long long k,long long b){
    line a={k,b};
    while(sz>1 && check(ln[sz-1],a,ln[sz]))sz--;
    ln[++sz]=a;
}

long long can(long long num,long long x){
    return ln[num].k*x+ln[num].b;
}

long long bs(long long x){
    long long l=0,r=sz,mid;
    while(r-l>1){
        mid=(l+r)/2;
        if(can(mid,x)<can(mid+1,x))r=mid;
        else l=mid;
    }
    return can(r,x);
}

long long C;

int main()
{
    cin>>n>>C;
    for(i=1;i<=n;i++)cin>>a[i];

    add(-2*a[1],a[1]*a[1]);
    dp[1]=0;

    for(i=2;i<=n;i++){
        dp[i]=bs(a[i])+a[i]*a[i]+C;
        add(-2*a[i],dp[i]+a[i]*a[i]);
    }

    cout<<dp[n]<<endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
    while(true)
    {
        int N;
        scanf("%d", &N);
        if(N == 0) break;

        int a;

        bool t[210];
        memset(t, 0, 2 * N);
        bool h[210];
        memset(h, 0, 2 * N);

        REP(i, N)
        {
            scanf("%d", &a);
            t[a - 1] = 1;
        }
        REP(i, 2 * N)
        {
            if(!t[i])
            {
                h[i] = 1;
            }
        }
        int ba = 0;
        bool over = true;
        bool can = false;
        while(true)
        {
            //taro
            over = true;
            can = false;
            REP(i, 2 * N)
            {
                if(t[i])
                {
                    if((ba <= i) && (!can))
                    {
                        t[i] = false;
                        can = true;
                        ba = i;
                    }
                    else
                    {
                        over = false;
                    }
                }
            }
            if(!can)
            {
                ba = 0;
            }
            if(over)
            {
                int ans = 0;
                REP(i, 2 * N)
                {
                    if(h[i]) ans++;
                }
                printf("%d\n", ans);

                printf("0\n");
                break;
            }

            //hanako
            over = true;
            can = false;
            REP(i, 2 * N)
            {
                if(h[i])
                {
                    if((ba <= i) && (!can))
                    {
                        h[i] = false;
                        can = true;
                        ba = i;
                    }
                    else
                    {
                        over = false;
                    }
                }
            }
            if(!can)
            {
                ba = 0;
            }
            if(over)
            {
                printf("0\n");

                int ans = 0;
                REP(i, 2 * N)
                {
                    if(t[i]) ans++;
                }
                printf("%d\n", ans);
                break;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second
int INF=1e9;
string s;
P init=P(INF,-INF);
vector<vector<P> >dp(200,vector<P>(200,init));

P dfs(int l,int r){
	if(l==r)return P(s[l]-'0',s[l]-'0');
	if(dp[l][r]!=init)return dp[l][r];
	P res=init;
	if(s[l]=='('&&r-l>2) res=dfs(l+1,r);
	if(s[r]==')'&&r-l>2) res=dfs(l,r-1);
	for(int i=l+1;i<r;i++){
		if(!(s[i]=='-'||s[i]=='+'))continue;
		P a=dfs(l,i-1);
		P b=dfs(i+1,r);
		if(s[i]=='-'){
			res.F=min(res.F,a.F-b.S);
			res.S=max(res.S,a.S-b.F);
		}
		if(s[i]=='+'){
			res.F=min(res.F,a.F+b.F);
			res.S=max(res.S,a.S+b.S);
		}
	}
	return dp[l][r]=res;
}

main(){
	cin>>s;
	cout<<dfs(0,s.size()-1).S<<endl;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n, x, y;

int a[maxn];

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

    cin>>n>>x>>y;
    --x;
    --y;
    
    for (int i=0; i<n; i++) {
	for (int j=i+1; j<n; j++) {
	    int dist = j-i;
	    dist = min(dist, abs(i-x)+1+abs(y-j));
	    dist = min(dist, abs(i-y)+1+abs(x-j));
	    a[dist]++;
	}
    }

    for (int i=1; i<n; i++) {
	cout<<a[i]<<"\n";
    }


    return 0;
}


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	vector<int> b(n + 1, 0);
	for (int i = 0; i < n; i++)
		b[a[i]]++;
	sort(b.rbegin(), b.rend());
	int sum = 0;
	for (int i = 0; i < k; i++)
		sum += b[i];
	cout << n - sum << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
#include <queue>
#include <bits/stdc++.h>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;

int main()
{
    int64_t N,K,i,j,ans,seg,root,Z,C,root2;
    bool T;
    T=true;
    ans=1;
    root=0;
    cin >> N >> K;
    Z=K;
    vector<int> A(N),B(N);
    rep(i,N){
        cin >> A[i];
    }
    while(T){
       B[ans-1]++;
       seg=A[ans-1];
       if(B[ans-1]<=1){
           ans=seg;
           Z--;
       }else{
           if(B[ans-1]==2){
               root++;
               ans=seg;
           Z--;
           }
       }
       if(Z==0){
           T=false;
       }
       if(B[ans-1]>=3){
           root2=root;
           T=false;
       }
    }
	C=Z%root2;
    if(root2>0){
        rep(i,C){
            ans=A[ans-1];
        }
        cout << ans <<endl;
        return 0;
    }else{
        cout << ans <<endl;
        return 0;
    }
    
}

Measured memory_bytes: 4844
def examA():
    N = I()
    L = LI()
    L.sort()
    ans = sum(L[::2])
    print(ans)
    return

def examB():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    N, X = LI()
    ans = 3*(N - gcd(N-X,X))
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examB()

"""

"""

Measured memory_bytes: 4720
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
const int N=1e5+1;
const int INF=1e9+7;

int32_t main()
{
 ios_base::sync_with_stdio(0);
 cin.tie(0); cout.tie(0);
 int n,m; cin>>n>>m;
 char A[n][m];
 for(int i=0;i<n;i++)
 {
     for(int j=0;j<m;j++)
     {
         cin>>A[i][j];
     }
 }
 int dp[n][m];
 memset(dp,0,sizeof(dp));
 dp[0][0]=1;
 for(int i=0;i<n;i++)
 {
     for(int j=0;j<m;j++)
     {
         if(A[i][j]=='.')
         {
             if(i==0 && j>0){dp[i][j]=(dp[i][j-1])%INF;}
             else if(j==0 && i>0){dp[i][j]=(dp[i-1][j])%INF;}
             else if(i>0 && j>0){dp[i][j]=(dp[i-1][j]+dp[i][j-1])%INF;}
         }
     }
 }
 cout<<dp[n-1][m-1];
}

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

int main(){
	int n,i=1,a,c=0;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&a);
		if(i%2==1&&a%2==1) c++;
		i++;
	}
	cout <<c;
	return 0;	
}

Measured memory_bytes: 3656
//Smart Calculator
#include <iostream>
#include <cstdio>
#include <cassert>
#define rep(i,n) for(int i = 0;i < n;i++)
#define mp make_pair
using namespace std;
string S;
size_t cur = 0;
bool isdigit(char);
int digit();
int number();
int term();
int expression();
int factor();
int parse(){
    return expression();
}

int main(){
    int n;
    cin >> n;
    rep(i,n){
        cur = 0;
        cin >> S;
        S.resize(S.size()-1);
        cout << parse() << endl;
    }
}

bool isdigit(char c){
    return c >= '0' && c <= '9';
}
int digit(){
    assert(isdigit(S[cur]));
    int n = S[cur] - '0';
    cur = cur + 1;
    return n;
}
int number(){
    int n = digit();
    while(cur<S.size()&&isdigit(S[cur])){
        n = n*10+digit();
    }
    return n;
}

int expression(){
    int mult = 1;
    if(S[cur]=='-'){
        mult = -1;
        cur++;
    }
    int sum = term()*mult;
    while(cur < S.size()&&(S[cur]=='+'||S[cur]=='-')){
        char op = S[cur];
        cur++;
        if(op == '+'){
            sum += term();
        }else{
            sum -= term();
        }
    }
    return sum;
}
int term(){
    int ret = factor();
    while(cur < S.size() &&( S[cur]=='*'||S[cur]=='/')){
        char op = S[cur];
        cur++;
        if(op == '*'){
            ret *= factor();
        }else{
            ret /= factor();
        }
    }
    return ret;
}
int factor(){
    if(S[cur]!='(')
        return number();
    cur += 1;
    int n = expression();
    assert(S[cur]==')');
    cur++;
    return n;
}

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

int main(void)
{
  int n;
  string s;
  cin >> n >> s;
  
  int x=0, max_x=0;
  for(int i=0; i<n; i++){
      if(s[i]=='I'){
          x++;
          max_x = max(x, max_x);
      }
      else
        x--;
  }
  cout << max_x << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, T;
	cin >> N >> T;

	vector<lint> t(N);
	for (int i = 0; i < N; i++) cin >> t[i];
	t.emplace_back(LINF); // 番兵
	
	lint ans = 0;
	for (int i = 0; i < N; i++) {
		if (t[i + 1] - t[i] > T) ans += T;
		else ans += t[i + 1] - t[i];
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, l, t, nxt;
vector<int> arv;
int main() {
	cin >> n >> l >> t;
	for (int i = 0; i < n; i++) {
		int x, w;
		cin >> x >> w;
		if (w == 1) {
			arv.push_back((x + t) % l);
			if (l - x <= t)
				nxt += (t - (l - x)) / l + 1;
			nxt %= n;
		}
		else {
			arv.push_back(((x - t) % l + l) % l);
			if (x < t) 
				nxt -= (t - (x + 1)) / l + 1;
			nxt %= n;
		}
	}
	nxt = ((nxt % n) + n) % n;
	sort(arv.begin(), arv.end());
	for (int i = nxt; i < arv.size(); i++)
		cout << arv[i] << "\n";
	for (int i = 0; i < nxt; i++)
		cout << arv[i] << "\n";
	return 0;
}


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

int main() {
  string S;
  int price = 700;
  cin >> S;
  for (int i = 0; i < S.size(); i++){
    if(S.at(i)=='o'){
      price += 100;
    }
  }
  cout << price << endl;
}


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

int main() {
	int h, w;
	while(cin>>h>>w && !(h==0 && w==0))
	{
		for(int i=0; i<h; i++)
		{
			for(int j=0; j<w; j++)
			{
				if(i==0 || i==h-1) { cout<<"#"; continue; }
				if( (i!=0 &&  j==0) ||  (i!=0 && j==w-1) || (h-1!=0 &&  j==0) ||  (h-1!=0 && j==w-1) ) { cout<<"#"; } 				
				else { cout<<"."; }
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}



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

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp  make_pair

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int Pow(int a , int b){
    if(b==0)return 1;
    ll r = Pow(a,b/2);
    if(b&1)return r * r %  mod * a % mod;
    return r * r % mod;
}
int n , X , Y;
int fac[maxn],rfac[maxn];
int a[maxn];

vector<int> adj[maxn];
map<int,int> mmap;
vector<ii> val[maxn];
void add(int u ,int v){
    adj[u].pb(v);adj[v].pb(u);
}
bool vis[maxn];
void  dfs(int u){
    vis[u] = 1 ;mmap[a[u]]++;
    for(int c : adj[u]){
        if(vis[c]==0)dfs(c);
    }
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
	}
    cin  >> n >> X >> Y;
    for(int i = 1 ; i <= n ; ++i){
        int c , w;cin >> c >> w;
        val[c].pb(mp(w,i));
        a[i] = c;
    }
    ii best = mp(1e9+1,0);
    for(int i = 1 ; i <= n ; ++i){
        sort(val[i].begin(),val[i].end());
        for(auto c : val[i]){
            if(val[i][0].first+c.first <= X){
                add(val[i][0].second,c.second);
            }
            best = min(best,c);
        }
    }
    ii sbest = mp(1e9+1,0);
    for(int i = 1 ; i <= n ; ++i){
        if(a[best.second]==i)continue;
        for(auto c : val[i]){
            if(c.first+best.first <= Y){
                add(c.second,best.second);
            }
            sbest = min(sbest,c);
        }
    }
    for(int i = 1 ; i <= n ; ++i){
        if(a[sbest.second]==i)continue;
        for(auto c : val[i]){
            if(c.first+sbest.first <= Y){
                add(c.second,sbest.second);
            }
        }
    }
    int res = 1;
    fac[0] = rfac[0] = 1;
    for(int i = 1 ; i <= n ; ++i){
        fac[i] = (ll)fac[i - 1] * i % mod;
        rfac[i] = (ll)rfac[i - 1] * Pow(i,mod-2)%mod;
    }
    for(int i  = 1 ; i <= n; ++i){
        if(vis[i]==0){
            mmap.clear();
            dfs(i);
            int tot = 0;
            for(auto c : mmap){
                res = (ll)res * rfac[c.second]%mod;
                tot += c.second;
            }
            res = (ll)res * fac[tot]%mod;
        }
    }
    cout << res;
}


Measured memory_bytes: 30804
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int K;
        int N;
        int[] Ai;
        try (Scanner sc = new Scanner(System.in)) {
            K = sc.nextInt();
            N = sc.nextInt();
            Ai = new int[N];
            for (int i = 0; i < N; i++) {
                Ai[i] = sc.nextInt();
            }
        }
        int dist = Ai[0] + (K-Ai[N-1]);
        for (int i = 0; i < N-1; i++) {
            if(dist < Ai[i+1] -Ai[i]){
                dist = Ai[i+1] -Ai[i];
            };
        }
        System.out.println(K - dist);
    }
}


Measured memory_bytes: 85952
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

struct coord {
  int x;
  int y;
};
int H,W;
char map[1005][1005];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int ans;
long long blackcount;
std::queue<coord> queue_next;
void bfs(){
  while (blackcount<H*W){
    std::queue<coord > queue(queue_next);
    while(queue.size()){
      coord thiscoord = queue.front();
      queue.pop();
      queue_next.pop();
      for (int i=0; i<4; i++){
        if (thiscoord.x+dx[i]>=0 && thiscoord.x+dx[i]<H && thiscoord.y+dy[i]>=0 && thiscoord.y+dy[i]<W){
          if (map[thiscoord.x+dx[i]][thiscoord.y+dy[i]]=='.'){
            map[thiscoord.x+dx[i]][thiscoord.y+dy[i]]='#';
            queue_next.push((coord){thiscoord.x+dx[i], thiscoord.y+dy[i]});
            blackcount++;
            //printf("map[%d][%d] is pushed to stack\n",thiscoord.x+dx[i],thiscoord.y+dy[i]);
          }
        }
      }
    }
    ans++;
    //printf("ans=%d\n",ans);
  }
  return;
}

int main(){

  scanf("%d",&H);
  scanf("%d",&W);
  //printf("H=%d, W=%d\n",H,W);
  std::string S;
  blackcount = 0;
  for (int i=0; i<H; i++){
    std::cin >> S;
    //printf("S=%s\n",S.c_str());
    for (int j=0; j<W; j++){
      map[i][j]=S[j];
      if (S[j]=='#'){
        queue_next.push((coord){i,j});
        blackcount++;
      }
    }
  }
  //printf("read end\n");
  //  printf("blackcount=%lld\n",blackcount);
  bfs();
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 11008
a,b,c=gets.split.map &:to_i
if a==b&&b==c
p [-1,0][a%2]
else
p (0..1/0.0).find{|i|a%2>0||b%2>0||c%2>0||!(a,b,c=b/2+c/2,c/2+a/2,a/2+b/2;1)}
end

Measured memory_bytes: 1788
from collections import *
 
n = int(input())
dic = defaultdict(int)
for i in range(n):
  dic["".join(sorted(input()))] += 1
 
ans = 0
for k,v in dic.items(): 
  ans += int(v*(v-1)/2)
  #ans += v*(v-1)//2
print(ans)

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()
const D eps=1e-8;
const D inf=1e12;
struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};
D cross(P a,P b){ return (conj(a)*b).Y; }
D dot(P a,P b){ return (conj(a)*b).X; }
int ccw(P a,P b,P c) {
  b=b-a;c=c-a;
  if(cross(b,c)>0) return +1;       // counter clockwise
  if(cross(b,c)<0) return -1;       // clockwise
  if(dot(b,c)<0)   return +2;       // c--a--b on line
  if(norm(b)<norm(c)) return -2;       // a--b--c on line
  return 0;
}
P crosspoint(L l,L m) {
  D A=cross(l[1]-l[0],m[1]-m[0]);
  D B=cross(l[1]-l[0],l[1]-m[0]);
  if (abs(A)<eps&&abs(B)<eps) return m[0]; // same line
  if (abs(A)<eps) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0]+B/A*(m[1]-m[0]);
}

vector<P> convex_cut(vector<P>& poly,L l) {
  vector<P> Q;
  int sz=poly.size();
  for (int i = 0; i < sz; i++) {
    P A = poly[i], B = poly[(i+1)%sz];
    if(ccw(l[0], l[1], A) != -1)Q.push_back(A);
    if(ccw(l[0], l[1], A)*ccw(l[0], l[1], B) < 0){
      Q.push_back(crosspoint(L(A, B), l));
    }
  }
  return Q;
}

L bisector_line(L l){
  P hp=0.5*(l[0]+l[1]);
  P v=l[1]-l[0];
  return L(hp,hp+P(-v.Y,v.X));
}

D calc_area(vector<P>& poly) {
  D res = 0;
  int sz=poly.size();
  for (int i = 0; i < sz; i++){
    res += cross(poly[i], poly[(i+1)%sz]);
  }
  return res/2.0;
}

int main(){
  while(1){
    int n,m;
    vector<P> ps,cs;
    cin>>n>>m;
    if(n==0||m==0)break;
    rep(i,n){
      D px,py;
      cin>>px>>py;
      ps.push_back(P(px,py));
    }
    rep(i,m){
      D cx,cy;
      cin>>cx>>cy;
      cs.push_back(P(cx,cy));
    }
    rep(i,m){
      vector<P> tmp=ps;
      rep(j,m){
        if(j==i)continue;
        L l=bisector_line(L(cs[i],cs[j]));
        tmp=convex_cut(tmp,l);
      }
      D res=calc_area(tmp);
      printf("%.10f\n", res);
    }
  }
  return 0;
}



Measured memory_bytes: 3244
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,0,n)cin>>v[i];
    int q;cin>>q;
    rep(i,0,q){
        int com,a,b;
        cin>>com>>a>>b;
        if(com==0)cout<<*min_element(v.begin()+a,v.begin()+b)<<endl;
        else cout<<*max_element(v.begin()+a,v.begin()+b)<<endl;
    }

    

}



/*
1 2 3 4 5

6
*/



Measured memory_bytes: 3100
N = int(input())
a = list(map(int, input().split()))
flag = []

for i in range(0,N):
  if a[i]%2 == 0:
    if a[i]%3 == 0 or a[i]%5 == 0:
        flag.append(0)
    else:
        flag.append(1)
if sum(flag) == 0:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
s = input()
if s == 'SAT':
    print(1)
elif s == 'FRI':
    print(2)
elif s == 'THU':
    print(3)
elif s == 'WED':
    print(4)
elif s == 'TUE':
    print(5)
elif s == 'MON':
    print(6)
elif s == 'SUN':
    print(7)
else:
    exit()

Measured memory_bytes: 3060