akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/04  Problem: ABC 084 C / Link: http://arc084.contest.atcoder.jp/tasks/arc084_c  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N, K;

LL ans = 0LL;

// N,K grobal
VI f1() {
	VI a(N, (K + 1) / 2);
	if (K == 1)return VI((N+1)/2, 1);
	FOR(i, 0, N / 2) {
		FORR(j, N - 1, -1) {
			if (a[j] > 0) {
				a[j]--;
				if (a[j] > 0) {
					FOR(l, j + 1, N) {
						a[l] = K;
					}
				}
				break;
			}
		}
	}
	return a;
}

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

	cin >> K >> N;
	if (K % 2 == 0) {// K 偶数
		cout << K / 2;
		FOR(i, 1, N) {
			cout << " " << K;
		}cout << endl;
	}
	else { // 半分が簡単
		VI a = f1();
		FOR(i, 0, SZ(a)) {
			if (a[i] == 0)break;
			else if(i!=0)cout << " ";
			cout << a[i];
		}cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3456
#include <stdio.h>
int main(){
  int a, b,c;
scanf("%d %d %d",&a,&b,&c);
  if(a <= b && b <= c)printf("%d %d %d\n",a,b,c);
  else if(a <= c && c <= b)printf("%d %d %d\n",a,c,b);
  else if(b <= a && a <= c)printf("%d %d %d\n",b,a,c);
  else if(b <= c && c <= a)printf("%d %d %d\n",b,c,a);
  else if(c <= a && a <= b)printf("%d %d %d\n",c,a,b);
  else if(c <= b && b <= a)printf("%d %d %d\n",c,b,a);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    set<string> st;
    string S; cin >> S;
    int K; cin >> K;
    for (int i = 0; i < S.size(); i++)
        for (int j = 1; j <= K; j++)
            if (i + j <= S.size()) st.insert(S.substr(i, j));

    for (auto s : st) {
        K--;
        if (K == 0) cout << s << '\n';
    }
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll h,w,m; cin>>h>>w>>m;
  
  vll y_sum(h), x_sum(w);
  
  vector<set<ll>> s(h);
  rep(i,m){
    ll y,x; cin>>y>>x; y--,x--;
    s[y].insert(x);
    y_sum[y]++;
    x_sum[x]++;
  }
  
  vpll xs;
  rep(i,w){
    if(x_sum[i]){
      xs.emplace_back(x_sum[i],i);
    }
  }
  sort(xs.rbegin(),xs.rend());
  ll mx=xs[0].first;
  set<ll> max_s;
  rep(i,xs.size()){
    max_s.insert(xs[i].second);
    if(i+1<xs.size() && xs[i].first>xs[i+1].first) break;
  }
  
  // cout<<mx<<endl;
  // for(auto e: max_s) cout<<e<<' ';
  // cout<<endl;
  
  ll ans=0;
  rep(i,h){
    if(max_s.size()>s[i].size()){
      chmax(ans, y_sum[i]+mx);
    }else{
      for(auto e: max_s){
        if(s[i].count(e)) chmax(ans, y_sum[i]+mx-1);
        else chmax(ans, y_sum[i]+mx);
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 54900
#include <stdio.h>
int main(void)
{
 int a, b, c, x;

 scanf("%d %d %d",&a,&b,&c);

 if(a>b){
  x=a;
  a=b;
  b=x;
 }
 if(a>c){
  x=a;
  a=c;
  c=x;
 }
 if(b>c){
  x=b;
  b=c;
  c=x;
 }

 printf("%d %d %d\n",a,b,c);

 return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>

using namespace std;

const int MOD = 1000 * 1000 * 1000 + 7;

int addm(int a, int b)
{
	return (0LL + a + b) % MOD;
}

int subm(int a, int b)
{
	return addm(a, (MOD - b) % MOD);
}

int mulm(int a, int b)
{
	return (1LL * a * b) % MOD;
}

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A) {
		cin >> x;
	}

	vector<int> acc(N + 1, 0);
	for (int i = 0; i < N; ++i) {
		acc[i + 1] = addm(acc[i], A[i]);
	}

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans = addm(ans, mulm(A[i], subm(acc[N], acc[i + 1])));
	}
	cout << ans << endl;
}


Measured memory_bytes: 4756
import sys
N, K = map(int, input().split())
x = list(map(int, input().split()))

def fast(x, y):
  return min(abs(x), abs(y)) + abs(x) + abs(y)

n = N
for k in range(N):
  if x[k] >= 0:
    n = k
    if x[k] == 0:
      K -= 1
      N -= 1
      x.pop(k)
    break

if n == 0:
  if K == 0:
    print(0)
    sys.exit()
  print(x[K-1])
  sys.exit()

if n == N:
  print(int(abs(x[N-K])))
  sys.exit()

time = 3*10**8 + 100
if (n-K) >= 0:
  time = abs(x[n-K])
for j in range(K-n-1, N-n):
  time = min(time, fast(x[n-K+1+j], x[n+j]) )
if n + K <= N:
  time = min(time, abs(x[n+K-1]))

print(int(time))

Measured memory_bytes: 14384
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
const ll MOD = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v(k);
  for (int i = 0; i < k; ++i)
    cin >> v[i].first >> v[i].second;
  vector<ll> sum(n + 1);
  sum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    ll curr = 0;
    for (int j = 0; j < k; ++j) {
      if (v[j].first >= i)
        continue;
      int l = max(1, i - v[j].second);
      int r = i - v[j].first;
      curr += sum[r] - sum[l - 1];
    }
    curr %= MOD;
    if (curr < 0)
      curr += MOD;
    sum[i] = (sum[i - 1] + curr) % MOD;
  }
  ll ans = sum[n] - sum[n - 1];
  if (ans < 0)
    ans += MOD;
  cout << ans;
}

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

int main(){
    int a ,b;
    cin >> a >> b;
    if ( a < b ) {
    cout <<"a < b"<< endl;
    }  if ( a > b ) { 
    cout <<"a > b"<< endl;
    }  if ( a == b ) {
    cout <<"a == b"<< endl;
    }
}

 



Measured memory_bytes: 3056
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto v = RDA;
	v.sort();
	double ans = v[0];
	foreach (i; 1..N)
	{
		ans = (ans+v[i]) / 2;
	}

	writefln(FMT_F, ans);
	stdout.flush();
	debug readln();
}

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

int A[100][100];
char type[100];
int d[100];//経路の長さ<-初期値15000
int n;

int Dijkstra(int k){
    type[k] = 'B';
    int min = 0;
    for(int i=1; i<n; i++){
        if((A[k][i] != -1) && (type[i] != 'B')){
            type[i] = 'G';
            //長さを調査、短ければ更新
            if(d[k] + A[k][i] < d[i]){
                d[i] = d[k] + A[k][i];
            }
        }
    }
    int FLAG = 0;
    for(int j=1; j<n; j++){
        if(type[j] == 'G'){
            if(FLAG == 0){
                min = j;
            } else {
                if(d[j] < d[min]){
                min = j;
                }
            }
            FLAG = 1;
        }
    }
    if(min == 0){
        return 0;
    } else {
        Dijkstra(min);
    }
}

int main(){
    cin >> n;
    for(int i=0; i<n; i++){//Aを-1に初期化,dを最大値に初期化
        d[i] = 100000000;
        type[i] = 'W';
        for(int j=0; j<n; j++){
            A[i][j] = -1;
        }
    }
    //↓↓↓ここで、入力を表の形に代入
    int p, q, r, s;
    for(int i=0; i<n; i++){
        cin >> p;//点の名前
        cin >> r;//隣接点の数
        for(int j=0; j<r; j++){
            cin >> q;//隣接点の名前
            cin >> s;//pとqの間の重み
            A[p][q] = s;
        }
    }
    //↑↑↑

    d[0] = 0;

    Dijkstra(0);

    for(int i=0; i<n; i++){
        cout << i << " " << d[i] <<  endl;
    }
}


Measured memory_bytes: 3116
import math as mt
import itertools as it
import functools as ft
import random as rnd

stdin = lambda type_ = "int", sep = " ": list(map(eval(type_), input().split(sep)))
joint = lambda sep = " ", *args: sep.join(str(i) if type(i) != list else sep.join(map(str, i)) for i in args)

N, M = stdin()
X = stdin()
X.sort()
dif = [0] * (len(X) - 1)
for i in range(len(X) - 1):
    dif[i] = X[i + 1] - X[i]

dif.sort()
ans = X[-1] - X[0] - sum(dif[-1:-N:-1])
print(0 if ans <= 0 else ans)



Measured memory_bytes: 15092
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    cout << pow(N, 3) << endl;
    return 0;
}



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

using namespace std;

const long long INF = LONG_LONG_MAX;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    vector<long long> dp(n, INF);
    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        for (int j = 1; j <= k; j++) {
            if (i - j < 0) break;
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1408
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=0
high=max(A)
sig=(low+high)//2
tf=0
if K==0:
  tf=1
  ans=high
while tf==0:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define IN freopen("input.txt", "r", stdin);
#define OUT freopen("output.txt", "w", stdout);
#define LL long long
#define MOD 1000000007
#define INF 1000000000000000000
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)

using namespace std;

const int N = 1e5+1;
int n, F[N], h[N];

int main()
{
	//IN;
	FASTIO;
	cin >> n;
	for (int i=1; i<=n; i++) cin>>h[i];
	h[0] = -1e8;
	for (int i=2; i<=n; i++) {
		F[i] = F[i-1] + abs(h[i]-h[i-1]);
		F[i] = min(F[i], F[i-2]+abs(h[i]-h[i-2]));
	}
	cout << F[n];
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
//#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
	int n;
	cin >> n;
	if (n % 2 == 1) {
		cout << n / 2 + 1 << endl;
	}
	else {
		cout << n / 2 << endl;
	}
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    mint n,m,k;
    cin >> n.x >> m.x >> k.x;
    mint ans = mint(0);
    mint t = mint(1);
    for(mint i = mint(1);i.x<=k.x-2LL;i+=mint(1)){
        t *= (n*m-k+i);
        t /= i;
    }
    for(mint d = mint(1);d.x<=n.x-1;d+=mint(1)){
        ans += (n-d)*m*m*d;
    }
    for(mint d = mint(1);d.x<=m.x-1;d+=mint(1)){
        ans += (m-d)*n*n*d;
    }
    ans *= t;
    cout << ans.x << endl;

    return 0;
}

Measured memory_bytes: 256
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdio>
#include<vector>
#include<iostream>
#include<string>
#include<algorithm> 
using namespace std;
int main(){
	int a,b,ans;
	cin>>a>>b;
	ans=a-1;
	if(b>=a){
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

struct edge{int from; int to; ll cost;};

int N, M;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

bool bellman_ford(int s, vector<edge> &vec, vector<ll> &vertex, vector<int> &active){
    
    for(int i=0; i<=N; i++){
        bool update=false;
        for(int j=0; j<M; j++){
            edge e=vec[j];
            if((active[e.from]&active[e.to])==0){
                continue;
            }
            if(vertex[e.to]>vertex[e.from]+e.cost){
                //cout << (int)(active[e.to]&active[e.from]) << endl;;
                vertex[e.to]=vertex[e.from]+e.cost;
                update=true;
            }
        }
        if(update==false){
            return true;
        }
    }

    return false;
}

vector<int> cutting(vector<edge> &vec){
    vector<int> A(N,0);
    vector<int> B(N,0);
    A[0]=B[N-1]=1;
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            edge e=vec[j];
            if(A[e.from]==1){
                A[e.to]=1;
            }
            if(B[e.to]==1){
                B[e.from]=1;
            }
        }
    }
    //cout_vec(A);
    //cout_vec(B);
    vector<int> ret(N,0);
    for(int i=0; i<N; i++){
        ret[i]=A[i]&B[i];
    }
    return ret;
}

int main(){
    ll P;
    cin >> N >> M >> P;
    vector<edge> vec(M);

    for(int i=0; i<M; i++){
        int A, B, C;
        cin >> A >> B >> C;
        A--;
        B--;
        C-=P;
        vec[i]={A,B,-C};
    }

    vector<ll> vertex(N,MOD*MOD);
    vertex[0]=0;

    vector<int> active=cutting(vec);
    
    //cout_vec(active);

    if(bellman_ford(0, vec, vertex, active)){
        cout << max(0LL,-vertex[N-1]) << endl;
    }else{
        cout << -1 << endl;
    }
    //cout_vec(vertex);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  vector<int> X(N);
  for(int i = 0;i < N;i++) cin >> X.at(i);

  sort(X.begin(),X.end());
  int m = X.at(0),M = X.back();
  int mi = INT_MAX;
  for(int i = m;i <= M;i++) {
    int sum = 0;
    for(int j = 0;j < N;j++) {
      int num = X.at(j);
      sum += (num-i)*(num-i);
    }
    mi = min(mi,sum);
  }

  cout << mi << endl;
}


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

int main(){
	int n,k; cin>>n>>k;
	long double ans=0;
	for(int i=1;i<=n;++i){
		long double a=(long double)1/n;
		for(int j=i;j<k;j*=2){
			a*=0.5l;
		}
		ans+=a;
	}
	cout<<fixed<<setprecision(12)<<ans<<"\n"s;
}


Measured memory_bytes: 256
import math

a, b, C = map(int, input().split())
S = (a*b*math.sin(math.radians(C))) / 2
L = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C)))
h = b * math.sin(math.radians(C))
print("%f" %S)
print("%f" %L)
print("%f" %h)


Measured memory_bytes: 5712
#include <stdio.h>
#include <string.h>

static const int MAX = 36;

typedef struct {
  char  s;
  short v;
} card;

void output( card *p, short n ) {
  short i;
  for ( i = 0; i < (n - 1); i++ ) {
    printf( "%c%d ", p[i].s, p[i].v );
  }
  printf( "%c%d\n", p[i].s, p[i].v );
}

void swap(card *a, card *b ) {
  card t;
  t = *a;
  *a = *b;
  *b = t;
}

short isStable( card *a, card *b, short n ) {
  short i, flag = 1;
  for( i = 0; i < n; i++ ) {
    if( (a[i].v == b[i].v) && (a[i].s != b[i].s) ) {
      return flag = 0;
    }
  }
  return flag;
}

void selectionSort( card *p, short n ) {
  short i, j, idx;
  for ( i = 0; i < n; i++ ) {
    idx = i;
    for ( j = i; j < n; j++ ) {
      if (p[j].v < p[idx].v) idx = j;
    }
    if ( idx != i ) swap( &p[i], &p[idx] );
  }
}

void bubbleSort( card *p, short n ) {
  short i, j;

  for( i = 1; i <= (n - 1); i++ ) {
    for ( j = (n - 1); j >= 1; j-- ) {
      if ( p[j].v < p[j - 1].v ) swap( &p[j], &p[j - 1] );
    }
  }
}

int main( void ) {
  short i, n;
  card c01[MAX + 1], c02[MAX + 1];

  scanf( "%d%*c", &n );
  for ( i = 0; i < n; i++ ) {
    scanf( "%c%d%*c", &c01[i].s, &c01[i].v );
    memcpy( &c02[i], &c01[i], sizeof(card) );
  }

  bubbleSort( c01, n );
  output( c01, n );
  printf( "Stable\n" );

  selectionSort( c02, n );
  output( c02, n );
  if ( isStable(c01,c02,n) )
    printf( "Stable\n" );
  else
    printf( "Not stable\n" );

  return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

ll mod;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

class combination{
private:
    vector<mint> fact,inv,finv;
public:
    combination(int N){
        fact = inv = finv = vector<mint>(N+1);
        fact[0] = fact[1] = 1;
        inv[0] = inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(ll i=2;i<=N;i++){
            fact[i] = fact[i-1]*i;
            inv[i] = (mint) mod - inv[mod%i]*(mod/i);
            finv[i] = finv[i-1]*inv[i];
        }
    }
    mint f(int i){
        return fact[i];
    }
    mint comb(int n,int k){
        if(n<k) return 0;
        if(n<0 || k<0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }
    mint hcomb(int n,int k){
        if(n==0 && k==0) return 1;
        return comb(n+k-1,k);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N >> mod;
    mint ans = 0;
    combination C(2*N);
    vec<ll> pow2(N+1,1);
    for(int i=1;i<=N;i++) pow2[i] = pow2[i-1]*2%(mod-1);
    vvec<mint> dp(N+1,vec<mint>(N+1));
    dp[0][0] = 1;
    for(int i=0;i<N;i++) for(int j=0;j<=i;j++){
        dp[i+1][j+1] += dp[i][j];
        dp[i+1][j] += dp[i][j];
        dp[i+1][j] += dp[i][j]*j;
    }

    for(int i=0;i<=N;i++){
        mint now = 0;
        mint t = 1;
        for(int j=1;j<=N-i;j++) t *= 2;
        for(int j=0;j<=i;j++){
            now += dp[i][j]*t.pow(j);
        }
        now *= C.comb(N,i)*((mint) 2).pow(pow2[N-i]);
        if(i%2) ans -= now;
        else ans += now;
    }

    cout << ans << "\n";
}

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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> p(n);
    
    ll mi = n+10;
    
    ll res = 0;
    
    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
        mi = min(mi,p[i]);
        if(p[i]==mi){
            res++;
        }
    }
    
    std::cout << res << std::endl;
}

Measured memory_bytes: 1920
#include <iostream>
int main(){int a,b,c,d,e,f,g,h,i,j;std::cin>>a>>b>>c>>d>>e>>f>>g>>h;i=a+b+c+d;j=e+f+g+h;std::cout<<((i>j)?i:j)<<std::endl;return 0;}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

class stone{
public:
	int place;
	// white:0,black:1
	int color;

	stone(int _place,int _color){
		place = _place;
		color = _color;
	}
	stone();
};

int main(){

	int n;
	while(cin >> n && n != 0){
		stack<stone> ss;
		for(int i = 0; i < n; i++){
			int t;
			cin >> t;
			if(ss.size() == 0){
				ss.push(stone(1,t));
			}
			else{
				stone s = ss.top();
				// ツつィツつュツつセツつッ
				if(i % 2==0){
					if(s.color == t){
						ss.pop();
						ss.push(stone(s.place+1,t));
					}
					else{
						ss.push(stone(s.place+1,t));
					}
				}
				// ツ板スツ転ツ渉按猟敖づつゥ
				else{
					if(s.color == t){
						ss.pop();
						ss.push(stone(s.place+1,t));
					}
					else{
						ss.pop();
						if(ss.size() == 0)
							ss.push(stone(s.place+1,t));
						else{
							ss.pop();
							ss.push(stone(s.place+1,t));
						}
					}
				}
			}
		}

		int cnt = 0;
		int prv = 0;
		bool flag = false;
		while(ss.size()){
			stone tmp = ss.top();
			if(tmp.color == 0){
				prv = tmp.place;
				ss.pop();
				if(ss.size() == 0){
					cnt += prv;
					break;
				}
				else{
					stone sto = ss.top();
				//	ss.pop();
					cnt += (prv - sto.place);
					prv = sto.place;
				}
			}
			else{
			//	prv = tmp.place;
				ss.pop();
				if(ss.size() != 0){
					prv = ss.top().place;
				}
			}
		}
		cout << cnt << endl;
	}

	return 0;
}

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

int main()
{
  int A, B, C, X;
  int answer = 0;
  std::cin >> A >> B >> C >> X;
  for(int a = 0; a <= A; ++a) {
    for(int b = 0; b <= B; ++b) {
      for(int c = 0; c <= C; ++c) {
        int amount = a * 500 + b * 100 + c * 50;
        if(amount == X) ++answer;
      }
    }
  }
  std::cout << answer << std::endl;
  return 0;
}


Measured memory_bytes: 256
c = 3.times.map{gets.chomp.split(" ").map(&:to_i)}
if c[0][1]-c[0][0] == c[1][1]-c[1][0] && c[0][2]-c[0][0] == c[1][2]-c[1][0] && c[0][1]-c[0][0] == c[2][1]-c[2][0] && c[0][2]-c[0][0] == c[2][2]-c[2][0]
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG




int main() {
  ll N;
  cin >> N;
  //vector<ll> a(N);
  //vector<vector<int>> data(3, vector<int>(4));
  
  cout << round(N/2.0) << endl;

  return 0;
}


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

int main(){
    using namespace std;
    unsigned long K;
    cin >> K;
    unsigned long ans{0};
    for(unsigned long a{1}; a <= K; ++a)for(unsigned long b{1}; b <= K; ++b)for(unsigned long c{1}; c <= K; ++c)ans += gcd(a, gcd(b, c));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
h, w, k = map(int, input().split())
c = []
for i in range(h):
    ci = input()
    c.append(ci)

ans = 0
for x in range(2 ** h):
    for y in range(2 ** w):
        cnt = 0
        for i in range(h):
            if x & (1 << i):
                continue
            for j in range(w):
                if y & (1 << j):
                    continue
                if c[i][j] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)



Measured memory_bytes: 68228
n,k=gets.chomp.split(' ').map(&:to_i)
ans = [*(1..n)]
k.times do
  gets
  candy = gets.chomp.split(' ').map(&:to_i)
  candy.each do |c|
    if ans.include?(c)
      ans.delete(c)
    end
  end
end
puts ans.size

Measured memory_bytes: 14096
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]
    C = [int(i) for i in readline().split()]

    A.sort()
    B.sort()
    C.sort()

    a_ind = []
    b_ind = []
    for i in range(N):
        a_ind.append(bisect_right(B, A[i]))
        b_ind.append(N - bisect_right(C, B[i]))


    b_acc = [0]
    for b in b_ind:
        b_acc.append(b_acc[-1] + b)


    sum_b = b_acc[-1]
    ans = 0
    for i in a_ind:
        ans += sum_b - b_acc[i]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 29220
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;
typedef vector<vi> mat;
 
inline ll read(){
	ll Hashimoto=0,Kanna=1;
	char I_Love=getchar();
	while(I_Love<'0'||I_Love>'9'){
		if(I_Love=='-')Kanna=-1;
		I_Love=getchar();
	}
	while(I_Love>='0'&&I_Love<='9'){
		Hashimoto=Hashimoto*10+I_Love-'0';
		I_Love=getchar();
	}
	return Hashimoto*Kanna;
}
 
#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<Kanna;I_Love++)cout<<Hashimoto[I_Love]<<(I_Love==Kanna-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<Kanna;I_Love++)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e15
#define mod (inf+7)
 
int n,m;
vpli g[111111];
ll s[111111][2];
bool v[111111][2];
 
void bfs(){
	queue<pii>q;
	q.push({0,1});
	v[0][1]=1;
	s[0][1]=0;
	while(!q.empty()){
		int u=q.front().first;
		int sym=q.front().second;
		q.pop();
		FOR(i,0,g[u].size()){
			ll val=g[u][i].first-s[u][sym];
			int to=g[u][i].second;
			if(v[to][1-sym]){
				if(s[to][1-sym]!=val){
					Tone(0);
					exit(0);
				}
			}
			else{
				s[to][1-sym]=val;
				v[to][1-sym]=1;
				q.push({to,1-sym});
			}
			if(v[to][sym]){
				ll check=s[to][0]-s[to][1];
				if(check<=0){
					Tone(0);
					exit(0);
				}
				if(check%2!=0){
					Tone(0);
					exit(0);
				}
			}
		}
	}
	ll mn=linf,mx=1;
	ll val=linf;
	FOR(i,0,n){
		if(v[i][0]&&v[i][1]){
			if(val==linf){
				val=s[i][0]-s[i][1];
				val/=2;
			}
			else {
				if(val!=(s[i][0]-s[i][1])/2){
					Tone(0);
					exit(0);
				}
			}
		}
		if(v[i][0]){
			mn=min(mn,s[i][0]-1);
		}
		if(v[i][1]){
			if(s[i][1]<=0)mx=max(mx,1-s[i][1]);
		}
	}
	if(val!=linf){
		if(val>=mx&&val<=mn)Tone(1)
		else Tone(0); 
	}
	else if(mx>mn)Tone(0)
	else Tone(mn-mx+1)
}
 
int I_Love_Hashimoto_Kanna() {
  fastio;
  n=read();m=read();
  FOR(i,0,m){
  	int a,b;
		ll s;
  	a=read()-1;
  	b=read()-1;
  	s=read();
  	g[a].push_back({s,b});
  	g[b].push_back({s,a});
	}
	bfs();
  
  return 0;
}


Measured memory_bytes: 11776
import java.util.Scanner;

public class Main{
  static long s, c;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    s = sc.nextLong(); c = sc.nextLong();

    if(c == 0 || c == 1){
      System.out.println(0);
      return;
    }

    long ans = Math.min(s, c / 2);

    c -= 2 * ans;

    if(c > 0){
      ans += c / 4;
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 22996
i= int(input())
s = input()
en = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
s_list = [(en[(en.index(k)+i)%26]) for k in s]
print(''.join(s_list))

Measured memory_bytes: 3064
#include <stdio.h>
 
using namespace std;
 
#define MAX 100000
 
int n, k;
long long T[MAX];
 
int check(long long p) {
    int  i = 0;
    for(int j = 0; j < k; j++) {
        long long s = 0;
        while(s + T[i] <= p) {
            s = s + T[i];
            i++;
            if(i == n) return n;
        }
    }
    return i;
}
 
int solve()
{
    long long left = 0;
    long long right = 100000 * 10000;
    long long mid;
 
    while(right - left > 1) {
        mid = (left + right) / 2;
        int v = check(mid);
        if(v >= n) right = mid;
        else left = mid;
    }
    return right;
}
 
int main() {
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++) {
        scanf("%lld", &T[i]);
    }
    int res = solve();
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 3532
s = input()
s = s.split('/')
for i in range(len(s)):
  s[i] = int(s[i])
if s[0]<2019:
  print('Heisei')
elif s[0]>2019:
  print('TBD')
elif s[1]<=4:
  print('Heisei')
else:
  print('TBD')

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

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; }
#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
typedef pair<int, int> the;

const int INF = 1 << 29;
const ll LINF = 1LL << 60;
const int R = 1e9 + 7;

int main()
{
	ll n, k, q;
	cin >> n >> k >> q;
	vector<int> a(q);
	rep(i, q)  cin >> a[i];

	vector<ll> s(n, q);
	rep(i, q) {
		s[--a[i]]--;
	}
	rep(i, n) {
		if (s[i] < k)  cout << "Yes" << endl;
		else  cout << "No" << endl;
	}
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n,t;
    cin>>n>>t;
    vector<ll> a(n+1);
    ll ans=0;
    repi(i,1,n+1){
        cin>>a[i];
        ans+=min(t,a[i]-a[i-1]);
    }
    ans+=t;
    cout<<ans;
}

Measured memory_bytes: 4744
S = input()
res =  [0] * (len(S) + 1)

for i in range(len(S)):
    if S[i] == "<":
        res[i + 1] = res[i] + 1

for i in range(len(S)-1, -1, -1):
  if S[i]=='>':
    res[i] = max(res[i], res[i + 1] + 1)

print(sum(res))


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

int main() {
	int N;
  	cin >> N;
  	vector<int> Mochi(N);
  	int d;
  	for(int i = 0; i < N; i++){
    	cin >> d;
      	Mochi.at(i) = d;
    }
  	int duplex = 0; //重複したもちの数を数えるための変数
  	int Check;
  	for(int i = 0; i < N; i++){
    	Check = Mochi.at(i);
      	for(int j = i + 1; j < N; j++){
            // すでに重複としてカウントしたもちは -1 としているので除外する
          	if(Mochi.at(j) == -1){
            	continue;
            }
            // -1じゃないもちだけを対象に重複がないかチェックする
        	if(Mochi.at(j) == Check){
            	duplex += 1;
              	Mochi.at(j) = -1;
            }
        }
    }
  	cout << N - duplex << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void){
	int H, W; cin >> H >> W;
	int c[10][10];
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			cin >> c[i][j];
		}
	}

	int num[10] = {0};
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			int a; cin >> a;
			if(a != -1) num[a]++;
		}
	}

	for(int k = 0; k < 10; k++){
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}

	int res = 0;
	for(int i = 0; i < 10; i++){
		res += (num[i] * c[i][1]);
	}

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 2e5 + 10;

int dp[N][2];
vector<int>adj[N];

LL add(LL a, LL b) {
	
	return (a + b) % MOD;
}

LL mult(LL a, LL b) {

	return (a*b) % MOD;
}

void dfs(int i, int pr) {

	dp[i][0] = dp[i][1] = 1;

	for (auto x : adj[i])
		if (x == pr)continue;
		else {
			dfs(x, i);
			dp[i][0] = mult(dp[i][0], add(dp[x][0], dp[x][1]));
			dp[i][1] = mult(dp[i][1], dp[x][0]);
		}
		return;
}

int main() {
		
	int n;
	scanf("%d", &n);

	for (int i = 0;i < n - 1;i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(1, 1);
	printf("%lld\n", add(dp[1][0], dp[1][1]));
	cin >> n;
}

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

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







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


ll pw(ll x, ll y) {
    ll res=1;
    while (y) {
	if (y%2) res=res*x%mod;
	x=x*x%mod;y=y/2;
    }
    return ((res%mod)+mod)%mod;
}

int n;
vector<int> g[maxn];

int par[maxn];
int siz[maxn];
vector<int> subtrees[maxn];

void dfs(int at, int p=0) {
    siz[at]=1;
    for (int to: g[at]) {
	if (to == p) continue;
	dfs(to, at);
	par[to] = at;
	siz[at] += siz[to];
    }
}


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

    cin>>n;
    for (int i=0; i<n-1; i++) {
	int u,v; cin>>u>>v;
	g[u].push_back(v);
	g[v].push_back(u);
    }

    dfs(1);

    
    for (int at=1; at<=n; at++) {
	ll tot = 0;
	for (int to: g[at]) {
	    if (to==par[at]) continue;
	    tot += siz[to];
	    subtrees[at].push_back(siz[to]);
	}
	ll up = n-1-tot;
	if (up>0) subtrees[at].push_back(up);
    }


    // Considering that a node is white, what's the Pr that it's contained?
    // Count cases where at least 2 subtrees have a black node (this means that we are contained)
    
    // Count the inverse:
    // all configurations: 2^(n-1)
    // subtract case where the other n-1 nodes are white
    // subtract cases where only one subtree is white
    

    ll res = 0;
    for (int i=1; i<=n; i++) {
	ll all = pw(2,n-1);
	all --;
	for (ll x: subtrees[i]) {
	    all -= (pw(2,x)-1);
	    all %= mod;
	}
	res += all;
	res %= mod;
    }

    res %= mod;
    res += mod;
    res %= mod;

    ll ans = res*pw(pw(2,n),mod-2)%mod;
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 75736
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(){
  int n;
  while(1){
    cin >> n;
    if(n==0)break;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());
    int mini=10000000;
    rep(i,n-1){
      mini = min(mini,a[i]-a[i+1]);
      if(mini==0)break;
    }
    cout << mini << endl;
  }
  return 0;
}



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

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

Measured memory_bytes: 256
S=input()
N=len(S)
count=0
if S==S[::-1]:
  if S[(N-1)//2:]==S[(N-1)//2::-1] and S[(N+3)//2-1:]==S[(N+3)//2-1:][::-1]:
    print('Yes')
  else:
    print('No')
else:
  print('No')


Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    N = len(S)
    ans = sys.maxsize
    for i in range(N-1):
        if S[i] != S[i+1]:
            ans = min(ans, max(i+1, N-i-1))

    if ans == sys.maxsize:
        return N
    return ans


def main():
    S = read_str().strip()
    # S = ''.join([random.choice('01') for _ in range(100000)])
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61676
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int int64_t
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class T,class U> using umap = unordered_map<T,U>;

inline int64_t updiv(int64_t n,int64_t d){
    return ((n + d -1) / d);
}
/*
inline double Sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
*/
// }}}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,n;
    cin >> w >> h >> n;
    int a = 0,b = 0,c = w,d = h;
    rep(i,n){
        int x,y,cmd;
        cin >> x >> y >> cmd;
        if(cmd == 1){
            chmax(a,x);
        }
        if(cmd == 2){
            chmin(c,x);
        }
        if(cmd == 3){
            chmax(b,y);
        }
        if(cmd == 4){
            chmin(d,y);
        }
    }

    int x,y;
    if(c >= a) x = c - a;
    else x = 0;
    if(d >= b) y = d - b;
    else y = 0;
    cout << x * y << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;
using namespace chrono;

#ifdef DEBUG
	//~ #define LOCAL_INPUT_FILE
#else
	//#define USE_FILE_IO
#endif

#ifdef USE_FILE_IO
	#define INPUT_FILE "input.txt"
	#define OUTPUT_FILE "output.txt"
	#define cin ____cin
	#define cout ____cout
	ifstream cin(INPUT_FILE);
	ofstream cout(OUTPUT_FILE);
#else
	#ifdef LOCAL_INPUT_FILE
		#define cin ____cin
		ifstream cin("input.txt");
	#endif
#endif

const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7; 
const long double eps = 1e-8;

mt19937_64 randGen(system_clock().now().time_since_epoch().count());

inline void raiseError(string errorCode) {
	cerr << "Error : " << errorCode << endl;
	exit(42);
}

signed main() {
	#ifndef USE_FILE_IO
		ios_base::sync_with_stdio(false);
	#endif
	int n; cin >> n;
	vector<int64_t> v(n);
	int64_t s = 0;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		s += v[i];
	}
	assert(s % 2 == 0);
	s /= 2;
	int64_t v1 = s;
	for (int i = 1; i < n; i += 2) {
		v1 -= v[i];
	}
	vector<int64_t> res(n);
	res[0] = v1;
	for (int i = 1; i < n; ++i) {
		res[i] = v[i-1] - res[i-1];
	}
	for (int i = 0; i < n; ++i) {
		cout << res[i]*2 << " ";
	}
	cout << "\n";
	return 0;
}


Measured memory_bytes: 2944