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/10/04  Problem: Nagoya_univ_contest_17_j  / Link: http://arc063.contest.atcoder.jp/tasks/arc063_c  ----- */
/* ------問題------

N 頂点の木があり、頂点には 1,2,…,N と番号が振られています。
i (1≦i≦N−1) 番目の辺は頂点 Ai と頂点 Bi を結んでいます。
高橋君は木の K 個の頂点に整数を書き込みました。具体的には、各 1≦j≦K について、
頂点 Vj に整数 Pj を書き込みました。その後、高橋君は居眠りを始めました。
木を見つけた青木君は、残りのすべての頂点に整数を書き込み、高橋君を驚かせようとしています。
高橋君を驚かせるためには、木が次の条件を満たさなければなりません。
条件: 辺で直接結ばれた 2 つの頂点に書かれている整数の差がちょうど 1 である。
残りのすべての頂点に書き込む整数を工夫することで、木が条件を満たすようにできるか判定してください。
もし可能な場合は、どのように整数を書き込めばよいかを具体的にひとつ求めて下さい。

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



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

LL N, K;

LL ans = 0LL;
int visit[100005];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);


	cin >> N;
	vector<vector<int>>G(N, vector<int>());
	FOR(i, 0, N - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].PB(b);
		G[b].PB(a);
	}
	FOR(i, 0, 100005)visit[i] = -1;

	priority_queue<PII, vector<PII>, greater<PII>>pq;

	cin >> K;
	FOR(i, 0, K) {
		int a, b; cin >> a >> b;
		a--;
		visit[a] = b;
		pq.push(PII(b, a));
	}
	while (!pq.empty()) {
		int v = pq.top().second;
		pq.pop();
		FOR(i, 0, SZ(G[v])) {
			int u = G[v][i];
			if (visit[u] != -1) {
				if (abs(visit[u] - visit[v]) != 1) {
					cout << "No" << endl;
					return 0;
				}
			}
			else {
				visit[u] = visit[v] + 1;
				pq.push(PII(visit[u], u));
			}
		}

	}

	cout << "Yes" << "\n";
	FOR(i, 0, N) {
		cout << visit[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 7924
#include <iostream>
#include <cstdio>
#define N 105
using namespace std;

int n, mx, c[N];
int main()
{
	int i, t;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf("%d", &t);
		c[t]++;
		mx = max(mx, t);
	}
	for (i = 1; i <= mx; i++) {
		if (i < (mx + 1) / 2 && c[i]) {cout << "Impossible"; return 0;}
		if (i == (mx + 1) / 2 && c[i] != mx % 2 + 1) {cout << "Impossible"; return 0;}
		if (i > (mx + 1) / 2 && c[i] < 2) {cout << "Impossible"; return 0;}
	}
    cout << "Possible";
    return 0;
}

Measured memory_bytes: 256
import functools
import fractions

def resolve():
	n,x=map(int,input().split())
	x_list=list(map(int,input().split()))
	x_list.append(x)
	x_list.sort()
	a=[abs(x_list[i]-x_list[i+1]) for i in range(n)]
	print(functools.reduce(fractions.gcd,a))
resolve()

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    string s;
    cin >> s;

    bool yy = true, mm = true;

    if((s[0] == '1' && s[1] >= '3') || s[0] >= '2' || s.substr(0, 2) == "00"){
        mm = false;
    }
    if((s[2] == '1' && s[3] >= '3') || s[2] >= '2' || s.substr(2, 2) == "00"){
        yy = false;
    }

    if(yy && mm){
        cout << "AMBIGUOUS" << endl;
    }else if(yy){
        cout << "YYMM" << endl;
    }else if(mm){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;
vector<pair<pii, int> > v;
set<pii> s;
set<pii>::iterator it;
int ans;

bool check(int x, int y){
    it = s.end();
    while(!s.empty()){
        --it;
        int cury = it->f, curx = it->s;
        if(curx < x && cury < y){
            s.erase(it);
            return 1;
        }
        if(it == s.begin()) break;
    }
    return 0;
}

int solve(){
    cin >> n;
    for(int i = 0, x, y; i < n; ++i){
        cin >> x >> y;
        v.pb(mp(mp(x, y), 0));
    }
    for(int i = 0, x, y; i < n; ++i){
        cin >> x >> y;
        v.pb(mp(mp(x, y), 1));
    }

    sort(all(v));

    for(int i = 0; i < 2 * n; ++i){
        int x = v[i].f.f, y = v[i].f.s, c = v[i].s;
        if(!c) s.insert(mp(y, x));
        else ans += check(x, y);
    }
    return ans;
}

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

    cout << solve() << "\n";
    
    return 0;
}

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

using namespace std;
const int MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
	int n, m;
	cin >> n >> m;
	vector<bool> a(n+1, true);
	for (int i = 0; i < m; i++) {
		int num;
		cin >> num;
		a[num] = false;
	}
	
	vector<int> dp(n+1, 0);
	dp[0] = 1;
	if (a[1]) {
		dp[1] = 1;
	}
	
	for (int i = 2; i <= n; i++) {
		if (a[i-1]) dp[i] += dp[i-1];
		if (a[i-2]) dp[i] += dp[i-2];
		dp[i] %= MOD;
	}
	
	cout << dp[n] << endl;
}

Measured memory_bytes: 640
import scala.io.StdIn._

object Main extends App {

  val n = readInt()
  val L = readLine().split(" ").map(_.toInt)

  def solve() = {
    (0 until n).combinations(3).foldLeft(0) { (acc, combi) =>
      val (a,b,c) = (L(combi(0)), L(combi(1)), L(combi(2)))
      val max = Math.max(Math.max(a,b), c)
      val isTriangle = max < a+b+c - max
      val isUnique = a != b && b != c && c != a
      if(isTriangle && isUnique) acc+1 else acc
    }
  }

  println(solve())

}



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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int n; scanf("%d", &n);
	printf("ABC%d", n);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
	int n, m;
	cin >> n >> m;
	VI b(n), p(m);
	REP(i,n) cin >> b[i];
	REP(i,m) cin >> p[i];
	int ones = 0;
	REP(i,n) ones += b[i];
	VI t(n);
	int x = p[0];
	FOR(i,1,m-1){
		FOR(j,x,x+p[i]-1){
			t[j] = t[x-1] ^ 1;
		}
		x += p[i];
	}

	int ans = 1e9;
	int s1 = 0, res1 = 0;
	int s2 = 0, res2 = 0;
	REP(i,n){
		s1 += b[i] - t[i];
		res1 += abs(s1);
		s2 += b[i] - (t[i] ^ 1);
		res2 += abs(s2);
	}
	if (s1 == 0) ans = min(ans, res1);
	if (s2 == 0) ans = min(ans, res2);

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;

bool vis[nax];

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

    for (int i = 1 ; i <= n ; ++ i) {
        int y ;
        cin >> y;
        vis[y] = true;
    }

    int dif = INT_MAX, ans = -1;

    for (int i = 0 ; i <= 105 ; ++ i) {
        if (!vis[i]) {
            if (abs(i - x) < dif) {
                dif = abs(i - x);
                ans = i;
            }
        }
    }

    printf("%d\n", ans);


}


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

int main(){
    int n, m;
    cin >> n >> m;
    int a[n];
    rep(i, n){
        cin >> a[i];
    }
    vector <pair <int, int>> p(m);
    rep(i, m){
        cin >> p[i].second;
        cin >> p[i].first;
    }

    sort(a, a+n);
    sort(p.begin(), p.end(), greater<pair<int, int>>());

    int idx = 0;
    rep(i, n){
        if(a[i]<p[idx].first){
            a[i] = p[idx].first;
            p[idx].second--;
        }else{
            break;
        }

        if(p[idx].second==0){
            idx++;
        }
        if(idx>m-1){
            break;
        }
    }
    ll sum = 0;
    rep(i, n){    
        sum += (ll) a[i];
    }
    printf("%lld\n", sum);
    return 0;
}

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

#define ll long long
#define INF 2147483647
#define mod 998244353

ll fact[500010], ifact[500010];

ll fpow(ll a, ll b){
    ll sum = 1;
    for(; b; b >>= 1){
        if(b & 1){
            sum *= a;
            sum %= mod;
        }
        a *= a;
        a %= mod;
    }
    return sum;
}

ll C(int a, int b){
    return fact[a] * ifact[a - b] % mod * ifact[b] % mod;
}

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    fact[0] = ifact[0] = 1;
    for(int i = 1; i <= 500000; i++){
        fact[i] = fact[i - 1] * i % mod;
        ifact[i] = fpow(fact[i], mod - 2);
    }

    ll ans = fpow(n + 1, m) * fpow(m + 1, n) % mod;
    ll num = -1;
    for(int i = 1; i <= std::min(n, m); i++){
        ans += num * (C(n, i) * C(m, i) % mod * fact[i] % mod * fpow(n + 1, m - i) % mod * fpow(m + 1, n - i) % mod);
        ans += mod;
        ans %= mod;
        num *= -1;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define ull unsigned long long
#define pi acos(-1)
using namespace std;
typedef long long ll;
const ll inf = 0x3f3f3f3f;
const ll maxn = 1e7+5;
const ll mod = 1e9+7;

int main(){
	int n;
	cin>>n;
	if(n) cout<<0<<'\n';
	else cout<<1<<'\n'; 
	return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
long long a,b,c,d,e,f;
scanf("%lld %lld",&a,&b);
//if (abs(c-a)<=d || abs (b-a)<=d && abs (c-b)<=d)
/*if ((a*b)%2==0)
printf("Even");
else
printf("Odd");*/
d=a+b;
e=a-b;
f=a*b;
if (d>=e && d>=f)printf("%lld",d);

else if (e>=d && e>=f)printf("%lld",e);
else printf("%lld",f);
}


Measured memory_bytes: 1736
/*
If you want to shine like a sun, first burn like a sun.
*/

#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 mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
    ll h,w;
    cin>>h>>w;

    if(h == 1 || w == 1)
    {
        cout<<1;
        return 0;
    }

    ll total = 0;

    ll a = w - (w/2);
    ll b = (w/2);

    total = a*(h - (h/2)) + b*(h/2);

    cout<<total;












    return 0;
}


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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


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

    if (400 <= x && x < 600)
        prt(8);
    else
    if (600 <= x && x < 800)
        prt(7);
    else
    if (800 <= x && x < 1000)
        prt(6);
    else
    if (1000 <= x && x < 1200)
        prt(5);
    else
    if (1200 <= x && x < 1400)
        prt(4);
    else
    if (1400 <= x && x < 1600)
        prt(3);
    else
    if (1600 <= x && x < 1800)
        prt(2);
    else
    if (1800 <= x && x < 2000)
        prt(1);

    return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll dp[222];

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

    ll n;cin >> n;
    vector<ll> p(4);REP(i, 4)cin >> p[i];
    vector<ll> t(4);REP(i, 4)cin >> t[i];

    REP(i, 222)dp[i] = INF;
    dp[0] = 0;

    REP(i, 111){
        REP(j, 4){
            dp[i+t[j]] = min(dp[i+t[j]], dp[i] + p[j]);
        }
    }

    REV(i, 111){
        dp[i] = min(dp[i+1], dp[i]);
    }

    cout << dp[n] << endl;

	return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<pair<int,int> > G[N];
int d[N],id[N],col[N],val[N<<1];
bool cmp(int x,int y) {
	return d[x]<d[y];
}
int main() {
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) {
		scanf("%d",&d[i]);
		id[i]=i,col[i]=-1;
	}
	for(int i=1,u,v;i<=m;i++) {
		scanf("%d%d",&u,&v);
		G[u].push_back({v,i});
		G[v].push_back({u,i});
	}
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++) {
		int u=id[i];
		if(~col[u]) continue;
		bool f=false;
		for(auto it:G[u]) {
			int v=it.first;
			if(d[u]>=d[v]) {
				if(~col[v]) col[u]=col[v]^1;
				else col[v]=0,col[u]=col[v]^1;
				val[it.second]=d[u];
				f=true;
				break;
			}
		}
		if(!f) {
			printf("-1\n");
			return 0;
		}
	}
	for(int i=1;i<=n;i++) {
		printf("%c",col[i]?'W':'B');
	}
	printf("\n");
	for(int i=1;i<=m;i++) {
		if(!val[i]) val[i]=1e9;
		printf("%d\n",val[i]);
	}
	return 0;
}

Measured memory_bytes: 12288
I = [int(_) for _ in open(0).read().split()]
H, W = I[:2]
A = I[2:2 + H * W]
B = I[2 + H * W:]
D = [abs(a - b) for a, b in zip(A, B)]
dp = [set([])] + [set([0])] + [set([])] * (W - 1)
for h in range(H):
    dpo = dp
    dp = [set([])] * (W + 1)
    for w, d in enumerate(D[W * h:W * (h + 1)]):
        s = dp[w] | dpo[w + 1]
        dp[w + 1] = {v + d for v in s} | {abs(v - d) for v in s}
print(min(dp[-1]))


Measured memory_bytes: 223656
D, G = map(int, input().split())
X = [0] + [list(map(int, input().split())) for _ in range(D)]

def func(i, t):
    if i == 0 or i > D:
        return 10 ** 9
    
    # Solve all problems, or part of them
    k = min(t // (100 * i), X[i][0])
    s = 100 * i * k
    
    # If all problems are solved, add bonus
    if k == X[i][0]:
        s += X[i][1]
        
    # If score < objective, go next step
    if s < t:
        k += func(i - 1, t - s)
        
    # Select minimum number of solved problems
    # k: solve i-th line
    # func(i-1,t): pass i-th line
    return min(k, func(i - 1, t))

# Solve backward
print(func(D, G))


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

using namespace std;
using ll = long long;

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

    ll ans = 0;
    ans = n*(n-1)/2;
    cout << ans << "\n";
    

}


Measured memory_bytes: 256
n,v;
s;
S[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x6f};
main(b,i){
	for(;scanf("%d",&n),~n;){
		s=0;
		for(;n--;){
			scanf("%d",&v);
			b=S[v]^s;
			for(i=7;i--;)
				putchar('0'+(b>>i)%2);
			puts("");
			s^=b;
		}
	}
	exit(0);
}

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

int main() {
	int n;
	std::cin >> n;

	std::vector<int> a(n);
	for (auto&& e : a)
		std::cin >> e;

	std::vector<int> cum1(n + 1), cum2(n + 1);
	for (int i = 0; i < n; ++i) {
		cum1[i + 1] = std::max(cum1[i], a[i]);
		cum2[n - 1 - i] = std::max(cum2[n - i], a[n - 1 - i]);
	}

	for (int i = 0; i < n; ++i)
		std::cout << std::max(cum1[i], cum2[i + 1]) << std::endl;
}

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

int main() {
  int a, b; cin >> a >> b;
  string s; cin >> s;
  for (int i=0; i<a+b+1; ++i) {
    if ((i == a) ^ (s[i] == '-')) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
 ll gcd(ll a,ll b){
 if(b == 0) return a;
 return gcd(b,a%b);
 }

//最小公倍数
 ll lcm(ll a,ll b){
 ll g = gcd(a,b);
 return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 







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

int cnt = 0;
REP(i,N)REP(j, N)REP(K, N)cnt++;
print(cnt);

}

Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#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;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;

int n;

int tab[nax];
int p[nax];

vi wyn;

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
		scanf("%d", &tab[i]);
	for (int i=n; i; i--)
	{
		int x=tab[i];
		for (int j=2*i; j<=n; j+=i)
			x^=p[j];
		if (x)
		{
			p[i]=1;
			wyn.push_back(i);
		}
	}
	reverse(wyn.begin(), wyn.end());
	printf("%d\n", (int)wyn.size());
	for (int i : wyn)
		printf("%d ", i);
	printf("\n");
	return 0;
}


Measured memory_bytes: 6392
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}


int main() {
  ll k; cin >> k;
  ll out=0;
   for (int i=1;i<k+1;++i){
    for (int j=1;j<k+1;++j){
    	ll tmp = gcd(i,j);
    	for(int l=1;l<k+1;++l){
    		out += gcd(tmp,l);
    	}
	   }
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] signs = {'+', '-'};
        int num = sc.nextInt();
        int[] numbers = {0, 0, 0, 0};
        boolean done = false;

        for (int i = numbers.length - 1; i >= 0; i--) {
            numbers[i] = num % 10;
            num = num / 10;
        }

        for (char i:signs) {
            for (char j:signs) {
                for (char k:signs) {
                    int sum = numbers[0];
                    if (i == '+') {
                        sum += numbers[1];
                    } else if (i == '-') {
                        sum -= numbers[1];
                    }
                    if (j == '+') {
                        sum += numbers[2];
                    } else if (j == '-') {
                        sum -= numbers[2];
                    }
                    if (k == '+') {
                        sum += numbers[3];
                    } else if (k == '-') {
                        sum -= numbers[3];
                    }

                    if (sum == 7 && done == false) {
                        System.out.println(String.valueOf(numbers[0]) + i + String.valueOf(numbers[1]) + j + String.valueOf(numbers[2]) + k + String.valueOf(numbers[3]) + "=7");
                        done = true;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 22612
#include <iostream>
using  namespace std;
#define ll      long long int
#define pai     pair<int,int>
#define vi      vector<int>
#define vd      vector<double>
#define vs      vector<string>
#define vp      vector< pair <string,int> >
#define mpi     map<int,int>
#define mps     map<char,int>
#define sti     stack<int>
#define stc     stack<char>
#define sei     set<int>
#define ses     set<string>
#define multii  multiset<int>
#define forn(i,n)    for (int i = 0; i < n; i++)
#define fork(i,k,n)  for (int i = k; i <= n; i++)
#define forkr(i,k,n) for (int i = k; i >= n; i--)

 int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
ll a;
cin>>a;
cout<<a+(a*a)+(a*a*a)<<endl;


}






Measured memory_bytes: 3164
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>
#include<cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(NULL);

 int D, CT = 26;
 cin >> D;
 vector<int> C(CT);
 vector<vector<int>> S(D, vector<int>(CT));
 rep(i, CT) cin>>C[i];
 rep(i, D) rep(j, CT) cin>>S[i][j];

 for(int i = 0;i < D;i++) {
   int j = rand() % 26;
   cout << j + 1 << endl;
 }


 return 0;
}


Measured memory_bytes: 3728
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    ss=readline().rstrip()
    if ss==ss.lower():
        print("a")
    else:
        print("A")
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int n=read(),last=read();
	assert(1<=n&&n<=100000);
	assert(1<=last&&last<=1000000000);
	int cur[2]{1,1},nx[2];
	REP(i,n-1){
		REP(k,2)nx[k]=min(cur[0],cur[1])+1;
		int x=read();
		assert(1<=x&&x<=1000000000);
		if(last<=x)chmin(nx[0],cur[0]);
		if(last>=x)chmin(nx[1],cur[1]);
		swap(cur,nx);
		last=x;
	}
	cout<<min(cur[0],cur[1])<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

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

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

template <typename T>
inline T gcd(T a, T b) {
    for (; b; a %= b, swap(a, b));
    return a; 
}

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

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

    int N, M; cin >> N >> M;
    vi rst(N+1, 0);

    vb visit(N+1, 0);
    while (M--) {
        int s, c; cin >> s >> c;
        if (visit[s]) {
            if (rst[s] == c) continue;
            else {
                cout << -1;
                return 0;
            }
        }

        visit[s] = 1;
        rst[s] = c;
    }

    if (N > 1 && rst[1] == 0)  {
        if (visit[1]) {
            cout << -1;
            return 0;
        }
        rst[1] = 1;
    }

    for (int i = 1; i <= N; i++) cout << rst[i];
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef struct node
{
    long long a,b;
}NODE,*PNODE;
vector<NODE> vec;
bool cmp(const NODE x,const NODE y)
{
    return x.a<y.a;
}
int main()
{
    int n,m;
    int i;
    long long ans=0;
    scanf("%d %d",&n,&m);
    vec.resize(n+1);
    for(i=1;i<=n;i++)
    {
        scanf("%lld %lld",&vec[i].a,&vec[i].b);
    }
    sort(vec.begin()+1,vec.end(),cmp); 
    for(i=1;i<=n;i++)
    {
        if(m>vec[i].b)
        {
            m-=vec[i].b;
            ans+=(vec[i].b*vec[i].a);
        }
        else if(m<=vec[i].b)
        {
            ans+=(m*vec[i].a);
            break;
        }
    }
    printf("%lld\n",ans);
    return 0;
} 

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

// change minimum
// aよりbが小さかったら、aの値をbの値に置き換えて、trueを返す
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1LL << 60;

const int MAX_N = 110;
const int MAX_V = 100100;

// i-1番目までの品物から価値がsum_v以上を達成するように選んだとき、重さの総和の最小値
long long dp[MAX_N][MAX_V];

int main()
{
    long long N, W;
    cin >> N >> W;
    long long w[N], v[N];
    rep(i, N) cin >> w[i] >> v[i];

    rep(i, MAX_N)
    {
        rep(j, MAX_V)
        {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    for (long long i = 0; i < N; i++)
    {
        for (long long sum_v = 0; sum_v < MAX_V; ++sum_v)
        {
            // i番目の品物を選ぶとき
            if (sum_v - v[i] >= 0)
                chmin(dp[i + 1][sum_v], dp[i][sum_v - v[i]] + w[i]);

            // i番目の品物を選ばないとき
            chmin(dp[i + 1][sum_v], dp[i][sum_v]);
        }
    }

    long long answer = 0;
    for (long long sum_v = 0; sum_v < MAX_V; ++sum_v)
    {
        if (dp[N][sum_v] <= W)
            answer = sum_v;
    }

    cout << answer << endl;
}

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

typedef long long ll;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

typedef long double D;
typedef complex<D> P;

#define X real()
#define Y imag()

const D eps=1e-8;
const D inf=1e12;
const D PI=acos(-1);

namespace std{
  bool operator<(const P& a,const P& b){
    return a.X==b.X?a.Y<b.Y:a.X<b.X;
  }
}
bool cmp_x(const P& a,const P& b){ return abs(a.X-b.X)<eps?a.Y<b.Y:a.X<b.X; }
bool cmp_y(const P& a,const P& b){ return abs(a.Y-b.Y)<eps?a.X<b.X:a.Y<b.Y; }
bool cmp_a(const P& a,const P& b){ return arg(a)==arg(b)?norm(a)<norm(b):arg(a)<arg(b); }
D cross(P a,P b){ return (conj(a)*b).Y; }
D dot(P a,P b){ return (conj(a)*b).X; }
D toRag(D deg){ return deg*PI/180.0; }
P rot(P base,P a,D theta){ return base+polar(abs(a-base),arg(a-base)+theta); }

struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

vector<P> convex_hull(vector<P> ps){
  sort(ps.begin(),ps.end(),cmp_x);
  int n=ps.size(),k=0;
  vector<P> qs(n*2);
  for(int i=0;i<n;i++){
    while(k>1&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0)k--;
    qs[k++]=ps[i];
  }
  for(int i=n-2,t=k;i>=0;i--){
    while(k>t&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0)k--;
    qs[k++]=ps[i];
  }
  qs.resize(k-1);
  return qs;
}

int main(){
	cin.sync_with_stdio(false);
  int n;
  vector<P> ps;
  cin>>n;
  rep(i,n){
    D x,y;
    cin>>x>>y;
    ps.push_back(P(x,y));
  }
  vector<P> res=convex_hull(ps);
  int st=0;
  rep(i,res.size()){
    if(cmp_y(res[i],res[st]))st=i;
  }
  cout<<res.size()<<endl;
  rep(i,res.size()){
    cout<<res[(st+i)%res.size()].X<<" "<<res[(st+i)%res.size()].Y<<endl;
  }
	return 0;
}

Measured memory_bytes: 15428
W, H, N = gets.split.map(&:to_i)
xya = N.times.map { gets.split.map(&:to_i) }
map = Array.new(W * H, true)

xya.each do |x,y,a|
  w_min = 0
  w_max = W - 1
  h_min = 0
  h_max = H - 1
  case a
  when 1
    w_max = x - 1
  when 2
    w_min = x
  when 3
    h_max = y - 1
  when 4
    h_min = y
  end
  (w_min..w_max).each do |w|
    (h_min..h_max).each do |h|
      map[h * W + w] = false
    end
  end
end

p map.count(&:itself)


Measured memory_bytes: 1916
n,m=map(int,input().split())
if abs(n-m)>1:
	ans=0
elif n!=m:
	ans=1
	for i in range(n):
		ans*=i+1
		ans%=10**9+7
	for i in range(m):
		ans*=i+1
		ans%=10**9+7
else:
	ans=2
	for i in range(2):
		for j in range(n):
			ans*=j+1
			ans%=10**9+7
print(ans)




Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    string s;
    cin>>s;

    string t;
    cin>>t;

    map<char,vector<int> > p;

    rep(i,0,s.length())
    {
        p[s[i]].pb(i);
    }
    int sz = s.length();
    int found = 0;
    int ans = 0;
    int x = -1;
    rep(i,0,t.length())
    {
        if( p[t[i]].size() == 0 )
        {
            found = 1;
            break;
        }

        auto it = upper_bound(all(p[t[i]]),x);

        if ( it == p[t[i]].end() )
        {
            ans++;
            x = *(p[t[i]].begin());  
        }
        else
        {
            x = *(it);
        }
    }

    if ( found == 1 )
    {
        cout<<"-1"<<endl;
    }
    else
    {
        cout<<ans*sz + x + 1<<endl;
    }
    
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 1736
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
Point a[20];
//j番目からきてi番目からk番目に行く
ld cost[20][20][20];
ld dot(Point a, Point b) {
	return real(conj(a)*b);
}
ld d[20][20][10000];
struct vertice { 
	int x, y, t;
	bool operator<(const vertice &v) const {
		if (x!=v.x)return x < v.x;
		if (y != v.y)return y < v.y;
		return t < v.t;
	}
};
typedef pair<ld, vertice> speP;
int main(){
	int n; cin >> n;
	ld r, theta;
	cin >> r >> theta;
	theta = theta * pi / 180.0;
	rep(i, n) {
		ld x, y; cin >> x >> y;
		a[i] = { x,y };
	}
	rep(i, n) {
		rep(j, n) {
			rep(k, n) {
				if (i == j || i == k) {
					cost[i][j][k] = 10010;
				}
				else {
					ld t = dot(a[i] - a[j], a[k] - a[i]);
					t /= abs(a[i] - a[j]);
					t /= abs(a[k] - a[i]);
					if (cos(theta) > t) {
						cost[i][j][k] = 10010;
					}
					else {
						cost[i][j][k] = abs(a[k] - a[i]);
					}
				}
			}
		}
	}
	rep(i, 20) {
		rep(j, 20) {
			rep(k, 10000) {
				d[i][j][k] = 10000;
			}
		}
	}
	priority_queue<speP, vector<speP>, greater<speP>> q;
	rep(i, n) {
		if (i > 0) {
			d[i][0][1] = abs(a[i] - a[0]);
			q.push(speP{ d[i][0][1],vertice{i,0,1} });
		}
	}
	while (!q.empty()) {
		speP nex = q.top(); q.pop();
		vertice v = nex.second;
		if (d[v.x][v.y][v.t]+eps < nex.first)continue;
		rep(i, n) {
			ld nd = nex.first + cost[v.x][v.y][i];
			if (nd + eps < d[i][v.x][v.t + 1]) {
				d[i][v.x][v.t + 1] = nd;
				q.push({ nd,{i,v.x,v.t + 1} });
			}
		}
	}
	int out = 0;
	rep(i, n) {
		rep(j, n) {
			rep(k, 10000) {
				if (d[i][j][k] + eps < r) {
					out = max(out, k);
				}
			}
		}
	}
	cout << out << endl;
	return 0;
}


Measured memory_bytes: 66264
#include <stdio.h>
#define MAX_N 20

int main()
{
  int n;
  int p[MAX_N];
  int i;
  int c = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++)
  {
    scanf("%d", &p[i]);
  }
  for (i = 0; i < n - 2; i++)
  {
    if ((p[i] > p[i + 1] && p[i + 1] > p[i + 2]) || (p[i] < p[i + 1] && p[i + 1] < p[i + 2]))
    {
      c++;
    }
  }
  printf("%d\n", c);
}

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

int main() {
  string a, b;
  cin >> a >> b;
  if (a.at(0)==b.at(2) && a.at(1)==b.at(1) && a.at(2)==b.at(0)) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll n,m,vis[N],dist[N],deg[N];
vector<ll> adj[N];
void dfs(ll node){
    vis[node]=1;
    for(auto &v:adj[node]){
        if(!vis[v])dfs(v);
        dist[node]=max(dist[node],dist[v]);
    }
    dist[node]+=1;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>m;
    for(ll i=0,u,v;i<m;i++)cin>>u>>v,adj[u].push_back(v),deg[v]++;
    for(ll i=1;i<=n;i++)if(!deg[i])dfs(i);
    cout<<*max_element(dist+1,dist+n+1)-1;
}

Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

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

    vector<int> vec(10,0);

    int max_=0;
    int min_=0;
    int flag=0;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        a/=400;
        if(a>=8){
            max_++;
            vec[9]++;
            if(min_==0){
                min_++;
                flag++;
            }
        }else if(vec[a]==0){
            max_++;
            if(flag>0){
                flag--;
            }else{
                min_++;
            }
            vec[a]++;
        }

    }
    cout << min_ << ' ' << max_ << endl;
}

Measured memory_bytes: 256
// Binary Search

#include <iostream>

using namespace std;

const int SIZE = 100000;
const int QSIZE = 50000;

bool binarySearch(int *a, int key, int n) {
    int left = 0;
    int right = n;
    int mid;

    while (left < right) {
        mid = (left + right) / 2;
        if (a[mid] == key) return true;
        if (key < a[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return false;
}

int main () {
    int n;
    cin >> n;
    int S[SIZE];
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }
    int q;
    cin >> q;
    int T[QSIZE];
    for (int i = 0; i < q; i++) {
        cin >> T[i];
    }
    int count = 0;
    for(int i = 0; i < q; i++) {
        int c = T[i];
        if(binarySearch(S, c, n)) count++;
    }
    cout << count << endl;
}



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

int isPrime(int x) {
  int i;
  if (x < 2) return 0;
  else if (x == 2) return 1;

  if (x % 2 == 0) return 0;

  for (i = 3; i*i <= x; i+=2) {
    if (x % i == 0) return 0;
  }

  return 1;
}

int main() {
  int n, x, i;
  int cnt = 0;

  cin >> n;

  for (i = 0; i < n; i++) {
    cin >> x;
    if (isPrime(x)) cnt++;
  }

  cout << cnt << endl;
 
  return 0;

}


Measured memory_bytes: 3072
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{

  public static void main
  (
    String[] args
  )
  {
    BufferedReader in_stream;
    String         in_str;
    String[]       in_str_split;

    int in_N;
    int in_T;

    int c;
    int t;
    int cnt;
    int ans;

    ans = 9999;

    try
    {
      in_stream = new BufferedReader(new InputStreamReader(System.in));

      /*----------------
       * 引数
       *----------------*/
      in_str       = new String(in_stream.readLine());
      in_str_split = in_str.split(" ");
      in_N         = Integer.parseInt(in_str_split[0]);
      in_T         = Integer.parseInt(in_str_split[1]);

      for(cnt=0; cnt<in_N; cnt++)
      {
        in_str       = new String(in_stream.readLine());
        in_str_split = in_str.split(" ");
        c            = Integer.parseInt(in_str_split[0]);
        t            = Integer.parseInt(in_str_split[1]);

        if(t <= in_T)
        {
          if(c < ans)
          {
            ans = c;
          }
        }
      }

      /*----------------
       * 計算
       *----------------*/
      if(9999 == ans)
      {
        System.out.println("TLE");
      }
      else
      {
        System.out.println(String.valueOf(ans));
      }
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 21076
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const ll N = 3e5;
ll n,k;
ll arr[N][3],dp[N][3];
int main(){
	speed;
	cin >> n;
	for(int i = 0 ; i < n ; i++)
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	for(int i = 1 ; i <= n ; i++){
		dp[i][0] = max(dp[i - 1][1],dp[i - 1][2]) + arr[i - 1][0];
		dp[i][1] = max(dp[i - 1][0],dp[i - 1][2]) + arr[i - 1][1];
		dp[i][2] = max(dp[i - 1][1],dp[i - 1][0]) + arr[i - 1][2];
	}
	cout << max({dp[n][0],dp[n][1],dp[n][2]});
}
/*
Timus : 288471KD
CF : Zhabka
mail : dzhon.snoudin@mail.ru
*/



Measured memory_bytes: 8448
//we'll get thru it believe me 
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (int r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
const long long INF=1e11+1, MAX=1e5+2;
void min_self(long long& a, long long b){
	a=min(a, b);
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int N, W, ans=0;
	cin>>N>>W;
	vector<vector<long long>>dp(N+1, vector<long long>(MAX, INF));
	vector<long long>ws(N), vs(N);
	for(int i=0; i<N; i++)cin>>ws[i]>>vs[i];
	dp[0][0]=0;
	for(int i=0; i<N; i++){
		for(int v=0; v<MAX; v++){
			if(v+vs[i]<MAX){
				min_self(dp[i+1][v+vs[i]], dp[i][v]+ws[i]);
			}
			min_self(dp[i+1][v], dp[i][v]);
		}
	}
	for(int v=0; v<MAX; v++){
		if(dp[N][v]<=W)ans=v;
	}
	cout<<ans<<"\n";
}


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

int main()
{
  int n;
  cin>>n;
  int a[n],b[n],c[n-1];
  int i;
  for(i=0;i<n;i++){
    cin>>a[i];
    a[i]--;
  }
  for(i=0;i<n;i++){
    cin>>b[i];
  }
  for(i=0;i<n-1;i++){
    cin>>c[i];
  }
  int ans;
  ans=b[a[0]];
  for(i=1;i<n;i++){
    ans+=b[a[i]];
    if(a[i]-a[i-1]==1){
      ans+=c[a[i-1]];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256