akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MAXN = 607;
vector<int> g[MAXN];
int n, m;
double dp[MAXN], dp2[MAXN];
int heavy[MAXN];

void solve() {
	cin >> n >> m;

	for(int i = 0; i < m; ++i) {
		int v = fetch<int>() - 1;
		int u = fetch<int>() - 1;

		g[v].push_back(u);
	}

	dp[n - 1] = 0.;

	for(int v = n - 2; v >= 0; --v) {
		heavy[v] = g[v].front();

		for(auto& u: g[v]) {
			dp[v] += dp[u];

			if(dp[u] > dp[heavy[v]]) {
				heavy[v] = u;
			}
		}

		dp[v] /= len(g[v]);
		dp[v] += 1.;
	}

	DBG(dp[0]);
	double answ = dp[0];

	for(int v = 0; v < n; ++v) {
		if(len(g[v]) < 2) {
			continue;
		}

		for(int u = 0; u < n; ++u) {
			dp2[u] = 0.;
		}

		for(int u = n - 2; u >= 0; --u) {
			for(auto& w: g[u]) {
				if(w == heavy[u] && u == v) {
					continue;
				}

				dp2[u] += dp2[w];
			}

			dp2[u] /= len(g[u]) - (u == v);
			dp2[u] += 1.;
		}

		answ = min(answ, dp2[0]);
	}

	cout << fixed << setprecision(12) << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


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

int dp[101][4][2];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S;
	cin >> S;
	int n = S.size();
	int K;
	cin >> K;
	dp[0][0][0] = 1;
	rep(i, n)rep(j, 4)rep(k, 2) {
		int h = S[i] - '0';
		rep(d, 10) {
			//aは桁,bは0出ない個数,cは判定
			//dpだからか...
			int a = i + 1, b = j, c = k;
			if (d != 0) b++;
			if (b > K) continue;
			if (k == 0) {
				if (d > h) continue;
				if (d < h) c = 1;
			}
			dp[a][b][c] += dp[i][j][k];
		}
	}
	int ans = dp[n][K][0] + dp[n][K][1];
	dunk(ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MIN_P 1
#define MAX_P 5000
#define MIN_X 1
#define MAX_X 100000

int main (void) {
	int a, b, c, x, y, min_price, nx, ny;
	scanf("%d %d %d %d %d[^\n]", &a, &b, &c, &x, &y);
	if (a < MIN_P || a > MAX_P || b < MIN_P || b > MAX_P || c < MIN_P || c > MAX_P || x < MIN_X || x > MAX_X || y < MIN_X || y > MAX_X) return -1;
	if (x >= y) {
		min_price = (a + b <= 2 * c) ? (a + b) * y : 2 * c * y;
		nx = x - y;
		min_price = a * nx + min_price;
		min_price = (min_price <= 2 * x * c) ? min_price : 2 * x * c;
	} else {
		min_price = (a + b <= 2 * c) ? (a + b) * x : 2 * c * x;
		ny = y - x;
		min_price = b * ny + min_price;
		min_price = (min_price <= 2 * y * c) ? min_price : 2 * y * c;
	}
	printf("%d\n", min_price);
	return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    static String classify(double a, double b) {
        if (a < 35.5 && b < 71) {
            return "AAA";
        } else if (a < 37.5 && b < 77) {
            return "AA";
        } else if (a < 40 && b < 83) {
            return "A";
        } else if (a < 43 && b < 89) {
            return "B";
        } else if (a < 50 && b < 105) {
            return "C";
        } else if (a < 55 && b < 116) {
            return "D";
        } else if (a < 70 && b < 148) {
            return "E";
        } else {
            return "NA";
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;

        while ((line = br.readLine()) != null) {
            String[] input = line.split(" ");
            double a = Double.parseDouble(input[0]);
            double b = Double.parseDouble(input[1]);
            System.out.println(classify(a, b));
        }
    }
}


Measured memory_bytes: 24180
#include <bits/stdc++.h>
using namespace std;
deque<int> Q;
int i, j, n, t;
int main(){
	for(cin>>n,i=0; i<n; i++){
		cin>>t;
		if(i&1)
			Q.push_front(t);
		else
			Q.push_back(t);
	}
	if(i&1)
		for(i=0; i<(int)Q.size(); i++){
			printf("%d ", Q[(int)Q.size()-i-1]);
		}
	else
		for(auto c:Q)
			printf("%d ", c);
	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,see=0;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    for(int i=0;i<n;i++){
        int count=1;
        for(int j=0;j<i;j++){
            if(h[j]>h[i]){
                count=0;
                break;
            }
        }
        if(count==1){
            see++;
        }
    }
    cout<<see<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,H,M;
  cin>>A>>B>>H>>M;
  double f=30*H+M*0.5;//分針（度）
  double j=M*6;//時針（度）
  double C=(A*A+B*B-2*A*B*cos((f-j)*M_PI/180.0));
  double ans=sqrt(C);
  cout<<std::setprecision(12)<<ans<<endl;
  
}

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


int main(){
int N;
cin >> N;
int ans = 0;
for (int i = 1;i <= N;i++) {
ans += i;
}
cout << ans << endl;
return 0;

}

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

void solve(){
    int n;
    map<string, int> mp;
    int tmpmax = 0;
    cin >> n;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        mp[s]++;
        tmpmax = max(tmpmax, mp[s]);
    }

    for(auto it=mp.begin(); it!=mp.end(); it++){
        if(it->second == tmpmax){
            cout << it->first << '\n';
        }
    }

}

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

Measured memory_bytes: 23808
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    System.out.println(b - a == c - b ? "YES" : "NO");
  }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cnt5 = 0;
		int cnt7 = 0;

		for (int i = 0; i < 3; i++) {
			int tmp = sc.nextInt();
			if (tmp == 5)
				cnt5++;
			if (tmp == 7)
				cnt7++;
		}

		String ans = cnt5 == 2 && cnt7 == 1 ? "YES" : "NO";
		System.out.println(ans);

		sc.close();
	}
}


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

int mod = 1e9 + 7;

map<pair<long long, long long>, long long> mp;
long long modpow(long long x, long long y){
    if (mp[{x, y}]) return mp[{x, y}];
    if (y == 0) return 1;
    if (y % 2) {
        long long res = x * modpow(x, y - 1) % mod;
        mp[{x, y}] = res;
        return res;
    }
    long long res = modpow(x, y / 2) * modpow(x, y / 2) % mod;
    mp[{x, y}] = res;
    return res;
}

int main(){
    long long ans = 0;
    vector<long long> fac(1e7, 1);
    for (int i = 2; i < 1e7; i++) fac[i] = fac[i - 1] * i % mod;
    vector<long long> inv(1e7, 1);
    for (int i = 2; i < 1e7; i++) inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    long long a = (fac[r1 + c2 + 1] * modpow(fac[r1 + 1], mod - 2) % mod) * modpow(fac[c2], mod - 2) % mod;
    long long b = (fac[r1 + c1] * modpow(fac[r1 + 1], mod - 2) % mod) * modpow(fac[c1 -1], mod - 2) % mod;
    ans += (mod + a - b) % mod;
    ans %= mod;
    for (int r = r1 + 1; r <= r2; r++)
    {
        a *= r + c2 + 1;
        a %= mod;
        a *= inv[r + 1];
        a %= mod;
        b *= r + c1;
        b %= mod;
        b *= inv[r + 1];
        b %= mod;
        ans += (mod + a - b) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 156544
N = int(input())
S = input()

# 組み合わせ総数
ans = S.count('R') * S.count('G') * S.count('B')

for i in range(N):
    for j in range(i+1,N):
        k = 2 * j - i
        if k >= N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)



Measured memory_bytes: 9192
#include <stdio.h>

#define min(a, b) (a) > (b) ? b : a

typedef long long ll;

int main(void) {
  ll a, b, c;
  scanf("%lld %lld %lld", &a, &b, &c);
  if (a%2==0||b%2==0||c%2==0) printf("0");
  else printf("%lld", min(a*b, min(a*c, b*c)));
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    int a, cnt_4, cnt_o;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (a % 4 == 0) cnt_4++;
        if (a % 2 == 1) cnt_o++;
    }

    if (cnt_4 >= N / 2) cout << "Yes" << endl;
    else if (cnt_4 >= cnt_o) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

	int *d = new int[N];

	rep(i, N) {
		cin >> d[i];
	}
	int sum = 0;
	for (int i = 0; i < N - 1; i++)
	{
		for (int j = i + 1; j < N; j++)
		{
			sum += d[i] * d[j];

		}
	}

	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    ll t = 1, a = 1;
    rep(i, n) {
        ll x, y; cin >> x >> y;
        ll m = max((t + (x - 1)) / x, (a + (y - 1)) / y);
        t = m * x, a = m * y;
    }
    cout << t + a << endl;
    return 0;
}

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

int main() {
    int N,K,S;
    cin >> N >> K >> S;

    rep(i,K)
        cout << S << " ";
    
    rep(i,N-K)
        if(S != 1e9)
            cout << "1000000000 ";
        else
            cout << "1 ";
    cout << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define int long long 
using ldb = long double;
using pa = pair < int, int >;
using vec = vector < int >;

#define pb push_back
#define F  first
#define S  second
#define int int
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    fast();
    string s;
    cin >> s;
    int a=s.size();
    f(i,0,a){
        cout<<"x";
    }
    return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int func(int a) {
	int ret = 0;
	while (a >= 10) {
		ret += a % 10;
		a /= 10;
	}
	return a + ret;
}

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

	int ans = std::numeric_limits<int>::max();

	for (int i = 1; i < n; i++) {
		int a = n - i;
		ans = std::min(ans, func(a) + func(i));
	}
	std::cout << ans << std::endl;
	return 0;
}

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

signed main(){
    int N; string S; cin>>N>>S;
    map<char,set<int>> dic;
    for(char i='a';i<='z';i++){
        set<int> tmp;
        dic[i]=tmp;
    }
    for(int i=0;i<N;i++){
        dic[S[i]].insert(i);
    }
    int Q; cin>>Q;
    for(int i=0;i<Q;i++){
        int a; cin>>a;
        if(a==1){
            int j; char c; cin>>j>>c; j--;
            if(S[j] == c)   continue;
            dic[S[j]].erase(j);
            dic[c].insert(j);
            S[j] = c;
        }
        else if(a==2){
            int l,r; cin>>l>>r; l--; r--;
            int ans=0;
            for(char c='a';c<='z';c++){
                auto it = dic[c].lower_bound(l);
                if(it == dic[c].end())  continue;
                int tmp = *it;
                if(l<=tmp && tmp<=r){
                    ans++;
                }
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)
ll mod=1e9+7;

//cf dont use unordered map. use simply map<... , ... > m;

//They are Iterator minus v.begin() krna //lower_bound(v.begin(),v.end(),x)-v.begin()  //upper_bound(v.begin(),v.end(),x)-v.begin()
// lower bound tells greater than or equal to // upper bound tells strictly greater than
//int a[1001][1001] //aise global me hi// ll lcm(ll a, ll b){ return a / __gcd(a, b) * b; }
//memset can initialize to 0 or -1 ONLY //memset(str, 't', sizeof(str)); // string //memset(a, 0, sizeof(a));  //1D array    // memset(a,0,sizeof(a[0][0])*n*n); //2D array
// set.insert(),find() //for(auto it=set.begin();....) cout<<*it;   // sort(v.begin(),v.end(),compare)

ll power_mod(ll x,ll n,ll m) // x^n %mod // O(Log Power n)
{ll ans=1;
while(n!=0)
{
    if(n&1==1)
    {
        ans=(ans%m * x%m)%m;
    }
    x=(x%m * x%m)%m;
    n=n>>1;
}
    return ans;
}
void solve()
{
    ll n,k;cin>>n>>k;
n++;

    ll pre[n],suf[n];
    pre[0]=0;suf[n-1]=n-1;
    f(i,1,n) pre[i]=(pre[i-1]%mod+i%mod)%mod;
    for(int i=n-2;i>=0;i--) suf[i]=(i%mod+suf[i+1]%mod)%mod;
ll ans=0;

// f(i,0,n) cout<<pre[i]<<" ";
// cout<<endl;
// f(i,0,n) cout<<suf[i]<<" ";


    f(i,k,1+n)
    {
       ans=(ans%mod+suf[n-i]%mod-pre[i-1]%mod+1+mod)%mod;
        //cout<<ans<<endl;
    }
    cout<<ans;
}




int main()
{

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

    ll t=1;
   // cin>>t;
    while(t--)
    {
     solve();
    }
}

Measured memory_bytes: 6692
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	io;
	ll n;
	cin>>n;
	vector<pair<pair<string,ll>,ll> >v;
	for(ll i=0;i<n;i++)
	{
		string s;
		ll x;
		cin>>s>>x;
		v.pb(mp(mp(s,-x),i));
	}
	sort(v.begin(),v.end());
	for(ll i=0;i<n;i++)
	{
		cout<<v[i].se+1<<"\n";
	}
}

Measured memory_bytes: 256
import sys
N, Y = map(int, input().split())

for i in range(N+1):
    for j in range(N+1):
        k = N - i - j
        if k >= 0 and k <= N and 10000*i + 5000*j + 1000*k == Y:
            print(i, j, k)
            sys.exit()
print(-1, -1, -1)

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    int a,b;
    cin>>a>>b;
    int cnt=0,c=1;
    while(c<b){
        c=c+a-1;
        cnt++;
    }
    cout<<cnt;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T &a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T &a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T a) { return 1ll * a * a; }
template <class T> void compress(T &a){
  sort(all(a)); a.resize(unique(all(a)) - a.begin());  
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

int main()
{
  fastio;
  long n; cin >> n;
  int res = 0;
  for (long i = 2; i * i <= n; i++){
    if (n % i == 0){
      int cnt = 0;
      while (n % i == 0){
        n /= i; cnt++;
      }
      int cur = 0;
      for (int j = 1; ; j++){
        cur += j;
        if (cur > cnt) break;
        res++;
      }
    }  
  }
  if (n != 1) res++;
  cout << res;
  return 0;
}

Measured memory_bytes: 3612
local str = io.read()
local len = #str
local ret = ""
for i = 1, len do
  local sstr = str:sub(i, i)
  if sstr == "B" then
    if(0 < #ret) then ret = ret:sub(1, #ret - 1) end
  else
    ret = ret .. sstr
  end
end
print(ret)

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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long y,const mint& m){ return m+y; }
mint operator*(long long y,const mint& m){ return m*y; }

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

mint fact_inverse(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		memo[n]=inverse(fact(n));
		for(int i=n;i>k;i--) memo[i-1]=memo[i]*i;
	}
	return memo[n];
}

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

	vector<vector<mint>> dp(2,vector<mint>(n+1));
	dp[0][0]=1;
	for(int x=a;x<=b;x++){
		dp[1]=dp[0];
		for(int y=c;y<=d;y++){
			mint coef=pow(fact_inverse(x),y)*fact_inverse(y);
			for(int w=n;w>=y*x;w--){
				dp[1][w]+=coef*dp[0][w-y*x];
			}
		}
		dp[0]=dp[1];
	}
	cout<<fact(n)*dp[0][n]<<'\n';

	return 0;
}


Measured memory_bytes: 256
import math
import collections
import sys

#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

a,b=MI()
if a%b==0:
    print(0)
else:
    print(1)

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

int s[1000], d[1000], t[1000][1000], y[1000];
P p[100000];
int main() {
	int n, m, h, k;
	while (scanf("%d%d%d%d", &n, &m, &h, &k), n) {
		rep(i, n) {
			scanf("%d", &s[i]);
			d[i] = t[0][i] = i;
		}
		rep(i, m) {
			int a, b; scanf("%d%d", &a, &b);
			p[i] = P(b, a);
		}
		sort(p, p + m);
		int u = 0;
		for (int i = 1; i < h; i++) {
			while (p[u].first == i) {
				swap(d[p[u].second - 1], d[p[u].second]); u++;
			}
			rep(j, n)t[i][j] = d[j];
		}
		rep(i, n)y[d[i]] = i;
		int Min = 0;
		rep(i, n) {
			if (d[i] < k)Min += s[i];
		}
		rep(i, m) {
			swap(d[y[t[p[i].first - 1][p[i].second - 1]]], d[y[t[p[i].first - 1][p[i].second]]]);
			int sum = 0;
			rep(i, n) {
				if (d[i] < k)sum += s[i];
			}
			Min = min(Min, sum);
			swap(d[y[t[p[i].first - 1][p[i].second - 1]]], d[y[t[p[i].first - 1][p[i].second]]]);
		}
		printf("%d\n", Min);
	}
}

Measured memory_bytes: 7908
#test
class Combi():
    def __init__(self, N, mod):
        self.power = [1 for _ in range(N+1)]
        self.rev = [1 for _ in range(N+1)]
        self.mod = mod
        for i in range(2, N+1):
            self.power[i] = (self.power[i-1]*i) % self.mod
        self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
        for j in range(N, 0, -1):
            self.rev[j-1] = (self.rev[j]*j) % self.mod

    def com(self, K, R):
        if K < R:
            return 0
        else:
            return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod

    def pom(self, K, R):
        if K < R:
            return 0
        else:
            return (self.power[K])*(self.rev[K-R]) % self.mod


def main():
    N, M = map(int, input().split())
    mod = 10**9+7
    c = Combi(5*10**5, mod)
    ans = c.pom(M, N)**2 % mod
    for k in range(1, N+1):
        s = (-1)**((k-1) % 2)
        t = c.com(N, k)
        u = c.pom(M-k, N-k)**2
        v = c.pom(M, k)
        ans -= s*t*u*v
        ans = ans % mod
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 48736
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lo;
typedef pair< lo,lo > PII;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
 
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s,ss,sss;
vector<int> v;

int main(void){
	fio();
	cin>>n>>s;
	if(n%2==1){cout<<"No\n";return 0;}
	for(int i=0;i<(int)n/2;i++)ss+=s[i];
	for(int i=n/2;i<(int)n;i++)sss+=s[i];
	if(ss!=sss){cout<<"No\n";return 0;}
	cout<<"Yes\n";return 0;
	return 0;
}



Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

count = [0] * (10**5 + 2)

for i in a:
    if i == 0:
        count[i] += 1
        count[i+1]+= 1
    else:
        count[i-1] += 1
        count[i] += 1
        count[i+1] += 1

print(max(count))


Measured memory_bytes: 14008
# Problem D - Road to Millionaire

# input
N = int(input())
a_nums = list(map(int, input().split()))

# initialization
max_list = [0] * N
max_list[0] = 1000

# max calc
for i in range(1, N):
    for j in range(0, i):
        a_remain = max_list[j] % a_nums[j]
        a_count = max_list[j] // a_nums[j]
        max_list[i] = max(max_list[j], a_nums[i]*a_count+a_remain)

# output
print(max_list[N-1])


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(){
    sonic();
    int n;
    cin >> n;
    int A[n];
    rep(i, n){
        int a;
        cin >> a;
        A[i] = a;
    }
    int now=0, cnt=0;
    while (now != 1){
        now = A[now] - 1;
        cnt += 1;
        if (cnt > n + 1){cnt = -1; break;}
    }
    cout << cnt << "\n";
}



Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] ans = new int[n];
		Arrays.fill(ans, -1);
		for (int i = 0; i < m; i++) {
			int s = sc.nextInt() - 1;
			int c = sc.nextInt();
			if (ans[s] == -1) {
				ans[s] = c;
			} else if (ans[s] != c) {
				System.out.println(-1);
				sc.close();
				return;
			}
		}
		sc.close();

		if (m == 0) {
			if (n == 1) {
				System.out.println(0);
			} else if (n == 2) {
				System.out.println(10);
			} else {
				System.out.println(100);
			}
			return;
		}
		boolean flg = false;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < ans.length; i++) {
			if (ans[i] <= 0) {
				if (flg) {
					sb.append(0);
				} else {
					if (ans[i] == 0) {
						if (i == n - 1) {
							sb.append(0);
							break;
						} else {
							System.out.println(-1);
							return;
						}
					}
					sb.append(1);
					flg = true;
				}
			} else {
				sb.append(ans[i]);
				flg = true;
			}
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 23636
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

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

int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i)
  {
    string sl, sr;
    cin >> sl >> sr;
    int l = 0, r = 0;
    for (int j = 0; j < sl.size(); ++j)
    {
      int t = 1;
      if (isdigit(sl[j]))
      {
        t = sl[j] - '0';
        j++;
      }
      if (sl[j] == 'm')
        l += t * 1000;
      else if (sl[j] == 'c')
        l += t * 100;
      else if (sl[j] == 'x')
        l += t * 10;
      else if (sl[j] == 'i')
        l += t;
    }
    for (int j = 0; j < sr.size(); ++j)
    {
      int t = 1;
      if (isdigit(sr[j]))
      {
        t = sr[j] - '0';
        j++;
      }
      if (sr[j] == 'm')
        r += t * 1000;
      else if (sr[j] == 'c')
        r += t * 100;
      else if (sr[j] == 'x')
        r += t * 10;
      else if (sr[j] == 'i')
        r += t;
    }
    int sum = l + r;
    string ans = "";
    if (sum / 1000)
    {
      if (sum / 1000 > 1)
        ans += char(sum / 1000 + '0');
      ans += 'm';
    }
    sum %= 1000;
    if (sum / 100)
    {
      if (sum / 100 > 1)
        ans += char(sum / 100 + '0');
      ans += 'c';
    }
    sum %= 100;
    if (sum / 10)
    {
      if (sum / 10 > 1)
        ans += char(sum / 10 + '0');
      ans += 'x';
    }
    sum %= 10;
    if (sum)
    {
      if (sum > 1)
        ans += char(sum + '0');
      ans += 'i';
    }
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3148
import java.io.*;
import java.io.IOException;
import java.util.*;

@SuppressWarnings({"rawtypes", "unchecked"})
class Main {
    final static int INF = 1 << 28;
    final static long LNF = 1L << 60;
    final static double EPS = 1e-9;
    final static double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

    static final long MOD = 1_000_000_007;

    public static void main(String[] args) throws Exception {
        final MyScanner sc = new MyScanner();
        long S;
        S = sc.nextLong();
        long W;
        W = sc.nextLong();
        solve(S, W);
    }

    static void solve(long S, long W){
        if(W >= S) System.out.println("unsafe"); 
        else System.out.println("safe");
    }


    static class MyScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }
 
        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String next() {
            return nn();
        }

        String nextLine() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }
 
        char nextChar() {
            return nn().charAt(0);
        }
 
        int nextInt() {
            return Integer.parseInt(nn());
        }
 
        long nextLong() {
            return Long.parseLong(nn());
        }
 
        double nextDouble() {
            return Double.parseDouble(nn());
        }
 
        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
 
        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
    }

}


Measured memory_bytes: 32700
#include <iostream>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    ll l, r;
    cin >> l >> r;
    int ans = 2018;
    for(ll i = l; i < r; i++) {
        for(ll j = i+1; j <= r; j++) {
            ans = min(ans, (int)(i*j % 2019));
            if(!ans) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>

using namespace std;

bool f[100001];
int b[100001];

int main() {

  int n, m, popp, ans = 0, bad = 0;
  string verdict;
  cin >> n >> m;
  for(int i = 1;i <= m;i++){
    cin >> popp >> verdict;
    if(verdict == "WA" && f[popp] == false){
      b[popp]++;
    }
    if(verdict == "AC" && f[popp] == false){
      f[popp] = true;
      ans++;
      bad += b[popp];

    }
  }
  cout << ans << ' ' << bad;
  return 0;
}


Measured memory_bytes: 4056
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, T, sum(0);
  cin >> n >> T;
  vector<int> ti(n);
  for (int i = 0; i < n; i ++) {
    cin >> ti[i];
  }
  sum += T;
  for (int i = n - 1; i > 0; i--) {
    int diff = ti[i] - ti[i - 1];
    sum += diff < T ? diff : T;
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 1024
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, r;

    while (true) {
        cin >> n >> r;
        if (n + r == 0) return 0;

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

        for (int i = 0; i < r; i++) {
            int p, c;
            cin >> p >> c;

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

            for (int j = 0; j < n; ++j) {
                a[j] = b[j];
            }
        }
        cout << a[0] << endl;
    }
}

/*
 *
 */


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

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;

int main() {
  int n;
  scanf("%d ", &n);
  FOR(i,n,1000) {
    if (i%10 == (i%100)/10 && (i%100)/10 == i/100) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
A = np.array([0] + [int(x) for x in input().split()])

A_abs = np.abs(A)

x = A_abs.argmax()
if x == 0:
  x = 1
value = A[x]

answer = []

for j in range(1,N+1):
  if j == x:
    continue
  answer.append((x,j))
# 符号がそろった

if value > 0:
  for j in range(1,N):
    answer.append((j,j+1))
else:
  for j in range(N,1,-1):
    answer.append((j,j-1))
    
print(len(answer))
for a,b in answer:
  print(a,b)

Measured memory_bytes: 14432
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

a,b,c,d = map(int,input().split())

m = int(c*d/gcd(c,d))
xc = b//c - (a-1)//c
xd = b//d - (a-1)//d
xm = b//m - (a-1)//m
print(b-a+1-xc-xd+xm)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()

using namespace std;

ll n,m,k,y,cnt;
string s;
vector <int> v;
pair <int, int> p[100005];


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> m;
        if (m % 2 != 0){
            cnt++;
        }
    }
    if (cnt % 2 == 0){
        cout << "YES";
    }
    else {
        cout << "NO";
    }
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    var ts = parseInt(chunk);
    var s = ts % 60;
    var tm = (ts - s) / 60;
    var m = tm % 60;
    var th = (tm - m) / 60;
    var h = th;
    console.log('%d:%d:%d', h, m, s);
});

Measured memory_bytes: 7648
import java.util.Scanner;

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

        int n = sc.nextInt();

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int ans = 1000000;

        for (int i = 0; i < n; i++) {
            int a = 0;
            int b = 0;

            for (int j = 0; j <= i; j++) {
                a += array[j];
            }

            for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            }

            int min = Math.abs(a - b);

            if (min < ans) {
                ans = min;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
#define ll long long

int main(){
	int N;
	cin>>N;
	cout<<(ll)N*(N-1)/2;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void){

    ll n;
    cin>>n;

    vector<ll> a(n);

    ll sum = 0;

    for(int i= 0;i<n;i++){
        ll x;
        cin>>x;
        a[i] = x;
        if(x%2 == 1) sum++;
    }

    if(sum == 0) cout<<"second"<<endl;
    else cout<<"first"<<endl;

    return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from collections import deque,defaultdict,Counter
def main():
    N,M = map(int,input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    
    ans = N*(N - 1)//2 - M
    color = [-1] * N
    q = deque([0])
    color[0] = 0
    bi = True
    while q:
        v = q.popleft()
        for e in G[v]:
            if color[e] >= 0:
                if color[e] == color[v]:
                    bi = False
                continue
            color[e] = color[v]^1
            q.append(e)
    if bi:
        white = 0
        black = 0
        for i in range(N):
            if color[i] == 0:
                white += 1
            else:
                black += 1
        ans -= white*(white - 1)//2 + black*(black - 1)//2
    print(ans)
if __name__ == '__main__':
    main()

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

int main()
{
  	string s;
  	cin>>s;
  	int b, e;
  	for(int i = 0; i < s.size(); i++)
    {
    	if(s[i] == 'A')
        {
          b = i;
          break;
        }
    }
  	for(int i = s.size()-1; i >= 0; i--)
    {
    	if(s[i] == 'Z')
        {
          e = i;
          break;
        }
    }
  	cout<<e-b+1<<"\n";
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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

//約数の列挙
vector<int> divisor(int n){
    vector<int> res;
    for(int i=1; i*i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin>>N>>M;
    vector<int> res = divisor(M);
    int ans=1;
    for(auto x:res){
        //cout<<x<<endl;
        if(x<=M/N) chmax(ans,x);
        //else break;
    }
    cout<<ans<<endl;
}


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

typedef long long ll;

#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    ll N; cin >>N;
    vector<ll> A(N);
    vector<ll> s(N);
    rep(i, N) {
        cin >> A[i];
        if (i == 0) {
            s[i] = A[i];
        } else {
            s[i] = s[i-1] + A[i];
        }
    }
    ll sum = s.back();
    ll ans = LLONG_MAX;

    rep(i, N-1) {
        chmin(ans, abs(sum - s[i] - s[i]));
    }

    cout << ans << endl;
}


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

int n, s, t, a;

int main() {
	cin >> n;
	s = 0;
	t = 99999999;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a > s)s = a;
		if (a < t)t = a;
	}
	cout << s - t << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline
n, m = map(int, input().split())
g = [[] for _ in range(n)]
revg = [[] for _ in range(n)]
ins = [0] * n
for i in range(m):
    x, y = map(int, input().split())
    g[x - 1].append(y - 1)
    revg[y - 1].append(x - 1)
    ins[y - 1] += 1
tl = []
q = deque(v1 for v1 in range(n) if ins[v1] == 0)
while q:
    v1 = q.popleft()
    tl.append(v1)
    for v2 in g[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)
dp = [0] * n
for p in tl:
    for node in revg[p]:
        dp[p] = max(dp[p], dp[node] + 1)
print(max(dp))

Measured memory_bytes: 71216
X = int(input())

ans = 0
if 400 <= X <= 599:
    ans = 8
elif 600 <= X <= 799:
    ans = 7
elif 800 <= X <= 999:
    ans = 6
elif 1000 <= X <= 1199:
    ans = 5
elif 1200 <= X <= 1399:
    ans = 4
elif 1400 <= X <= 1599:
    ans = 3
elif 1600 <= X <= 1799:
    ans = 2
elif 1800 <= X <= 1999:
    ans = 1

print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

int main(){
    int n;
    string s;
    int k;
    cin >>  n >> s >> k;
    k--;
    for(int i = 0; i < n; i++){
        if(s[i] != s[k]) s[i] = '*';
    }
    cout << s << endl;
}

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

class Cube
{
  public:
	  int f[6];
	  Cube (){}
	  void roll_z()
	  {
		  roll(1, 2, 4, 3);
	  }
	  void roll_y()
	  {
		  roll(0, 2, 5, 3);
	  }
	  void roll_x()
	  {
		  roll(0, 1, 5, 4);
	  }
	  void roll(int i, int j, int k, int l)
	  {
		  int t = f[i];
		  f[i] = f[j];
		  f[j] = f[k];
		  f[k] = f[l];
		  f[l] = t;
	  }
};

int getRight ( Cube c, int a, int b)
{
	for ( int i = 0; i < 6; i++)
	{
		for ( int j = 0; j < 4; j++)
		{
			if ( c.f[0] == a && c.f[1] == b)
			{
				return c.f[2];
			}
				c.roll_z();
		}
		if ( i % 2 == 0 )
		{
			c.roll_y();
		}
		else
		{
			c.roll_x();
		}
	}
		return -1;
	}

int main()
{
    Cube c;
	int q;
	int a;
	int b;
	
	for ( int i = 0; i < 6; i++ )
	{
		cin >> c.f[i];
	}
	cin >> q;

	for ( int i = 0; i < q; i++ )
	{
		cin >> a >> b;

	cout << getRight(c, a, b) << endl;
	}
	return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;


set<int> v[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; i++){
        v[s[i] - 'a'].insert(i);
    }
    int q;
    cin >> q;
    while(q--){
        int op;
        cin >> op;
        if(op == 1){
            int idx;
            char from, to;
            cin >> idx >> to;
            idx--;
            from = s[idx];
            v[from -'a'].erase(idx);
            v[to - 'a'].insert(idx);
            s[idx] = to;
        }
        else{
            int from, to;
            cin >> from >> to;
            from--;
            to--;
            int ans = 0;
            for(int i = 0; i < 26; i++){
                auto it = v[i].lower_bound(from);
                if(it == v[i].end()) continue;
                if((*it) <= to) ans++;
            }
            cout << ans << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 36608