akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;



void solve() {
	int n;
	map<string, ll> m;
	ll m_value = -maxn;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		m[s]++;
		m_value = max(m_value, m[s]);
		}
		for(auto x : m) if( x.second== m_value) cout << x.first << endl;
}


int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	int t;
	solve();
	return 0;
}
 
 
 


Measured memory_bytes: 19248
#include <stdio.h>
int main() {
    int n, i;
    int data[100];
    scanf("%d", &n);
    for(i = 0; i < n; i++) scanf("%d", &data[i]);
    for(i = n - 1; i >= 0; i--) {
        printf("%d", data[i]);
        if(i > 0) printf(" ");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1856
import sys
input = sys.stdin.buffer.readline

from collections import deque

N, M = map(int, input().split())

X = [-10**9, 0, 10**9]
Y = [-10**9, 0, 10**9]

tate = []
yoko = []

for _ in range(N):
    a, b, c = map(int, input().split())
    X.append(a)
    X.append(b)
    Y.append(c)
    tate.append((a, b, c))

for _ in range(M):
    d, e, f = map(int, input().split())
    X.append(d)
    Y.append(e)
    Y.append(f)
    yoko.append((d, e, f))

X = sorted(set(X))
Y = sorted(set(Y))

Cx = {val: idx * 2 for idx, val in enumerate(X)}
Cy = {val: idx * 2 for idx, val in enumerate(Y)}

H = len(X) * 2 - 1
W = len(Y) * 2 - 1

G = [0] * (H * W)

for a, b, c in tate:
    j = Cy[c]
    for i in range(Cx[a], Cx[b] + 1):
        G[i * W + j] = -1

for d, e, f in yoko:
    i = Cx[d]
    for j in range(Cy[e], Cy[f] + 1):
        G[i * W + j] = -1

for i in range(1, H, 2):
    for j in range(1, W, 2):
        G[i * W + j] = (X[(i + 1) // 2] - X[(i - 1) // 2]) * (Y[(j + 1) // 2] - Y[(j - 1) // 2])

queue = deque([Cx[0] * W + Cy[0]])
visited = [0] * (H * W)
visited[Cx[0] * W + Cy[0]] = 1
res = 0

while queue:
    z = queue.popleft()
    nz = z + W
    if G[nz] != -1 and not visited[nz]:
        nx = nz // W
        if nx == H - 1:
            print('INF')
            break
        visited[nz] = 1
        res += G[nz]
        queue.append(nz)
    nz = z - W
    if G[nz] != -1 and not visited[nz]:
        nx = nz // W
        if nx == 0:
            print('INF')
            break
        visited[nz] = 1
        res += G[nz]
        queue.append(nz)
    nz = z + 1
    if G[nz] != -1 and not visited[nz]:
        ny = nz % W
        if ny == W - 1:
            print('INF')
            break
        visited[nz] = 1
        res += G[nz]
        queue.append(nz)
    nz = z - 1
    if G[nz] != -1 and not visited[nz]:
        ny = nz % W
        if ny == 0:
            print('INF')
            break
        visited[nz] = 1
        res += G[nz]
        queue.append(nz)
else:
    print(res)

Measured memory_bytes: 814616
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

class BellmanFord {
 private:
  const ll INF = 1LL << 60;
  int n_;
  vector<tuple<int, int, ll>> edges_;
  vector<vector<int>> to_, rto_;
  vector<ll> dist_;
  vector<bool> reachableFromSrc_, reachableToDst_;

  void dfs(int u, const vector<vector<int>>& to, vector<bool>& reachable) {
    if (reachable[u]) return;
    reachable[u] = true;
    for (int v : to[u]) {
      dfs(v, to, reachable);
    }
  }

 public:
  BellmanFord(int n)
      : n_(n),
        dist_(n, INF),
        to_(n),
        rto_(n),
        reachableFromSrc_(n, false),
        reachableToDst_(n, false) {}

  void addEdge(int u, int v, ll w) {
    edges_.emplace_back(u, v, w);
    to_[u].emplace_back(v);
    rto_[v].emplace_back(u);
  }

  bool exec(int src, int dst, ll& ans) {
    // To remove edges which is not involved in path from src to dst
    dfs(src, to_, reachableFromSrc_);
    dfs(dst, rto_, reachableToDst_);

    dist_[src] = 0;
    rep(i, n_) {
      for (auto& e : edges_) {
        int u = get<0>(e);
        int v = get<1>(e);
        ll w = get<2>(e);
        if (reachableFromSrc_[u] && reachableFromSrc_[v] &&
            reachableToDst_[u] && reachableToDst_[v]) {
          if (dist_[v] > dist_[u] + w) {
            dist_[v] = dist_[u] + w;
          }
        }
      }
    }
    for (auto& e : edges_) {
      int u = get<0>(e);
      int v = get<1>(e);
      ll w = get<2>(e);
      if (reachableFromSrc_[u] && reachableFromSrc_[v] && reachableToDst_[u] &&
          reachableToDst_[v]) {
        if (dist_[v] > dist_[u] + w) {
          // has negative cycle
          return true;
        }
      }
    }
    // no negative cycle
    ans = dist_[dst];
    return false;
  }
};

int main() {
  //
  int n, m;
  cin >> n >> m;
  BellmanFord g(n);

  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--;
    b--;
    g.addEdge(a, b, -c);
  }
  ll ret = 0;
  if (g.exec(0, n - 1, ret)) {
    cout << "inf" << endl;
  } else {
    cout << -ret << endl;
  }

  return 0;
}


Measured memory_bytes: 512
<?php
fscanf(STDIN, '%d', $N);
$arr = explode(' ', trim(fgets(STDIN)));

for ($i = 0, $len = count($arr), $swapCnt = 0; $i < $len; $i++) {
    $minj = $i;
    for ($j = $i; $j < $len; $j++) {
        if ($arr[$j] < $arr[$minj]) {
            $minj = $j;
        }
    }

    if ($minj !== $i) {
        $tmp = $arr[$i];
        $arr[$i] = $arr[$minj];
        $arr[$minj] = $tmp;
        $swapCnt++;
    }
}

echo implode(' ', $arr), PHP_EOL, $swapCnt, PHP_EOL;



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

using namespace std;

#define DEBUG_MODE
#ifdef DEBUG_MODE
	#define _(n) n;
#else
	#define _(n) ;
#endif
#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


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

int main()
{
	ll n;cin >> n;
	vector<ll> v(n);
	
	REP(i,n){
		cin >> v[i];
	}
	
	REP(i,n-1){
		v[i+1] += v[i];
	}
	v.PB(0);n++;
	sort(ALL(v));
	v.PB(1000000000000000000LL);
		
	ll now = -1000000000000000LL;
	ll ans = 0;
	ll cou = 0;
	REP(i,n+1){
		if(now == v[i]){
			cou++;
		}
		else{
			if(cou > 1){
				ans += cou * (cou - 1) / 2;
			}
			now = v[i];
			cou = 1;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

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

int a, b, c;
int dp[100001][4];

int main() {
    ll n, notAvailable = 0, maxSum = 0;

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a >> b >> c;

        dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + a;
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + b;
        dp[i][3] = max(dp[i - 1][1], dp[i - 1][2]) + c;
    }

    cout << max(max(dp[n][1], dp[n][2]), dp[n][3]);

    return 0;
}


Measured memory_bytes: 5192
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;

  // c[i][j] = count of number k <= N  where first digit is i and last digit is j
  // ans = sum_i sum_j c[i][j] * c[j][i]
  vector<vector<int>> c(10, vector<int>(10));
  for (int i = 1; i <= n; ++i) {
    int lastDigit = i % 10;
    // cout << "lastDigit: " << lastDigit << endl;
    int firstDigit;
    int j = i;
    while (j > 0) {
      // cout << "j: " << j << endl;
      firstDigit = j;
      j /= 10;
    }
    ++c[firstDigit][lastDigit];
  }
  ll ans = 0;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      ans += c[i][j] * c[j][i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	unsigned int a, b;
	bool evenFlg = false;
	cin >> a >> b;
	
	if (a % 2 == 0) evenFlg = true;
	if (b % 2 == 0) evenFlg = true;
	if (evenFlg)
	{
		cout << "Even" << endl;
	}
	else
	{
		cout << "Odd" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n;
		cin >> n;
		int h[n];
		rep(i,0,n) cin >> h[i];
		int dp[n];
		dp[0] = 0;
		rep(i,1,n){
			dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
			if(i-2>=0) dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
		}
		cout<<dp[n-1];
	}
}

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

template<class T>struct costflowGraph{
	typedef pair<T, int> P;
	struct edge{
		int to, cap, rev;
		T cost;
		edge(int to, int cap, T cost, int rev) :
			to(to), cap(cap), cost(cost), rev(rev){
			}
	};
	
	int n, *prevv, *preve;
	T *dist;
	vector<vector<edge> > G;
	
	costflowGraph(int sz) : n(sz){
		G.resize(n);
		dist = new T[n];
		prevv = new int[n]; preve = new int[n];
	}
	~costflowGraph(){
		delete dist;
		delete prevv; delete preve;
	}
	
	void add(int s, int t, int cap, T cost){
		G[s].pb(edge(t, cap, cost, G[t].size()));
		G[t].pb(edge(s, 0, -cost, G[s].size() - 1));
	}
	pi min_cost_flow(int s, int t){
		T res = 0;
		int f = 0;
		while(1){
			fill(dist, dist + n, inf);
			dist[s] = 0;
			while(1){
				bool update = 0;
				rep(v, n){
					if(dist[v] == inf) continue;
					rep(i, G[v].size()){
						edge &e = G[v][i];
						if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + EPS){
							dist[e.to] = dist[v] + e.cost;
							prevv[e.to] = v;
							preve[e.to] = i;
							update = 1;
						}
					}
				}
				if(!update) break;
			}
			if(dist[t] == inf) return mp(f, res);
		
			int d = inf;
			for(int v = t; v != s; v = prevv[v]) d = min(d, G[prevv[v]][preve[v]].cap);
			f += d;
			res += d * dist[t];
			for(int v = t; v != s; v = prevv[v]){
				edge &e = G[prevv[v]][preve[v]];
				e.cap -= d;
				G[v][e.rev].cap += d;
			}
			assert(d > 0);
		}
	}
};

int cost[500][500];

int main(){
	int n, m, k; cin >> n >> m >> k;
	rep(i, n){
		string s; cin >> s;
		rep(j, m) if(s[j] == '1') cost[i][j + n]++;
	}
	rep(i, m){
		string s; cin >> s;
		rep(j, n) if(s[j] == '1') cost[j][i + n]++;
	}
	
	costflowGraph<int> g(n + m + 2);
	rep(i, n) rep(j, m) if(cost[i][j + n] < 2) g.add(i, j + n, 1, cost[i][j + n]);
	rep(i, n) g.add(n + m, i, 1, 0);
	rep(i, m) g.add(i + n, n + m + 1, 1, 0);
	
	pi res = g.min_cost_flow(n + m, n + m + 1);
	
	//cerr<<res.first<<" "<<res.second<<endl;
	
	int ans = res.first;
	if(res.second < k) ans = min(min(n, m), ans + (k - res.second) / 2);
	else ans = max(0, ans - (res.second - k));
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5016
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    aa = np.array(list(map(int, input().split())), dtype="i8")
    bb = np.array(list(map(int, input().split())), dtype="i8")
    ans = 0
    for k in range(29):
        t = 1 << k
        t2 = t << 1
        am = aa % t2
        bm = bb % t2
        # am.sort(reverse=True)
        bm.sort()
        # print(am)
        # print(bm)
        cnt = n % 2
        for tk in range(t, t * 4, t):
            cnt += np.sum(np.searchsorted(bm, tk - am))
        if cnt % 2:
            ans += t
    print(ans)

main()


Measured memory_bytes: 36224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	int N, M;
	cin >> N >> M;
	if(N==1){
		cout << M << endl;
		return 0;
	}
	int ans=1;
	for(int i=2; i*i<=M; i++){
		if(N*i>M) break;
		if(M%i==0){
			if(i<N) ans=max(ans,i);
			else ans=max(ans,M/i);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int n;
int main(int argc,char const* argv[])
{
  int x;
  cin >> x;
  if(x==3 || x==5 || x==7)
    {
      cout << "YES" << endl;
    }
  else
    {
      cout << "NO" << endl;
    }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
int test[313456];
signed main() {
	int n, m = 0, a, ans = 0; cin >> n;
	for (int h = 0; h < n * 3; h++) {
		cin >> test[h];
	}
	sort(test, test + (n * 3));
	m = (n * 3 - 2) % 2;
	for (int h = n * 3 - 2; h >= n; h--) {
		if (h % 2 == m) {
			ans += test[h];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
/*
 
 * This code is written by Sanskar Agarwal
 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

#define ll long long
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VPLL vector<PLL>
#define VPII vector<PII>
#define PQ priority_queue<PLL,VPLL, greater<PLL> > 
#define PQI priority_queue<PII,VPII,greater<PII> >
#define S second
#define F first
#define PB push_back


int a[100],n;
int dp[100001][2];
int mini=100000000;

int solve(int k,int ch)
{
    if(k<mini) {
        if(ch==0)
            return dp[k][ch]=1;
        else
            return dp[k][ch]=0;
    }
    if(dp[k][ch]!=-1)
        return dp[k][ch];

    int sm,op;
    if(ch==0) {
        sm=1;op=1;
    } else {
        sm=0;op=0;
    }


    for(int i=0;i<n;i++) {
        if(a[i]<=k) {
            if(ch==1)
                sm=max(sm,solve(k-a[i],op));
            else
                sm=min(sm,solve(k-a[i],op));
        }
    }
    return dp[k][ch]=sm;
}

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

    int k;
    cin>>n>>k;
    for(int i=0;i<n;i++) {
        cin>>a[i];
        if(a[i]<mini)
            mini=a[i];
    }
    memset(dp,-1,sizeof dp);
    int ans=solve(k,1);
    if(ans)
        cout << "First";
    else
        cout << "Second";

    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    int cnt[300000] = {};
    int n; cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        v[i] = a;
        cnt[a]++;
    }
    
    int ma = 0;
    for(int i = 0; i < n; i++){
        ma = max(ma, v[i]);
    } 

    int sma = 0;
    for(int i = 0; i < n; i++){
        if(v[i] == ma) continue;
        sma = max(sma, v[i]);
    }

    for(int i = 0; i < n; i++){
        if(v[i] == ma){
            if(cnt[ma] == 1) cout << sma << endl;
            else cout << ma << endl;
        }else cout << ma << endl;
    }
    
    return 0;
}


Measured memory_bytes: 5504
#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 N, R;
    cin >> N >> R;

    if(N>=10) {
        cout << R << endl;
    }else{
        cout << R + 100 * (10 - N) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N, M, P = map(int, input().split())
edges = []
edges1 = [[] for _ in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    edges1[b-1].append(a-1)
    edges.append((a-1, b-1, -c+P))
from collections import deque
que = deque([N-1])
flag = [True]*N
flag[-1] = False
while que:
    v = que.pop()
    for e in edges1[v]:
        if flag[e]:
            que.append(e)
            flag[e] = False
def f(n,w,es):
    #負の経路の検出
    #n:頂点数, w:辺の数, es[i]: [辺の始点,辺の終点,辺のコスト]
    d = [float("inf")] * n
    d[0] = 0 
    #この始点はどこでもよい
    for i in range(n):
        for j in range(w):
            e = es[j]
            if flag[e[1]]:
                continue
            if d[e[1]] > d[e[0]] + e[2]:
                d[e[1]] = d[e[0]] + e[2]
                if i == n-1:
                    return False
    return d
d = f(N, M, edges)
if d:
    print(max(-d[-1], 0))
else:
    print(-1)   
        


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

struct edge {
    int to, cost;
};

vector<vector<edge>> g;
vector<int> dist;
vector<int> pre;

//ダイクストラ法
void dijkstra(int n, int s) {
    dist.resize(n, INF);
    pre.resize(n, -1);

    //最小値を取り出す優先度付きキュー
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;

    dist[s] = 0;
    que.push(make_pair(0, s)); //距離を最初にして、優先度付きキューで最小値を出せるようにする

    while (!que.empty()) {
        pair<int, int> p = que.top(); que.pop();
        int v = p.second;

        //記録してある最短距離よりも取り出した要素に入っている距離情報が大きい場合は打ち切り
        if (dist[v] < p.first) continue;

        for (int i = 0; i < g[v].size(); ++i) {
            edge e = g[v][i];

            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                pre[e.to] = v; //頂点vを通って、e.toにたどり着いた
                que.push(make_pair(dist[e.to], e.to));
            }
        }
    }
}

int main() {

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

    g.resize(n);
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        --a; --b;

        g[a].push_back(edge({b, 1}));
        g[b].push_back(edge({a, 1}));
    }

    dijkstra(n, 0);

    cout << "Yes" << endl;
    for (int i = 0; i < n; ++i) {
        if (i == 0) continue;

        cout << pre[i] + 1 << endl;
    }
}

Measured memory_bytes: 13492
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

struct UnionFind {
    UnionFind(int n) : p(n, -1), r(n) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (r[u] > r[v]) swap(u, v);
        p[u] = v;
        r[v] += (r[u] == r[v]);
    }
    vector<int> p, r;
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n * 2);
    for (int i = 0; i < m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        u--; v--;
        uf.unite(u, v + n);
        uf.unite(u + n, v);
    }

    int64_t k[3] = {};
    for (int i = 0; i < n * 2; i++) {
        if (uf.p[i] >= 0) continue;
        if (uf.r[i] == 0) k[0]++;
        else {
            int v = i < n ? i + n : i - n;
            k[1 + uf.same(i, v)]++;
        }
    }

    k[0] /= 2;
    k[1] /= 2;
    k[2] += k[1];
    int64_t r = k[0] * (n * 2 - k[0]) + k[2] * k[2] + k[1] * k[1];

    cout << r << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
int n,i;
double k,ans;
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%lf",&k);
		ans+=1/k;
	}
	printf("%lf\n",1/ans);
	return 0;
}

Measured memory_bytes: 128
k, a, b = map(int, input().split())

if (k == 1):
    print(2)
    exit()

if (b <= (a + 1)):
    print(k + 1)
    exit()
else:
    tmp1 = k - (a - 1)
    sabun = b - a

    if (tmp1 % 2 == 0):
        bis = int((tmp1 / 2 - 1)) * int(sabun) + b
    else:
        zouka = int((tmp1 // 2 - 1)) * int(sabun)
        bis = zouka + b + 1

    print(bis)

Measured memory_bytes: 3064
import sys
import math
import numpy as np
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, l = na()
if l > 0:
    print((l+1 + l+n-1) * (n-1) // 2)
elif l + n - 1 < 0:
    print((l + l+n-2) * (n-1) // 2)
else:
    print((l + l+n-1) * n // 2)

Measured memory_bytes: 13408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

const int N = 200010;
vector<int> v[N];
int pre[N];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	while (m--) {
		int x, y;
		scanf("%d%d", &x, &y);
		v[x].push_back(y);
		v[y].push_back(x);
	}

	queue<int> q;
	q.push(1);
	memset(pre, -1, sizeof(pre));
	pre[1] = 0;
	int tot = 0;
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		tot++;
		for (int i = 0; i < v[u].size(); i++) {
			int x = v[u][i];
			if (pre[x] == -1) {
				q.push(x);
				pre[x] = u;
			}
		}
	}

	if (tot < n) {
		printf("No\n");
		return 0;
	}

	printf("Yes\n");
	for (int i = 2; i <= n; i++)
		printf("%d\n", pre[i]);
	return 0;
}


Measured memory_bytes: 12664
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <cmath>

#define MY_PI 3.14159265358979323846

#define pb push_back
     
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
     
bool debug = false;
     

struct state
{
    ll a,b,c;

    state(ll a, ll b, ll c) : a(a), b(b), c(c)
    {

    }

  bool operator==(const state &other) const
  { return (a == other.a
            && b == other.b
            && c == other.c);
  }
};


struct KeyHasher
{
    size_t operator()(const state& k) const
  {
    //using std::size_t;
    //using std::hash;
    //using std::string;

    return ((hash<ll>()(k.a)
               ^ (hash<ll>()(k.b) << 1)) >> 1)
               ^ (hash<ll>()(k.c) << 1);
  }
};  


void solve(ll casen)
{
    ll res = 0;
    
    cout << "Case #" << casen << ": " << res << endl;
}

int main()
{
    // $ g++ -std=c++14 -Wshadow -Wall -o c C.cpp

    // !!! Here, unordered map was too slow!!!
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    
   double a, b, h, m;

   cin >> a >> b >> h >> m;

   double alpha = 2.0*MY_PI*abs((h + m/60.0)/12.0  -  m/60.0); //abs((12.0 - h)/12.0  -  (60.0 - m)/60.0));

   //cout << "alpha = " << alpha << endl;

   double x = sqrt(a*a + b*b - 2*a*b*cos(alpha));

   cout << fixed << setprecision(10);
   cout << x << endl;

    return 0;
}

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

"""abc080_d"""


import sys


def main():
    """Main function."""
    N, C = map(int, input().split(' '))
    table = [[0]*100000 for _ in range(C)]

    for _ in range(N):
        s, t, c = map(int, input().split(' '))
        table[c-1][s-1:t] = [1]*(t-s+1)

    print(max(map(sum, zip(*table))))


if __name__ == '__main__':
    sys.exit(main())

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

using namespace std;

using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	ll n, c;
	cin >> n >> c;
	vector<ll> pos(n);
	vector<ll> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> pos[i] >> v[i];
	}
	vector<ll> bst(n + 1);
	{
		ll cal = 0;
		for (int i = 1; i <= n; ++i) {
			cal += v[i - 1];
			bst[i] = max(bst[i - 1], cal - pos[i - 1]);
		}
	}
	ll ans = bst[n];
	ll cal = 0;
	for (int i = n - 1; i >= 0; --i) {
		cal += v[i];
		ll cur = cal - (c - pos[i]) + max(0ll, bst[i] - (c - pos[i]));
		ans = max(cur, ans);
	}
	reverse(pos.begin(), pos.end());
	reverse(v.begin(), v.end());
	for (int i = 0; i < n; ++i) {
		pos[i] = c - pos[i];
	}
	{
		ll cal = 0;
		for (int i = 1; i <= n; ++i) {
			cal += v[i - 1];
			bst[i] = max(bst[i - 1], cal - pos[i - 1]);
		}
	}
	cal = 0;
	for (int i = n - 1; i >= 0; --i) {
		cal += v[i];
		ll cur = cal - (c - pos[i]) + max(0ll, bst[i] - (c - pos[i]));
		ans = max(cur, ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N,M;
  cin>>N>>M;
  vector<int>H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  vector<int>A(M),B(M);
  for(int i=0;i<M;i++){
    cin>>A[i]>>B[i];
    A[i]--;B[i]--;
  }
  //vector<int>MAX(N+1);
  vector<bool>high(N+1,true);
  for(int i=0;i<M;i++){
     if(H[A[i]]>H[B[i]]){high[B[i]+1]=false;}
     else if(H[A[i]]<H[B[i]]){high[A[i]+1]=false;}
     else{high[A[i]+1]=false;high[B[i]+1]=false;}
     //cout<<H[A[i]]<<" "<<H[B[i]]<<endl;
  }
  int cnt=0;
  for(int i=1;i<N+1;i++){
    if(high[i]){cnt++;}
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 4588
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define mp           make_pair
#define int          long long
#define uint         unsigned long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define repr(i,x,m)  for(int i=x;i>=m;i--)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define vs           vector<string>
#define pi           pair<int,int>
#define di           deque<int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define pqs          priority_queue<int,vi,greater<int> >
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define noob         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int fac[2000005]={0};
void factorial(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=((i%MOD)*(fac[i-1]%MOD))%MOD;}
int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int ncr(int n,int r){return ((fac[n]*power(fac[r],MOD-2))%MOD*power(fac[n-r],MOD-2))%MOD;}

void ram5564()
{
    string s;
    cin>>s;
    cout<<s[0]<<s[1]<<s[2];
}

signed main()
{
        noob
        // #ifndef ONLINE_JUDGE
        //  freopen("input.txt","r",stdin);
        //  freopen("output.txt","w",stdout);
        //  #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 3612
#include<cstdio>

int main(){
    int n;
    double sum = 0.0;
    
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        int tmp;
        scanf("%d",&tmp);
        sum+=(1.0/tmp);
    }

    printf("%lf\n",1/sum);

    return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p.at(i);
    int sum = 0;

    sort(p.begin(), p.end());
    for (int i = 0; i < K; i++) sum += p.at(i);
    cout << sum << endl;
}

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

#define ll long long
#define linf (1ll << 60)
#define all(x) (x).begin(), (x).end()

// -------- Main Code -------- //
void runcase() {
    int n, x, t;
    cin >> n >> x >> t;
    int need = ceil(1.0 * n / x);
    cout << t * need << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // int t;
    // cin >> t;
    // while (t-- > 0)
        runcase();
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;

int main(){
    string s,t; cin >> s >> t;
    ll n = s.size();
    ll m = t.size();
    ll index = -1;
    for(ll i=n-m; i>=0; i--){
        rep(j,m){
            if(s[i+j] != '?' && s[i+j]!=t[j]) break;
            if(j==m-1) index = i;
        }
        if(index != -1) break;
    }
    if(index == -1) puts("UNRESTORABLE");
    else{
        REP(i,index,index+m){
            s[i] = t[i-index];
        }
        rep(i,n) if(s[i]=='?') s[i] = 'a';
        cout << s << endl;
    }
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a >= b) {
		rep(i, a) {
			cout << b;
		}
	}
	else {
		rep(i, b){
			cout << a;
			}
		}
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A;
  long sumy=0;
  for(int i=0; i<N; i++){
    int a; cin >> a;
    sumy+=a;
    A.push_back(a);
  }
  long min = 1e15;
  long sumx =0;
  for(int i=0; i<N-1; i++){
    sumx+=A[i];
    sumy-=A[i];
    if(abs(sumx-sumy)<min){
      min=abs(sumx-sumy);
    }
  }
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    cout << a[0] << ' ' << a[1] << ' ' << a[2] << endl;
}


Measured memory_bytes: 3140
S=input()

ans=0
for i in range(1<<len(S)-1):
  S2=S
  for j in range(0,len(S)-1):
    if ((i>>j)&1)==1:
      S2=S2[:-(len(S)-j)+1]+'+'+S2[-(len(S)-j)+1:]
  ans+=sum(map(int,S2.split('+')))
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
  int a,b,co = 0;
  cin >> a >> b;
  while (1){
      a -= b;
    co++;

      if(a <= 0){
          break;
      }

  }
  cout << co << endl;

    return 0;
}



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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,m;
    cin >> n >> m;
    const ll MOD = 1e9 + 7;

    int max_number = n;
    
    vector<ll> fac(max_number+1,1);
    vector<ll> inv(max_number+1,1);
    vector<ll> finv(max_number+1,1);
    vector<ll> nCk(max_number+1,1);
    for(i = 2;i <= max_number;++i){
        inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
    }
    for(i = 1;i <= max_number;++i){
        fac.at(i) = fac.at(i-1)*i%MOD;
        finv.at(i) = finv.at(i-1)*inv.at(i)%MOD;
    }
    for(i = 1;i <= max_number;++i){
        nCk.at(i) = fac.at(max_number)*finv.at(i)%MOD*finv.at(max_number-i)%MOD;
    }

    vector<ll> mPk(n+1, 1);
    for(i = 1;i <= n;++i){
        mPk.at(i) = mPk.at(i-1)*(m - i + 1)%MOD;
    }

    vector<ll> mkPnk(n+1, 1);
    for(i = n-1;i >= 0;--i){
        mkPnk.at(i) = mkPnk.at(i+1)*(m-i)%MOD;
    }

    ll ans = 0;
    for(i = 0;i <= n;++i){
        ll tmp = nCk.at(i)*mPk.at(i)%MOD*mkPnk.at(i)%MOD*mkPnk.at(i)%MOD;
        if(i%2) ans += MOD - tmp;
        else ans += tmp;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 26524
n, m = map(int, input().split())

graph = {}
for u in range(1, n + 1):
  graph[u] = set()
for i in range(m):
  u, v = map(int, input().split())
  graph[u].add(v)
  graph[v].add(u)
  
# check if has eulerian cycle
odd = 0
v6 = []
v4 = []
for u in range(1, n + 1): 
  if len(graph[u]) % 2 != 0: 
    odd += 1
    break
  elif len(graph[u]) >= 6:
    v6.append(u)
  elif len(graph[u]) == 4:
    v4.append(u)
if odd: 
  print('No')
else:
  # for has 3 cycles if any vertices has minimal six degree
  # or more than 2 vertices have 4 degrees
  if len(v6) > 0 or len(v4) > 2:
    print('Yes')
  # if vertices with 4 degrees less than 2
  elif len(v4) < 2:
    print('No')
  else:
    s = v4.pop()
    t = v4.pop()
    has_3_cycles= False
    for c in graph[s]:
      visited = {s, t}
      q = [c]
      while q:
        v = q.pop()
        if v in visited:
          continue
        visited.add(v)
        for u in graph[v]:
          if v != c and u == s:
            has_3_cycles = True
            break
          if u not in visited:
            q.append(u)
        if has_3_cycles:
          break
      if has_3_cycles:
        break
    print('Yes') if has_3_cycles else print('No')



Measured memory_bytes: 43620
// Comment
//

#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 5e3 + 100;
const int MOD = 1e9 + 7;

vector<int> Ed[MAX_N];
bool Vis[MAX_N];
int S[MAX_N], N;
int Dp[MAX_N][MAX_N][2];
int Temp[MAX_N][2];
int Cut[MAX_N];
void add(int &a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
int dfs(int v) {
	Vis[v] = true;
	S[v] = 1;
	vector<int> cs;
	for(int w: Ed[v]) {
		if(Vis[w]) continue;
		cs.push_back(w);
		S[v] += dfs(w);
	}
	int s = 1;
	Dp[v][1][0] = 1;
	for(int w: cs) {
		for(int i=1; i<=s; i++) for(int x=0; x<2; x++) {
			for(int j=1; j<=S[w]; j++) for(int y=0; y<2; y++) {
				add(Temp[i+j][(x+y)%2], 1ll * Dp[v][i][x] * Dp[w][j][y] % MOD);
				add(Temp[i][(x+y+1)%2], 1ll * Dp[v][i][x] * Dp[w][j][y] % MOD * Cut[j] % MOD);
			}
		}
		s += S[w];
		for(int i=1; i<=s; i++) for(int x=0; x<2; x++) Dp[v][i][x] = Temp[i][x];
		for(int i=1; i<=s; i++) for(int x=0; x<2; x++) Temp[i][x] = 0;
	}

	return S[v];
}

int main() {
	cin >> N;
	for(int i=1; i<N; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		Ed[x].push_back(y);
		Ed[y].push_back(x);
	}
	Cut[0] = 1;
	for(int i=2; i<=N; i+=2) {
		Cut[i] = 1ll * Cut[i-2] * (i-1) % MOD;
	}
	dfs(1);
	int ans = 0;
	for(int i=1; i<=N; i++) for(int x=0; x<2; x++) {
		Dp[1][i][x] = 1ll * Dp[1][i][x] * Cut[i] % MOD;
		ans += Dp[1][i][x] * (x == 0 ? 1 : -1);
		ans %= MOD;
	}
	ans += MOD;
	ans %= MOD;
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 59;

const int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0};

int main()
{
  int H, W, A, B, C, N;
  int S[100000], T[100000];
  int64 v[501][501];

  scanf("%d %d", &H, &W);
  scanf("%d %d %d", &A, &B, &C);
  scanf("%d", &N);

  queue< pair< int, int > > que;
  memset(v, -1, sizeof(v));
  for(int i = 0; i < N; i++) {
    scanf("%d %d", &S[i], &T[i]);
    v[S[i]][T[i]] = 0;
    que.emplace(S[i], T[i]);
  }

  while(!que.empty()) {
    int y, x;
    tie(y, x) = que.front();
    que.pop();
    for(int i = 0; i < 4; i++) {
      int ny = y + vy[i], nx = x + vx[i];
      if(ny < 0 || nx < 0 || ny > H || nx > W) continue;
      if(~v[ny][nx]) continue;
      que.emplace(ny, nx);
      v[ny][nx] = v[y][x] + 1;
    }
  }

  typedef tuple< int64, int, int, int > Node;
  int64 min_cost[501][501][5];
  priority_queue< Node, vector< Node >, greater< Node > > q;
  fill_n(**min_cost, 501 * 501 * 5, INF);
  q.emplace(0, S[0], T[0], 4);
  min_cost[S[0]][T[0]][4] = 0;
  while(!q.empty()) {
    int64 cost;
    int y, x, s;
    tie(cost, y, x, s) = q.top();
    q.pop();
    if(y == S[N - 1] && x == T[N - 1] && s == 4) {
      printf("%lld\n", cost);
      break;
    }
    if(s == 4) {
      for(int i = 0; i < 4; i++) {
        int ny = y + vy[i], nx = x + vx[i];
        if(ny < 0 || nx < 0 || ny > H || nx > W) continue;
        if(cost + B < min_cost[y][x][i]) {
          min_cost[y][x][i] = cost + B;
          q.emplace(min_cost[y][x][i], y, x, i);
        }
        if(cost + C < min_cost[ny][nx][4]) {
          min_cost[ny][nx][4] = cost + C;
          q.emplace(min_cost[ny][nx][4], ny, nx, 4);
        }
      }
    } else {
      if(cost + v[y][x] * C < min_cost[y][x][4]) {
        min_cost[y][x][4] = cost + v[y][x] * C;
        q.emplace(min_cost[y][x][4], y, x, 4);
      }
      int ny = y + vy[s], nx = x + vx[s];
      if(ny < 0 || nx < 0 || ny > H || nx > W) continue;
      if(cost + A < min_cost[ny][nx][s]) {
        min_cost[ny][nx][s] = cost + A;
        q.emplace(cost + A, ny, nx, s);
      }
    }
  }


}

Measured memory_bytes: 22432
#include <bits/stdc++.h>
#define rep(i,a,b) for (i=a;i<b;i++)
#define rep2(i,a,b) for (i=a;i>=b;i--)
#define mod 1000000007
#define mod2 998244353
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF  1e9+5
#define f first
#define s second
#define endl '\n'
#define ll long long
#define ii pair <int,int>
#define pll pair <ll,ll>
#define vi vector <int>
#define vl vector <ll>
#define vvi vector < vi >
#define vii vector < ii >
#define vpl vector < pll >
#define vvii vector < vii >
#define vll vector < ll >
#define vb  vector <bool>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define pg priority_queue<ll, vector<ll>, greater<ll>>
#define pq priority_queue<ll>
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define cset(a) __builtin_popcountll(a)
#define FILL(a, b, T) fill_n((T *)a, sizeof(a) / sizeof(T), b)
#define debug(x) cerr << #x << " is " << x << endl;
using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define pis pair<ll,pll>
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// unordered_map<long long, int, custom_hash> safe_map;
// FOR VIEWERS, CODE STARTS HERE
#define N 200005
vector<vll> e(N);
vll res(N), a(N);
// int lis(vll v)
// {
//   vll a;
//   ll pos, i;
//   a.pb(v[0]);
//   rep(i,1,sz(v))
//   {
//     if( a.back() < v[i])
//     {
//       a.pb(v[i]);
//     }
//     else
//     {
//       pos = lower_bound(all(a), v[i]) - a.begin();
//       a[pos] = v[i];
//     }
//   }
//   for(auto p: a)
//     cout<<p<<" ";
//   cout<<endl;
//   return sz(a);
// }
void dfs(ll x, ll par, vll &tmp)
{
  ll flag = 0, val, pos;
  if( tmp.back() < a[x])
  {
    tmp.pb(a[x]);
    flag = 1;
  }
  else
  {
    pos = lower_bound(all(tmp), a[x]) - tmp.begin();
    val = tmp[pos];
    tmp[pos] = a[x];

  }
  res[x] = sz(tmp);
  for(auto p: e[x])
  {
    if( p == par)
      continue;
    dfs(p, x, tmp);
  }
  if(flag)
    tmp.pop_back();
  else
    tmp[pos] = val;

}
int main()
{
    
    FIO;
    ll t, q, n, m, prev, maxx,  i, j, k1, k2, k3, k, x, y, flag, sum, cnt, ans, minn, cur;
    cin>>n;
    rep(i,1,n+1)
    {
      cin>>a[i];
    }
    rep(i,0,n-1)
    {
      cin>>x>>y;
      e[x].pb(y);
      e[y].pb(x);
    }
    vll tmp;
    tmp.pb(a[1]);
    dfs(1, -1, tmp);
    rep(i,1,n+1)
    {
      cout<<res[i]<<endl;
    }
    return 0;    
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

  cout << N + pow(N,2) + pow(N,3);
}


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

int main()
{
    int a,b;
    int c;
    scanf("%d%d",&a,&b);
    c=a+b>a-b?a+b:a-b;
    c=c>a*b?c:a*b;
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define hahashad ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
#define VL vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define what(A) cout<<#A<<" is "<<A<<endl;
ll isprime[1000005];
ll ans;
void divisors()
{
    FOR(i,1,1e6+1)
    {
        if(isprime[i]==0)
            continue;
        if(isprime[i]==1)
        {
            ans++;
        }
        for(ll j=2*i;j<=1e6;j+=i)
        {
            isprime[j]=0;
        }
    }
}

int main()
{
	ll n;
	cin >> n;
	FOR(i, 0, n)
	{
		IN(inp)
		isprime[inp]++;
	}
    divisors();
    cout<<ans;
}

Measured memory_bytes: 11404
n,m=map(int,input().split())
num=[]
for i in range(m):
    num.append(list(map(int,input().split())))
num3=[[] for _ in range(n)]
for i in range(m):
    for j in range(1,num[i][0]+1):
        num3[num[i][j]-1].append(i+1)
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    num2=[0]*m
    num4=0
    for j in range(n):
        if (i>>j) & 1:
            for k in range(len(num3[j])):
                num2[num3[j][k]-1]+=1
    for j in range(m):
        if num2[j]%2!=p[j]:
            num4=1
            break
    if num4==0:
        ans+=1
print(ans)


Measured memory_bytes: 9228
using System;

namespace newEx
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] l = Console.ReadLine().Split(' ');
            int p = int.Parse(l[0]);
            int q = int.Parse(l[1]);
            int r = int.Parse(l[2]);

            Console.WriteLine(Solve(p, q, r));
        }

        public static int Solve(int N, int A, int B)
        {
            int x = N * A; //修正200630
            int y = B;          //修正200630

            if (x < y)            //修正200630
            {
                return x;     //修正200630
            }
            else
            {
                return y;    //修正200630
            }
        }
    }
}


Measured memory_bytes: 27468
def main():
    a, b = map(int, input().split())

    if a > 0:
        print("Positive")
        return

    if b > 0 and a <= 0:
        print("Zero")
        return

    print("Positive" if(b - a + 1) % 2 == 0 else "Negative")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int  main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0; i<n; ++i) cin >> h[i];
  sort(h.begin(), h.end());
  int mn = pow(10, 9);
  for(int i=0; i<n-k+1; i++){
    mn = min(h[i+k-1]-h[i], mn);
  }
  cout << mn; 
  return 0;
}

Measured memory_bytes: 768