akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define Abs(_A) (_A > 0 ? _A : -(_A))

const int MaxN = 100010;
namespace Steaunk
{
	int n, m, ans, s[MaxN], sta[MaxN], tot, a[MaxN];
	int Point[MaxN], Next[MaxN << 1], To[MaxN << 1], q = 1;
	bool vis[MaxN];
	void Add(int u, int v)
	{
		Next[++q] = Point[u]; Point[u] = q; To[q] = v;
		Next[++q] = Point[v]; Point[v] = q; To[q] = u;
	}
	void dfs(int u, int from)
	{
		s[u] = 0;
		for(int j = Point[u]; j; j = Next[j]) if(To[j] != from && !vis[To[j]])
			dfs(To[j], u);
		if(u != from)
		{
			s[from] += 1 - s[u];
			ans += Abs(1 - s[u]);
			s[u] = 1;
		}
	}
	int dfs1(int u, int from)
	{
		vis[u] = 1; //printf("(%d)\n", u);
		for(int j = Point[u]; j; j = Next[j]) if(j != (from ^ 1))
		{	
			if(vis[To[j]]){ vis[sta[tot++] = u] = 0; return To[j]; }
			int t;
			if(!vis[To[j]] && (t = dfs1(To[j], j)))
			{
				vis[u] = 0;
				//printf("<%d, %d>\n", t, u);
				if(~t) return (sta[tot++] = u) == t ? -1 : t;
				else return t;
			}
		}
		vis[u] = 0;
		return 0;
	}
	void main()
	{
		scanf("%d %d", &n, &m);
		for(int i = 1; i <= n; ++i) Point[i] = 0; q = 1;
		for(int i = 1; i <= m; ++i)
		{
			int u, v;
			scanf("%d %d", &u, &v);
			Add(u, v);
		}
		if(n & 1){ puts("-1"); return ; }
		ans = 0;
		if(m == n - 1) 
		{
			dfs(1, 1);
			if(s[1] != 1) puts("-1");
			else printf("%d\n", ans);
		}
		else
		{
			tot = 0;
			dfs1(1, 0);
			for(int *i = sta; i < sta + tot; ++i) vis[*i] = 1;
			for(int *i = sta; i < sta + tot; ++i) dfs(*i, *i);
			for(int *i = sta; i < sta + tot; ++i) vis[*i] = 0;
			sta[tot] = sta[0];
		//	for(int i = 1; i <= n; ++i) printf("%d ", s[i]); puts("");
		//	for(int *i = sta; i < sta + tot; ++i) printf("[%d] ", *i); puts("");
			for(int i = 1; i < tot; ++i) a[i] = 1 - s[sta[i - 1]] - a[i - 1];
			a[tot] = 1 - s[sta[tot - 1]];
		//	for(int i = 0; i <= tot; ++i) printf("%d ", a[i]); puts("");
			if(tot & 1)
			{
				if(a[tot] + a[tot - 1] & 1) puts("-1");
				else 
				{
					int t = (a[tot] - a[tot - 1]) / 2;
				//	printf("%d %d\n", ans, t);
				//	for(int i = 0; i < tot; ++i) printf("%d ", a[i]); puts("");
					for(int i = 0; i < tot; ++i)
						if(i & 1) ans += Abs(a[i] - t);
						else ans += Abs(a[i] + t);
					printf("%d\n", ans);
				}
			}
			else
			{
				if(a[tot] != a[tot - 1]) puts("-1");
				else //median
				{
					//for(int *i = sta; i < sta + tot; ++i) printf("%d ", s[*i]); puts("");
					for(int i = 0; i < tot; ++i) 
						if(i & 1) s[i] = a[i];
						else s[i] = -a[i];
					//for(int i = 0; i < tot; ++i) printf("%d ", a[i]); puts("");
					//for(int i = 0; i < tot; ++i) printf("%d ", s[i]); puts("");
					std::nth_element(s, s + (tot >> 1), s + tot);
					int t = s[tot >> 1];
					//printf("<%d>\n", t);
					for(int i = 0; i < tot; ++i)
						if(i & 1) ans += Abs(a[i] - t);
						else ans += Abs(a[i] + t);
					printf("%d\n", ans);
				}
			}
			//for(int i = 1; i <= tot; ++i) printf("%d ", a[i]); puts("\n");
		}
	}
}
int main()
{
	int T;
	//scanf("%d", &T);
	//while(T--) 
	Steaunk::main();
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef RUS_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef RUS_HOME
    freopen("input", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(4) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

void smain() {

    int n, a, b;
    cin >> n >> a >> b;
    int v = (abs(a - b) - 1);
    if (v % 2 == 1) {
        cout << "Alice";
    } else {
        cout << "Borys";
    }


}

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


int main() {
  int a, b, c;
  cin >> a >> b >>c;
  if ((a-b) <= c) {
    cout << c - (a-b) << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    lint N,A,B;
    cin >> N >> A >> B;
    lint sum=A+B;
    lint whole=N/sum;
    lint ans=0;
    ans+=whole*A;
    lint rem=N%sum;
    ans+=min(A,rem);
    cout << ans << endl;
}

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

signed main(){
    int p[10]={0,1,2,3,4,5,6,7,8,9};

    string s;cin>>s;
    int n=s.size();
    stringstream ss(s);int a;ss>>a;ss.clear();

    int x=0,y=101010101010101;

    int d=1;rep(i,n)d*=10;
    do{
        rep(i,n)ss<<p[i];
        int b;ss>>b;
        ss.clear();
        int hoge=abs(a-b);
        int piyo=min(hoge,d-hoge);
        if(x<piyo){
            x=piyo;
            y=b;
        }
        else if(x==piyo){
            chmin(y,b);
        }
    }while(next_permutation(p,p+10));

    ss<<y;ss>>s;
    while(s.size()<n)s="0"+s;
    cout<<s<<endl;
    return 0;
}

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


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


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

Measured memory_bytes: 256
import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[] a = new int[n];
                for(int i = 0 ; i < n ; i++){
                        a[i] = sc.nextInt();
                }
                sc.close();
                Arrays.sort(a);
                int yono = 0;
                for(int i = 0 ; i < n - 1 ; i++){
                        if(Math.abs(a[n - 1] - 2 * a[yono]) > Math.abs(a[n - 1] - 2 * a[i])) yono = i;
                }
                System.out.println(a[n - 1] + " " + a[yono]);
        }
}

Measured memory_bytes: 60232
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        //System.setIn(Main.class.getResourceAsStream("input"));
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int monsters = sc.nextInt();
        int specialMoves = sc.nextInt();
        sc.nextLine();
        int[] healths = toArray(sc.nextLine());
        if(specialMoves >= monsters) System.out.println(0);
        else {
            long sum = Arrays.stream(healths).sorted().limit(monsters-specialMoves).mapToLong(i -> (long)i).sum();
            System.out.println(sum);
        }
    }

    private static int nextInt(Scanner sc) {
        return Integer.valueOf(sc.nextLine());
    }

    private static int[] toArray(String text) {
        return Arrays.stream(text.split("\\s")).mapToInt(Integer::valueOf).toArray();
    }

}

Measured memory_bytes: 77328
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

vector<int>P;
int p[20005];

void init()
{
  p[0] = p[1] = 1;
  for(int i=2;i<20005;i++)
    for(int j=i+i;j<20005;j+=i) p[j] = 1;
  for(int i=3;i<20005;i++){
    if(p[i] == 0 && (i%4 == 3)) P.push_back(i);
  }
}

int fanc1(int x)
{
  return x%4 == 1 && p[x] == 0;
}

int fanc2(int x)
{
  rep(i, P.size()) if(x == P[i]*P[i]) return 1;
  return 0;
}

int main()
{
  init();
  int N;
  cin >> N;
  rep(i, N){
    int m, n;
    cin >> m >> n;
    int x = m*m + n*n;
    if(x == 2 || fanc1(x) || fanc2(x)) cout << "P\n";
    else cout << "C\n";
  }
  return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

vector<pair<long long, int>> factorize(long long n){
    vector<pair<long long, int>> res;
    
    if(n%2 == 0){
        res.emplace_back(2,0);
        while(n%2 == 0){
            n /= 2;
            res.back().second++;
        }
    }
    
    for(int i=3; i*i<=n; i+=2){
        if(n%i) continue;
        res.emplace_back(i,0);
        while(n%i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(void){
    ll n; cin >> n;
    auto v = factorize(n);
    cout << n << ":";
    for(P f : v){
        REP(i,f.second) cout << " " << f.first;
    }
    cout << en;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 2019;
const int MAXN = 1005;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for(int &i : v)
		cin >> i;
	int ans = 0;
	for(int i = 1; i < n-1; i++) {
		if( (v[i] > v[i-1] && v[i] < v[i+1]) or (v[i] > v[i+1] && v[i] < v[i-1])) {
			ans++;
		}
	}
	cout << ans << endl;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 3;
const int N = 4e7 + 10, M = 1e7 + 10;
const ll INF = 1e18;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

#define pi acos(-1)

int main()
{
    int n;
    string str;
    cin >> n;
    cin >> str;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        if (str[i] == 'W')
            sum++;
    }
    int ans = min(sum, n - sum);
    sum = n - sum;
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (str[i] == 'W')
            cnt++;
        else
        {
            sum--;
        }
        int u = cnt, v = sum;
        int d = min(sum, cnt); //右边r和左边w交换
        u -= d;
        v -= d;
        ans = min(ans, u + v + d);
    }
    cout << ans << endl;
    return 0;
}

/*
rwwww
rrwww
rrrww

*/


Measured memory_bytes: 3716
n = int(input())
cnt = 0
dp = [0] * (10**4 + 1)
for i in range(1,10**2 + 1):
    for j in range(1,10**2 + 1):
        for k in range(1,10**2 + 1):
            a = i**2 + j ** 2 + k**2 +i*j + j*k + k*i
            if a <= 10 ** 4:
                dp[a] += 1


for i in range(1,n+1):
    print(dp[i])

Measured memory_bytes: 9244
import sys
import numpy as np
from collections import Counter

# 実行環境(0:vscode, 1:atcoder)
MODE = 1

# 入力の次元
DIMENSION = 2

# int型に変換
INT_TYPE = 1

if not (MODE):
    with open("input.txt", "r") as f:
        s = f.read()
else:
    s = sys.stdin.read()

if DIMENSION == 0:
    if INT_TYPE == 1:
        s = int(s)
elif DIMENSION == 1:
    if INT_TYPE == 0:
        s = s.split()
    elif INT_TYPE == 1:
        s = [int(x) for x in s.split()]
elif DIMENSION == 2:
    if INT_TYPE == 0:
        s = [x.split() for x in s.splitlines()]
    elif INT_TYPE == 1:
        s = [[int(y) for y in x.split()] for x in s.splitlines()]

N = s[0][0]
A = np.array(s[1])
Q = s[2][0]
BC = np.array(s[3:])
B = BC[:, 0]
C = BC[:, 1]

A_sum = np.sum(A)

D = Counter(A)

for i in range(Q):
    b = B[i]
    c = C[i]
    A_sum += D[b] * (c - b)
    print(A_sum)
    D[c] += D[b]
    D[b] = 0


Measured memory_bytes: 62724
#include <iostream>
#include <vector>
#include <numeric>

using namespace std; 

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


int main() {
    
  int P,Q,R, ans = 0, min = 1000;

  cin >> P >> Q >> R;

  ans = P + Q;
  if(min >= ans) { min = ans; }
  ans = P + R;
  if(min >= ans) { min = ans; }
  ans = Q + R;
  if(min >= ans) { min = ans; }

  cout << min << endl;

  return 0;
}

/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
import glob


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\AGC\\A'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:
    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index - 1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class A(Common):

    def resolve(self):

        q_string = self.input_data().split()[0]

        con_num = 1
        con_num_list = []

        q_list = list(q_string)
        for i in range(len(q_list)):
            if i == len(q_list)-1 or q_list[i] != q_list[i+1]:
                con_num_list.append(con_num)
                con_num = 1
            else:
                con_num += 1

        result = 0
        remain = False
        for n in con_num_list:
            if remain:
                m = n - 1
                result += 1
                if m % 3 == 0:
                    result += int(m/3) * 2
                    remain = False
                elif m % 3 == 1:
                    result += int(m/3) * 2 + 1
                    remain = False
                elif m % 3 == 2:
                    result += int(m/3) * 2 + 1
                    remain = True

            else:
                if n % 3 == 0:
                    result += int(n/3) * 2
                    remain = False
                elif n % 3 == 1:
                    result += int(n/3) * 2 + 1
                    remain = False
                elif n % 3 == 2:
                    result += int(n/3) * 2 + 1
                    remain = True

        print(str(result))


solver = A(REL_PATH)
solver.exec_resolve()

Measured memory_bytes: 7396
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, A, B, C, D;

int main(){
  cin >> N >> A >> B >> C >> D;
  
  REP(i, N) {
    if(C * (N - 1 - i) - D * i <= B - A && B - A <= (- C * i) + (N - 1 - i) * D){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	int X; cin >> X;
	int max500 = X / 500; 
	int max5 = (X % 500) / 5;
	int ans = max500 * 1000 + max5 * 5;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
ll x[15], y[15], p[15];
vector<int> vx[1<<15],vy[1<<15];
ll min_diff_x[1<<15][15];
ll min_diff_y[1<<15][15];

// s: people, t: rail
ll calc_x(int s, int t){
    ll ans = 0;
    for(int i = 0; i < N; i++){
        if(!((1<<i)&s)) continue;
        ans += min_diff_x[t][i];
    }
    return ans;
}

// s: people, t: rail
ll calc_y(int s, int t){
    ll ans = 0;
    for(int i = 0; i < N; i++){
        if(!((1<<i)&s)) continue;
        ans += min_diff_y[t][i];
    }
    return ans;
}

ll min_x[1<<15][16];
ll min_y[1<<15][16];

int full;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    full = (1<<N)-1;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> p[i];
    }
    for(int i = 1; i < (1<<N); i++){
        for(int j = 0; j <= N; j++){
            min_x[i][j] = 1e18;
            min_y[i][j] = 1e18;
        }
    }
    for(int i = 0; i < (1<<N); i++){
        vx[i].push_back(0);
        vy[i].push_back(0);
        vx[i].push_back(-100000);
        vy[i].push_back(-100000);
        vx[i].push_back(100000);
        vy[i].push_back(100000);
        for(int j = 0; j < N; j++){
            if(i&(1<<j)){
                vx[i].push_back(x[j]);
                vy[i].push_back(y[j]);
            }
        }
        sort(vx[i].begin(), vx[i].end());
        sort(vy[i].begin(), vy[i].end());

        for(int j = 0; j < N; j++){
            auto ptr = lower_bound(vx[i].begin(), vx[i].end(), x[j]);
            ll m = 1e15;
            if(ptr != vx[i].end()) m = *ptr-x[j];
            ptr--;
            m = min(m, x[j]-(*ptr));
            min_diff_x[i][j] = p[j]*m;
        }

        for(int j = 0; j < N; j++){
            auto ptr = lower_bound(vy[i].begin(), vy[i].end(), y[j]);
            ll m = 1e15;
            if(ptr != vy[i].end()) m = *ptr-y[j];
            ptr--;
            m = min(m, y[j]-(*ptr));
            min_diff_y[i][j] = p[j]*m;
        }
    }
    for(int i = 0; i < (1<<N); i++){
        for(int j = i; j >= 0; j = (j-1)&i){
            int cnt = 0;
            for(int k = 0; k < N; k++){
                if(j&(1<<k)) cnt++;
            }
            min_x[i][cnt] = min(min_x[i][cnt], calc_x(i, j));
            min_y[i][cnt] = min(min_y[i][cnt], calc_y(i, j));
            if(j == 0) break;
        }
    }
    for(int i = 0; i <= N; i++){
        ll ans = 1e18;
        for(int j = 0; j < (1<<N); j++){
            for(int k = 0; k <= i; k++){
                ll tmp = min_x[j][k]+min_y[full-j][i-k];
                ans = min(ans, tmp);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 25840
#include<bits/stdc++.h>
using namespace std;
const bool DEBUG = true;
#define coutd if(DEBUG) cout 
#define ff first
#define ss second
#define debug(x) cout << "> x:" << x << endl;
#define len(x) int(x.size())
#define all(x) x.begin(), x.end()
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
const double PI = acos(-1);
const double EPS = 1e-9;
const int MAXN = 2*1e5+8;
vector<int> adj_list[MAXN];
bitset<MAXN> visited;
int wt[MAXN];
int dad[MAXN];
int ans[MAXN];
void visit(int u){
	if(u!=1) wt[u]+=wt[dad[u]];
	ans[u]=wt[u];
	visited[u]=true;
	for(auto v:adj_list[u]){
		if(visited[v]) continue;
		dad[v]=u;
		visit(v);
	}
}

int main(){
	ios::sync_with_stdio(0);
	int n, q;
	cin >> n >> q;
	for(int i=0; i<n-1; ++i){
		int a, b;
		cin >> a >> b;
		adj_list[a].push_back(b);
		adj_list[b].push_back(a);
	}
	for(int i=0; i<q; ++i){
		int p, x;
		cin >> p >> x;
		wt[p]+=x;
	}
	visit(1);
	for(int i=1; i<=n; ++i)
		cout << ans[i] << ((i==n)?"\n":" ");
}

Measured memory_bytes: 25088
#include<stdio.h>

int main(void)
{
	int a,x;
	scanf("%d",&a);
	for (int i = 1; i <= a; i++)
	{
		if (i%3 == 0)
		{
			printf(" %d", i);
		}
		else
		{
			x = i;
			while (x)
			{
				if (x % 10 != 3)
				{
					x /= 10;
				}
				else
				{
					printf(" %d", i);
					break;
				}
			}
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2104
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = set(a)
b = list(b)
ans = [0]*len(b)
tmp = a[0]
ans[0] += 1
cnt = 0

for i in range(1,n):
    if tmp == a[i]:
        ans[cnt] += 1
    else:
        cnt += 1
        ans[cnt] += 1
        tmp = a[i]

f = len(ans)-k
cnt1 = 0
if f <= 0:
    print(0)
else:
    ans.sort()
    for i in range(f):
        cnt1 += ans[i]
    print(cnt1)

Measured memory_bytes: 118264
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
#include <atcoder/string>
using namespace std;
using namespace atcoder;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n"

void solve(){
    string S;
    cin >> S;
    vector<int> sa = suffix_array(S);
    ll n = S.size();
    ll ans = n * (n+1) / 2;
    for(auto &e: lcp_array(S, sa)){
        ans -= e;
    }
    print(ans);


}

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

Measured memory_bytes: 15612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String S=scan.next();
		char[] y=S.toCharArray();
		if(y[0]==y[1] || y[1]==y[2] || y[2]==y[3])
		{
			System.out.println("Bad");
		}
		else {
			System.out.println("Good");
		}

	}

}

Measured memory_bytes: 35636
#include <stdio.h>
#define MAX 100
  int G[MAX][MAX];
int main(void){

  int chouten_suu;
  int i,j;
  int no,kosuu;
  int retsu;
  scanf("%d",&chouten_suu);
  for(i = 0; i < chouten_suu;i++)
    {
      scanf("%d%d",&no,&kosuu);
        for (j = 0;j < kosuu; j++)
          {
            scanf("%d",&retsu);
            G[no-1][retsu-1] = 1;
          }
    }
  for (i = 0;i < chouten_suu ; i++)
    {
      for (j = 0; j < chouten_suu -1; j++)
        {
          printf("%d ",G[i][j]);
    
        }
      printf("%d\n",G[i][j]);
    }
return 0;
}

Measured memory_bytes: 632
def main():
    N, K = map(int, input().split())
    S = input()

    score = 0
    s = S[0]
    for i in range(1, N):
        t = S[i]
        if s == t:
            score += 1
        s = t
    ans = min(score + 2 * K, N - 1)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
import numpy as np
import pdb

def main():
    row1 = list(raw_input())
    row2 = list(raw_input())

    matoriginal = np.array([row1, row2])
    rotated1 = row2[::-1]
    rotated2 = row1[::-1]
    matrotate = np.array([rotated1, rotated2])

    if np.prod(matoriginal == matrotate):
        print 'YES'
    else:
        print 'NO'


if __name__ == '__main__':
    main()


Measured memory_bytes: 10532
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  int n,k;
  cin >> n >> k;
  vector<int>baket(n + 1,INF);
  set<int>count;
  int tmp;
  rep(i,n){
    cin >> tmp;
    if(baket[tmp] == INF){
      baket[tmp] = 1;
    }
    else{
      baket[tmp]++;
    }
    count.insert(tmp);
  }
  sort(all(baket));
  int now = count.size();
  int ans = 0;
  int j = 0;
  while(now > k){
    ans += baket[j];
    now--;
    j++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10368
#include "bits/stdc++.h"
using namespace std;

int n, m, q;
vector<vector<int>> abcd;
vector<int> a;
int ans = 0;

int calc1()		// 得点を計算する関数
{
	int ret = 0;
	for (auto abcd_ele : abcd) {
		int ai, bi, ci, di;
		ai = abcd_ele.at(0);
		bi = abcd_ele.at(1);
		ci = abcd_ele.at(2);
		di = abcd_ele.at(3);
		if (a.at(bi - 1) - a.at(ai - 1) == ci) {
			ret += di;
		}
	}
	return ret;
}

void dfs(int index, int num)	// 数列を生成する関数
{
	for (int i = num; i <= m; i++) {
		a.at(index) = i;
		if (index == n - 1) {	// 数列が完成したら得点を計算
			ans = max(ans, calc1());
		} else {
			dfs(index + 1, i);	// 未完の場合は次の要素に移る
		}
	}

}

int main()
{
	cin >> n >> m >> q;
	abcd.resize(q);
	for (int i = 0; i < q; i++) {
		int a_in, b_in, c_in, d_in;
		cin >> a_in >> b_in >> c_in >> d_in;
		abcd.at(i) = { a_in, b_in, c_in, d_in };
	}

	a.resize(n);
	dfs(0, 1);

	cout << ans << endl;

}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

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; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


int mp[10][10], ans=0;
int check(vector<int> v){
	if( v.empty() ) return 0;
	int k = v.back(); v.pop_back();
	return mp[check(v)][k];
}

bool solve(vector<int> v){
	rep(i,5){
		auto u = v;
		rep(k,10){
			u[i] = k;
			if( u != v && check(u) == 0 ) return true;
		}
	}
	rep(i,4){
		auto u = v;
		swap( u[i], u[i+1] );
		if( u != v && check(u) == 0 ) return true;
	}
	return false;
}

void dfs(vector<int> v={}){
	if( v.size() == 4 ){
		v.push_back( check(v) );
		ans += solve(v);
	}else{
		v.emplace_back();
		rep(i,10){
			v.back() = i;
			dfs(v);
		}
	}
}

int main(){

	rep(i,10) rep(j,10) cin >> mp[i][j];

	dfs();

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3148
def jump_cost(value1, value2):
  return abs(value1 - value2)

def stone_jump(n, stones):
  cost = [float("inf")] * n
  cost[0] = 0

  for index in range(len(stones) - 1):
    cost[index + 1] = min(cost[index + 1], cost[index] + jump_cost(stones[index], stones[index + 1]))
    if index + 2 < n:
      cost[index + 2] = min(cost[index + 2], cost[index] + jump_cost(stones[index], stones[index + 2]))

  print(cost[-1])
  return cost[-1]

n = int(input())
stones = [int(i) for i in input().split()]
stone_jump(n, stones)

Measured memory_bytes: 14052
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[100010],b[100010];
    ll ans=0;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        b[a[i]]=i+1;
    }
    set<ll> st;
    st.insert(0),st.insert(n+1);
    for(ll i=n;i>0;i--){
        ll x=b[i];
        ll cnt=0; 
        ll A,B,C,D;
        A=*(--st.lower_bound(x));
        B=*(st.upper_bound(x));
        if(A!=0){
            C=*--st.lower_bound(A);
            cnt+=(A-C)*(B-x);
            // cout<<"YEs"<<endl;
        }
        if(B!=n+1){
            D=*st.upper_bound(B);
            cnt+=(D-B)*(x-A);
            // cout<<"NO"<<endl;
        }
        // cout<<i<<endl;
        // cout<<A<<" "<<B<<" "<<C<<" "<<D<<endl;
        // cout<<cnt<<endl;
        ans+=i*cnt;
        st.insert(b[i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second


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

    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vi pre;
    pre.pb(0);

    for(int i = 0; i < n; ++i)
    {
        int pro = pre.back();
        if(s[i] == 'C')
        {
            if(i-1 >= 0 && s[i-1] == 'A')
                ++pro;
        }
        pre.pb(pro);
    }

    for(int i = 0; i < q; ++i)
    {
        int l, r;
        cin >> l >> r;
        int ans = pre[r] - pre[l-1];

        if(s[l-1] == 'C')
        {
            if(l-2 >= 0 && s[l-2] == 'A')
                --ans;
        }

        cout << ans << '\n';
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD
ll n,k;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>k;
    ll ans=0;


    if(n==k) ans = 0;
    else if(n < k){
        ans = min(n, (ll)abs(n-k));
    }else{
        n = n%k;
        ans = min(n, (ll)abs(n-k));
    }

    cout << ans << endl;

    return 0;

    // 2 100
    // 98 100
    // 2 100
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,c;
	while(scanf("%d %d %d",&a,&b,&c)==3)
	{
		int i;
		int min=10000;
		for(i=0;i<10000;i++)
		{	
			int sum=0;
			sum+=fabs(i-a)+fabs(i-b)+fabs(i-c);
			if(sum<min)
			min=sum;
		}
		printf("%d\n",min);
		
	}
}

Measured memory_bytes: 128
h,w = map(int, input().split())

b = [list(input()) for i in range(h)]
yoko = [[0]*w for i in range(h)]
for i in range(h):
    now = 0
    while now < w:
        if b[i][now] == "#":
            now += 1
            continue
        cnt = 0
        to = now
        while to<w and b[i][to] == ".":
            cnt += 1
            to += 1
        for j in range(now, to):
            yoko[i][j] = cnt
        now = to

for i in range(w):
    now = 0
    while now < h:
        if b[now][i] == "#":
            now += 1
            continue
        cnt = 0
        to = now
        while to<h and b[to][i] == ".":
            cnt += 1
            to += 1
        for j in range(now, to):
            yoko[j][i] += cnt
        now = to

ans = 0
for i in range(h):
    for j in range(w):
        if ans < yoko[i][j]:
            ans = yoko[i][j]
if ans:
    ans -= 1
print(ans)

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

int main() {
  ll L, R;
  cin >> L >> R;
  ll ans;
  if (L/2019 == R/2019) {
    ans = 1000000;
    for (ll i = L; i < R; i++) {
      for (ll j = i+1; j <= R; j++) {
        ll mod = (i%2019) * (j%2019);
        mod %= 2019;
        ans = min(ans, mod);
      }
    }
  }
  else {
    ans = 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from collections import Counter

N, M = map(int, readline().split())
D = list(map(int, readline().split()))
Edge = [[] for _ in range(N)]
Edgenum = Counter()
for i in range(M):
    u, v = map(int, readline().split())
    u -= 1
    v -= 1
    Edge[u].append((D[v], i, v))
    Edge[v].append((D[u], i, u))
    Edgenum[(u, v)] = i
    Edgenum[(v, u)] = i

inf = 10**9+7
table = [inf]*M

Col = [None]*N
def solve():
    Di = sorted([(D[i], i) for i in range(N)])
    for dvn, vn in Di:
        dvf, enum, vf = min(Edge[vn])
        if dvn < dvf:
            return False
        table[enum] = dvn
    
    used = set()
    for i in range(N):
        if i in used:
            continue
        Col[i] = 1
        stack = [i]
        while stack:
            vn = stack.pop()
            for _, enum, vf in Edge[vn]:
                if table[enum] == inf:
                    continue
                if vf in used:
                    continue
                Col[vf] = not Col[vn]
                used.add(vf)
                stack.append(vf)
    for i in range(M):
        if table[i] == inf:
            table[i] = 10**9
    return True

if not solve():
    print(-1)
else:
    print(''.join(['B' if Col[i] else 'W' for i in range(N)]))
    print('\n'.join(map(str, table)))


Measured memory_bytes: 177392
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  char a;
  cin >> a;
  if(a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o'){
    cout << "vowel" << endl;
  }
  else cout << "consonant" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long 

/////////////  

signed main()
{
    fastio;
    int n;
    cin>>n;
    int a[n];
    map<int,int> m;
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
        m[a[i]]++;
    }
    sort(a,a+n);
    int ans=0;
    for(int i=n-1;i>=0;--i)
    {
        if(m[a[i]]<=0)
            continue;
        int y=1;
        while(y<=a[i])
            y*=2;
        y-=a[i];
        if(y==a[i])
        {
            if(m[y]>1)
            {
                ++ans;
                m[y]-=2;
            }
            continue;
        }
        if(m[y]>0)
        {
            m[y]--;
            m[a[i]]--;
            ++ans;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 26880
/*
 * @Author: clorf 
 * @Date: 2020-08-25 14:54:43 
 * @Last Modified by: clorf
 * @Last Modified time: 2020-08-25 16:10:24
 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#include<queue>
#define INF 1e9
using namespace std;
const int maxn=210;
const double Pi=acos(-1.0);
template<class T>void read(T &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9') {f|=(ch=='-');ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return;
}
int n,m;
long long c[maxn],d[maxn],s;
long long head[maxn],cnt;
long long dis[maxn][3010];
bool vis[maxn][3010];
struct node
{
    int next;
    int to;
    long long num;
    long long x;
}e[maxn<<1];
void add(int from,int to,long long num,long long x)
{   
    e[++cnt].next=head[from];
    e[cnt].to=to;
    e[cnt].num=num;
    e[cnt].x=x;
    head[from]=cnt;
}
void dijkstra(int x)
{
    priority_queue<pair<long long,pair<long long,int> > > q;
    memset(dis,0x3f,sizeof(dis));
    memset(vis,false,sizeof(vis));
    dis[1][min(s,(long long)2500)]=0;
    q.push(make_pair(0,make_pair(min(s,(long long)2500),x)));
    while(!q.empty())
    {
        int u=q.top().second.second;
        long long num=q.top().second.first;
        q.pop();
        if(vis[u][num]||num>2500)
            continue;
        vis[u][num]=1;
        for(int i=head[u];i;i=e[i].next)
        {
            int v=e[i].to;
            long long w=e[i].num;
            long long sum=e[i].x;
            if(num>=sum)
            {
                if(dis[v][num-sum]>dis[u][num]+w)
                {
                    dis[v][num-sum]=dis[u][num]+w;
                    q.push(make_pair(-dis[v][num-sum],make_pair(num-sum,v)));
                }
            }
        }
        long long o=min((long long)2500,num+c[u]);
        if(dis[u][o]>dis[u][num]+d[u])
        {
            dis[u][o]=dis[u][num]+d[u];
            q.push(make_pair(-dis[u][o],make_pair(o,u)));
        }
    }
}
int main()
{
    scanf("%d%d%lld",&n,&m,&s);
    for(int i=1;i<=m;i++)
    {
        int u,v;
        long long x,t;
        scanf("%d%d%lld%lld",&u,&v,&x,&t);
        add(u,v,t,x);
        add(v,u,t,x);
    }
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&c[i],&d[i]);
    dijkstra(1);
    for(int i=2;i<=n;i++)
    {
        long long ans=0x3f3f3f3f3f3f3f3f;
        for(int j=0;j<=2500;j++)
            ans=min(ans,dis[i][j]);
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 11352
/*
Author : N_o_o_B
Created : April 26 2020 18:30:16 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;
ll powmod(ll a,ll n,ll m){
    ll res = 1;
    while(n){
        if(n&1) res = res*a%m;
        n >>= 1;
        a = a*a%m;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    string s;
    cin >> s;
    int n = sz(s);
    vi a(n),b(n);
    ll ans = 0;
    fori(i,n){
        a[i] = s[i] - '0';
        a[i] = a[i]*powmod(10,n-1-i,673);
        b[i] = s[i]-'0';
        b[i] = b[i]*powmod(10,n-1-i,3);
        if(i) a[i] += a[i-1];
        if(i) b[i] += b[i-1];
        a[i] %= 673;
        b[i] %= 3;
        // trace(i,a[i],b[i]);
        if(a[i]==0 and b[i]==0) ans++;
    }

    map<pii,int> cnt;

    ford(i,n){
        ans += cnt[{a[i],b[i]}];
        cnt[{a[i],b[i]}]++;
    }

    cout << ans << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 5160