akhauriyash/Code-Regression huggingface dataset:
// AOJ 2021: Princess in Danger
// 2017.12.11 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 20000
typedef struct { int t, node, s; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int n, int t, int s)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].node = n, que[i].t = t, que[i].s = s;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 0x7fffff

typedef struct { int to[101], t[101]; } TBL;
TBL tbl[101];
int len[101];
char f[101];
int dist[101][101];

void dijkstra(int start, int m)
{
	int i, j, s, t, k, s2, t2, x;

	memset(dist, 0x33, sizeof(dist));
	qsize = 0;
	enq(start, 0, m);
	while (qsize) {
		s = que[0].node, t = que[0].t, k = que[0].s; deq();
		if (dist[s][k] < t) continue;
		for (i = 0; i < len[s]; i++) {
			s2 = tbl[s].to[i], t2 = tbl[s].t[i];
			if (f[s]) {
				for (j = 0; j <= m; j++) {
					if (k+j > m) break;
					if (k+j < t2) continue;
					if ((x = t+j+t2) < dist[s2][k+j-t2]) {
						dist[s2][k+j-t2] = x;
						enq(s2, x, k+j-t2);
					}
				}
			} else {
				if (k < t2) continue;
				if ((x = t+t2) < dist[s2][k-t2]) {
					dist[s2][k-t2] = x;
					enq(s2, x, k-t2);
				}
			}
		}
	}
}

char buf[400], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int n, m, l, k, a, h, i, x, y, t, ans;

	while (fgets(p=buf, 60, stdin) && *p != '0') {
		n = getint(), m = getint(), l = getint();
		k = getint(), a = getint(), h = getint();

		memset(f, 0, sizeof(f));
		if (l > 0) {
			fgets(p=buf, sizeof(buf), stdin);
			while (l--) f[getint()] = 1;
		}

		memset(len, 0, sizeof(len));
		while (k--) {
			fgets(p=buf, 20, stdin);
			x = getint(), y = getint(), t = getint();
			i = len[x]++, tbl[x].to[i] = y, tbl[x].t[i] = t;
			i = len[y]++, tbl[y].to[i] = x, tbl[y].t[i] = t;
		}

		dijkstra(a, m);
		ans = INF;
		for (i = 0; i <= m; i++) if (dist[h][i] < ans) ans = dist[h][i];
		if (ans == INF) puts("Help!");
		else printf("%d\n", ans);
	}
	return 0;
}

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
    ll a,b,m;
    cin >> a >> b >> m;
    cout << (a * min(b-1,m))/b << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
   // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 3640
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
struct X{
	int num;
	int val;
	X(){
		num=0;
		val=0;
	}
};
bool Comp(X&l,X&r){
	return l.num>r.num;
}
int main(int argc, char* argv[])
{
	int n;
	cin>>n;
	map<int,int> EvenMap;
	map<int,int> OddMap;
	map<int,int>::iterator mit;
	int i;
	int value;

	for (i=1;i<=n;i++){
		cin>>value;
		if (i%2==0){
			mit=EvenMap.find(value);
			if (mit==EvenMap.end()){
				EvenMap[value]=1;
			}else{
				(*mit).second++;
			}
		}else{
			mit=OddMap.find(value);
			if (mit==OddMap.end()){
				OddMap[value]=1;
			}else{
				(*mit).second++;
			}
		}
	}

	vector<X> EvenVec(EvenMap.size()),OddVec(OddMap.size());
	i=0;
	for (mit=EvenMap.begin();mit!=EvenMap.end();mit++){
		EvenVec[i].num=(*mit).second;
		EvenVec[i].val=(*mit).first;
		i++;
	}
	i=0;
	for (mit=OddMap.begin();mit!=OddMap.end();mit++){
		OddVec[i].num=(*mit).second;
		OddVec[i].val=(*mit).first;
		i++;
	}
	sort(EvenVec.begin(),EvenVec.end(),Comp);
	sort(OddVec.begin(),OddVec.end(),Comp);
	if (EvenVec[0].val!=OddVec[0].val){
		cout<<n-EvenVec[0].num-OddVec[0].num<<endl;
		return 0;
	}
	int MinNum=n+1;
	int j;
	for (i=0;i<EvenVec.size();i++){
		int num=EvenVec[i].num;
		int val=EvenVec[i].val;
		bool bFind=false;
		for (j=0;j<OddVec.size();j++){
			if (val!=OddVec[j].val){
				if (MinNum>n-num-OddVec[j].num){
					MinNum=n-num-OddVec[j].num;
				}
				bFind=true;
				break;
			}
		}
		if (bFind){
			break;
		}
	}
	for (i=0;i<OddVec.size();i++){
		int num=OddVec[i].num;
		int val=OddVec[i].val;
		bool bFind=false;
		for (j=0;j<EvenVec.size();j++){
			if (val!=EvenVec[j].val){
				if (MinNum>n-num-EvenVec[j].num){
					MinNum=n-num-EvenVec[j].num;
				}
				bFind=true;
				break;
			}
		}
		if (bFind){
			break;
		}
	}
	if (MinNum==n+1){
		MinNum=n/2;
	}
	cout<<MinNum<<endl;
	return 0;
}

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


int main(){
	int n,l,tot=0;
	scanf("%d %d",&n,&l);
	tot=(l*n+(n-1)*n/2);
	if(l>0) printf("%d\n",tot-l);
	else if(l<=0 && l+n-1>=0) printf("%d\n",tot);
	else if(l+n-1<<0) printf("%d\n",tot-l-n+1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; 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 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 sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<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 set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  ll W,H,x,y;
  cin >> W >> H >> x >> y;
  bool xsame = false;
  bool ysame = false;
  if(W % 2 == 0) {
    if(W / 2 == x) {
      xsame = true;
    }
  }
  if(H % 2 == 0) {
    if(H / 2 == y) {
      ysame = true;
    }
  }
  double area = (H * W) / 2.0;
  cout << std::setprecision(20) << area << " ";
  if(xsame && ysame) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// clang-format off

#include <bits/stdc++.h>

#define int long long int
#define main signed main()
#define bye return 0
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define sum(v) accumulate(all(v), 0)
#define stlice(s, l) substr(s, (s) + (l) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!((n) % 2))

#define INF 1000000000
#define MOD 1000000007

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define str string
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<str>

using namespace std;

// clang-format on

int N, W;
int w[100], v[100];
map<pair<int, int>, int> mm;

int f(int i, int j) {
  auto p = mp(i, j);
  if (!mm.count(p)) {
    if (i == N) {
      mm[p] = 0;
    } else if (j < w[i]) {
      mm[p] = f(i + 1, j);
    } else {
      mm[p] = max(f(i + 1, j), f(i + 1, j - w[i]) + v[i]);
    }
  }
  return mm[p];
}

main {
  cin >> N >> W;
  rep(i, N) cin >> w[i] >> v[i];
  cout << f(0, W) << endl;
  bye;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define rep(i,n) for ( int i = 0; i < (n); ++i )
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long int;
const long long int INF = 1001001001001001LL;
const int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;


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

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

    vector<vector<int>> e(n, vector<int>());
    vector<int> deg(n, 0);
    vector<int> dp(n, 0);
    
    rep(i,m) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        e[x].push_back( y );
        deg[y]++;
    }
    
    queue<int> q;
    rep(y, n) if(deg[y] == 0) q.push(y);
    
    while( q.size() ) {
        int x = q.front(); q.pop();
        for( int y: e[x] ) {
            deg[y]--;
            if( deg[y] == 0 ) {
                q.push(y);
                dp[y] = max( dp[y], dp[x] + 1 );
            }
        }
    }
    
    cout << *max_element( all(dp) ) << endl;

    return 0;
}

Measured memory_bytes: 6528
s = input()
t = input()
abc = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(abc)):
	a = 0
	for j in range(len(s)):
		if abc[i] == s[j]:
			if a == 0:
				st = t[j]
				a = 1
			else:
				if t[j] != st:
					print("No")
					exit(0)
	a = 0
	for j in range(len(t)):
		if abc[i] == t[j]:
			if a == 0:
				st = s[j]
				a = 1
			else:
				if s[j] != st:
					print("No")
					exit(0)
print("Yes")


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

ll modpower(ll x, ll n, ll mod)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll inv(ll n)
{
    return modpower(n, MOD - 2, MOD);
}
void COMinit(vector<ll> &fact, vector<ll> &invfact, ll k)
{ //空っぽの配列を二つ
    fact.resize(k, 0);
    invfact.resize(k, 0);
    fact[0] = 1;
    repi(i, k, 1)
    {
        fact[i] = fact[i - 1] * i % MOD;
    }
    invfact[k - 1] = inv(fact[k - 1]);
    repd(i, k - 2, -1)
    {
        invfact[i] = invfact[i + 1] * (i + 1) % MOD;
    }
    return;
}
ll nCk(vector<ll> &fact, vector<ll> &invfact, ll n, ll k)
{ //この関数を使う前にCOMinit
    if (k < 0 || n < k)
        return 0LL;
    return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}

//---------main function----------

int main()
{
    string n;
    cin >> n;
    if (n[n.size() - 1] == '3')
    {
        cout << "bon" << endl;
    }else if(n[n.size()-1] == '0' || n[n.size()-1] =='1' || n[n.size()-1] =='6' || n[n.size()-1] == '8'){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
   return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  rep(i, h) rep(j, w) cin >> a[i][j];

  vector<int> cnt(26, 0);
  rep(i, h) rep(j, w) cnt[a[i][j] - 'a']++;

  bool ok = true;
  if (h % 2 == 0 && w % 2 == 0) {
    rep(i, 26) if (cnt[i] % 4) ok = false;
  }
  if (h % 2 == 0 && w % 2 == 1) {
    int t = 0;
    rep(i, 26) {
      if (cnt[i] % 2) ok = false;
      else if (cnt[i] % 4) ++t;
    }
    if (2 * t > h) ok = false;
  }
  if (h % 2 == 1 && w % 2 == 0) {
    int t = 0;
    rep(i, 26) {
      if (cnt[i] % 2) ok = false;
      else if (cnt[i] % 4) ++t;
    }
    if (2 * t > w) ok = false;
  }
  if (h % 2 == 1 && w % 2 == 1) {
    int o = 0, t = 0;
    rep(i, 26) {
      if (cnt[i] % 2) ++o;
      else if (cnt[i] % 4) ++t;
    }
    if (o > 1) ok = false;
    if (2 * t > h + w - 2) ok = false;
  }

  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

const int D = 80 * 160 + 10;
const int D2 = D*2;
typedef bitset<D2> bs;
int a[100][100];
bs dp[90][90];



const int N = 20;
int h;
int w;
vector<vector<char>> maze(N, vector<char>(N,'#'));

const int MAX_WH = 21;
int d[MAX_WH][MAX_WH];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
const int INF = 1001001001;
int bfs(int x, int y) {
    queue<P> que;
    rep(i,MAX_WH) {
        rep(j,MAX_WH) {
            d[j][i] = INF;
        }
    }
    que.push(P(x,y));
    d[x][y] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();
        for (int i=0; i< 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[nx][ny] != '#' && d[nx][ny] == INF) {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    int mx = 0;
    rep(i,h) rep(j,w) {
            if (d[j][i] == INF) continue;
            mx = max(mx, d[j][i]);
        }
    return mx;
}

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.first < secondElof.first;
}
void dfs(){

}
const int MX = 100000;
vector<int> G[MX];

int main(){
    int a,b,c; cin >> a >> b >> c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if (s.size() == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}



Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

class Progaram
{
    static List<char> resl = new List<char>();

    static void Main(string[] args)
    {
        var N = long.Parse(Console.ReadLine());
        Saiki(N);
        Console.WriteLine(new String(resl.ToArray()));
    }

    static void Saiki(long N)
    {
        var w = N / 26;
        var z = N % 26;
        var ca = (int)'a';
        if (z == 0)
        {
            w--;
            z = 26;
        }
        ca += (int)z - 1;
        resl.Insert(0, (char)ca);
        if (w == 0) return;
        Saiki(w);
    }
}

Measured memory_bytes: 27844
import           Control.Monad
import qualified Data.Array.IO               as IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

main = do
  s <- getLine
  putStrLn $ if (length $ filter (== '7') s) > 0 then "Yes" else "No"

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;

vector<int> vi;

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

    cout << (a <= b ? a : a - 1) << endl;

    return 0;
}


Measured memory_bytes: 256
n,m,k=map(int,input().split())
M=10**9+7
def combi(x,y):
  c=1
  m=min(x-y,y)
  for iii in range(y):
    c=c*(x-iii)*pow(y-iii,M-2,M)%M
  return c

rem_combi=combi(n*m-2,k-2)

def calc(num):
  out=0
  for iii in range(num):
    out+=iii*(num-iii)%M
  return out

x_cost=m*m*calc(n)%M
y_cost=n*n*calc(m)%M
ans=rem_combi*(x_cost+y_cost)%M
print(int(ans))

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private static final int MM = 21000;

    private void solve() throws IOException {
        int n = nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[nextInt() - 1] = i;
        }
        for (int i = 0; i < n; i++) {
            out.print(i * MM + 1 + " ");
        }
        out.println();
        for (int i = 0; i < n; i++) {
            out.print((n - 1 - i) * MM + 1 + p[i] + " ");
        }
        out.println();
    }

    private BufferedReader br;
    private PrintWriter out;
    private StringTokenizer st;

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

}


Measured memory_bytes: 18656
/*input
3 3 4


*/

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

int main() { 
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b and b != c) {
		cout << "Yes\n";
	}
	else if(a == c and a != b) {
		cout << "Yes\n";
	}
	else if(b == c and a != b) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	return 0; 
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << "\n"; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(ll, a, b, x);
    Cout(b/x - (a+x-1)/x + 1);
}


Measured memory_bytes: 256
a, b = map(int, input().split())
tmp_a = int((a / 0.08) // 1)
tmp_b = int((b / 0.10) // 1)
check = True
# print(tmp_a, tmp_b)
for i in range(min(tmp_a,tmp_b), max(tmp_a + 1, tmp_b + 1) + 1):
    if int((i * 0.08)//1) == a and int((i * 0.10)//1) == b:
        print(i)
        check = False
        break
if check:
    print(-1)

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

int main()
{
	int n;
	cin >> n;
	long long a[n+5], ans[n+5];
	memset(ans, 0, sizeof(ans));
	for(int i = 1 ; i<=n ; i++)
		cin >> a[i];
	for(int i = 2 ; i<=n ; i++)
	{
		if(i==2)
			ans[i] = ans[i-1]+abs(a[i]-a[i-1]);
		else
			ans[i] = min(ans[i-1]+abs(a[i]-a[i-1]), ans[i-2]+abs(a[i]-a[i-2]));
	}
	cout << ans[n];
	return 0;
}

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

int n;
int A[2000];
int solve(int i,int m){
    if(m==0){
        return 1;
    }
    else if(i>=n){
        return 0;
    }
    int flag = solve(i+1,m) || solve(i+1,m-A[i]);
    return flag;
}
int main(){
    cin >> n;
    int q,m;
    for(int i=0;i<n;++i){
        cin >> A[i];
    }
    cin >> q;
    
    for(int i=0;i<q;++i){
        cin >> m;
        if(solve(0,m)){
            cout << "yes" << endl;
        }
        else{
            cout << "no" << endl;
        }
    }
}


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

using Int = int;
Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}

int main(void) {
	int x, y;
	cin >> x >> y;
	cout << gcd(x, y) << endl;
	return 0;
}


Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	vector<int> as(N);
	REP(i, N)
	{
		cin >> as[i]; --as[i];
	}
	int ans = 0;
	REP(i, N)
	{
		if (i == as[as[i]]) ++ans;
	}
	cout << ans / 2 << endl;
}

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

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

	int N;
	int i,j;
	int tmp;
	int answer;
	int counter=0;
	double ave;
	string given;

	cin >> given;

	int len=given.size();
	for(i=0;i<len/2;i++){
		if(given[i]!=given[len-1-i]) counter++;
	}

	//sort(given.begin(),given.end());
	//sort(given.begin(),given.end(),greater<int>());
	
	answer=counter;
	cout << answer << endl;

	return 0;
}



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

int SelSort(int *,int);
void ShowData(int *,int);

int main(){
  int i,n,N;
  int *P;

  scanf("%d",&n);
  P=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&P[i]);
  }
  N=SelSort(P,n);
  ShowData(P,n);
  printf("%d\n",N);
  return 0;
}

int SelSort(int *P,int n){
  int i,j,min,tmp,N=0;
  
  for(i=0;i<n-1;i++){
    min=i;
    for(j=i+1;j<n;j++){
      if(P[j]<P[min]){
	min=j;
      }
    }
    if(P[i]>P[min]){
      tmp=P[i];
	 P[i]=P[min];
	 P[min]=tmp;
	 N++;
    }
  }
  return N;
    }

void ShowData(int *P,int n){
  int i;
  for(i=0;i<n;i++){
    if(i!=n-1){
      printf("%d ",P[i]);
    }
      else{
	printf("%d",P[i]);
      }
  }
      printf("\n");
}
  
       
    



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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

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

	int i;
	int sum=0; 
	for(i=0; sum < n; i++){
		sum += 2 * d + 1;
	}

	cout << i << endl;



    return 0;
}



Measured memory_bytes: 256
<?php
list($N, $K) = array_map("intval", explode(" ", trim(fgets(STDIN))));
$hArray = array_map("intval", explode(" ", trim(fgets(STDIN))));

$dp[0] = 0;
for($i = 1; $i < $N; $i++){
    $dp[$i] = 10**18;
    $limit = min($i, $K);
    for($j = 1; $j <= $limit; $j++){
        $dp[$i] = min($dp[$i], $dp[$i-$j] + abs($hArray[$i] - $hArray[$i-$j]));
    }
}
echo $dp[$N-1];

Measured memory_bytes: 18932
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vll vector<ll>
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll solve(string s)
{
     if(s[0]=='R' && s[1]=='R' && s[2]=='R')
        return 3;
     else if((s[0]=='R' && s[1]=='R')||(s[1]=='R' && s[2]=='R'))
        return 2;
     else if(s[0]=='R' || s[1]=='R' || s[2]=='R')
        return 1;
    else return 0;
}
int main()
{
    ll t=1;
    string s;
    while(t--)
    {
        cin>>s;
        cout<<solve(s)<<endl;
    }
}


Measured memory_bytes: 3628
import java.util.*

fun <T> permutationList(sortedList: Array<T>): List<List<T>> {
    val permutations = mutableListOf<List<T>>()
    val queue = ArrayDeque<List<T>>().apply { addLast(listOf()) }
    while (queue.isNotEmpty()) {
        val p = queue.removeLast()

        if (p.size == sortedList.size) {
            permutations.add(p)
        } else {
            sortedList.filterNot { p.contains(it) }
                .forEach { queue.addLast(p + it) }
        }
    }

    return permutations
}

fun main(args: Array<String>) {
    val n = readInteger()
    val p = readIntegerList()
    val q = readIntegerList()

    val per = permutationList((1..n).toList().toTypedArray())
    Math.abs(per.indexOf(p) - per.indexOf(q)).let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 46528
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------


int n;
int a[110];

void print(void)
{
	for (int i = 0; i<n; i++) {
		if (i>0) cout << " ";
		cout << a[i];
	}
	cout << endl;
}

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

	for (int i = 1; i<n; i++) {
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		print();
	}


	return 0;
}

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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int main() {
    lld N;
    lld A[100005];
    cin >> N;
    bool flg = false;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if(A[i] == 0){
            flg = true;
        }
    }
    if(flg == true){
        cout << "0" << endl;
        exit(0);
    }
    lld ans = 1;
    for (int i = 0; i < N; i++) {
        if(ans < LLONG_MAX / A[i]){
            ans *= A[i];
        } else {
            cout << "-1" << endl;
            exit(0);
        }
        if(ans > 1000000000000000000){
            cout << "-1" << endl;
            exit(0);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4376
if __name__ == '__main__':
	m,f,r = map(int, input().split())
	while True:
		if m == -1 and f == -1 and r == -1:
			break
		if m == -1 or f == -1:
			print("F")
		elif m + f >= 80:
			print("A")
		elif m + f >= 65 and m + f < 80:
			print("B")
		elif m + f >= 50 and m + f < 65:
			print("C")
		elif m + f >= 30 and m + f < 50:
			if r >= 50:
				print("C")
			else:
				print("D")
		else:
			print("F")
		m,f,r = map(int, input().split())


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<sqrt(n);i++)
    {
        if(n%i==0)
        {
          c++;
        }
    }
    c=c*2;
    if(pow(sqrt(n),2)==(sqrt(n)*sqrt(n)))
        c++;
    return  c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   

 int a,b,c,d;
 cin>>a>>b>>c>>d;
 if(b<c || a>d)
    cout<<0;
else if(b>=d && a<=c)
    cout<<d-c;
else if(b<=d && a>=c)
    cout<<b-a;
else if(b<=d && b>=c && a<=c && b<=d)
    cout<<b-c;
else if(a>=c && b>=d && d>=a)
    cout<<d-a;
else 
    cout<<b-c;



 return 0;
}








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

int main() {
  
  int N;
  cin >> N;
  
  for (int i = 0;i < N;i++) {
    string S;
    cin >> S;
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
    
    else if (S != "Y" && i == N - 1) {
      cout << "Three" << endl;
    }
    
    else {
      continue;
    }
  }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
    elif a[i] < b[i]:
        ans += a[i]
        if b[i] - a[i] <= a[i+1]:
            ans += b[i] - a[i]
            a[i+1] = a[i+1] -b[i] + a[i]
        elif b[i] -a[i] > a[i+1]:
            ans += a[i+1]
            a[i+1] = 0
print(ans)

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

int main() {
    int a,b;cin >> a >> b;
    if(a%(2*b+1)!=0){
        cout << (a/(2*b+1))+1 << endl;
    }else{
        cout << a/(2*b+1) << endl;
    }
}



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

void solve(long long N, long long K)
{
    cout << floor(log(N) / log(K)) + 1 << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1000000000+7)

int main() {
    ll N, L;
    cin >> N >> L;
    int id = 0;
    if (L>0) id = 1;
    else if (L+N-1 < 0) id = N;
    else {
        id = 1-L;
    }
    
    int sum = 0;
    REP(i, N) {
        if (i+1 != id) sum += L+i-1+1;
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

class UnionFind{
public:
    vector<int> v;

    UnionFind(int n){
        v.assign(n,-1);
    }
    
    int find(int x){
        if(v[x]<0) return x;
        v[x]=find(v[x]);
        return v[x];
    }
    
    bool same(int a,int b){
        if(find(a)==find(b)) return true;
        return false;
    }
    
    void union_u(int a,int b){
        if(same(a,b)) return;
        int a_p=find(a),b_p=find(b);
        if(a_p>b_p) swap(a_p,b_p);
        v[a_p]+=v[b_p]; v[b_p]=a_p;
    }
    
    int size(int a){
        return -v[find(a)];
    }

    int group_cnt(){
        int res=0;
        for(auto p:v)if(p<0) res++;
        return res;
    }
};


int main(){
    int n,q; cin>>n>>q;
    UnionFind uf(n);
    rep(_,q){
        int t,u,v; cin>>t>>u>>v;
        if(t==0){
            uf.union_u(u,v);
        }
        else{
            printf("%d\n",(int)uf.same(u,v));
        }
    }
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
 #define REP(i, n) for(int i=0; i<(int)(n); i++)
 #define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
 #define ALL(x) begin(x),end(x)
 #define PB push_back
 using namespace std;
 typedef int64_t LL;
 typedef vector<int> VI;
 typedef pair<int,int> PII;
 
 template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
 template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
 template<class T> using MaxHeap = priority_queue<T>;
 template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
 template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
     sort(begin(v),end(v),f);
     v.resize(unique(begin(v),end(v))-begin(v));
 }
 
 int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,w,z;
    cin >> n >> w >> z;
    VI a(n);
    REP(i,n) cin >> a[i];
    if ( n==1 ) {
        cout << abs(a[n-1]-z) << endl;
    } else {
        cout << max(abs(a[n-1]-z), abs(a[n-2]-a[n-1])) << endl;    
    }
    return 0;
 }




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

int main(){
  int N;
  cin >> N;
  
  vector<int> H(N);
  repeat(i,N) cin >> H[i];
  
  int max = 0;
  string ans = "Yes";
  repeat(i,N){
    if(H[i]-max<-1){
      ans = "No";
      break;
    }
    if(max<H[i]) max = H[i];
  }
  cout << ans << endl;
}

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

int main() {
	int A,B;
	cin >> A >> B;

  cout << max({A+B,A-B,A*B}) << endl;
}

Measured memory_bytes: 256
N = int(input())
A = dict()
for i in range(N):
    tmp = input()
    if(tmp in A): A[tmp] += 1
    else: A[tmp] = 1

A = sorted(A.items(), key=lambda x:x[1], reverse=True)

#print(A)

B = dict()

MAX = 0

c = 0


for i in A:
    if(c == 0):
        MAX = i[1]
        B[i[0]] = i[1]
        c += 1
    else:
        if(i[1] == MAX):
            B[i[0]] = i[1]
        else:
            break

#print(B)


B_sorted = sorted(B.items(), key=lambda x:x[0])

for i in B_sorted:
    print(i[0])




Measured memory_bytes: 68312
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

std::map<long long, long long> primeFactorization(
    long long n) { /* prime factorization * nを素因数分解する */
  std::map<long long, long long> pf;
  for (long long i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      ++pf[i];
    }
  }
  if (n > 1) {
    ++pf[n];
  }
  return pf;
}
LL N;
LL dfs(map<LL, LL> pf, LL Sum) {
  DUMP("dfs", pf, Sum);
  if (pf.size() == 0) {
    LL m = max(Sum - 1, 1LL);
    DUMP("edge ", m, N, N / m, N % m);
    if (N / m == N % m)
      return m;
    else
      return 0;
  }
  LL ans = 0;
  pair<long, long> r = *pf.begin();
  pf.erase(pf.begin());
  REP(i, 0, r.second + 1) {
    LL t = pow(r.first, i);
    DUMP("         ", i, r, pf, t, Sum * t);
    ans += dfs(pf, Sum * t);
  }
  return ans;
}
int main() {
  cin >> N;
  LL sum = 0;
//   REP(m, 1, N) {
//     if (N / m == N % m) {
//       DUMP(m, sum);
//       sum += m;
//     }
//   }
//   DUMP("simple", sum);

  auto pf = primeFactorization(N);
  LL ans = dfs(pf, 1LL);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

int main() {
  ll N, T;
  cin >> N >> T;

  ll ans = 0;
  ll cur, prev;
  cin >> prev;
  for (int i = 1; i < N; i++) {
    cin >> cur;
    ans += min(T, cur - prev);
    prev = cur;
  }
  ans += T;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll x;cin>>x;
  for(ll a = 0; a < 1e9; a++){
    ll A = lpow(a,5);
    ll A_1 = lpow(a-1,5);
    if(A - A_1 > x) break;
    for(ll b = a - 1; true; b--){
      ll B = lpow(b,5);
      if(A - B > x) break;
      if(A - B == x){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define MAX (ll)(1e6 + 7)
#define INF (ll)(1e18 + 7)
#define MOD (ll)(1e9 + 7)

using namespace std;
using ll = long long;
using cd = complex<double>;

int main () {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max ({a * c, a * d, b * c, b * d}) << "\n";
}


Measured memory_bytes: 3636
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
 
sm=[0]*(n+1)
d=defaultdict(int)
for i in range(1,n+1):
    sm[i]=sm[i-1]+a[i-1]
    d[sm[i]]+=1
 
d[0]+=1
ans=0
for i,j in d.items():
    ans+=(j*(j-1))//2
 
print(ans)

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

namespace ConsoleApplication84
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[4];
            a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] b = new int[4];
            for(int c =0;c<4;c++)
                b[c]=a[c];
            Array.Sort(a);
            if (b[1] < b[2] || b[0] > b[3])
                Console.WriteLine(0);
            else
            Console.WriteLine(a[2] - a[1]);
        }
    }
}


Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace 東京海上日動2020C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = RLong;
            var k = RInt;

            var a = RLongs;

            for (int i = 0; i < k; i++)
            {
                long[] next = new long[n + 1];
                for (int j = 0; j < n; j++)
                {
                    next[Math.Max(0, j - a[j])] += 1;
                    next[Math.Min(n, j + a[j] + 1)] -= 1;
                }

                a[0] = next[0];
                for (int j = 1; j < n; j++)
                {
                    a[j] = next[j] + a[j - 1];
                }

                if (a.Sum() >= n * n) break;
            }

            Console.WriteLine(string.Join(" ", a));
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 61100
N,K = map(int, input().split())
A = [0] + [*map(lambda x:int(x), input().split())]
index = [-1]*(N+1)
path = [1]
while index[path[-1]] < 0:
    index[path[-1]] = len(path)
    path += [A[path[-1]]]
one = index[path[-1]]
loops = len(path) - one
if K < one: print(path[K])
else: print(path[(K-one) % loops + one])


Measured memory_bytes: 32376
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int N,w,d;
	while(cin>>N>>w>>d&&w&&d){

		int p,s,tmp1,tmp2;
		pair<int,int> rect[110],rect1,rect2;//w,d
		int ans[110];
		int pw,pd;
		rect[1]={w,d};
		REP(i,2,N+2){
			cin>>p>>s;
			pw=rect[p].first;
			pd=rect[p].second;

			s%=pw+pd;

			if(s<pw){
				rect1={pw-s,pd};
				rect2={s,pd};
			}else{
				s-=pw;
				rect1={pw,pd-s};
				rect2={pw,s};
			}
			tmp1=rect1.first*rect1.second;
			tmp2=rect2.first*rect2.second;
			if(tmp1>tmp2){
				swap(rect1,rect2);
			}
			for(int j=p+1;j<=i-1;j++){
				rect[j-1]=rect[j];
			}
			rect[i-1]=rect1;
			rect[i]=rect2;
		}
		REP(i,1,N+2){
			ans[i-1]=rect[i].first*rect[i].second;
		}
		sort(ans,ans+N+1);
		REP(i,0,N){
			cout<<ans[i]<<" ";
		}
		p(ans[N]);
	}
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n;
	cin>>n;

	lli t=0,x=0,y=0;

	REP(i,0,n){
		lli tt,xx,yy;
		cin>>tt>>xx>>yy;

		lli diff = abs(x-xx)+abs(y-yy);
		lli diffT = tt-t;
		if( (diff > diffT) || (diff%2 != diffT%2)){
			cout<<"No"<<endl;
			return 0;
		}
		t = tt,x=xx,y=yy;
	}

	cout<<"Yes"<<endl;

	return 0;
}

Measured memory_bytes: 256